Changeset 9129 in josm for trunk/src/org


Ignore:
Timestamp:
2015-12-15T11:11:43+01:00 (4 years ago)
Author:
bastiK
Message:

javadoc

File:
1 edited

Legend:

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

    r9120 r9129  
    12841284    }
    12851285
    1286     @Retention(RetentionPolicy.RUNTIME) public @interface pref { }
    1287     @Retention(RetentionPolicy.RUNTIME) public @interface writeExplicitly { }
     1286    /**
     1287     * Annotation used for converting objects to String Maps and vice versa.
     1288     * Indicates that a certain field should be considered in the conversion
     1289     * process. Otherwise it is ignored.
     1290     *
     1291     * @see #serializeStruct(java.lang.Object, java.lang.Class)
     1292     * @see #deserializeStruct(java.util.Map, java.lang.Class)
     1293     */
     1294    @Retention(RetentionPolicy.RUNTIME) // keep annotation at runtime
     1295    public @interface pref { }
     1296
     1297    /**
     1298     * Annotation used for converting objects to String Maps.
     1299     * Indicates that a certain field should be written to the map, even if
     1300     * the value is the same as the default value.
     1301     *
     1302     * @see #serializeStruct(java.lang.Object, java.lang.Class)
     1303     */
     1304    @Retention(RetentionPolicy.RUNTIME) // keep annotation at runtime
     1305    public @interface writeExplicitly { }
    12881306
    12891307    /**
     
    13221340
    13231341    /**
    1324      * Save a list of hashes represented by a struct-like class.
     1342     * Convenience method that saves a MapListSetting which is provided as a
     1343     * Collection of objects.
     1344     *
     1345     * Each object is converted to a <code>Map&lt;String, String&gt;</code> using
     1346     * the fields with {@link pref} annotation. The field name is the key and
     1347     * the value will be converted to a string.
     1348     *
    13251349     * Considers only fields that have the @pref annotation.
    13261350     * In addition it does not write fields with null values. (Thus they are cleared)
     
    13291353     * Fields equal to the default value are not written unless the field has
    13301354     * the @writeExplicitly annotation.
     1355     * @param <T> the class,
    13311356     * @param key main preference key
    13321357     * @param val the list that is supposed to be saved
     
    13841409    }
    13851410
     1411    /**
     1412     * Convert an object to a String Map, by using field names and values as map
     1413     * key and value.
     1414     *
     1415     * The field value is converted to a String.
     1416     *
     1417     * Only fields with annotation {@link pref} are taken into account.
     1418     *
     1419     * Fields will not be written to the map if the value is null or unchanged
     1420     * (compared to an object created with the no-arg-constructor).
     1421     * The {@link writeExplicitly} annotation overrides this behavior, i.e. the
     1422     * default value will also be written.
     1423     *
     1424     * @param <T> the class of the object <code>struct</code>
     1425     * @param struct the object to be converted
     1426     * @param klass the class T
     1427     * @return the resulting map (same data content as <code>struct</code>)
     1428     */
    13861429    public static <T> Map<String, String> serializeStruct(T struct, Class<T> klass) {
    13871430        T structPrototype;
     
    14181461    }
    14191462
     1463    /**
     1464     * Converts a String-Map to an object of a certain class, by comparing
     1465     * map keys to field names of the class and assigning map values to the
     1466     * corresponding fields.
     1467     *
     1468     * The map value (a String) is converted to the field type. Supported
     1469     * types are: boolean, Boolean, int, Integer, double, Double, String and
     1470     * Map&lt;String, String&gt;.
     1471     *
     1472     * Only fields with annotation {@link pref} are taken into account.
     1473     * @param <T> the class
     1474     * @param hash the string map with initial values
     1475     * @param klass the class T
     1476     * @return an object of class T, initialized as described above
     1477     */
    14201478    public static <T> T deserializeStruct(Map<String, String> hash, Class<T> klass) {
    14211479        T struct = null;
Note: See TracChangeset for help on using the changeset viewer.