Ignore:
Timestamp:
2020-03-21T22:09:31+01:00 (4 years ago)
Author:
simon04
Message:

see #18954, see #18864 - fix SonarQube issues

Location:
trunk/src/org/openstreetmap/josm/tools
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/GenericParser.java

    r16184 r16188  
    1010 * Utility class to parse various types from other values.
    1111 *
     12 * @param <U> the type of the objects to parse
    1213 * @since 16184
    1314 */
     
    1617    protected final Map<Class<?>, Function<U, ?>> parsers;
    1718
     19    /**
     20     * Creates an empty {@code GenericParser}
     21     */
    1822    public GenericParser() {
    1923        this(new LinkedHashMap<>());
     
    2933    }
    3034
     35    /**
     36     * Creates a new {@code GenericParser} with the same parsers as the specified map
     37     *
     38     * @param parsers the parsers
     39     */
    3140    protected GenericParser(Map<Class<?>, Function<U, ?>> parsers) {
    3241        this.parsers = parsers;
     
    8089     * or {@code Optional.empty()} (if parsing fails, or the type is not {@linkplain #supports supported})
    8190     */
    82     public <T> Optional<?> tryParse(Class<?> type, U value) {
     91    public <T> Optional<T> tryParse(Class<T> type, U value) {
    8392        try {
    8493            return Optional.ofNullable(parse(type, value));
  • trunk/src/org/openstreetmap/josm/tools/StringParser.java

    r16184 r16188  
    3636            .parsers));
    3737
     38    /**
     39     * Creates an empty {@code StringParser}
     40     */
    3841    public StringParser() {
    3942        super();
     
    4952    }
    5053
    51     protected StringParser(Map<Class<?>, Function<String, ?>> parsers) {
     54    private StringParser(Map<Class<?>, Function<String, ?>> parsers) {
    5255        super(parsers);
    5356    }
  • trunk/src/org/openstreetmap/josm/tools/XmlObjectParser.java

    r16181 r16188  
    126126        }
    127127
    128         private void setValue(Entry entry, String fieldName, String value) throws SAXException {
    129             if (value != null) {
    130                 value = value.intern();
    131             }
     128        private void setValue(Entry entry, String fieldName, String value0) throws SAXException {
     129            final String value = value0 != null ? value0.intern() : null;
    132130            CheckParameterUtil.ensureParameterNotNull(entry, "entry");
    133131            if ("class".equals(fieldName) || "default".equals(fieldName) || "throw".equals(fieldName) ||
     
    142140                    f = entry.getField("locale_" + fieldName.substring(lang.length()));
    143141                }
    144                 Optional<?> parsed;
    145                 if (f != null && Modifier.isPublic(f.getModifiers()) && (parsed = primitiveParsers.tryParse(f.getType(), value)).isPresent()) {
     142                Optional<?> parsed = Optional.ofNullable(f)
     143                        .filter(field -> Modifier.isPublic(field.getModifiers()))
     144                        .flatMap(field -> primitiveParsers.tryParse(field.getType(), value));
     145                if (parsed.isPresent()) {
    146146                    f.set(c, parsed.get());
    147147                } else {
Note: See TracChangeset for help on using the changeset viewer.