List of usage examples for java.util TreeSet size
public int size()
From source file:org.dasein.cloud.util.APITrace.java
static public String[] listOperations(@Nonnull String provider, @Nonnull String cloud) { provider = provider.replaceAll(DELIMITER_REGEX, "_"); cloud = cloud.replaceAll(DELIMITER_REGEX, "_"); TreeSet<String> list = new TreeSet<String>(); synchronized (operationCount) { for (String call : operationCount.keySet()) { String[] parts = call.split(DELIMITER_REGEX); if (parts.length > 3 && parts[0].equals(provider) && parts[1].equals(cloud)) { if (parts.length == 4) { list.add(parts[3]);//from www . ja va 2 s . co m } else { StringBuilder tmp = new StringBuilder(); for (int i = 3; i < parts.length; i++) { tmp.append(parts[i]); if (i < parts.length - 1) { tmp.append(DELIMITER); } } list.add(tmp.toString()); } } } } return list.toArray(new String[list.size()]); }
From source file:org.egov.works.master.service.ContractorService.java
public String[] getContractorMasterMandatoryFields() { final TreeSet<String> set = new TreeSet<>(Arrays.asList(getcontractorMasterSetMandatoryFields())); set.removeAll(Arrays.asList(getcontractorMasterSetHiddenFields())); return set.toArray(new String[set.size()]); }
From source file:com.kelveden.rastajax.representation.flat.FlatRepresentationBuilder.java
@Override public Set<FlatResource> buildRepresentationFor(final Set<ResourceClass> resourceClasses) { final TreeSet<FlatResource> result = new TreeSet<FlatResource>(RESOURCE_COMPARATOR); for (ResourceClass rawResource : resourceClasses) { result.addAll(buildRepresentationFor(rawResource)); }//from ww w. j a va 2 s . c o m LOGGER.info("Representation completed with {} resources.", result.size()); return result; }
From source file:org.apache.hadoop.yarn.server.resourcemanager.monitor.capacity.FifoIntraQueuePreemptionPlugin.java
public void validateOutSameAppPriorityFromDemand(Resource cluster, TreeSet<TempAppPerPartition> appsOrderedfromLowerPriority) { TempAppPerPartition[] apps = appsOrderedfromLowerPriority .toArray(new TempAppPerPartition[appsOrderedfromLowerPriority.size()]); if (apps.length <= 0) { return;/* w w w .j av a 2s . c o m*/ } int lPriority = 0; int hPriority = apps.length - 1; while (lPriority < hPriority && !apps[lPriority].equals(apps[hPriority]) && apps[lPriority].getPriority() < apps[hPriority].getPriority()) { Resource toPreemptFromOther = apps[hPriority].getToBePreemptFromOther(); Resource actuallyToPreempt = apps[lPriority].getActuallyToBePreempted(); Resource delta = Resources.subtract(apps[lPriority].toBePreempted, actuallyToPreempt); if (Resources.greaterThan(rc, cluster, delta, Resources.none())) { Resource toPreempt = Resources.min(rc, cluster, toPreemptFromOther, delta); apps[hPriority].setToBePreemptFromOther(Resources.subtract(toPreemptFromOther, toPreempt)); apps[lPriority].setActuallyToBePreempted(Resources.add(actuallyToPreempt, toPreempt)); } if (Resources.lessThanOrEqual(rc, cluster, apps[lPriority].toBePreempted, apps[lPriority].getActuallyToBePreempted())) { lPriority++; continue; } if (Resources.equals(apps[hPriority].getToBePreemptFromOther(), Resources.none())) { hPriority--; continue; } } }
From source file:com.mawujun.util.ObjectUtils.java
/** * Find the "best guess" middle value among comparables. If there is an even * number of total values, the lower of the two middle values will be returned. * @param <T> type of values processed by this method * @param items to compare/* ww w. jav a2 s .c o m*/ * @return T at middle position * @throws NullPointerException if items is {@code null} * @throws IllegalArgumentException if items is empty or contains {@code null} values * @since 3.0.1 */ public static <T extends Comparable<? super T>> T median(T... items) { Validate.notEmpty(items); Validate.noNullElements(items); TreeSet<T> sort = new TreeSet<T>(); Collections.addAll(sort, items); @SuppressWarnings("unchecked") //we know all items added were T instances T result = (T) sort.toArray()[(sort.size() - 1) / 2]; return result; }
From source file:org.apache.myfaces.custom.schedule.AbstractCompactScheduleRenderer.java
/** * <p>// ww w. j av a 2 s . c om * Draw the schedule entries in the specified day cell * </p> * * @param context * the FacesContext * @param schedule * the schedule * @param day * the day * @param writer * the ResponseWriter * * @throws IOException * when the entries could not be drawn */ protected void writeEntries(FacesContext context, HtmlSchedule schedule, ScheduleDay day, ResponseWriter writer) throws IOException { final String clientId = schedule.getClientId(context); final FormInfo parentFormInfo = RendererUtils.findNestingForm(schedule, context); final String formId = parentFormInfo == null ? null : parentFormInfo.getFormName(); final TreeSet entrySet = new TreeSet(comparator); for (Iterator entryIterator = day.iterator(); entryIterator.hasNext();) { ScheduleEntry entry = (ScheduleEntry) entryIterator.next(); entrySet.add(entry); } if (entrySet.size() > 0) { writer.startElement(HTML.TABLE_ELEM, schedule); writer.writeAttribute(HTML.CELLPADDING_ATTR, "0", null); writer.writeAttribute(HTML.CELLSPACING_ATTR, "0", null); writer.writeAttribute(HTML.STYLE_ATTR, "width: 100%;", null); for (Iterator entryIterator = entrySet.iterator(); entryIterator.hasNext();) { ScheduleEntry entry = (ScheduleEntry) entryIterator.next(); writer.startElement(HTML.TR_ELEM, schedule); writer.startElement(HTML.TD_ELEM, schedule); if (isSelected(schedule, entry)) { writer.writeAttribute(HTML.CLASS_ATTR, getStyleClass(schedule, "selected"), null); } //compose the CSS style for the entry box StringBuffer entryStyle = new StringBuffer(); entryStyle.append("width: 100%;"); String entryColor = getEntryRenderer(schedule).getColor(context, schedule, entry, isSelected(schedule, entry)); if (isSelected(schedule, entry) && entryColor != null) { entryStyle.append(" background-color: "); entryStyle.append(entryColor); entryStyle.append(";"); entryStyle.append(" border-color: "); entryStyle.append(entryColor); entryStyle.append(";"); } writer.writeAttribute(HTML.STYLE_ATTR, entryStyle.toString(), null); // draw the tooltip if (schedule.isTooltip()) { getEntryRenderer(schedule).renderToolTip(context, writer, schedule, entry, isSelected(schedule, entry)); } if (!isSelected(schedule, entry) && !schedule.isReadonly()) { writer.startElement(HTML.ANCHOR_ELEM, schedule); writer.writeAttribute(HTML.HREF_ATTR, "#", null); writer.writeAttribute(HTML.ONCLICK_ATTR, "fireEntrySelected('" + formId + "', '" + clientId + "', '" + entry.getId() + "');", null); } // draw the content getEntryRenderer(schedule).renderContent(context, writer, schedule, day, entry, true, isSelected(schedule, entry)); if (!isSelected(schedule, entry) && !schedule.isReadonly()) { writer.endElement(HTML.ANCHOR_ELEM); } writer.endElement(HTML.TD_ELEM); writer.endElement(HTML.TR_ELEM); } writer.endElement(HTML.TABLE_ELEM); } }
From source file:com.mawujun.util.ObjectUtils.java
/** * Find the "best guess" middle value among comparables. If there is an even * number of total values, the lower of the two middle values will be returned. * @param <T> type of values processed by this method * @param comparator to use for comparisons * @param items to compare// ww w .j a va 2s .c o m * @return T at middle position * @throws NullPointerException if items or comparator is {@code null} * @throws IllegalArgumentException if items is empty or contains {@code null} values * @since 3.0.1 */ public static <T> T median(Comparator<T> comparator, T... items) { Validate.notEmpty(items, "null/empty items"); Validate.noNullElements(items); Validate.notNull(comparator, "null comparator"); TreeSet<T> sort = new TreeSet<T>(comparator); Collections.addAll(sort, items); @SuppressWarnings("unchecked") //we know all items added were T instances T result = (T) sort.toArray()[(sort.size() - 1) / 2]; return result; }
From source file:com.yahoo.ycsb.bulk.hbase.RangePartitioner.java
private synchronized Text[] getCutPoints() throws IOException { if (cutPointArray == null) { String cutFileName = conf.get(CUTFILE_KEY); Path[] cf = DistributedCache.getLocalCacheFiles(conf); if (cf != null) { for (Path path : cf) { if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) { TreeSet<Text> cutPoints = new TreeSet<Text>(); Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString()))); try { while (in.hasNextLine()) cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes()))); } finally { in.close();/*from www. ja va 2s . c o m*/ } cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]); break; } } } if (cutPointArray == null) throw new FileNotFoundException(cutFileName + " not found in distributed cache"); } return cutPointArray; }
From source file:tvbrowser.ui.settings.looksSettings.SkinLNFSettings.java
private String[] getThemePacks() { final TreeSet<String> themepacks = new TreeSet<String>(); themepacks.addAll(Arrays.asList(getThemePacks(new File("themepacks")))); themepacks.addAll(Arrays.asList(getThemePacks(new File(Settings.getUserDirectoryName(), "themepacks")))); if (OperatingSystem.isMacOs()) { themepacks.addAll(/*from www. jav a2 s . c o m*/ Arrays.asList(getThemePacks(new File(Settings.getOSLibraryDirectoryName() + "themepacks")))); } return themepacks.toArray(new String[themepacks.size()]); }
From source file:org.mrgeo.data.accumulo.partitioners.AccumuloMrGeoRangePartitioner.java
private synchronized TileIdWritable[] getCutPoints() throws IOException { if (cutPointArray == null) { String cutFileName = conf.get(CUTFILE_KEY); Path[] cf = DistributedCache.getLocalCacheFiles(conf); if (cf != null) { for (Path path : cf) { if (path.toUri().getPath().endsWith(cutFileName.substring(cutFileName.lastIndexOf('/')))) { TreeSet<Text> cutPoints = new TreeSet<Text>(); Scanner in = new Scanner(new BufferedReader(new FileReader(path.toString()))); try { while (in.hasNextLine()) cutPoints.add(new Text(Base64.decodeBase64(in.nextLine().getBytes()))); } finally { in.close();/*from ww w. ja v a 2 s . com*/ } cutPointArray = cutPoints.toArray(new Text[cutPoints.size()]); break; } } } if (cutPointArray == null) throw new FileNotFoundException(cutFileName + " not found in distributed cache"); } tileIdPointArray = new TileIdWritable[cutPointArray.length]; for (int x = 0; x < cutPointArray.length; x++) { byte[] b = cutPointArray[x].getBytes(); ByteBuffer buffer = ByteBuffer.wrap(b); long k = buffer.getLong(); tileIdPointArray[x] = new TileIdWritable(k); } return tileIdPointArray; }