List of usage examples for java.util SortedSet addAll
boolean addAll(Collection<? extends E> c);
From source file:net.big_oh.algorithms.search.informed.astar.AStarSearch.java
public AStarSearchResult<SearchNodeType> doSearch(SearchNodeType startNode) { Duration searchDuration = new Duration(); // create priority queue SortedSet<SearchNodeType> prioritySet = new TreeSet<SearchNodeType>(new Comparator<SearchNodeType>() { public int compare(SearchNodeType o1, SearchNodeType o2) { switch (searchType) { case MIN: return Double.compare(getF(o1), getF(o2)); case MAX: return -1 * Double.compare(getF(o1), getF(o2)); default: throw new RuntimeException("Unexpected search type: " + searchType); }/* w w w .j a va 2 s .c o m*/ } }); // enqueue the start node prioritySet.add(startNode); // declare tracking member variables int numSearchNodesGenerated = 0; int numSearchNodesConsidered = 0; int maxPossibleBranchingFactor = 1; // search for a goal state SearchNodeType goalNode = null; while (!prioritySet.isEmpty()) { // Remove the best candidate node from the queue SearchNodeType candidateSearchNode = prioritySet.first(); prioritySet.remove(candidateSearchNode); numSearchNodesConsidered++; // get the next search node candidates Collection<SearchNodeType> nextSearchNodes = nextNodesGenerator.getNextSearchNodes(candidateSearchNode); // do some record keeping numSearchNodesGenerated += nextSearchNodes.size(); maxPossibleBranchingFactor = Math.max(maxPossibleBranchingFactor, nextSearchNodes.size()); if (candidateSearchNode.isGoalState()) { // sanity check assert (nextSearchNodes.isEmpty()); // found an optimal solution goalNode = candidateSearchNode; break; } else { // enqueue all next search nodes Duration enqueueDuration = new Duration(); prioritySet.addAll(nextSearchNodes); if (logger.isDebugEnabled()) { logger.debug("Enqueued " + nextSearchNodes.size() + " A* search nodes in " + enqueueDuration.stop() + " milliseconds."); } } } // return the search results AStarSearchResult<SearchNodeType> results = new AStarSearchResult<SearchNodeType>(goalNode, numSearchNodesGenerated, calculateEffectiveBranchingFactor(goalNode.getNodeDepth(), numSearchNodesConsidered, maxPossibleBranchingFactor)); logger.debug("Completed an A* search in " + searchDuration.stop() + " milliseconds."); logger.debug("Number of nodes generated: " + results.getNumSearchNodesGenerated()); logger.debug("Depth of goal node: " + results.getGoalNode().getNodeDepth()); logger.debug("Effective branching factor: " + results.getEfectiveBranchingFactor()); return results; }
From source file:org.apache.uima.ruta.engine.HtmlConverter.java
@Override public void process(JCas jcaz) throws AnalysisEngineProcessException { JCas jcas;/* ww w .j a v a 2s .c o m*/ try { if (inputViewName != null) { jcas = jcaz.getView(inputViewName); } else { jcas = jcaz; } } catch (CASException e1) { throw new AnalysisEngineProcessException(e1.getCause()); } // init: String documentText = jcas.getDocumentText(); String splitSeq = documentText.contains("\r\n") ? "\r\n" : "\n"; map = new int[documentText.length() + 1]; JCas modview = null; try { // check if view already exists: Iterator<JCas> viewIterator = jcas.getViewIterator(); while (viewIterator.hasNext()) { JCas jCas2 = (JCas) viewIterator.next(); if (jCas2.getViewName().equals(modifiedViewName)) { modview = jCas2; getContext().getLogger().log(Level.WARNING, "view with name \"" + modifiedViewName + "\" already exists."); } } if (modview == null) { modview = jcas.createView(modifiedViewName); } } catch (CASException e) { e.printStackTrace(); return; } SortedSet<HtmlConverterPSpan> visibleSpansSoFar = new TreeSet<HtmlConverterPSpan>(); SortedSet<HtmlConverterPSpan> linebreaksFromHtmlTags = new TreeSet<HtmlConverterPSpan>(); SortedSet<HtmlConverterPSpan> gapsFromHtmlTags = new TreeSet<HtmlConverterPSpan>(); // process try { Parser parser = new Parser(documentText); NodeList list = parser.parse(null); HtmlConverterVisitor visitor = new HtmlConverterVisitor(newlineInducingTags, newlineInducingTagRegExp, gapInducingTags, gapText, skipWhitespaces, processAll); list.visitAllNodesWith(visitor); visibleSpansSoFar = visitor.getTextSpans(); linebreaksFromHtmlTags = visitor.getLinebreaksFromHtmlTags(); gapsFromHtmlTags = visitor.getGapsFromHtmlTags(); } catch (ParserException e) { throw new AnalysisEngineProcessException(e); } if (replaceLinebreaks) { visibleSpansSoFar = this.handleLinebreaksInDocumentText(visibleSpansSoFar, splitSeq); } if (conversionPolicy.equals("heuristic")) { visibleSpansSoFar = this.htmlDecoding(visibleSpansSoFar); } else if (conversionPolicy.equals("explicit")) { for (int i = 0; i < conversionPatterns.length; i++) { String pat = conversionPatterns[i]; String rep = conversionReplacements[i]; visibleSpansSoFar = this.handleConversion(visibleSpansSoFar, pat, rep); } } visibleSpansSoFar.addAll(linebreaksFromHtmlTags); visibleSpansSoFar.addAll(gapsFromHtmlTags); // create new doc-text and the map from deletions and visible-text-spans: StringBuffer sbu = new StringBuffer(documentText.length()); int originalOffsetI = 0; int outOffset = 0; for (HtmlConverterPSpan vis : visibleSpansSoFar) { final int begin = vis.getBegin(); final int end = vis.getEnd(); // map text before annotation: while (originalOffsetI < begin) { map[originalOffsetI++] = outOffset; } // get and map text/replacement: String s = ""; if (vis instanceof HtmlConverterPSpanReplacement) { // conversion/replacement: s = vis.getTxt(); // asserts that s is shorter than the original source while (originalOffsetI < begin + s.length()) { map[originalOffsetI++] = outOffset++; } while (originalOffsetI < end) { map[originalOffsetI++] = outOffset; } } else { // simple annotation: s = documentText.substring(begin, end); while (originalOffsetI < end) { map[originalOffsetI++] = outOffset++; } } sbu.append(s); } while (originalOffsetI < documentText.length()) { map[originalOffsetI++] = outOffset; } map[documentText.length()] = outOffset + 1; // handle doc end separately String modTxt = sbu.toString(); modview.setDocumentText(modTxt); // copy annotations using the 'map': try { mapAnnotations(jcas, map, modifiedViewName); } catch (CASException e) { e.printStackTrace(); } }
From source file:pt.ist.expenditureTrackingSystem.presentationTier.actions.organization.OrganizationAction.java
private SortedSet<Unit> sortUnitsByCostCenter(final Set<Unit> units) { final SortedSet<Unit> result = new TreeSet<Unit>(new Comparator<Unit>() { @Override/*from w w w . ja v a 2s .c om*/ public int compare(final Unit u1, final Unit u2) { final int cc1 = getMinCostCenter(u1); final int cc2 = getMinCostCenter(u2); return cc1 - cc2; } private int getMinCostCenter(final Unit unit) { if (unit instanceof CostCenter) { final CostCenter costCenter = (CostCenter) unit; return Integer.parseInt(costCenter.getCostCenter()); } int min = Integer.MAX_VALUE; for (final Unit subUnit : unit.getSubUnitsSet()) { final int cc = getMinCostCenter(subUnit); min = Math.min(min, cc); } return min; } }); result.addAll(units); return result; }
From source file:org.apache.atlas.hive.hook.HiveHookIT.java
private String sortEventsAndGetProcessQualifiedName(final HiveHook.HiveEventContext event) throws HiveException { SortedSet<ReadEntity> sortedHiveInputs = event.getInputs() == null ? null : new TreeSet<ReadEntity>(entityComparator); SortedSet<WriteEntity> sortedHiveOutputs = event.getOutputs() == null ? null : new TreeSet<WriteEntity>(entityComparator); if (event.getInputs() != null) { sortedHiveInputs.addAll(event.getInputs()); }/*from www.j av a2 s .co m*/ if (event.getOutputs() != null) { sortedHiveOutputs.addAll(event.getOutputs()); } return getProcessQualifiedName(hiveMetaStoreBridge, event, sortedHiveInputs, sortedHiveOutputs, getSortedProcessDataSets(event.getInputs()), getSortedProcessDataSets(event.getOutputs())); }
From source file:net.sourceforge.fenixedu.domain.DegreeCurricularPlan.java
public boolean canSubmitImprovementMarkSheets(final ExecutionYear executionYear) { SortedSet<ExecutionDegree> sortedExecutionDegrees = new TreeSet<ExecutionDegree>( ExecutionDegree.EXECUTION_DEGREE_COMPARATORY_BY_YEAR); sortedExecutionDegrees.addAll(getExecutionDegreesSet()); return sortedExecutionDegrees.last().getExecutionYear().equals(executionYear.getPreviousExecutionYear()); }
From source file:org.apache.atlas.hive.hook.HiveHookIT.java
private void assertProcessIsNotRegistered(HiveHook.HiveEventContext event) throws Exception { try {// w w w . ja va 2s . c om SortedSet<ReadEntity> sortedHiveInputs = event.getInputs() == null ? null : new TreeSet<ReadEntity>(entityComparator); SortedSet<WriteEntity> sortedHiveOutputs = event.getOutputs() == null ? null : new TreeSet<WriteEntity>(entityComparator); if (event.getInputs() != null) { sortedHiveInputs.addAll(event.getInputs()); } if (event.getOutputs() != null) { sortedHiveOutputs.addAll(event.getOutputs()); } String processQFName = getProcessQualifiedName(hiveMetaStoreBridge, event, sortedHiveInputs, sortedHiveOutputs, getSortedProcessDataSets(event.getInputs()), getSortedProcessDataSets(event.getOutputs())); LOG.debug("Searching for process with query {}", processQFName); assertEntityIsNotRegistered(HiveDataTypes.HIVE_PROCESS.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, processQFName); } catch (Exception e) { LOG.error("Exception : ", e); } }
From source file:org.apache.atlas.hive.hook.HiveHookIT.java
private String assertProcessIsRegistered(final HiveHook.HiveEventContext event, final Set<ReadEntity> inputTbls, final Set<WriteEntity> outputTbls) throws Exception { try {// w w w. j av a 2 s.c o m SortedSet<ReadEntity> sortedHiveInputs = event.getInputs() == null ? null : new TreeSet<ReadEntity>(entityComparator); SortedSet<WriteEntity> sortedHiveOutputs = event.getOutputs() == null ? null : new TreeSet<WriteEntity>(entityComparator); if (event.getInputs() != null) { sortedHiveInputs.addAll(event.getInputs()); } if (event.getOutputs() != null) { sortedHiveOutputs.addAll(event.getOutputs()); } String processQFName = getProcessQualifiedName(hiveMetaStoreBridge, event, sortedHiveInputs, sortedHiveOutputs, getSortedProcessDataSets(inputTbls), getSortedProcessDataSets(outputTbls)); LOG.debug("Searching for process with query {}", processQFName); return assertEntityIsRegistered(HiveDataTypes.HIVE_PROCESS.getName(), AtlasClient.REFERENCEABLE_ATTRIBUTE_NAME, processQFName, new AssertPredicate() { @Override public void assertOnEntity(final Referenceable entity) throws Exception { List<String> recentQueries = (List<String>) entity.get("recentQueries"); Assert.assertEquals(recentQueries.get(0), lower(event.getQueryStr())); } }); } catch (Exception e) { LOG.error("Exception : ", e); throw e; } }
From source file:net.sourceforge.fenixedu.domain.student.Student.java
public SortedSet<Attends> getAttendsForExecutionPeriod(ExecutionSemester executionSemester) { SortedSet<Attends> attends = new TreeSet<Attends>(Attends.ATTENDS_COMPARATOR_BY_EXECUTION_COURSE_NAME); for (Registration registration : getRegistrationsSet()) { attends.addAll(registration.getAttendsForExecutionPeriod(executionSemester)); }// w w w . j a v a 2s .co m return attends; }
From source file:org.apache.fop.fonts.truetype.TTFFile.java
/** * Returns the order in which the tables in a TrueType font should be written to file. * @param directoryTabs the map that is to be sorted. * @return TTFTablesNames[] an array of table names sorted in the order they should appear in * the TTF file./* w w w .j av a 2 s . co m*/ */ SortedSet<Map.Entry<TTFTableName, TTFDirTabEntry>> sortDirTabMap( Map<TTFTableName, TTFDirTabEntry> directoryTabs) { SortedSet<Map.Entry<TTFTableName, TTFDirTabEntry>> sortedSet = new TreeSet<Map.Entry<TTFTableName, TTFDirTabEntry>>( new Comparator<Map.Entry<TTFTableName, TTFDirTabEntry>>() { public int compare(Entry<TTFTableName, TTFDirTabEntry> o1, Entry<TTFTableName, TTFDirTabEntry> o2) { return (int) (o1.getValue().getOffset() - o2.getValue().getOffset()); } }); sortedSet.addAll(directoryTabs.entrySet()); return sortedSet; }
From source file:net.sourceforge.fenixedu.domain.student.Student.java
public SortedSet<ExternalEnrolment> getSortedExternalEnrolments() { final SortedSet<ExternalEnrolment> result = new TreeSet<ExternalEnrolment>( ExternalEnrolment.COMPARATOR_BY_NAME); for (final Registration registration : getRegistrationsSet()) { result.addAll(registration.getExternalEnrolmentsSet()); }// w w w. j a v a 2 s . co m return result; }