Changeset 16953 in josm


Ignore:
Timestamp:
2020-08-29T07:53:11+02:00 (4 weeks ago)
Author:
simon04
Message:

Java 8: use Comparator.comparing

Location:
trunk
Files:
12 edited

Legend:

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

    r16942 r16953  
    88import java.util.Collection;
    99import java.util.Collections;
     10import java.util.Comparator;
    1011import java.util.Date;
    1112import java.util.HashMap;
     
    374375                }
    375376            }
    376             segSpans.sort((o1, o2) -> o1.firstTime.compareTo(o2.firstTime));
     377            segSpans.sort(Comparator.comparing(o -> o.firstTime));
    377378        }
    378379        return segSpans;
  • trunk/src/org/openstreetmap/josm/data/notes/Note.java

    r12540 r16953  
    5151
    5252    /** Sorts notes strictly by creation date */
    53     public static final Comparator<Note> DATE_COMPARATOR = (n1, n2) -> n1.createdAt.compareTo(n2.createdAt);
     53    public static final Comparator<Note> DATE_COMPARATOR = Comparator.comparing(n -> n.createdAt);
    5454
    5555    /** Sorts notes by user, then creation date */
  • trunk/src/org/openstreetmap/josm/data/notes/NoteComment.java

    r12540 r16953  
    4141
    4242    /** Sorts note comments strictly by creation date */
    43     public static final Comparator<NoteComment> DATE_COMPARATOR = (n1, n2) -> n1.commentTimestamp.compareTo(n2.commentTimestamp);
     43    public static final Comparator<NoteComment> DATE_COMPARATOR = Comparator.comparing(n -> n.commentTimestamp);
    4444
    4545    /**
  • trunk/src/org/openstreetmap/josm/data/osm/DefaultNameFormatter.java

    r16952 r16953  
    225225    }
    226226
    227     private final Comparator<INode> nodeComparator = (n1, n2) -> format(n1).compareTo(format(n2));
     227    private final Comparator<INode> nodeComparator = Comparator.comparing(this::format);
    228228
    229229    @Override
     
    315315    }
    316316
    317     private final Comparator<IWay<?>> wayComparator = (w1, w2) -> format(w1).compareTo(format(w2));
     317    private final Comparator<IWay<?>> wayComparator = Comparator.comparing(this::format);
    318318
    319319    @Override
  • trunk/src/org/openstreetmap/josm/gui/ImageryMenu.java

    r16138 r16953  
    100100     */
    101101    public static final Comparator<ImageryInfo> alphabeticImageryComparator =
    102             (ii1, ii2) -> ii1.getName().toLowerCase(Locale.ENGLISH).compareTo(ii2.getName().toLowerCase(Locale.ENGLISH));
     102            Comparator.comparing(ii -> ii.getName().toLowerCase(Locale.ENGLISH));
    103103
    104104    private final transient Action offsetAction = new AdjustImageryOffsetAction();
  • trunk/src/org/openstreetmap/josm/gui/conflict/tags/TagConflictResolutionUtil.java

    r16643 r16953  
    66import java.util.Collection;
    77import java.util.Collections;
     8import java.util.Comparator;
    89import java.util.HashMap;
    910import java.util.LinkedHashSet;
     
    288289                return new TreeSet<>();
    289290            } else if ("Integer".equals(sort)) {
    290                 return new TreeSet<>((String v1, String v2) -> Long.valueOf(v1).compareTo(Long.valueOf(v2)));
     291                return new TreeSet<>(Comparator.comparing(Long::valueOf));
    291292            } else {
    292293                return new LinkedHashSet<>();
  • trunk/src/org/openstreetmap/josm/gui/dialogs/changeset/ChangesetContentTableModel.java

    r16436 r16953  
    44import java.util.ArrayList;
    55import java.util.Arrays;
     6import java.util.Comparator;
    67import java.util.Iterator;
    78import java.util.List;
     
    9495     */
    9596    protected void sort() {
    96         data.sort((c1, c2) -> {
    97             int d = c1.getModificationType().compareTo(c2.getModificationType());
    98             if (d == 0) {
    99                 d = Long.compare(c1.getPrimitive().getId(), c2.getPrimitive().getId());
    100             }
    101             return d;
    102             }
     97        data.sort(Comparator.comparing(ChangesetContentEntry::getModificationType).thenComparingLong(c -> c.getPrimitive().getId())
    10398        );
    10499    }
  • trunk/src/org/openstreetmap/josm/gui/layer/gpx/ImportAudioAction.java

    r16438 r16953  
    273273
    274274        // we must have got at least one waypoint now
    275         ((ArrayList<WayPoint>) waypoints).sort((wp, other) -> wp.compareTo(other));
     275        ((ArrayList<WayPoint>) waypoints).sort(Comparator.naturalOrder());
    276276
    277277        firstTime = -1.0; // this time of the first waypoint, not first trackpoint
  • trunk/src/org/openstreetmap/josm/gui/preferences/imagery/HeadersTable.java

    r16913 r16953  
    55
    66import java.awt.GridBagLayout;
     7import java.util.Comparator;
    78import java.util.List;
    89import java.util.Map;
     
    106107
    107108    private static List<String[]> getHeadersAsVector(Map<String, String> headers) {
    108         return headers.entrySet().stream().sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey()))
     109        return headers.entrySet().stream().sorted(Comparator.comparing(Map.Entry::getKey))
    109110                .map(e -> new String[] {e.getKey(), e.getValue()}).collect(Collectors.toList());
    110111    }
  • trunk/src/org/openstreetmap/josm/io/GpxWriter.java

    r16643 r16953  
    1111import java.util.ArrayList;
    1212import java.util.Collection;
     13import java.util.Comparator;
    1314import java.util.Date;
    1415import java.util.List;
     
    9798            data.getLayerPrefs().entrySet()
    9899            .stream()
    99             .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey()))
     100            .sorted(Comparator.comparing(Map.Entry::getKey))
    100101            .forEach(entry -> {
    101102                GpxExtension e = layerExts.add("josm", "entry");
  • trunk/src/org/openstreetmap/josm/io/OsmWriter.java

    r16663 r16953  
    320320    }
    321321
    322     protected static final Comparator<Entry<String, String>> byKeyComparator = (o1, o2) -> o1.getKey().compareTo(o2.getKey());
     322    protected static final Comparator<Entry<String, String>> byKeyComparator = Comparator.comparing(Entry::getKey);
    323323
    324324    protected void addTags(Tagged osm, String tagname, boolean tagOpen) {
  • trunk/test/unit/org/openstreetmap/josm/gui/layer/gpx/ConvertToDataLayerActionTest.java

    r15497 r16953  
    142142        List<String> ways = osm.getWays().stream()
    143143                .map(w -> Integer.toString(w.getNodes().size()) + ":" + w.getKeys().entrySet().stream()
    144                         .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).collect(Collectors.toList()).toString())
     144                        .sorted(Comparator.comparing(Map.Entry::getKey)).collect(Collectors.toList()).toString())
    145145                .sorted()
    146146                .collect(Collectors.toList());
     
    148148        List<String> waysExpected = osmExpected.getWays().stream()
    149149                .map(w -> Integer.toString(w.getNodes().size()) + ":" + w.getKeys().entrySet().stream()
    150                         .sorted((e1, e2) -> e1.getKey().compareTo(e2.getKey())).collect(Collectors.toList()).toString())
     150                        .sorted(Comparator.comparing(Map.Entry::getKey)).collect(Collectors.toList()).toString())
    151151                .sorted()
    152152                .collect(Collectors.toList());
Note: See TracChangeset for help on using the changeset viewer.