Ignore:
Timestamp:
2016-07-23T15:46:39+02:00 (9 years ago)
Author:
Don-vip
Message:

see #11390 - sonar - squid:S1604 - Java 8: Anonymous inner classes containing only one method should become lambdas

File:
1 edited

Legend:

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

    r10134 r10608  
    1616import org.openstreetmap.josm.data.notes.NoteComment;
    1717import org.openstreetmap.josm.gui.JosmUserIdentityManager;
    18 import org.openstreetmap.josm.tools.Predicate;
    1918import org.openstreetmap.josm.tools.Utils;
    2019
     
    3736     * Within each subgroup it sorts by ID
    3837     */
    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()));
    5652    };
    5753
    5854    /** 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)) {
    6262            return n1.getCreatedAt().compareTo(n2.getCreatedAt());
    6363        }
     64        return n1.getFirstComment().getUser().getName().compareTo(n2.getFirstComment().getUser().getName());
    6465    };
    6566
    66     /** Sorts notes by user, then creation date */
    67     public static final Comparator<Note> USER_COMPARATOR = new Comparator<Note>() {
    68         @Override
    69         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 
    7967    /** 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);
    8772    };
    8873
     
    169154            } else {
    170155                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());
    177157                if (!isDirty) {
    178158                    noteList.put(newNote);
Note: See TracChangeset for help on using the changeset viewer.