Ignore:
Timestamp:
2017-10-12T16:02:15+02:00 (7 years ago)
Author:
bastiK
Message:

see #15410 - change preferences scheme for named colors - makes runtime color name registry obsolete

File:
1 edited

Legend:

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

    r12854 r12987  
    4545import java.util.List;
    4646import java.util.Locale;
     47import java.util.Optional;
    4748import java.util.concurrent.ExecutionException;
    4849import java.util.concurrent.Executor;
     
    17311732        }
    17321733    }
     1734
     1735    /**
     1736     * Helper method to replace the "<code>instanceof</code>-check and cast" pattern.
     1737     *
     1738     * @param <T> the type for the instanceof check and cast
     1739     * @param o the object to check and cast
     1740     * @param klass the class T
     1741     * @return {@link Optional} containing the result of the cast, if it is possible, an empty
     1742     * Optional otherwise
     1743     */
     1744    @SuppressWarnings("unchecked")
     1745    public static <T> Optional<T> instanceOfAndCast(Object o, Class<T> klass) {
     1746        if (klass.isInstance(o))
     1747            return Optional.of((T) o);
     1748        return Optional.empty();
     1749    }
     1750
    17331751}
Note: See TracChangeset for help on using the changeset viewer.