Created
April 30, 2014 14:10
-
-
Save jotak/277aef843126ef24bd01 to your computer and use it in GitHub Desktop.
That's collector
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@SuppressWarnings("unchecked") | |
private static <T,U> Map<U, List<T>> formatMapClefEnsembleValeursAvecOuSansLimitateur(List<Map<String, Object>> liste, | |
String identifiant, String valeur, Integer limitation) { | |
final Map<U, List<T>> mapKeyValue = new HashMap<U, List<T>>(); | |
final Map<U, Integer> mapLimitation = new HashMap<U, Integer>(); | |
if (!isEmpty(liste)) { | |
final boolean ligneComplete = StrUtil.isEmpty(valeur); | |
for (final Map<String, ?> map : liste) { | |
final U key = (U) map.get(identifiant); | |
if (mapKeyValue.containsKey(key)) { | |
final Integer limitationEnCours = mapLimitation.get(key); | |
if (limitationEnCours < limitation || limitation == 0) { | |
final List<T> listeResult = mapKeyValue.get(key); | |
if (ligneComplete) { | |
listeResult.add((T)map); | |
} else { | |
listeResult.add((T)map.get(valeur)); | |
} | |
mapKeyValue.put(key, listeResult); | |
mapLimitation.put(key, limitationEnCours + 1); | |
} | |
} else { | |
final List<T> listeResult = new ArrayList<T>(); | |
if (ligneComplete) { | |
listeResult.add((T)map); | |
} else { | |
listeResult.add((T)map.get(valeur)); | |
} | |
mapKeyValue.put(key, listeResult); | |
mapLimitation.put(key, 1); | |
} | |
} | |
} | |
return mapKeyValue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment