List of usage examples for java.util SortedSet size
int size();
From source file:com.cyberway.issue.net.PublicSuffixes.java
protected static void buildRegex(String stem, StringBuilder regex, SortedSet<String> prefixes) { if (prefixes.isEmpty()) { return;//from w ww . j a va2 s . c o m } if (prefixes.size() == 1 && prefixes.first().equals(stem)) { // avoid unnecessary "(?:)" return; } regex.append("(?:"); if (stem.length() == 0) { regex.append("\n "); // linebreak-space before first character } Iterator<String> iter = prefixes.iterator(); char c = 0; while (iter.hasNext()) { String s = iter.next(); if (s.length() > stem.length()) { char d = s.charAt(stem.length()); if (d == '+') { // convert exception to zero-width-positive-lookahead regex.append("(?=" + s.substring(stem.length() + 1) + ")"); } else { if (d == c) { continue; } c = d; regex.append(c); String newStem = s.substring(0, stem.length() + 1); SortedSet<String> tail = prefixes.tailSet(newStem); SortedSet<String> range = null; successor: for (String candidate : tail) { if (!candidate.equals(newStem)) { range = prefixes.subSet(s, candidate); break successor; } } if (range == null) { range = prefixes.tailSet(s); } buildRegex(newStem, regex, range); } regex.append('|'); } else { // empty suffix; insert dummy to be eaten when loop exits regex.append('@'); } } // eat the trailing '|' (if no empty '@') or dummy regex.deleteCharAt(regex.length() - 1); regex.append(')'); if (stem.length() == 1) { regex.append('\n'); // linebreak for TLDs } }
From source file:com.jakev.genaidl.App.java
private static int processDex(String outputDirectory) { int rtn = 0;/* w ww . j a v a 2 s .c om*/ int i = 0; Set<? extends DexBackedClassDef> classDefs = gDexFile.getClasses(); /* Find all IInterfaces first */ for (DexBackedClassDef classDef : classDefs) { String className = descriptorToDot(classDef.getType()); /* No support AIDL */ if (className.startsWith("android.support")) { continue; } SortedSet<String> interfaces = new TreeSet(classDef.getInterfaces()); if (interfaces.size() != 1) { continue; } if (descriptorToDot(interfaces.first()).equals(IINTERFACE_CLASS)) { /* Now grab the Stub.Proxy, to get the protocols */ String stubProxyName = className + ".Stub.Proxy"; DexBackedClassDef stubProxyDef = getStubProxy(classDefs, stubProxyName); if (stubProxyDef == null) { System.err.println( "[ERROR] Unable to find Stub.Proxy for class: " + stubProxyName + ", Skiping!"); continue; } AidlFile aidl = new AidlFile(className, outputDirectory); String shortClassName = Utils.getShort(className); /* Parse methods */ for (DexBackedMethod method : stubProxyDef.getVirtualMethods()) { String methodName = method.getName(); if (methodName.equals(GET_INT_DESC_METHOD_NAME) || methodName.equals(AS_BINDER_METHOD_NAME)) { continue; } String returnType = descriptorToDot(method.getReturnType()); /* Try to add returnType to imports */ aidl.addImport(returnType); String shortReturnType = Utils.getShort(returnType); StringBuilder paramStringBuilder = new StringBuilder(); int paramOffset = 0; for (MethodParameter param : method.getParameters()) { String dottedName = descriptorToDot(param.getType()); /* Try to add returnType to imports */ aidl.addImport(dottedName); String shortName = Utils.getShort(dottedName); String argName = ""; /* Is the name saved? */ if (param.getName() != null) { argName = param.getName(); } else { argName = "arg" + Integer.toString(paramOffset); } paramStringBuilder.append(shortName + " " + argName + ", "); paramOffset++; } String paramString = paramStringBuilder.toString().replaceAll(",\\s$", ""); /* Let's build the import list */ aidl.addMethod(" " + shortReturnType + " " + methodName + "(" + paramString + ");"); } /* Write it out. */ aidl.writeFile(); } } return rtn; }
From source file:edu.utah.further.core.api.collections.ArrayUtil.java
/** * @param set// ww w . j av a 2 s . com * @return */ public static double[] toDoubleArray(final SortedSet<Integer> set) { final int length = set.size(); final double[] doubleArray = new double[length]; int i = 0; for (final Integer element : set) { doubleArray[i] = element.intValue(); i++; } return doubleArray; }
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 a v a2 s . co m*/ return values.toArray(new String[values.size()]); }
From source file:org.eclipse.skalli.model.Issue.java
/** * Composes a message from a given message and the {@link Issue#getMessage() detail messages * of the given issues. The messages of the issues are appended in form of a bulleted list * (using <tt>"-"</tt> as bullet) in the order defined by {@link Issue#compareTo(Issue)}. * If no explicit <code>message</code> is specified, then only the list of issue messages * is returned. If there is only a single issue given, then {@link Issue#getMessage()} is * returned without leading bullet./*from w w w. j ava 2s . c o m*/ */ @SuppressWarnings("nls") public static String getMessage(String message, SortedSet<Issue> issues) { StringBuilder sb = new StringBuilder(); boolean hasMessage = StringUtils.isNotBlank(message); if (hasMessage) { sb.append(message); } if (issues != null) { int n = issues.size(); int i = 0; for (Issue issue : issues) { message = issue.getMessage(); if (StringUtils.isNotBlank(message)) { if (hasMessage && i == 0 || i > 0) { sb.append("\n"); } if (hasMessage || n > 1) { sb.append(" - "); } sb.append(message); ++i; } } } return sb.toString(); }
From source file:de.uni_potsdam.hpi.asg.logictool.helper.BDDHelper.java
public static BDD mergeBDDs(BDD bdd, NetlistVariable replaceVar, BDD replaceBdd, Netlist netlist) { Set<NetlistVariable> bddvars = BDDHelper.getVars(bdd, netlist); if (!bddvars.contains(replaceVar)) { logger.error("ReplaceVar not in Vars"); return null; }/* w ww .java 2 s. c o m*/ if (bddvars.size() == 1) { // logger.debug("Shortcut"); // logger.debug("BDD: " + getFunctionString(bdd, netlist)); // logger.debug("ReplBDD: " + getFunctionString(replaceBdd, netlist)); // logger.debug("ReplVar: " + replaceVar.getName()); if (isPos(bdd, replaceVar)) { return replaceBdd; } else { return replaceBdd.not(); } // return replaceBdd;//.and(netlist.getFac().one()); } SortedSet<NetlistVariable> newinputs = new TreeSet<>(); newinputs.addAll(bddvars); newinputs.addAll(BDDHelper.getVars(replaceBdd, netlist)); newinputs.remove(replaceVar); // System.out.println("New Inp: " + newinputs.toString()); BDD retVal = netlist.getFac().zero(); BitSet b = new BitSet(newinputs.size()); for (int i = 0; i < Math.pow(2, newinputs.size()); i++) { // System.out.println(i + ": " + BitSetHelper.formatBitset(b, newinputs.size())); int index = 0; BDD bdd_new = bdd; BDD replacBdd_new = replaceBdd; BDD minterm = netlist.getFac().one(); //TODO: xWITH for (NetlistVariable var : newinputs) { if (b.get(index)) { bdd_new = bdd_new.restrict(var.toBDD()); replacBdd_new = replacBdd_new.restrict(var.toBDD()); minterm = minterm.and(var.toBDD()); } else { bdd_new = bdd_new.restrict(var.toNotBDD()); replacBdd_new = replacBdd_new.restrict(var.toNotBDD()); minterm = minterm.and(var.toNotBDD()); } index++; } if (replacBdd_new.isZero()) { bdd_new = bdd_new.restrict(replaceVar.toNotBDD()); } else if (replacBdd_new.isOne()) { bdd_new = bdd_new.restrict(replaceVar.toBDD()); } else { logger.error("Repl BDD should be one or zero"); } if (bdd_new.isZero()) { } else if (bdd_new.isOne()) { retVal.orWith(minterm); } else { logger.error("BDD should be one or zero"); } BitSetHelper.dualNext(b); } // if(bddvars.size() == 1) { // logger.debug("RetVal: " + getFunctionString(retVal, netlist)); // } return retVal; }
From source file:org.codecyprus.android_client.sync.JsonParser.java
public static Category[] parseGetActiveCategories(final String json) throws JSONException, JsonParseException { final Category[] categories = parseGetCategories(json); // filter out finished competitions final SortedSet<Category> activeCategories = new TreeSet<>(); final long now = System.currentTimeMillis(); for (final Category category : categories) { try {/*from ww w . j a va 2s .co m*/ final Date validUntil = CategoriesAdapter.SIMPLE_DATE_FORMAT.parse(category.getValidUntil()); if (now < validUntil.getTime()) { activeCategories.add(category); } } catch (ParseException pe) { Log.e(TAG, pe.getMessage()); } } return activeCategories.toArray(new Category[activeCategories.size()]); }
From source file:org.freud.analysed.javasource.jdom.JavaSourceJdom.java
public static String[] parsePackagePath(final Element element) { SortedSet<Element> packagePathElementSortedSet = new TreeSet<Element>( JdomTreePositionComparator.getInstance()); for (Iterator iterator = element .getDescendants(new ElementFilter(JavaSourceTokenType.IDENT.getName())); iterator.hasNext();) { packagePathElementSortedSet.add((Element) iterator.next()); }/* w w w .ja v a 2s . com*/ boolean endsWithDotStar = (element.getChild(JavaSourceTokenType.DOTSTAR.getName()) != null); final String[] packagePath = new String[(endsWithDotStar) ? packagePathElementSortedSet.size() + 1 : packagePathElementSortedSet.size()]; int i = 0; for (Element pathElement : packagePathElementSortedSet) { packagePath[i++] = pathElement.getTextTrim(); } if (endsWithDotStar) { packagePath[i] = "*"; } return packagePath; }
From source file:org.mwc.debrief.track_shift.views.StackedDotHelper.java
/** * sort out data of interest/*from www . j a va 2 s . co m*/ * */ public static TreeSet<Doublet> getDoublets(final TrackWrapper sensorHost, final ISecondaryTrack targetTrack, final boolean onlyVis, final boolean needBearing, final boolean needFrequency) { final TreeSet<Doublet> res = new TreeSet<Doublet>(); // friendly fix-wrapper to save us repeatedly creating it final FixWrapper index = new FixWrapper(new Fix(null, new WorldLocation(0, 0, 0), 0.0, 0.0)); // loop through our sensor data final Enumeration<Editable> sensors = sensorHost.getSensors().elements(); if (sensors != null) { while (sensors.hasMoreElements()) { final SensorWrapper wrapper = (SensorWrapper) sensors.nextElement(); if (!onlyVis || (onlyVis && wrapper.getVisible())) { final Enumeration<Editable> cuts = wrapper.elements(); while (cuts.hasMoreElements()) { final SensorContactWrapper scw = (SensorContactWrapper) cuts.nextElement(); if (!onlyVis || (onlyVis && scw.getVisible())) { // is this cut suitable for what we're looking for? if (needBearing) { if (!scw.getHasBearing()) continue; } // aaah, but does it meet the frequency requirement? if (needFrequency) { if (!scw.getHasFrequency()) continue; } FixWrapper targetFix = null; TrackSegment targetParent = null; if (targetTrack != null) { // right, get the track segment and fix nearest to // this // DTG final Enumeration<Editable> trkData = targetTrack.segments(); final Vector<TrackSegment> _theSegments = new Vector<TrackSegment>(); while (trkData.hasMoreElements()) { final Editable thisI = trkData.nextElement(); if (thisI instanceof SegmentList) { final SegmentList thisList = (SegmentList) thisI; final Enumeration<Editable> theElements = thisList.elements(); while (theElements.hasMoreElements()) { final TrackSegment ts = (TrackSegment) theElements.nextElement(); _theSegments.add(ts); } } if (thisI instanceof TrackSegment) { final TrackSegment ts = (TrackSegment) thisI; _theSegments.add(ts); } } if (_theSegments.size() > 0) { final Iterator<TrackSegment> iter = _theSegments.iterator(); while (iter.hasNext()) { final TrackSegment ts = iter.next(); final TimePeriod validPeriod = new TimePeriod.BaseTimePeriod(ts.startDTG(), ts.endDTG()); if (validPeriod.contains(scw.getDTG())) { // sorted. here we go targetParent = ts; // create an object with the right time index.getFix().setTime(scw.getDTG()); // and find any matching items final SortedSet<Editable> items = ts.tailSet(index); if (items.size() > 0) { targetFix = (FixWrapper) items.first(); } } } } } final Watchable[] matches = sensorHost.getNearestTo(scw.getDTG()); if ((matches != null) && (matches.length > 0) && (targetFix != null)) { final FixWrapper hostFix = (FixWrapper) matches[0]; final Doublet thisDub = new Doublet(scw, targetFix, targetParent, hostFix); // if we've no target track add all the points if (targetTrack == null) { // store our data res.add(thisDub); } else { // if we've got a target track we only add points // for which we // have // a target location if (targetFix != null) { // store our data res.add(thisDub); } } // if we know the track } // if there are any matching items // if we find a match } // if cut is visible } // loop through cuts } // if sensor is visible } // loop through sensors } // if there are sensors return res; }
From source file:org.broadinstitute.gatk.engine.recalibration.BQSRGatherer.java
/** * Gathers the input recalibration reports into a single report. * * @param inputs Input recalibration GATK reports * @return gathered recalibration GATK report */// ww w . ja v a 2 s. co m public static GATKReport gatherReport(final List<File> inputs) { final SortedSet<String> allReadGroups = new TreeSet<String>(); final LinkedHashMap<File, Set<String>> inputReadGroups = new LinkedHashMap<File, Set<String>>(); // Get the read groups from each input report for (final File input : inputs) { final Set<String> readGroups = RecalibrationReport.getReadGroups(input); inputReadGroups.put(input, readGroups); allReadGroups.addAll(readGroups); } // Log the read groups that are missing from specific inputs for (Map.Entry<File, Set<String>> entry : inputReadGroups.entrySet()) { final File input = entry.getKey(); final Set<String> readGroups = entry.getValue(); if (allReadGroups.size() != readGroups.size()) { // Since this is not completely unexpected, more than debug, but less than a proper warning. logger.info(MISSING_READ_GROUPS + ": " + input.getAbsolutePath()); for (final Object readGroup : CollectionUtils.subtract(allReadGroups, readGroups)) { logger.info(" " + readGroup); } } } RecalibrationReport generalReport = null; for (File input : inputs) { final RecalibrationReport inputReport = new RecalibrationReport(input, allReadGroups); if (inputReport.isEmpty()) { continue; } if (generalReport == null) generalReport = inputReport; else generalReport.combine(inputReport); } if (generalReport == null) throw new ReviewedGATKException(EMPTY_INPUT_LIST); generalReport.calculateQuantizedQualities(); return generalReport.createGATKReport(); }