Changeset 15719 in josm


Ignore:
Timestamp:
2020-01-18T14:14:04+01:00 (4 years ago)
Author:
simon04
Message:

Java 8: deprecate Utils.exists, Utils.find

Location:
trunk/src/org/openstreetmap/josm
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/preferences/sources/MapPaintPrefHelper.java

    r15211 r15719  
    7474
    7575        // XML style is not bundled anymore
    76         list.remove(Utils.find(list, se -> "resource://styles/standard/elemstyles.xml".equals(se.url)));
     76        list.stream()
     77                .filter(se -> "resource://styles/standard/elemstyles.xml".equals(se.url))
     78                .findFirst()
     79                .ifPresent(list::remove);
    7780
    7881        return changed;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java

    r15680 r15719  
    3434import org.openstreetmap.josm.gui.tagging.presets.items.Roles;
    3535import org.openstreetmap.josm.gui.tagging.presets.items.Roles.Role;
     36import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    3637import org.openstreetmap.josm.tools.Utils;
    3738
     
    173174        for (TaggingPreset p : relationpresets) {
    174175            final boolean matches = TaggingPresetItem.matches(Utils.filteredCollection(p.data, KeyedItem.class), n.getKeys());
    175             final Roles r = Utils.find(p.data, Roles.class);
    176             if (matches && r != null) {
    177                 for (Role role: r.roles) {
     176            final SubclassFilteredCollection<TaggingPresetItem, Roles> roles = Utils.filteredCollection(p.data, Roles.class);
     177            if (matches && !roles.isEmpty()) {
     178                for (Role role: roles.iterator().next().roles) {
    178179                    allroles.put(role, p.name);
    179180                }
  • trunk/src/org/openstreetmap/josm/gui/SplashScreen.java

    r14153 r15719  
    1515import java.util.List;
    1616import java.util.Objects;
     17import java.util.Optional;
    1718import java.util.concurrent.CopyOnWriteArrayList;
    1819
     
    292293         */
    293294        public void finishTask(String title) {
    294             final Task task = Utils.find(tasks, new MeasurableTask(title)::equals);
    295             if (task instanceof MeasurableTask) {
     295            Optional<Task> taskOptional = tasks.stream()
     296                    .filter(new MeasurableTask(title)::equals)
     297                    .filter(MeasurableTask.class::isInstance)
     298                    .findAny();
     299            taskOptional.ifPresent(task -> {
    296300                ((MeasurableTask) task).finish();
    297301                if (Logging.isDebugEnabled()) {
     
    299303                }
    300304                listener.stateChanged(null);
    301             }
     305            });
    302306        }
    303307
  • trunk/src/org/openstreetmap/josm/gui/mappaint/ElemStyles.java

    r15097 r15719  
    4141import org.openstreetmap.josm.spi.preferences.PreferenceChangedListener;
    4242import org.openstreetmap.josm.tools.Pair;
    43 import org.openstreetmap.josm.tools.Utils;
    4443
    4544/**
     
    194193            }
    195194            if (!hasProperLineStyle) {
    196                 AreaElement area = Utils.find(p.a, AreaElement.class);
    197                 LineElement line = area == null ? LineElement.UNTAGGED_WAY : LineElement.createSimpleLineStyle(area.color, true);
     195                LineElement line = LineElement.UNTAGGED_WAY;
     196                for (StyleElement element : p.a) {
     197                    if (element instanceof AreaElement) {
     198                        line = LineElement.createSimpleLineStyle(((AreaElement) element).color, true);
     199                        break;
     200                    }
     201                }
    198202                p.a = new StyleElementList(p.a, line);
    199203            }
     
    288292                            break;
    289293                        } else if (wayColor == null && isDefaultLines()) {
    290                             AreaElement mpArea = Utils.find(mpElemStyles.a, AreaElement.class);
    291                             if (mpArea != null) {
    292                                 wayColor = mpArea.color;
     294                            for (StyleElement element : mpElemStyles.a) {
     295                                if (element instanceof AreaElement) {
     296                                    wayColor = ((AreaElement) element).color;
     297                                    break;
     298                                }
    293299                            }
    294300                        }
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r15718 r15719  
    108108     * @param clazz The class to search for.
    109109     * @return <code>true</code> if that item exists in the collection.
    110      */
     110     * @deprecated use {@link Stream#anyMatch}
     111     */
     112    @Deprecated
    111113    public static <T> boolean exists(Iterable<T> collection, Class<? extends T> clazz) {
    112114        CheckParameterUtil.ensureParameterNotNull(clazz, "clazz");
     
    120122     * @param predicate The predicate to match
    121123     * @return the item or <code>null</code> if there was not match.
    122      */
     124     * @deprecated use {@link Stream#filter} and {@link Stream#findFirst}
     125     */
     126    @Deprecated
    123127    public static <T> T find(Iterable<? extends T> collection, Predicate<? super T> predicate) {
    124128        for (T item : collection) {
     
    136140     * @param clazz The class to search for.
    137141     * @return the item or <code>null</code> if there was not match.
    138      */
     142     * @deprecated use {@link Stream#filter} and {@link Stream#findFirst}
     143     */
     144    @Deprecated
    139145    @SuppressWarnings("unchecked")
    140146    public static <T> T find(Iterable<? extends Object> collection, Class<? extends T> clazz) {
Note: See TracChangeset for help on using the changeset viewer.