Changeset 10608 in josm for trunk/src/org/openstreetmap/josm/data/osm
- Timestamp:
- 2016-07-23T15:46:39+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/data/osm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/osm/ChangesetCache.java
r9519 r10608 16 16 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 17 17 import org.openstreetmap.josm.gui.util.GuiHelper; 18 import org.openstreetmap.josm.tools.Predicate;19 18 import org.openstreetmap.josm.tools.Utils; 20 19 … … 70 69 71 70 protected void fireChangesetCacheEvent(final ChangesetCacheEvent e) { 72 GuiHelper.runInEDT(new Runnable() { 73 @Override public void run() { 74 for (ChangesetCacheListener l: listeners) { 75 l.changesetCacheUpdated(e); 76 } 71 GuiHelper.runInEDT(() -> { 72 for (ChangesetCacheListener l: listeners) { 73 l.changesetCacheUpdated(e); 77 74 } 78 75 }); … … 206 203 return getOpenChangesets(); 207 204 } else { 208 return new ArrayList<>(Utils.filter(getOpenChangesets(), new Predicate<Changeset>() { 209 @Override 210 public boolean evaluate(Changeset object) { 211 return JosmUserIdentityManager.getInstance().isCurrentUser(object.getUser()); 212 } 213 })); 205 return new ArrayList<>(Utils.filter(getOpenChangesets(), 206 object -> JosmUserIdentityManager.getInstance().isCurrentUser(object.getUser()))); 214 207 } 215 208 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r10590 r10608 47 47 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager; 48 48 import org.openstreetmap.josm.tools.FilteredCollection; 49 import org.openstreetmap.josm.tools.Predicate;50 49 import org.openstreetmap.josm.tools.Predicates; 51 50 import org.openstreetmap.josm.tools.SubclassFilteredCollection; … … 614 613 */ 615 614 public Collection<OsmPrimitive> getSelectedNodesAndWays() { 616 return new FilteredCollection<>(getSelected(), new Predicate<OsmPrimitive>() { 617 @Override 618 public boolean evaluate(OsmPrimitive primitive) { 619 return primitive instanceof Node || primitive instanceof Way; 620 } 621 }); 615 return new FilteredCollection<>(getSelected(), primitive -> primitive instanceof Node || primitive instanceof Way); 622 616 } 623 617 -
trunk/src/org/openstreetmap/josm/data/osm/NoteData.java
r10134 r10608 16 16 import org.openstreetmap.josm.data.notes.NoteComment; 17 17 import org.openstreetmap.josm.gui.JosmUserIdentityManager; 18 import org.openstreetmap.josm.tools.Predicate;19 18 import org.openstreetmap.josm.tools.Utils; 20 19 … … 37 36 * Within each subgroup it sorts by ID 38 37 */ 39 public static final Comparator<Note> DEFAULT_COMPARATOR = new Comparator<Note>() { 40 @Override 41 public int compare(Note n1, Note n2) { 42 if (n1.getId() < 0 && n2.getId() > 0) { 43 return 1; 44 } 45 if (n1.getId() > 0 && n2.getId() < 0) { 46 return -1; 47 } 48 if (n1.getState() == State.CLOSED && n2.getState() == State.OPEN) { 49 return 1; 50 } 51 if (n1.getState() == State.OPEN && n2.getState() == State.CLOSED) { 52 return -1; 53 } 54 return Long.compare(Math.abs(n1.getId()), Math.abs(n2.getId())); 55 } 38 public static final Comparator<Note> DEFAULT_COMPARATOR = (n1, n2) -> { 39 if (n1.getId() < 0 && n2.getId() > 0) { 40 return 1; 41 } 42 if (n1.getId() > 0 && n2.getId() < 0) { 43 return -1; 44 } 45 if (n1.getState() == State.CLOSED && n2.getState() == State.OPEN) { 46 return 1; 47 } 48 if (n1.getState() == State.OPEN && n2.getState() == State.CLOSED) { 49 return -1; 50 } 51 return Long.compare(Math.abs(n1.getId()), Math.abs(n2.getId())); 56 52 }; 57 53 58 54 /** Sorts notes strictly by creation date */ 59 public static final Comparator<Note> DATE_COMPARATOR = new Comparator<Note>() { 60 @Override 61 public int compare(Note n1, Note n2) { 55 public static final Comparator<Note> DATE_COMPARATOR = (n1, n2) -> n1.getCreatedAt().compareTo(n2.getCreatedAt()); 56 57 /** Sorts notes by user, then creation date */ 58 public static final Comparator<Note> USER_COMPARATOR = (n1, n2) -> { 59 String n1User = n1.getFirstComment().getUser().getName(); 60 String n2User = n2.getFirstComment().getUser().getName(); 61 if (n1User.equals(n2User)) { 62 62 return n1.getCreatedAt().compareTo(n2.getCreatedAt()); 63 63 } 64 return n1.getFirstComment().getUser().getName().compareTo(n2.getFirstComment().getUser().getName()); 64 65 }; 65 66 66 /** Sorts notes by user, then creation date */67 public static final Comparator<Note> USER_COMPARATOR = new Comparator<Note>() {68 @Override69 public int compare(Note n1, Note n2) {70 String n1User = n1.getFirstComment().getUser().getName();71 String n2User = n2.getFirstComment().getUser().getName();72 if (n1User.equals(n2User)) {73 return n1.getCreatedAt().compareTo(n2.getCreatedAt());74 }75 return n1.getFirstComment().getUser().getName().compareTo(n2.getFirstComment().getUser().getName());76 }77 };78 79 67 /** Sorts notes by the last modified date */ 80 public static final Comparator<Note> LAST_ACTION_COMPARATOR = new Comparator<Note>() { 81 @Override 82 public int compare(Note n1, Note n2) { 83 Date n1Date = n1.getComments().get(n1.getComments().size()-1).getCommentTimestamp(); 84 Date n2Date = n2.getComments().get(n2.getComments().size()-1).getCommentTimestamp(); 85 return n1Date.compareTo(n2Date); 86 } 68 public static final Comparator<Note> LAST_ACTION_COMPARATOR = (n1, n2) -> { 69 Date n1Date = n1.getComments().get(n1.getComments().size()-1).getCommentTimestamp(); 70 Date n2Date = n2.getComments().get(n2.getComments().size()-1).getCommentTimestamp(); 71 return n1Date.compareTo(n2Date); 87 72 }; 88 73 … … 169 154 } else { 170 155 final Note existingNote = noteList.get(newNote); 171 final boolean isDirty = Utils.exists(existingNote.getComments(), new Predicate<NoteComment>() { 172 @Override 173 public boolean evaluate(NoteComment object) { 174 return object.isNew(); 175 } 176 }); 156 final boolean isDirty = Utils.exists(existingNote.getComments(), object -> object.isNew()); 177 157 if (!isDirty) { 178 158 noteList.put(newNote); -
trunk/src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r10583 r10608 110 110 111 111 /** 112 * A tagged way that matches this pattern has a direction. 113 * @see #FLAG_HAS_DIRECTIONS 114 */ 115 private static volatile Match directionKeys; 116 117 /** 118 * A tagged way that matches this pattern has a direction that is reversed. 119 * <p> 120 * This pattern should be a subset of {@link #directionKeys} 121 * @see #FLAG_DIRECTION_REVERSED 122 */ 123 private static volatile Match reversedDirectionKeys; 124 125 static { 126 String reversedDirectionDefault = "oneway=\"-1\""; 127 128 String directionDefault = "oneway? | (aerialway=* -aerialway=station) | "+ 129 "waterway=stream | waterway=river | waterway=ditch | waterway=drain | "+ 130 "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+ 131 "junction=roundabout | (highway=motorway & -oneway=no & -oneway=reversible) | "+ 132 "(highway=motorway_link & -oneway=no & -oneway=reversible)"; 133 134 reversedDirectionKeys = compileDirectionKeys("tags.reversed_direction", reversedDirectionDefault); 135 directionKeys = compileDirectionKeys("tags.direction", directionDefault); 136 } 137 138 /** 112 139 * Replies the sub-collection of {@link OsmPrimitive}s of type <code>type</code> present in 113 140 * another collection of {@link OsmPrimitive}s. The result collection is a list. … … 174 201 * @see OsmPrimitive#isUsable() 175 202 */ 176 public static final Predicate<OsmPrimitive> isUsablePredicate = new Predicate<OsmPrimitive>() { 177 @Override 178 public boolean evaluate(OsmPrimitive primitive) { 179 return primitive.isUsable(); 180 } 181 }; 203 public static final Predicate<OsmPrimitive> isUsablePredicate = primitive -> primitive.isUsable(); 182 204 183 205 /** 184 206 * A predicate filtering primitives that are selectable. 185 207 */ 186 public static final Predicate<OsmPrimitive> isSelectablePredicate = new Predicate<OsmPrimitive>() { 187 @Override 188 public boolean evaluate(OsmPrimitive primitive) { 189 return primitive.isSelectable(); 190 } 191 }; 208 public static final Predicate<OsmPrimitive> isSelectablePredicate = primitive -> primitive.isSelectable(); 192 209 193 210 /** 194 211 * A predicate filtering primitives that are not deleted. 195 212 */ 196 public static final Predicate<OsmPrimitive> nonDeletedPredicate = new Predicate<OsmPrimitive>() { 197 @Override public boolean evaluate(OsmPrimitive primitive) { 198 return !primitive.isDeleted(); 199 } 200 }; 213 public static final Predicate<OsmPrimitive> nonDeletedPredicate = primitive -> !primitive.isDeleted(); 201 214 202 215 /** 203 216 * A predicate filtering primitives that are not deleted and not incomplete. 204 217 */ 205 public static final Predicate<OsmPrimitive> nonDeletedCompletePredicate = new Predicate<OsmPrimitive>() { 206 @Override public boolean evaluate(OsmPrimitive primitive) { 207 return !primitive.isDeleted() && !primitive.isIncomplete(); 208 } 209 }; 218 public static final Predicate<OsmPrimitive> nonDeletedCompletePredicate = 219 primitive -> !primitive.isDeleted() && !primitive.isIncomplete(); 210 220 211 221 /** 212 222 * A predicate filtering primitives that are not deleted and not incomplete and that are not a relation. 213 223 */ 214 public static final Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = new Predicate<OsmPrimitive>() { 215 @Override public boolean evaluate(OsmPrimitive primitive) { 216 return !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 217 } 218 }; 224 public static final Predicate<OsmPrimitive> nonDeletedPhysicalPredicate = 225 primitive -> !primitive.isDeleted() && !primitive.isIncomplete() && !(primitive instanceof Relation); 219 226 220 227 /** 221 228 * A predicate filtering primitives that are modified 222 229 */ 223 public static final Predicate<OsmPrimitive> modifiedPredicate = new Predicate<OsmPrimitive>() { 224 @Override public boolean evaluate(OsmPrimitive primitive) { 225 return primitive.isModified(); 226 } 227 }; 230 public static final Predicate<OsmPrimitive> modifiedPredicate = primitive -> primitive.isModified(); 228 231 229 232 /** … … 245 248 * A predicate filtering multipolygon relations. 246 249 */ 247 public static final Predicate<OsmPrimitive> multipolygonPredicate = new Predicate<OsmPrimitive>() { 248 @Override public boolean evaluate(OsmPrimitive primitive) { 249 return primitive.getClass() == Relation.class && ((Relation) primitive).isMultipolygon(); 250 } 251 }; 250 public static final Predicate<OsmPrimitive> multipolygonPredicate = 251 primitive -> primitive.getClass() == Relation.class && ((Relation) primitive).isMultipolygon(); 252 252 253 253 /** … … 256 256 * @see #FLAG_HAS_DIRECTIONS 257 257 */ 258 public static final Predicate<Tag> directionalKeyPredicate = new Predicate<Tag>() { 259 @Override 260 public boolean evaluate(Tag tag) { 261 return directionKeys.match(tag); 262 } 263 }; 258 public static final Predicate<Tag> directionalKeyPredicate = tag -> directionKeys.match(tag); 264 259 265 260 /** … … 843 838 } 844 839 845 /**846 * A tagged way that matches this pattern has a direction.847 * @see #FLAG_HAS_DIRECTIONS848 */849 private static volatile Match directionKeys;850 851 /**852 * A tagged way that matches this pattern has a direction that is reversed.853 * <p>854 * This pattern should be a subset of {@link #directionKeys}855 * @see #FLAG_DIRECTION_REVERSED856 */857 private static volatile Match reversedDirectionKeys;858 859 static {860 String reversedDirectionDefault = "oneway=\"-1\"";861 862 String directionDefault = "oneway? | (aerialway=* -aerialway=station) | "+863 "waterway=stream | waterway=river | waterway=ditch | waterway=drain | "+864 "\"piste:type\"=downhill | \"piste:type\"=sled | man_made=\"piste:halfpipe\" | "+865 "junction=roundabout | (highway=motorway & -oneway=no & -oneway=reversible) | "+866 "(highway=motorway_link & -oneway=no & -oneway=reversible)";867 868 reversedDirectionKeys = compileDirectionKeys("tags.reversed_direction", reversedDirectionDefault);869 directionKeys = compileDirectionKeys("tags.direction", directionDefault);870 }871 872 840 private static Match compileDirectionKeys(String prefName, String defaultValue) throws AssertionError { 873 841 try { -
trunk/src/org/openstreetmap/josm/data/osm/Relation.java
r10242 r10608 15 15 import org.openstreetmap.josm.data.osm.visitor.Visitor; 16 16 import org.openstreetmap.josm.tools.CopyList; 17 import org.openstreetmap.josm.tools.Predicate;18 17 import org.openstreetmap.josm.tools.Utils; 18 import org.openstreetmap.josm.tools.Utils.Function; 19 19 20 20 /** … … 349 349 */ 350 350 public Collection<RelationMember> getMembersFor(final Collection<? extends OsmPrimitive> primitives) { 351 return Utils.filter(getMembers(), new Predicate<RelationMember>() { 352 @Override 353 public boolean evaluate(RelationMember member) { 354 return primitives.contains(member.getMember()); 355 } 356 }); 351 return Utils.filter(getMembers(), member -> primitives.contains(member.getMember())); 357 352 } 358 353 … … 405 400 406 401 public List<OsmPrimitive> getMemberPrimitivesList() { 407 return Utils.transform(getMembers(), new Utils.Function<RelationMember, OsmPrimitive>() { 408 @Override 409 public OsmPrimitive apply(RelationMember x) { 410 return x.getMember(); 411 } 412 }); 402 return Utils.transform(getMembers(), (Function<RelationMember, OsmPrimitive>) x -> x.getMember()); 413 403 } 414 404 -
trunk/src/org/openstreetmap/josm/data/osm/event/SelectionEventManager.java
r10043 r10608 88 88 } 89 89 90 private final Runnable edtRunnable = new Runnable() { 91 @Override 92 public void run() { 93 if (selection != null) { 94 fireEvents(inEDTListeners, selection); 95 } 90 private final Runnable edtRunnable = () -> { 91 if (selection != null) { 92 fireEvents(inEDTListeners, selection); 96 93 } 97 94 }; -
trunk/src/org/openstreetmap/josm/data/osm/history/History.java
r10600 r10608 5 5 import java.util.ArrayList; 6 6 import java.util.Collections; 7 import java.util.Comparator;8 7 import java.util.Date; 9 8 import java.util.List; … … 70 69 public History sortAscending() { 71 70 List<HistoryOsmPrimitive> copy = new ArrayList<>(versions); 72 Collections.sort( 73 copy, 74 new Comparator<HistoryOsmPrimitive>() { 75 @Override 76 public int compare(HistoryOsmPrimitive o1, HistoryOsmPrimitive o2) { 77 return o1.compareTo(o2); 78 } 79 } 80 ); 71 Collections.sort(copy, (o1, o2) -> o1.compareTo(o2)); 81 72 return new History(id, type, copy); 82 73 } … … 88 79 public History sortDescending() { 89 80 List<HistoryOsmPrimitive> copy = new ArrayList<>(versions); 90 Collections.sort( 91 copy, 92 new Comparator<HistoryOsmPrimitive>() { 93 @Override 94 public int compare(HistoryOsmPrimitive o1, HistoryOsmPrimitive o2) { 95 return o2.compareTo(o1); 96 } 97 } 98 ); 81 Collections.sort(copy, (o1, o2) -> o2.compareTo(o1)); 99 82 return new History(id, type, copy); 100 83 } … … 106 89 */ 107 90 public History from(final Date fromDate) { 108 return filter( 109 this, 110 new FilterPredicate() { 111 @Override 112 public boolean matches(HistoryOsmPrimitive primitive) { 113 return primitive.getTimestamp().compareTo(fromDate) >= 0; 114 } 115 } 116 ); 91 return filter(this, primitive -> primitive.getTimestamp().compareTo(fromDate) >= 0); 117 92 } 118 93 … … 123 98 */ 124 99 public History until(final Date untilDate) { 125 return filter( 126 this, 127 new FilterPredicate() { 128 @Override 129 public boolean matches(HistoryOsmPrimitive primitive) { 130 return primitive.getTimestamp().compareTo(untilDate) <= 0; 131 } 132 } 133 ); 100 return filter(this, primitive -> primitive.getTimestamp().compareTo(untilDate) <= 0); 134 101 } 135 102 … … 150 117 */ 151 118 public History from(final long fromVersion) { 152 return filter( 153 this, 154 new FilterPredicate() { 155 @Override 156 public boolean matches(HistoryOsmPrimitive primitive) { 157 return primitive.getVersion() >= fromVersion; 158 } 159 } 160 ); 119 return filter(this, primitive -> primitive.getVersion() >= fromVersion); 161 120 } 162 121 … … 167 126 */ 168 127 public History until(final long untilVersion) { 169 return filter( 170 this, 171 new FilterPredicate() { 172 @Override 173 public boolean matches(HistoryOsmPrimitive primitive) { 174 return primitive.getVersion() <= untilVersion; 175 } 176 } 177 ); 128 return filter(this, primitive -> primitive.getVersion() <= untilVersion); 178 129 } 179 130 … … 194 145 */ 195 146 public History forUserId(final long uid) { 196 return filter( 197 this, 198 new FilterPredicate() { 199 @Override 200 public boolean matches(HistoryOsmPrimitive primitive) { 201 return primitive.getUser() != null && primitive.getUser().getId() == uid; 202 } 203 } 204 ); 147 return filter(this, primitive -> primitive.getUser() != null && primitive.getUser().getId() == uid); 205 148 } 206 149 … … 283 226 * @throws IndexOutOfBoundsException if index out or range 284 227 */ 285 public HistoryOsmPrimitive get(int idx) throws IndexOutOfBoundsException{228 public HistoryOsmPrimitive get(int idx) { 286 229 if (idx < 0 || idx >= versions.size()) 287 230 throw new IndexOutOfBoundsException(MessageFormat.format( … … 338 281 public String toString() { 339 282 StringBuilder result = new StringBuilder("History [" 340 + (type != null ? "type=" + type + ", ": "") + "id=" + id);283 + (type != null ? ("type=" + type + ", ") : "") + "id=" + id); 341 284 if (versions != null) { 342 285 result.append(", versions=\n");
Note:
See TracChangeset
for help on using the changeset viewer.