Ignore:
Timestamp:
2016-05-11T02:44:10+02:00 (4 years ago)
Author:
Don-vip
Message:

sonar - squid:AssignmentInSubExpressionCheck - Assignments should not be made from within sub-expressions

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/OsmChangeBuilder.java

    r8840 r10179  
    1313/**
    1414 * Creates an OsmChange document from JOSM edits.
    15  * See http://wiki.openstreetmap.org/index.php/OsmChange for a documentation of the
    16  * OsmChange format.
    17  *
     15 * See http://wiki.openstreetmap.org/index.php/OsmChange for a documentation of the OsmChange format.
     16 * @since 1071
    1817 */
    1918public class OsmChangeBuilder {
     19    /** Default OSM API version */
    2020    public static final String DEFAULT_API_VERSION = "0.6";
    2121
    2222    private String currentMode;
    23     private PrintWriter writer;
    24     private StringWriter swriter;
    25     private OsmWriter osmwriter;
     23    private final PrintWriter writer;
     24    private final StringWriter swriter;
     25    private final OsmWriter osmwriter;
    2626    private String apiVersion = DEFAULT_API_VERSION;
    2727    private boolean prologWritten;
    2828
     29    /**
     30     * Constructs a new {@code OsmChangeBuilder}.
     31     * @param changeset changeset
     32     */
    2933    public OsmChangeBuilder(Changeset changeset) {
    3034        this(changeset, null /* default api version */);
    3135    }
    3236
     37    /**
     38     * Constructs a new {@code OsmChangeBuilder}.
     39     * @param changeset changeset
     40     * @param apiVersion OSM API version
     41     */
    3342    public OsmChangeBuilder(Changeset changeset, String apiVersion) {
    3443        this.apiVersion = apiVersion == null ? DEFAULT_API_VERSION : apiVersion;
    35         writer = new PrintWriter(swriter = new StringWriter());
     44        swriter = new StringWriter();
     45        writer = new PrintWriter(swriter);
    3646        osmwriter = OsmWriterFactory.createOsmWriter(writer, false, apiVersion);
    3747        osmwriter.setChangeset(changeset);
     
    90100     */
    91101    public void append(Collection<? extends IPrimitive> primitives) {
    92         if (primitives == null) return;
    93         if (!prologWritten)
    94             throw new IllegalStateException(tr("Prolog of OsmChange document not written yet. Please write first."));
     102        if (primitives == null)
     103            return;
     104        checkProlog();
    95105        for (IPrimitive p : primitives) {
    96106            write(p);
    97107        }
     108    }
     109
     110    private void checkProlog() {
     111        if (!prologWritten)
     112            throw new IllegalStateException(tr("Prolog of OsmChange document not written yet. Please write first."));
    98113    }
    99114
     
    107122     */
    108123    public void append(IPrimitive p) {
    109         if (p == null) return;
    110         if (!prologWritten)
    111             throw new IllegalStateException(tr("Prolog of OsmChange document not written yet. Please write first."));
     124        if (p == null)
     125            return;
     126        checkProlog();
    112127        write(p);
    113128    }
     
    119134     */
    120135    public void finish() {
    121         if (!prologWritten)
    122             throw new IllegalStateException(tr("Prolog of OsmChange document not written yet. Please write first."));
     136        checkProlog();
    123137        if (currentMode != null) {
    124138            writer.print("</");
     
    129143    }
    130144
     145    /**
     146     * Returns XML document.
     147     * @return XML document
     148     */
    131149    public String getDocument() {
    132150        return swriter.toString();
Note: See TracChangeset for help on using the changeset viewer.