List of usage examples for java.util SortedSet add
boolean add(E e);
From source file:nl.surfnet.mujina.spring.User.java
private static SortedSet<GrantedAuthority> sortAuthorities(Collection<? extends GrantedAuthority> authorities) { SortedSet<GrantedAuthority> sortedAuthorities = new TreeSet<GrantedAuthority>(new AuthorityComparator()); for (GrantedAuthority grantedAuthority : authorities) { sortedAuthorities.add(grantedAuthority); }/*from w ww .j a v a2 s. c o m*/ return sortedAuthorities; }
From source file:com.asakusafw.runtime.stage.input.StageInputDriver.java
private static String[] buildDictionary(List<StageInput> inputList) { assert inputList != null; SortedSet<String> values = new TreeSet<>(); for (StageInput input : inputList) { values.add(input.getPathString()); values.add(input.getFormatClass().getName()); values.add(input.getMapperClass().getName()); values.addAll(input.getAttributes().keySet()); values.addAll(input.getAttributes().values()); }//from w w w . j av a2 s . c o m return values.toArray(new String[values.size()]); }
From source file:Main.java
public static <K, V extends Comparable<? super V>> SortedSet<Entry<K, V>> sortMapByValueDesc(Map<K, V> map) { SortedSet<Entry<K, V>> sorted = new TreeSet<>(new Comparator<Entry<K, V>>() { @Override/*w w w . j ava2s . c om*/ public int compare(Entry<K, V> e1, Entry<K, V> e2) { int r = e2.getValue().compareTo(e1.getValue()); return r == 0 ? 1 : r; } }); for (Entry<K, V> entry : map.entrySet()) sorted.add(new SimpleEntry(entry)); return sorted; }
From source file:Main.java
public static <K, V extends Comparable<? super V>> SortedSet<Entry<K, V>> sortMapByValueAsc(Map<K, V> map) { SortedSet<Entry<K, V>> sorted = new TreeSet<>(new Comparator<Entry<K, V>>() { @Override// www . j a v a 2 s . co m public int compare(Entry<K, V> e1, Entry<K, V> e2) { int r = e1.getValue().compareTo(e2.getValue()); return r == 0 ? 1 : r; } }); for (Entry<K, V> entry : map.entrySet()) sorted.add(new SimpleEntry(entry)); return sorted; }
From source file:de.shadowhunt.sonar.plugins.ignorecode.model.AbstractPattern.java
/** * Add a range of lines this {@link AbstractPattern} shall match, all lines between * from (including) and to (including) will be added * * @param from the first line in the range the {@link AbstractPattern} shall match, must be greater or equal than to * @param to the last line in the range the {@link AbstractPattern} shall match, must be smaller or equal than from * * @throws IllegalArgumentException if from is not greater or equal than to *///from w ww.ja va 2 s .co m static void addLines(final SortedSet<Integer> lines, final int from, final int to) { if (to < from) { throw new IllegalArgumentException("from: " + from + " must be greater or equal than to: " + to); } for (int line = from; line <= to; line++) { lines.add(line); } }
From source file:Main.java
/** * internal method to handle the selections if items are added / removed * * @param positions the positions map which should be adjusted * @param startPosition the global index of the first element modified * @param endPosition the global index up to which the modification changed the indices (should be MAX_INT if we check til the end) * @param adjustBy the value by which the data was shifted * @return the adjusted set/* w w w .j a v a 2 s . c om*/ */ public static SortedSet<Integer> adjustPosition(Set<Integer> positions, int startPosition, int endPosition, int adjustBy) { SortedSet<Integer> newPositions = new TreeSet<>(); for (Integer entry : positions) { int position = entry; //if our current position is not within the bounds to check for we can add it if (position < startPosition || position > endPosition) { newPositions.add(position); } else if (adjustBy > 0) { //if we added items and we are within the bounds we can simply add the adjustBy to our entry newPositions.add(position + adjustBy); } else if (adjustBy < 0) { //if we removed items and we are within the bounds we have to check if the item was removed //adjustBy is negative in this case if (position > startPosition + adjustBy && position <= startPosition) { ;//we are within the removed items range we don't add this item anymore } else { //otherwise we adjust our position newPositions.add(position + adjustBy); } } } return newPositions; }
From source file:app.core.Db.java
public static Set<Class> getEntityClassList() { SortedSet<Class> classes = new TreeSet<Class>(new ORMUtils.DependencyComparator()); SessionFactory sessionFactory = getSessionFactory(); try {// ww w . j a v a 2 s. c om for (String className : sessionFactory.getAllClassMetadata().keySet()) { classes.add(Class.forName(className)); } } catch (ClassNotFoundException e) { //log(); } return classes; }
From source file:de.tudarmstadt.ukp.experiments.argumentation.convincingness.sampling.Step5GoldLabelEstimator.java
/** * Extract all unique turker IDs from annotations, and returns them as a sorted list * * @param argumentPairs argument pairs// w w w. ja v a 2s .c o m * @return sorted IDs */ public static List<String> extractAndSortTurkerIDs(List<AnnotatedArgumentPair> argumentPairs) { // first, get the sorted set of all turkers SortedSet<String> uniqueTurkerSet = new TreeSet<>(); for (AnnotatedArgumentPair argumentPair : argumentPairs) { for (AnnotatedArgumentPair.MTurkAssignment assignment : argumentPair.mTurkAssignments) { uniqueTurkerSet.add(assignment.getTurkID()); } } // transform to a list return new ArrayList<>(uniqueTurkerSet); }
From source file:co.rsk.peg.BridgeSerializationUtils.java
public static SortedSet<Sha256Hash> deserializeSet(byte[] data) { SortedSet<Sha256Hash> set = new TreeSet<>(); if (data == null || data.length == 0) return set; RLPList rlpList = (RLPList) RLP.decode2(data).get(0); int nhashes = rlpList.size(); for (int k = 0; k < nhashes; k++) set.add(Sha256Hash.wrap(rlpList.get(k).getRLPData())); return set;// w ww . j av a2s.c o m }
From source file:org.neo4j.bench.chart.GenerateOpsPerSecChart.java
/** * Opens the operations per second file, reads in the contents and creates a * SortedSet of the therein stored Stats. */// ww w . j a v a 2 s . com public static SortedSet<Stats> loadOpsPerSecond(String fileName) { File dataFile = new File(fileName); if (!dataFile.exists()) { return null; } BufferedReader reader = null; SortedSet<Stats> result = new TreeSet<Stats>(); Stats currentStat; try { reader = new BufferedReader(new FileReader(dataFile)); String line; // The current line while ((line = reader.readLine()) != null) { currentStat = Stats.parse(line); if (currentStat != null) { result.add(currentStat); } } } catch (IOException e) { // This should not happen as we check above e.printStackTrace(); return null; } finally { if (reader != null) { try { reader.close(); } catch (IOException e) { e.printStackTrace(); } } } return result; }