List of usage examples for com.google.common.collect Sets newTreeSet
public static <E> TreeSet<E> newTreeSet(Comparator<? super E> comparator)
From source file:cc.kave.episodes.mining.evaluation.ProposalHelper.java
public static TreeSet<Tuple<Integer, Set<Fact>>> createFactsSortedSet() { final TreeSet<Tuple<Integer, Set<Fact>>> res = Sets.newTreeSet(new Comparator<Tuple<Integer, Set<Fact>>>() { @Override/* www. j ava2 s.co m*/ public int compare(final Tuple<Integer, Set<Fact>> o1, final Tuple<Integer, Set<Fact>> o2) { int valueOrdering = Double.compare(o2.getFirst(), o1.getFirst()); return valueOrdering; } }); return res; }
From source file:org.apache.isis.core.metamodel.layout.DeweyOrderSet.java
public static DeweyOrderSet createOrderSet(final List<? extends IdentifiedHolder> identifiedHolders) { final SortedMap<String, SortedSet<IdentifiedHolder>> sortedMembersByGroup = Maps.newTreeMap(); final SortedSet<IdentifiedHolder> nonAnnotatedGroup = Sets.newTreeSet(new MemberIdentifierComparator()); // spin over all the members and put them into a Map of SortedSets // any non-annotated members go into additional nonAnnotatedGroup set. for (final IdentifiedHolder identifiedHolder : identifiedHolders) { final MemberOrderFacet memberOrder = identifiedHolder.getFacet(MemberOrderFacet.class); if (memberOrder == null) { nonAnnotatedGroup.add(identifiedHolder); continue; }// w ww. j a v a 2 s.c o m final SortedSet<IdentifiedHolder> sortedMembersForGroup = getSortedSet(sortedMembersByGroup, memberOrder.name()); sortedMembersForGroup.add(identifiedHolder); } // add the non-annotated group to the first "" group. final SortedSet<IdentifiedHolder> defaultSet = getSortedSet(sortedMembersByGroup, ""); defaultSet.addAll(nonAnnotatedGroup); // create OrderSets, wiring up parents and children. // since sortedMembersByGroup is a SortedMap, the // iteration will be in alphabetical order (ie parent groups before // their children). final Set<String> groupNames = sortedMembersByGroup.keySet(); final SortedMap<String, DeweyOrderSet> orderSetsByGroup = Maps.newTreeMap(); for (final String string : groupNames) { final String groupName = string; final DeweyOrderSet deweyOrderSet = new DeweyOrderSet(groupName); orderSetsByGroup.put(groupName, deweyOrderSet); ensureParentFor(orderSetsByGroup, deweyOrderSet); } // now populate the OrderSets for (final String groupName : groupNames) { final DeweyOrderSet deweyOrderSet = orderSetsByGroup.get(groupName); // REVIEW: something fishy happens here with casting, hence warnings // left in final SortedSet sortedMembers = sortedMembersByGroup.get(groupName); deweyOrderSet.addAll(sortedMembers); deweyOrderSet.copyOverChildren(); } return orderSetsByGroup.get(""); }
From source file:org.eel.kitchen.jsonschema.keyword.PropertiesKeywordValidator.java
@Override public void validate(final ValidationContext context, final ValidationReport report, final JsonNode instance) { final Set<String> fields = JacksonUtils.fieldNames(instance); if (fields.containsAll(required)) return;/* w w w . j a v a 2 s. c om*/ final Set<String> requiredSorted = Sets.newTreeSet(required); final Set<String> missing = Sets.newTreeSet(required); missing.removeAll(fields); final ValidationMessage.Builder msg = newMsg().addInfo("required", requiredSorted) .addInfo("missing", missing).setMessage("required property(ies) not found"); report.addMessage(msg.build()); }
From source file:org.fenixedu.qubdocs.academic.documentRequests.providers.DiplomaSupplementExtraCurricularCoursesDataProvider.java
@Override public Set<CurriculumEntry> getCurriculumEntries() { if (this.curriculumEntries == null) { this.curriculumEntries = Sets.newTreeSet(CurriculumEntry.NAME_COMPARATOR(locale)); Collection<Registration> registrationList = includeAllRegistrations ? registration.getStudent().getActiveRegistrations() : Collections.singleton(registration); Set<CurriculumLine> extraCurricularCurriculumLines = Sets.newHashSet(); for (Registration activeRegistration : registrationList) { extraCurricularCurriculumLines.addAll(activeRegistration.getExtraCurricularCurriculumLines()); }//from w w w . ja v a2 s. c o m if (cycleType == CycleType.FIRST_CYCLE) { // Check for second cycle curriculum group final CycleCurriculumGroup secondCycleCurriculumGroup = registration.getLastStudentCurricularPlan() .getCycle(CycleType.SECOND_CYCLE); if (secondCycleCurriculumGroup != null) { extraCurricularCurriculumLines.addAll(secondCycleCurriculumGroup.getAllCurriculumLines()); } } for (CurriculumLine curriculumLine : extraCurricularCurriculumLines) { if (!curriculumLine.isApproved()) { continue; } if (curriculumLine.isEnrolment() && ((Enrolment) curriculumLine).isSourceOfAnyCreditsInCurriculum()) { continue; } if (curriculumLine.isDismissal() && !((Dismissal) curriculumLine).getCredits().isSubstitution()) { continue; } if (curriculumLine.isDismissal() && !includeSubstitutionCreditations) { continue; } curriculumEntries.addAll(CurriculumEntry.transform(registration, curriculumLine.getCurriculum().getCurriculumEntries(), remarksDataProvider)); } } return this.curriculumEntries; }
From source file:org.auraframework.component.auradev.ShowDependenciesModel.java
public ShowDependenciesModel(final String cmpname) { AuraContext context = Aura.getContextService().getCurrentContext(); DefDescriptor<?> descriptor;//www. j av a 2 s. c o m SortedSet<DefDescriptor<?>> sorted; MasterDefRegistry mdr = context.getDefRegistry(); String uid; this.error = true; this.items = Lists.newArrayList(); try { Definition def = Aura.getDefinitionService().getDefinition(cmpname, DefType.COMPONENT, DefType.APPLICATION); if (def == null) { this.title = "Unable to find component for input " + AuraTextUtil.escapeForHTML(cmpname); return; } descriptor = def.getDescriptor(); uid = mdr.getUid(null, descriptor); sorted = Sets.newTreeSet(mdr.getDependencies(uid)); this.title = String.format("Dependencies for %s [uid=%s]", descriptor.toString(), uid); this.error = false; } catch (Throwable t) { // If we get an exception, try to tell the user what happened. this.title = String.format("%s: %s : list of reached components...", AuraTextUtil.escapeForHTML(cmpname), t.getMessage()); sorted = Sets.newTreeSet(mdr.filterRegistry(null).keySet()); } try { for (DefDescriptor<?> dep : sorted) { Map<String, Object> itemData = Maps.newHashMap(); Definition def = mdr.getDef(dep); boolean valid = false; String hash = "------"; if (def != null) { valid = def.isValid(); hash = String.valueOf(def.getOwnHash()); } itemData.put("descriptor", dep.toString()); itemData.put("type", dep.getDefType()); itemData.put("uid", hash); itemData.put("error", !valid); this.items.add(itemData); } } catch (QuickFixException qfe) { // nothing useful to do here. this.error = true; } }
From source file:org.fenixedu.academic.ui.renderers.providers.enrollment.bolonha.ExecutionPeriodsForEnrolmentProvider.java
static private ExecutionYear getFirstExecutionYear(final StudentCurricularPlan plan) { final SortedSet<ExecutionYear> result = Sets.newTreeSet(ExecutionYear.COMPARATOR_BY_YEAR); // should be enough, if it wasn't for wrong data result.add(ExecutionYear.readByDateTime(plan.getStartDateYearMonthDay().toDateTimeAtCurrentTime())); // whatever the case, the SCP lines must be able to be accessible final ExecutionSemester firstSemester = plan.getFirstExecutionPeriod(); final ExecutionYear firstScpYear = firstSemester == null ? null : firstSemester.getExecutionYear(); if (firstScpYear != null) { result.add(firstScpYear);// ww w .j a v a2 s. c o m } return result.first(); }
From source file:org.jclouds.azureblob.blobstore.functions.ResourceToListBlobsResponse.java
public ListBlobsResponse apply(PageSet<? extends StorageMetadata> list) { Iterable<BlobProperties> contents = Iterables .transform(Iterables.filter(list, new Predicate<StorageMetadata>() { public boolean apply(StorageMetadata input) { return input.getType() == StorageType.BLOB; }/*w ww . j ava 2s . com*/ }), new Function<StorageMetadata, BlobProperties>() { public MutableBlobProperties apply(StorageMetadata from) { return blob2ObjectMd.apply((BlobMetadata) from); } }); SortedSet<String> commonPrefixes = Sets .newTreeSet(Iterables.transform(Iterables.filter(list, new Predicate<StorageMetadata>() { public boolean apply(StorageMetadata input) { return input.getType() == StorageType.RELATIVE_PATH; } }), new Function<StorageMetadata, String>() { public String apply(StorageMetadata from) { return from.getName(); } })); return new HashSetListBlobsResponse(contents, null, null, null, null, list.getNextMarker(), "/", commonPrefixes); }
From source file:org.fenixedu.academic.ui.renderers.providers.SourceExecutionCoursesProvider.java
static protected Set<ExecutionCourse> getExecutionCourses(final Degree degree, final AcademicInterval academicInterval) { final Set<ExecutionCourse> result = Sets.newTreeSet(ExecutionCourse.EXECUTION_COURSE_NAME_COMPARATOR); result.addAll(degree.getExecutionCourses(academicInterval)); return result; }
From source file:org.opentestsystem.delivery.testreg.upload.validator.fileformat.DuplicateRecordProcessor.java
private DuplicateUniquePair findDuplicates(final List<DataRecord> dataRecordList) { final List<DataRecord> duplicates = Lists.newArrayList(); final Set<DataRecord> uniqueRecordSet = Sets.newTreeSet(new DataRecordComparator()); for (final DataRecord record : dataRecordList) { if (!uniqueRecordSet.add(record)) { duplicates.add(record);/* w ww . j a v a 2s .co m*/ } } return new DuplicateUniquePair(duplicates, sort(uniqueRecordSet)); }
From source file:com.textocat.textokit.segmentation.heur.SentenceSplitter.java
@Override public void process(JCas jCas) throws AnalysisEngineProcessException { AnnotationIndex<Token> visibleTokenIdx = jCas.getAnnotationIndex(Token.class); if (visibleTokenIdx.size() == 0) { return;// ww w. j a v a 2 s .co m } NavigableSet<TokenBase> boundaryCandidates = Sets .newTreeSet(AnnotationOffsetComparator.instance(TokenBase.class)); for (Class<? extends TokenBase> bAnnoType : sentenceEndTokenTypes) { boundaryCandidates.addAll(JCasUtil.select(jCas, bAnnoType)); } String txt = jCas.getDocumentText(); FSIterator<Token> visibleIter = visibleTokenIdx.iterator(); // get first sentence start visibleIter.moveToFirst(); Token lastSentenceStart = visibleIter.get(); for (TokenBase boundaryCand : boundaryCandidates) { if (isBefore(boundaryCand, lastSentenceStart)) { continue; } Token nextVisToken = getNext(visibleIter, boundaryCand); Token prevVisToken = getPrevious(visibleIter, boundaryCand); boolean isBoundary = nextVisToken == null; if (!isBoundary && boundaryCand instanceof Token) { // i.e. candidate is a visible token // here nextVisToken is never null isBoundary = isBreakBetween(txt, boundaryCand, nextVisToken) || (distanceBetween(boundaryCand, nextVisToken) > 0 && !isAbbreviation(prevVisToken) && !isSW(nextVisToken)); } if (!isBoundary && boundaryCand instanceof WhiteSpace) { // candidate is a break isBoundary = !isSW(nextVisToken); } if (isBoundary) { Token sentEnd; if (boundaryCand instanceof Token) { sentEnd = (Token) boundaryCand; } else { sentEnd = prevVisToken; } makeSentence(jCas, lastSentenceStart, sentEnd); visibleIter.moveTo(sentEnd); visibleIter.moveToNext(); if (visibleIter.isValid()) { lastSentenceStart = visibleIter.get(); } else { lastSentenceStart = null; break; } } } if (lastSentenceStart != null) { visibleIter.moveToLast(); Token sentEnd = visibleIter.get(); makeSentence(jCas, lastSentenceStart, sentEnd); lastSentenceStart = null; } }