List of usage examples for java.util TreeSet size
public int size()
From source file:org.mrgeo.cmd.generatekeys.GenerateKeys.java
private static List<Integer> findRandomIndices(int num, int indexMin, int indexMax, Random r) { log.info("Start generating random indices"); int range = (indexMax - indexMin) + 1; log.info(String.format("Using index range %d %d", indexMin, indexMax)); TreeSet<Integer> indices = new TreeSet<Integer>(); while (indices.size() < num) { int index = r.nextInt(range) + indexMin; if (!indices.contains(index)) indices.add(index);//from www . j a v a2 s . c om } List<Integer> indicesList = new ArrayList<Integer>(); for (Integer index : indices) indicesList.add(index); for (Integer index : indicesList) log.info("Index = " + index); log.info("End generating random indices"); return indicesList; }
From source file:org.alfresco.bm.test.prop.TestPropertyFactory.java
/** * Convert Java properties into instances of {@link TestProperty} instances. * /*from w w w . j a v a 2s . co m*/ * @param inheritanceCSV comma-separated list of project property namespaces to inherit * @param properties Java properties with values defining defaults, types, etc * @return objects mapping all the values required to persist and present the test properties */ public static List<TestProperty> getTestProperties(String inheritanceCSV, Properties properties) { // Get property inheritance order TreeSet<String> inheritance = getInheritance(inheritanceCSV); if (inheritance.size() == 0) { logger.error("The property inheritance set is empty: " + inheritanceCSV); } // Extract project and property names Set<String> allPropNames = new HashSet<String>(113); getPropertyAndProjectNames(properties, allPropNames, inheritance); // Build the properties List<TestProperty> testProperties = new ArrayList<TestProperty>(57); for (String propName : allPropNames) { // Eliminate non-compliat properties Matcher propNameMatcher = PROP_NAME_PATTERN.matcher(propName); if (!propNameMatcher.matches()) { logger.error("Ignoring illegal property name '" + propName + "'. Values must match '" + PROP_NAME_REGEX + "' " + " i.e. start with a letter and then include letters, numbers, dots or dashes."); continue; } TestProperty testProperty = getProperty(properties, propName, inheritance); testProperties.add(testProperty); } // Done return testProperties; }
From source file:org.apache.hadoop.hbase.loadtest.MultiThreadedReader.java
static void debugMismatchResults(TreeSet<KeyValue> noDuplicateResultSet, TreeSet<KeyValue> kvExpected) { if (noDuplicateResultSet.size() != kvExpected.size()) { LOG.info("Expected size was: " + kvExpected.size() + " but result set was of size: " + noDuplicateResultSet.size()); }//from ww w .ja va 2s .c o m Iterator<KeyValue> expectedIterator = kvExpected.iterator(); Iterator<KeyValue> returnedIterator = noDuplicateResultSet.iterator(); while (expectedIterator.hasNext() || returnedIterator.hasNext()) { KeyValue expected = null; KeyValue returned = null; if (expectedIterator.hasNext()) { expected = expectedIterator.next(); } if (returnedIterator.hasNext()) { returned = returnedIterator.next(); } if (returned == null || expected == null) { LOG.info("MISMATCH!! Expected was : " + expected + " but got " + returned); } else if (KeyValue.COMPARATOR.compare(expected, returned) != 0) { LOG.info("MISMATCH!! Expected was : " + expected + " but got " + returned); } else { LOG.info("Expected was : " + expected + " and got " + returned); } } }
From source file:org.onosproject.drivers.microsemi.yang.utils.CeVlanMapUtils.java
/** * Add an additional vlan id to an existing string representation. * @param existingMap An array of vlan ids * @param newVlan The new vlan ID to add * @return A string representation delimited by commas and colons *//*from w ww . j a v a2s.com*/ public static String addtoCeVlanMap(String existingMap, Short newVlan) { Short[] vlanArray = getVlanSet(existingMap); TreeSet<Short> vlanSet = new TreeSet<>(); for (Short vlan : vlanArray) { vlanSet.add(vlan); } vlanSet.add(newVlan); return vlanListAsString(vlanSet.toArray(new Short[vlanSet.size()])); }
From source file:org.onosproject.drivers.microsemi.yang.utils.CeVlanMapUtils.java
/** * Remove a vlan id from an existing string representation. * @param existingMap An array of vlan ids * @param vlanRemove The vlan ID to remove * @return A string representation delimited by commas and colons *///from w ww. j a v a 2s . com public static String removeFromCeVlanMap(String existingMap, Short vlanRemove) { Short[] vlanArray = getVlanSet(existingMap); TreeSet<Short> vlanSet = new TreeSet<>(); for (Short vlan : vlanArray) { if (vlan.shortValue() != vlanRemove.shortValue()) { vlanSet.add(vlan); } } return vlanListAsString(vlanSet.toArray(new Short[vlanSet.size()])); }
From source file:de.knowwe.visualization.util.Utils.java
private static double getVariance(TreeSet<Integer> positions) { double average = 0; int last = 0; for (Integer position : positions) { average += position - last;// w w w.j a v a 2 s . com last = position; } average = average / positions.size() - 1; double var = 0; last = 0; for (Integer position : positions) { var += Math.abs((position - last) - average); last = position; } return var; }
From source file:com.ettoremastrogiacomo.sktradingjava.starters.Temp.java
public static java.util.ArrayList<TreeSet<UDate>> timesegments(java.util.TreeSet<UDate> dates, long maxgapmsec) { java.util.TreeMap<Integer, TreeSet<UDate>> rank = new java.util.TreeMap<>(); java.util.TreeSet<UDate> t = new TreeSet<>(); java.util.ArrayList<TreeSet<UDate>> list = new ArrayList<>(); for (UDate d : dates) { if (t.isEmpty()) { t.add(d);/*from w ww. java 2 s . co m*/ } else if (d.diffmills(t.last()) > maxgapmsec) { rank.put(t.size(), t); list.add(t); t = new TreeSet<>(); } else { t.add(d); } } return list; }
From source file:com.android.calendar.event.EventLocationAdapter.java
/** * Post-process the query results to return the first MAX_LOCATION_SUGGESTIONS * unique locations in alphabetical order. * <p/>/*from w ww.j a va2 s . com*/ * TODO: Refactor to share code with the recent titles auto-complete. */ private static List<Result> processLocationsQueryResults(Cursor cursor) { TreeSet<String> locations = new TreeSet<String>(String.CASE_INSENSITIVE_ORDER); cursor.moveToPosition(-1); // Remove dupes. while ((locations.size() < MAX_LOCATION_SUGGESTIONS) && cursor.moveToNext()) { String location = cursor.getString(EVENT_INDEX_LOCATION).trim(); locations.add(location); } // Copy the sorted results. List<Result> results = new ArrayList<Result>(); for (String location : locations) { results.add(new Result(null, location, R.drawable.ic_history_holo_light, null)); } return results; }
From source file:com.espertech.esper.event.vaevent.PropertyUtility.java
private static MultiKey<String> getPropertiesContributed(EventType deltaEventType, String[] allPropertiesSorted) { TreeSet<String> props = new TreeSet<String>(); for (String property : deltaEventType.getPropertyNames()) { for (String propInAll : allPropertiesSorted) { if (propInAll.equals(property)) { props.add(property);// w w w . jav a 2 s . c o m break; } } } return new MultiKey<String>(props.toArray(new String[props.size()])); }
From source file:com.almende.eve.protocol.jsonrpc.JSONRpc.java
/** * Describe all JSON-RPC methods of given class. * //from w w w . j a v a 2 s . c o m * @param c * The class to be described * @param requestParams * Optional request parameters. * @param auth * the authorizor * @return the list */ public static List<Object> describe(final Object c, final RequestParams requestParams, final Authorizor auth) { try { final Map<String, Object> methods = _describe(c, requestParams, "", auth); // create a sorted array final TreeSet<String> methodNames = new TreeSet<String>(methods.keySet()); final List<Object> sortedMethods = new ArrayList<Object>(methodNames.size()); for (final String methodName : methodNames) { sortedMethods.add(methods.get(methodName)); } return sortedMethods; } catch (final Exception e) { LOG.log(Level.WARNING, "Failed to describe class:" + c.toString(), e); return null; } }