Changeset 10715 in josm for trunk/src


Ignore:
Timestamp:
2016-08-03T15:01:43+02:00 (8 years ago)
Author:
simon04
Message:

see #11390, see #12890 - Deprecate Predicates class

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

Legend:

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

    r10657 r10715  
    1212import java.util.Set;
    1313import java.util.concurrent.CopyOnWriteArrayList;
    14 import java.util.function.Predicate;
    1514
    1615import org.openstreetmap.josm.data.osm.Node;
     
    4342    private final CopyOnWriteArrayList<IConflictListener> listeners;
    4443
    45     private static class FilterPredicate implements Predicate<Conflict<? extends OsmPrimitive>> {
    46 
    47         private final Class<? extends OsmPrimitive> c;
    48 
    49         FilterPredicate(Class<? extends OsmPrimitive> c) {
    50             this.c = c;
    51         }
    52 
    53         @Override
    54         public boolean test(Conflict<? extends OsmPrimitive> conflict) {
    55             return conflict != null && c.isInstance(conflict.getMy());
    56         }
    57     }
    58 
    59     private static final FilterPredicate NODE_FILTER_PREDICATE = new FilterPredicate(Node.class);
    60     private static final FilterPredicate WAY_FILTER_PREDICATE = new FilterPredicate(Way.class);
    61     private static final FilterPredicate RELATION_FILTER_PREDICATE = new FilterPredicate(Relation.class);
    62 
    6344    /**
    6445     * Constructs a new {@code ConflictCollection}.
     
    364345     */
    365346    public final Collection<Conflict<? extends OsmPrimitive>> getNodeConflicts() {
    366         return SubclassFilteredCollection.filter(conflicts, NODE_FILTER_PREDICATE);
     347        return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Node);
    367348    }
    368349
     
    373354     */
    374355    public final Collection<Conflict<? extends OsmPrimitive>> getWayConflicts() {
    375         return SubclassFilteredCollection.filter(conflicts, WAY_FILTER_PREDICATE);
     356        return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Way);
    376357    }
    377358
     
    382363     */
    383364    public final Collection<Conflict<? extends OsmPrimitive>> getRelationConflicts() {
    384         return SubclassFilteredCollection.filter(conflicts, RELATION_FILTER_PREDICATE);
     365        return SubclassFilteredCollection.filter(conflicts, c -> c != null && c.getMy() instanceof Relation);
    385366    }
    386367
  • trunk/src/org/openstreetmap/josm/data/osm/DataSet.java

    r10691 r10715  
    4848import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;
    4949import org.openstreetmap.josm.tools.FilteredCollection;
    50 import org.openstreetmap.josm.tools.Predicates;
    5150import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    5251import org.openstreetmap.josm.tools.Utils;
     
    458457     */
    459458    public Collection<OsmPrimitive> allPrimitives() {
    460         return getPrimitives(Predicates.alwaysTrue());
     459        return getPrimitives(o -> true);
    461460    }
    462461
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r10660 r10715  
    2828import org.openstreetmap.josm.gui.mappaint.StyleCache;
    2929import org.openstreetmap.josm.tools.CheckParameterUtil;
    30 import org.openstreetmap.josm.tools.Predicates;
    3130import org.openstreetmap.josm.tools.Utils;
    3231import org.openstreetmap.josm.tools.template_engine.TemplateEngineDataProvider;
     
    234233     * A predicate filtering nodes.
    235234     */
    236     public static final Predicate<OsmPrimitive> nodePredicate = Predicates.<OsmPrimitive>isOfClass(Node.class);
     235    public static final Predicate<OsmPrimitive> nodePredicate = Node.class::isInstance;
    237236
    238237    /**
    239238     * A predicate filtering ways.
    240239     */
    241     public static final Predicate<OsmPrimitive> wayPredicate = Predicates.<OsmPrimitive>isOfClass(Way.class);
     240    public static final Predicate<OsmPrimitive> wayPredicate = Way.class::isInstance;
    242241
    243242    /**
    244243     * A predicate filtering relations.
    245244     */
    246     public static final Predicate<OsmPrimitive> relationPredicate = Predicates.<OsmPrimitive>isOfClass(Relation.class);
     245    public static final Predicate<OsmPrimitive> relationPredicate = Relation.class::isInstance;
    247246
    248247    /**
  • trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java

    r10680 r10715  
    1919import org.openstreetmap.josm.data.validation.TestError;
    2020import org.openstreetmap.josm.tools.LanguageInfo;
    21 import org.openstreetmap.josm.tools.Predicates;
    2221import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    2322
     
    166165        final List<TestError> errors = new ArrayList<>();
    167166        for (final String key : SubclassFilteredCollection.filter(p.keySet(),
    168                 Predicates.stringMatchesPattern(Pattern.compile(".*:conditional(:.*)?$")))) {
     167                Pattern.compile(":conditional(:.*)?$").asPredicate())) {
    169168            if (!isKeyValid(key)) {
    170169                errors.add(new TestError(this, Severity.WARNING, tr("Wrong syntax in {0} key", key), 3201, p));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java

    r10657 r10715  
    2828import org.openstreetmap.josm.tools.MultiMap;
    2929import org.openstreetmap.josm.tools.Pair;
    30 import org.openstreetmap.josm.tools.Predicates;
    3130
    3231/**
     
    156155                boolean ignore = false;
    157156                for (String ignoredKey : IGNORED_KEYS.get()) {
    158                     if (error.getPrimitives().stream().anyMatch(Predicates.hasKey(ignoredKey))) {
     157                    if (error.getPrimitives().stream().anyMatch(p -> p.hasKey(ignoredKey))) {
    159158                        ignore = true;
    160159                        break;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/WayConnectedToArea.java

    r10657 r10715  
    1515import org.openstreetmap.josm.data.validation.TestError;
    1616import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    17 import org.openstreetmap.josm.tools.Predicates;
    1817
    1918/**
     
    6766        if (wayNode.isOutsideDownloadArea()) {
    6867            return;
    69         } else if (wayNode.getReferrers().stream().anyMatch(Predicates.hasTag("route", "ferry"))) {
     68        } else if (wayNode.getReferrers().stream().anyMatch(p1 -> p1.hasTag("route", "ferry"))) {
    7069            return;
    7170        } else if (isArea(p)) {
  • trunk/src/org/openstreetmap/josm/gui/SplashScreen.java

    r10611 r10715  
    3838import org.openstreetmap.josm.tools.GBC;
    3939import org.openstreetmap.josm.tools.ImageProvider;
    40 import org.openstreetmap.josm.tools.Predicates;
    4140import org.openstreetmap.josm.tools.Utils;
    4241import org.openstreetmap.josm.tools.WindowGeometry;
     
    276275         */
    277276        public void finishTask(String title) {
    278             final Task task = Utils.find(tasks, Predicates.<Task>equalTo(new MeasurableTask(title)));
     277            final Task task = Utils.find(tasks, new MeasurableTask(title)::equals);
    279278            if (task instanceof MeasurableTask) {
    280279                ((MeasurableTask) task).finish();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java

    r10691 r10715  
    105105import org.openstreetmap.josm.tools.LanguageInfo;
    106106import org.openstreetmap.josm.tools.OpenBrowser;
    107 import org.openstreetmap.josm.tools.Predicates;
    108107import org.openstreetmap.josm.tools.Shortcut;
    109108import org.openstreetmap.josm.tools.Utils;
     
    896895                positionString = Utils.getPositionListString(position);
    897896                // if not all objects from the selection are member of this relation
    898                 if (selection.stream().anyMatch(Predicates.inCollection(members).negate())) {
     897                if (selection.stream().anyMatch(p -> !members.contains(p))) {
    899898                    positionString += ",\u2717";
    900899                }
  • trunk/src/org/openstreetmap/josm/gui/dialogs/validator/ValidatorTreePanel.java

    r10657 r10715  
    3737import org.openstreetmap.josm.tools.Destroyable;
    3838import org.openstreetmap.josm.tools.MultiMap;
    39 import org.openstreetmap.josm.tools.Predicates;
    4039
    4140/**
     
    347346    public void selectRelatedErrors(final Collection<OsmPrimitive> primitives) {
    348347        final Collection<TreePath> paths = new ArrayList<>();
    349         walkAndSelectRelatedErrors(new TreePath(getRoot()), Predicates.inCollection(new HashSet<>(primitives)), paths);
     348        walkAndSelectRelatedErrors(new TreePath(getRoot()), new HashSet<>(primitives)::contains, paths);
    350349        getSelectionModel().clearSelection();
    351350        for (TreePath path : paths) {
  • trunk/src/org/openstreetmap/josm/gui/layer/LayerPositionStrategy.java

    r10592 r10715  
    33
    44import java.util.List;
     5import java.util.Objects;
    56import java.util.function.Predicate;
    6 
    7 import org.openstreetmap.josm.tools.Predicates;
    87
    98/**
     
    4645     */
    4746    static LayerPositionStrategy inFrontOf(Layer other) {
    48         return inFrontOfFirst(Predicates.equalTo(other));
     47        return inFrontOfFirst(obj -> Objects.equals(obj, other));
    4948    }
    5049
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Condition.java

    r10674 r10715  
    2828import org.openstreetmap.josm.gui.mappaint.Environment;
    2929import org.openstreetmap.josm.tools.CheckParameterUtil;
    30 import org.openstreetmap.josm.tools.Predicates;
    3130import org.openstreetmap.josm.tools.Utils;
    3231
     
    513512            this.matchType = matchType == null ? KeyMatchType.EQ : matchType;
    514513            this.containsPattern = KeyMatchType.REGEX.equals(matchType)
    515                     ? Predicates.stringContainsPattern(Pattern.compile(label))
     514                    ? Pattern.compile(label).asPredicate()
    516515                    : null;
    517516        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/ExpressionFactory.java

    r10691 r10715  
    1616import java.util.Collections;
    1717import java.util.List;
     18import java.util.Objects;
    1819import java.util.TreeSet;
    1920import java.util.function.Function;
     
    3738import org.openstreetmap.josm.tools.ColorHelper;
    3839import org.openstreetmap.josm.tools.Geometry;
    39 import org.openstreetmap.josm.tools.Predicates;
    4040import org.openstreetmap.josm.tools.RightAndLefthandTraffic;
    4141import org.openstreetmap.josm.tools.SubclassFilteredCollection;
     
    11351135        public Float aggregateList(List<?> lst) {
    11361136            final List<Float> floats = Utils.transform(lst, (Function<Object, Float>) x -> Cascade.convertTo(x, float.class));
    1137             final Collection<Float> nonNullList = SubclassFilteredCollection.filter(floats, Predicates.<Float>isNull().negate());
     1137            final Collection<Float> nonNullList = SubclassFilteredCollection.filter(floats, Objects::nonNull);
    11381138            return nonNullList.isEmpty() ? (Float) Float.NaN : computeMax ? Collections.max(nonNullList) : Collections.min(nonNullList);
    11391139        }
  • trunk/src/org/openstreetmap/josm/gui/mappaint/mapcss/Selector.java

    r10674 r10715  
    2424import org.openstreetmap.josm.tools.Geometry;
    2525import org.openstreetmap.josm.tools.Pair;
    26 import org.openstreetmap.josm.tools.Predicates;
    2726import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    2827import org.openstreetmap.josm.tools.Utils;
     
    322321                    }
    323322                    final Collection<Relation> multipolygons = Utils.filteredCollection(SubclassFilteredCollection.filter(
    324                             e.osm.getReferrers(), Predicates.hasTag("type", "multipolygon")), Relation.class);
     323                            e.osm.getReferrers(), p -> p.hasTag("type", "multipolygon")), Relation.class);
    325324                    final Relation multipolygon = multipolygons.iterator().next();
    326325                    if (multipolygon == null) throw new NoSuchElementException();
  • trunk/src/org/openstreetmap/josm/gui/tagging/presets/TaggingPresetReader.java

    r10590 r10715  
    4343import org.openstreetmap.josm.io.CachedFile;
    4444import org.openstreetmap.josm.io.UTFInputStreamReader;
    45 import org.openstreetmap.josm.tools.Predicates;
    4645import org.openstreetmap.josm.tools.XmlObjectParser;
    4746import org.xml.sax.SAXException;
     
    226225                    if (all.contains(tp)) {
    227226                        lastmenuOriginal = tp;
    228                         tp = (TaggingPresetMenu) all.stream().filter(Predicates.equalTo(tp)).findFirst().get();
     227                        tp = (TaggingPresetMenu) all.stream().filter(tp::equals).findFirst().get();
    229228                        lastmenuOriginal.group = null;
    230229                    } else {
  • trunk/src/org/openstreetmap/josm/tools/Predicates.java

    r10691 r10715  
    1111/**
    1212 * Utility class for creating {@link Predicate}s.
     13 * @deprecated Use corresponding lambda expressions instead
    1314 */
     15@Deprecated
    1416public final class Predicates {
    1517
     
    8789     */
    8890    public static Predicate<String> stringContainsPattern(final Pattern pattern) {
    89         return string -> pattern.matcher(string).find();
     91        return pattern.asPredicate();
    9092    }
    9193
     
    134136     */
    135137    public static <T> Predicate<T> isNull() {
    136         return object -> object == null;
     138        return Objects::isNull;
    137139    }
    138140
  • trunk/src/org/openstreetmap/josm/tools/Utils.java

    r10692 r10715  
    142142     */
    143143    public static <T> boolean exists(Iterable<T> collection, Class<? extends T> clazz) {
    144         return exists(collection, Predicates.<T>isInstanceOf(clazz));
     144        CheckParameterUtil.ensureParameterNotNull(clazz, "clazz");
     145        return exists(collection, clazz::isInstance);
    145146    }
    146147
     
    170171    @SuppressWarnings("unchecked")
    171172    public static <T> T find(Iterable<? extends Object> collection, Class<? extends T> clazz) {
    172         return (T) find(collection, Predicates.<Object>isInstanceOf(clazz));
     173        CheckParameterUtil.ensureParameterNotNull(clazz, "clazz");
     174        return (T) find(collection, clazz::isInstance);
    173175    }
    174176
     
    199201     */
    200202    public static <S, T extends S> SubclassFilteredCollection<S, T> filteredCollection(Collection<S> collection, final Class<T> clazz) {
    201         return new SubclassFilteredCollection<>(collection, Predicates.<S>isInstanceOf(clazz));
     203        CheckParameterUtil.ensureParameterNotNull(clazz, "clazz");
     204        return new SubclassFilteredCollection<>(collection, clazz::isInstance);
    202205    }
    203206
Note: See TracChangeset for help on using the changeset viewer.