private void keepLastUpdatedUnique ( ) { Map < String , SingleTokenStats > temp = new HashMap <> ( ) ; this . tokenStats . forEach ( candidate -> { SingleTokenStats current = temp . get ( candidate . tokenUuid ) ; if ( current == null ) { temp . put ( candidate . tokenUuid , candidate ) ; } else { int comparison = SingleTokenStats . COMP_BY_LAST_USE_THEN_COUNTER . compare ( current , candidate ) ; if ( comparison < 0 ) { // candidate was updated more recently (or has a bigger counter in case of perfectly equivalent dates) temp . put ( candidate . tokenUuid , candidate ) ; } } } ) ; this . tokenStats = new ArrayList <> ( temp . values ( ) ) ; }
In case of duplicate entries we keep only the last updated element