Changeset 12018 in josm for trunk/src/org


Ignore:
Timestamp:
2017-04-29T17:12:31+02:00 (7 years ago)
Author:
Don-vip
Message:

add OsmPrimitiveType.newVersionedInstance() + javadoc and unit tests

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitiveType.java

    r11349 r12018  
    3939    }
    4040
     41    /**
     42     * Returns the API type name / JOSM display name.
     43     * @return the API type name / JOSM display name
     44     */
    4145    public String getAPIName() {
    4246        return apiTypeName;
    4347    }
    4448
     49    /**
     50     * Returns the OSM class for data values, or null.
     51     * @return the OSM class for data values, or null
     52     */
    4553    public Class<? extends OsmPrimitive> getOsmClass() {
    4654        return osmClass;
    4755    }
    4856
     57    /**
     58     * Returns the data class.
     59     * @return the data class
     60     */
    4961    public Class<? extends PrimitiveData> getDataClass() {
    5062        return dataClass;
    5163    }
    5264
     65    /**
     66     * Returns enum value from API type name / JOSM display name, case sensitive.
     67     * @param typeName API type name / JOSM display name, case sensitive
     68     * @return matching enum value
     69     * @throws IllegalArgumentException if the type name does not match any valid type
     70     * @see #from(String)
     71     */
    5372    public static OsmPrimitiveType fromApiTypeName(String typeName) {
    5473        for (OsmPrimitiveType type : OsmPrimitiveType.values()) {
     
    7291    }
    7392
     93    /**
     94     * Returns enum value from API type name / JOSM display name, case insensitive.
     95     * @param value API type name / JOSM display name, case insensitive
     96     * @return matching enum value or null
     97     * @see #fromApiTypeName
     98     */
    7499    public static OsmPrimitiveType from(String value) {
    75         if (value == null) return null;
    76100        for (OsmPrimitiveType type: values()) {
    77101            if (type.getAPIName().equalsIgnoreCase(value))
     
    81105    }
    82106
     107    /**
     108     * Returns the values matching real OSM API data types (node, way, relation).
     109     * @return the values matching real OSM API data types (node, way, relation)
     110     */
    83111    public static Collection<OsmPrimitiveType> dataValues() {
    84112        return DATA_VALUES;
    85113    }
    86114
     115    /**
     116     * Constructs a new primitive instance (node, way or relation) without version.
     117     * @param uniqueId the unique id
     118     * @param allowNegative {@code true} to allow negative id
     119     * @return a new primitive instance (node, way or relation)
     120     * @throws IllegalArgumentException if uniqueId &lt; 0 and allowNegative is false
     121     */
    87122    public OsmPrimitive newInstance(long uniqueId, boolean allowNegative) {
    88123        switch (this) {
     
    98133    }
    99134
     135    /**
     136     * Constructs a new primitive instance (node, way or relation) with given version.
     137     * @param id The id. Must be &gt;= 0
     138     * @param version The version
     139     * @return a new primitive instance (node, way or relation) with given version
     140     * @throws IllegalArgumentException if id &lt; 0
     141     * @since 12018
     142     */
     143    public OsmPrimitive newVersionedInstance(long id, int version) {
     144        switch (this) {
     145        case NODE:
     146            return new Node(id, version);
     147        case WAY:
     148            return new Way(id, version);
     149        case RELATION:
     150            return new Relation(id, version);
     151        default:
     152            throw new AssertionError();
     153        }
     154    }
     155
    100156    @Override
    101157    public String toString() {
Note: See TracChangeset for help on using the changeset viewer.