Ignore:
Timestamp:
2016-07-27T02:08:34+02:00 (8 years ago)
Author:
Don-vip
Message:

see #11390, see #12890 - use Java 8 Predicates

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

Legend:

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

    r10626 r10657  
    3838import java.util.TreeMap;
    3939import java.util.concurrent.CopyOnWriteArrayList;
     40import java.util.function.Predicate;
    4041import java.util.regex.Matcher;
    4142import java.util.regex.Pattern;
     
    6970import org.openstreetmap.josm.tools.I18n;
    7071import org.openstreetmap.josm.tools.MultiMap;
    71 import org.openstreetmap.josm.tools.Predicate;
    7272import org.openstreetmap.josm.tools.Utils;
    7373import org.xml.sax.SAXException;
  • trunk/src/org/openstreetmap/josm/data/conflict/ConflictCollection.java

    r10378 r10657  
    1212import java.util.Set;
    1313import java.util.concurrent.CopyOnWriteArrayList;
     14import java.util.function.Predicate;
    1415
    1516import org.openstreetmap.josm.data.osm.Node;
     
    1819import org.openstreetmap.josm.data.osm.Way;
    1920import org.openstreetmap.josm.tools.CheckParameterUtil;
    20 import org.openstreetmap.josm.tools.Predicate;
    21 import org.openstreetmap.josm.tools.Utils;
     21import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    2222
    2323/**
     
    5252
    5353        @Override
    54         public boolean evaluate(Conflict<? extends OsmPrimitive> conflict) {
     54        public boolean test(Conflict<? extends OsmPrimitive> conflict) {
    5555            return conflict != null && c.isInstance(conflict.getMy());
    5656        }
     
    364364     */
    365365    public final Collection<Conflict<? extends OsmPrimitive>> getNodeConflicts() {
    366         return Utils.filter(conflicts, NODE_FILTER_PREDICATE);
     366        return SubclassFilteredCollection.filter(conflicts, NODE_FILTER_PREDICATE);
    367367    }
    368368
     
    373373     */
    374374    public final Collection<Conflict<? extends OsmPrimitive>> getWayConflicts() {
    375         return Utils.filter(conflicts, WAY_FILTER_PREDICATE);
     375        return SubclassFilteredCollection.filter(conflicts, WAY_FILTER_PREDICATE);
    376376    }
    377377
     
    382382     */
    383383    public final Collection<Conflict<? extends OsmPrimitive>> getRelationConflicts() {
    384         return Utils.filter(conflicts, RELATION_FILTER_PREDICATE);
     384        return SubclassFilteredCollection.filter(conflicts, RELATION_FILTER_PREDICATE);
    385385    }
    386386
     
    396396        ConflictCollection conflicts1 = (ConflictCollection) obj;
    397397        return Objects.equals(conflicts, conflicts1.conflicts) &&
    398                 Objects.equals(listeners, conflicts1.listeners);
     398               Objects.equals(listeners, conflicts1.listeners);
    399399    }
    400400}
  • trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java

    r10608 r10657  
    1616import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    1717import org.openstreetmap.josm.gui.util.GuiHelper;
    18 import org.openstreetmap.josm.tools.Utils;
     18import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1919
    2020/**
     
    203203            return getOpenChangesets();
    204204        } else {
    205             return new ArrayList<>(Utils.filter(getOpenChangesets(),
     205            return new ArrayList<>(SubclassFilteredCollection.filter(getOpenChangesets(),
    206206                    object -> JosmUserIdentityManager.getInstance().isCurrentUser(object.getUser())));
    207207        }
  • trunk/src/org/openstreetmap/josm/data/osm/FilterWorker.java

    r10308 r10657  
    66
    77import org.openstreetmap.josm.data.osm.FilterMatcher.FilterType;
    8 import org.openstreetmap.josm.tools.Utils;
     8import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    99
    1010/**
     
    3232        boolean changed;
    3333        // first relations, then ways and nodes last; this is required to resolve dependencies
    34         changed = doExecuteFilters(Utils.filter(all, OsmPrimitive.relationPredicate), filterMatcher);
    35         changed |= doExecuteFilters(Utils.filter(all, OsmPrimitive.wayPredicate), filterMatcher);
    36         changed |= doExecuteFilters(Utils.filter(all, OsmPrimitive.nodePredicate), filterMatcher);
     34        changed = doExecuteFilters(SubclassFilteredCollection.filter(all, OsmPrimitive.relationPredicate), filterMatcher);
     35        changed |= doExecuteFilters(SubclassFilteredCollection.filter(all, OsmPrimitive.wayPredicate), filterMatcher);
     36        changed |= doExecuteFilters(SubclassFilteredCollection.filter(all, OsmPrimitive.nodePredicate), filterMatcher);
    3737        return changed;
    3838    }
  • trunk/src/org/openstreetmap/josm/data/osm/NoteData.java

    r10619 r10657  
    1616import org.openstreetmap.josm.data.notes.NoteComment;
    1717import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    18 import org.openstreetmap.josm.tools.Utils;
    1918
    2019/**
     
    154153            } else {
    155154                final Note existingNote = noteList.get(newNote);
    156                 final boolean isDirty = Utils.exists(existingNote.getComments(), object -> object.isNew());
     155                final boolean isDirty = existingNote.getComments().stream().anyMatch(object -> object.isNew());
    157156                if (!isDirty) {
    158157                    noteList.put(newNote);
  • trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r10656 r10657  
    1919import java.util.Objects;
    2020import java.util.Set;
     21import java.util.function.Predicate;
    2122
    2223import org.openstreetmap.josm.Main;
     
    2728import org.openstreetmap.josm.gui.mappaint.StyleCache;
    2829import org.openstreetmap.josm.tools.CheckParameterUtil;
    29 import org.openstreetmap.josm.tools.Predicate;
    3030import org.openstreetmap.josm.tools.Predicates;
    3131import org.openstreetmap.josm.tools.Utils;
  • trunk/src/org/openstreetmap/josm/data/osm/Relation.java

    r10656 r10657  
    1616import org.openstreetmap.josm.data.osm.visitor.Visitor;
    1717import org.openstreetmap.josm.tools.CopyList;
     18import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    1819import org.openstreetmap.josm.tools.Utils;
    1920import org.openstreetmap.josm.tools.Utils.Function;
     
    350351     */
    351352    public Collection<RelationMember> getMembersFor(final Collection<? extends OsmPrimitive> primitives) {
    352         return Utils.filter(getMembers(), member -> primitives.contains(member.getMember()));
     353        return SubclassFilteredCollection.filter(getMembers(), member -> primitives.contains(member.getMember()));
    353354    }
    354355
  • trunk/src/org/openstreetmap/josm/data/validation/Test.java

    r10413 r10657  
    99import java.util.List;
    1010import java.util.Objects;
     11import java.util.function.Predicate;
    1112
    1213import javax.swing.JCheckBox;
     
    2526import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2627import org.openstreetmap.josm.tools.GBC;
    27 import org.openstreetmap.josm.tools.Predicate;
    2828import org.openstreetmap.josm.tools.Utils;
    2929
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Addresses.java

    r10608 r10657  
    2929import org.openstreetmap.josm.tools.Geometry;
    3030import org.openstreetmap.josm.tools.Pair;
    31 import org.openstreetmap.josm.tools.Utils;
     31import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    3232
    3333/**
     
    9191            // warning level only if several relations have different names, see #10945
    9292            final String name = list.get(0).get("name");
    93             if (name == null || Utils.filter(list, r -> name.equals(r.get("name"))).size() < list.size()) {
     93            if (name == null || SubclassFilteredCollection.filter(list, r -> name.equals(r.get("name"))).size() < list.size()) {
    9494                level = Severity.WARNING;
    9595            } else {
     
    243243        // No street segment found near this house, report error on if the relation does not contain incomplete street ways (fix #8314)
    244244        if (hasIncompleteWays) return;
    245         List<OsmPrimitive> errorList = new ArrayList<OsmPrimitive>(street);
     245        List<OsmPrimitive> errorList = new ArrayList<>(street);
    246246        errorList.add(0, house);
    247247        errors.add(new AddressError(this, HOUSE_NUMBER_TOO_FAR, errorList,
  • trunk/src/org/openstreetmap/josm/data/validation/tests/ConditionalKeys.java

    r10632 r10657  
    2020import org.openstreetmap.josm.tools.LanguageInfo;
    2121import org.openstreetmap.josm.tools.Predicates;
    22 import org.openstreetmap.josm.tools.Utils;
     22import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    2323
    2424/**
     
    156156    public List<TestError> validatePrimitive(OsmPrimitive p) {
    157157        final List<TestError> errors = new ArrayList<>();
    158         for (final String key : Utils.filter(p.keySet(), Predicates.stringMatchesPattern(Pattern.compile(".*:conditional(:.*)?$")))) {
     158        for (final String key : SubclassFilteredCollection.filter(p.keySet(),
     159                Predicates.stringMatchesPattern(Pattern.compile(".*:conditional(:.*)?$")))) {
    159160            if (!isKeyValid(key)) {
    160161                errors.add(new TestError(this, Severity.WARNING, tr("Wrong syntax in {0} key", key), 3201, p));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/Highways.java

    r10608 r10657  
    158158        final String highway = way.get("highway");
    159159        if (highway == null || !highway.endsWith("_link")
    160                 || !IN_DOWNLOADED_AREA.evaluate(way.getNode(0)) || !IN_DOWNLOADED_AREA.evaluate(way.getNode(way.getNodesCount()-1))) {
     160                || !IN_DOWNLOADED_AREA.test(way.getNode(0)) || !IN_DOWNLOADED_AREA.test(way.getNode(way.getNodesCount()-1))) {
    161161            return true;
    162162        }
     
    174174        }
    175175
    176         return Utils.exists(Utils.filteredCollection(referrers, Way.class),
     176        return Utils.filteredCollection(referrers, Way.class).stream().anyMatch(
    177177                otherWay -> !way.equals(otherWay) && otherWay.hasTag("highway", highway, highway.replaceAll("_link$", "")));
    178178    }
  • trunk/src/org/openstreetmap/josm/data/validation/tests/MapCSSTagChecker.java

    r10608 r10657  
    2626import java.util.Objects;
    2727import java.util.Set;
     28import java.util.function.Predicate;
    2829import java.util.regex.Matcher;
    2930import java.util.regex.Pattern;
     
    6667import org.openstreetmap.josm.tools.CheckParameterUtil;
    6768import org.openstreetmap.josm.tools.MultiMap;
    68 import org.openstreetmap.josm.tools.Predicate;
    6969import org.openstreetmap.josm.tools.Utils;
    7070
     
    390390
    391391        @Override
    392         public boolean evaluate(OsmPrimitive primitive) {
     392        public boolean test(OsmPrimitive primitive) {
    393393            // Tests whether the primitive contains a deprecated tag which is represented by this MapCSSTagChecker.
    394394            return whichSelectorMatchesPrimitive(primitive) != null;
     
    788788                    Main.debug("- Errors: "+pErrors);
    789789                }
    790                 final boolean isError = Utils.exists(pErrors, e -> e.getTester().equals(check.rule));
     790                final boolean isError = pErrors.stream().anyMatch(e -> e.getTester().equals(check.rule));
    791791                if (isError != i.getValue()) {
    792792                    final String error = MessageFormat.format("Expecting test ''{0}'' (i.e., {1}) to {2} {3} (i.e., {4})",
  • trunk/src/org/openstreetmap/josm/data/validation/tests/OverlappingWays.java

    r10608 r10657  
    2929import org.openstreetmap.josm.tools.Pair;
    3030import org.openstreetmap.josm.tools.Predicates;
    31 import org.openstreetmap.josm.tools.Utils;
    3231
    3332/**
     
    157156                boolean ignore = false;
    158157                for (String ignoredKey : IGNORED_KEYS.get()) {
    159                     if (Utils.exists(error.getPrimitives(), Predicates.hasKey(ignoredKey))) {
     158                    if (error.getPrimitives().stream().anyMatch(Predicates.hasKey(ignoredKey))) {
    160159                        ignore = true;
    161160                        break;
  • trunk/src/org/openstreetmap/josm/data/validation/tests/PowerLines.java

    r10363 r10657  
    7070                for (Node n : w.getNodes()) {
    7171                    if (!isPowerTower(n)) {
    72                         if (!isPowerAllowed(n) && IN_DOWNLOADED_AREA.evaluate(n)) {
     72                        if (!isPowerAllowed(n) && IN_DOWNLOADED_AREA.test(n)) {
    7373                            if (!w.isFirstLastNode(n) || !isPowerStation(n)) {
    7474                                potentialErrors.add(new PowerLineError(this, n, w));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/UntaggedNode.java

    r10046 r10657  
    4343        if (n.isUsable() && !n.isTagged() && n.getReferrers().isEmpty()) {
    4444
    45             if (!n.hasKeys() && IN_DOWNLOADED_AREA.evaluate(n)) {
     45            if (!n.hasKeys() && IN_DOWNLOADED_AREA.test(n)) {
    4646                String msg = marktr("No tags");
    4747                errors.add(new TestError(this, Severity.WARNING, ERROR_MESSAGE, tr(msg), msg, UNTAGGED_NODE_BLANK, n));
  • trunk/src/org/openstreetmap/josm/data/validation/tests/WayConnectedToArea.java

    r8870 r10657  
    1616import org.openstreetmap.josm.gui.mappaint.ElemStyles;
    1717import org.openstreetmap.josm.tools.Predicates;
    18 import org.openstreetmap.josm.tools.Utils;
    1918
    2019/**
     
    6867        if (wayNode.isOutsideDownloadArea()) {
    6968            return;
    70         } else if (Utils.exists(wayNode.getReferrers(), Predicates.hasTag("route", "ferry"))) {
     69        } else if (wayNode.getReferrers().stream().anyMatch(Predicates.hasTag("route", "ferry"))) {
    7170            return;
    7271        } else if (isArea(p)) {
Note: See TracChangeset for help on using the changeset viewer.