List of usage examples for com.google.common.collect Sets newTreeSet
public static <E extends Comparable> TreeSet<E> newTreeSet()
From source file:com.moz.fiji.schema.impl.FijiResultRowData.java
/** {@inheritDoc} */ @Override/*from ww w.jav a2 s. c o m*/ public NavigableSet<Long> getTimestamps(final String family, final String qualifier) { final FijiColumnName column = FijiColumnName.create(family, qualifier); validateColumnRequest(column); final NavigableSet<Long> timestamps = Sets.newTreeSet(); for (final FijiCell<?> cell : mResult.narrowView(column)) { timestamps.add(cell.getTimestamp()); } return timestamps; }
From source file:org.dllearner.algorithms.CELOEWrapper.java
@Override protected void learnAxioms() { // get the popularity of the class int popularity = reasoner.getPopularity(entityToDescribe); // we have to skip here if there are not instances for the given class if (popularity == 0) { logger.warn("Cannot compute statements for empty class " + entityToDescribe); return;//from ww w . jav a 2 s. co m } // get positive examples SortedSet<OWLIndividual> posExamples = reasoner.getIndividuals(entityToDescribe, maxNrOfPosExamples); // get negative examples SortedSet<OWLIndividual> negExamples = Sets.newTreeSet(); OWLOntology fragment = buildFragment(posExamples, negExamples); try { fragment.getOWLOntologyManager().saveOntology(fragment, new RDFXMLDocumentFormat(), new FileOutputStream("/tmp/ont.owl")); } catch (OWLOntologyStorageException | FileNotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { AbstractReasonerComponent rc = new ClosedWorldReasoner(new OWLAPIOntology(fragment)); rc.init(); AbstractClassExpressionLearningProblem lp = new PosNegLPStandard(rc, posExamples, negExamples); lp.init(); CELOE la = new CELOE(lp, rc); la.init(); la.start(); } catch (ComponentInitException e) { logger.error("CELOE execution failed.", e); } }
From source file:com.google.devtools.build.lib.skyframe.FileFunction.java
@Override public SkyValue compute(SkyKey skyKey, Environment env) throws FileFunctionException, InterruptedException { RootedPath rootedPath = (RootedPath) skyKey.argument(); RootedPath realRootedPath = null;/*from w w w. j a va 2s.com*/ FileStateValue realFileStateValue = null; PathFragment relativePath = rootedPath.getRelativePath(); // Resolve ancestor symlinks, but only if the current file is not the filesystem root (has no // parent) or a package path root (treated opaquely and handled by skyframe's DiffAwareness // interface). Note that this is the first thing we do - if an ancestor is part of a // symlink cycle, we want to detect that quickly as it gives a more informative error message // than we'd get doing bogus filesystem operations. if (!relativePath.equals(PathFragment.EMPTY_FRAGMENT)) { Pair<RootedPath, FileStateValue> resolvedState = resolveFromAncestors(rootedPath, env); if (resolvedState == null) { return null; } realRootedPath = resolvedState.getFirst(); realFileStateValue = resolvedState.getSecond(); if (realFileStateValue.getType() == Type.NONEXISTENT) { return FileValue.value(rootedPath, FileStateValue.NONEXISTENT_FILE_STATE_NODE, realRootedPath, realFileStateValue); } } FileStateValue fileStateValue; if (rootedPath.equals(realRootedPath)) { fileStateValue = Preconditions.checkNotNull(realFileStateValue, rootedPath); } else { fileStateValue = (FileStateValue) env.getValue(FileStateValue.key(rootedPath)); if (fileStateValue == null) { return null; } } if (realFileStateValue == null) { realRootedPath = rootedPath; realFileStateValue = fileStateValue; } ArrayList<RootedPath> symlinkChain = new ArrayList<>(); TreeSet<Path> orderedSeenPaths = Sets.newTreeSet(); while (realFileStateValue.getType().equals(FileStateValue.Type.SYMLINK)) { symlinkChain.add(realRootedPath); orderedSeenPaths.add(realRootedPath.asPath()); Pair<RootedPath, FileStateValue> resolvedState = getSymlinkTargetRootedPath(realRootedPath, realFileStateValue.getSymlinkTarget(), orderedSeenPaths, symlinkChain, env); if (resolvedState == null) { return null; } realRootedPath = resolvedState.getFirst(); realFileStateValue = resolvedState.getSecond(); } return FileValue.value(rootedPath, fileStateValue, realRootedPath, realFileStateValue); }
From source file:org.apache.druid.query.materializedview.DerivativeDataSourceManager.java
public static ImmutableSet<DerivativeDataSource> getDerivatives(String datasource) { return ImmutableSet.copyOf(derivativesRef.get().getOrDefault(datasource, Sets.newTreeSet())); }
From source file:com.facebook.buck.cli.AuditClasspathCommand.java
@VisibleForTesting int printClasspath(PartialGraph partialGraph) { List<BuildTarget> targets = partialGraph.getTargets(); DependencyGraph graph = partialGraph.getDependencyGraph(); SortedSet<Path> classpathEntries = Sets.newTreeSet(); for (BuildTarget target : targets) { BuildRule rule = graph.findBuildRuleByTarget(target); HasClasspathEntries hasClasspathEntries = getHasClasspathEntriesFrom(rule); if (hasClasspathEntries != null) { classpathEntries.addAll(hasClasspathEntries.getTransitiveClasspathEntries().values()); } else {/*from www . j a v a 2 s . co m*/ throw new HumanReadableException( rule.getFullyQualifiedName() + " is not a java-based" + " build target"); } } for (Path path : classpathEntries) { getStdOut().println(path); } return 0; }
From source file:org.eclipse.sirius.tests.swtbot.PaletteManagerAfterVSMSelectionChange.java
private TreeSet<String> getVisiblePaletteEntries() { Iterable<SectionPaletteDrawer> filtered = Iterables .filter(((SiriusPaletteViewer) editor.getSiriusPaletteGroupEditPartBot().part().getViewer()) .getPaletteRoot().getChildren(), SectionPaletteDrawer.class); TreeSet<String> result = Sets.newTreeSet(); for (PaletteEntry paletteEntry : filtered) { Iterable<PaletteEntry> visibleEntries = Iterables .filter(((SectionPaletteDrawer) paletteEntry).getChildren(), VISIBLE_ENTRY); for (PaletteEntry visiblePaletteEntry : visibleEntries) { result.add(visiblePaletteEntry.getLabel()); }//from w w w .ja v a2 s . com } return result; }
From source file:org.sosy_lab.cpachecker.cpa.predicate.persistence.PredicateAbstractionsStorage.java
private void parseAbstractionTree() throws IOException, PredicateParsingFailedException { Multimap<Integer, Integer> resultTree = LinkedHashMultimap.create(); Map<Integer, AbstractionNode> resultAbstractions = Maps.newTreeMap(); Set<Integer> abstractionsWithParents = Sets.newTreeSet(); String source = abstractionsFile.getName(); try (BufferedReader reader = abstractionsFile.asCharSource(StandardCharsets.US_ASCII) .openBufferedStream()) {// w ww .j a va 2s . c o m // first, read first section with initial set of function definitions Pair<Integer, String> defParsingResult = PredicatePersistenceUtils.parseCommonDefinitions(reader, abstractionsFile.toString()); int lineNo = defParsingResult.getFirst(); String commonDefinitions = defParsingResult.getSecond(); String currentLine; int currentAbstractionId = -1; Optional<Integer> currentLocationId = Optional.absent(); Set<Integer> currentSuccessors = Sets.newTreeSet(); AbstractionsParserState parserState = AbstractionsParserState.EXPECT_NODE_DECLARATION; while ((currentLine = reader.readLine()) != null) { lineNo++; currentLine = currentLine.trim(); if (currentLine.isEmpty()) { // blank lines separates sections continue; } if (currentLine.startsWith("//")) { // comment continue; } if (parserState == AbstractionsParserState.EXPECT_NODE_DECLARATION) { // we expect a new section header if (!currentLine.endsWith(":")) { throw new PredicateParsingFailedException( currentLine + " is not a valid abstraction header", source, lineNo); } currentLine = currentLine.substring(0, currentLine.length() - 1).trim(); // strip off ":" if (currentLine.isEmpty()) { throw new PredicateParsingFailedException("empty header is not allowed", source, lineNo); } if (!NODE_DECLARATION_PATTERN.matcher(currentLine).matches()) { throw new PredicateParsingFailedException( currentLine + " is not a valid abstraction header", source, lineNo); } currentLocationId = null; StringTokenizer declarationTokenizer = new StringTokenizer(currentLine, " (,):"); currentAbstractionId = Integer.parseInt(declarationTokenizer.nextToken()); while (declarationTokenizer.hasMoreTokens()) { String token = declarationTokenizer.nextToken().trim(); if (token.length() > 0) { if (token.startsWith("@")) { currentLocationId = Optional.of(Integer.parseInt(token.substring(1))); } else { int successorId = Integer.parseInt(token); currentSuccessors.add(successorId); } } } parserState = AbstractionsParserState.EXPECT_NODE_ABSTRACTION; } else if (parserState == AbstractionsParserState.EXPECT_NODE_ABSTRACTION) { if (!currentLine.startsWith("(assert ") && currentLine.endsWith(")")) { throw new PredicateParsingFailedException("unexpected line " + currentLine, source, lineNo); } BooleanFormula f; try { f = fmgr.parse(commonDefinitions + currentLine); } catch (IllegalArgumentException e) { throw new PredicateParsingFailedException(e, "Formula parsing", lineNo); } AbstractionNode abstractionNode = new AbstractionNode(currentAbstractionId, f, currentLocationId); resultAbstractions.put(currentAbstractionId, abstractionNode); resultTree.putAll(currentAbstractionId, currentSuccessors); abstractionsWithParents.addAll(currentSuccessors); currentAbstractionId = -1; currentSuccessors.clear(); parserState = AbstractionsParserState.EXPECT_NODE_DECLARATION; } } } // Determine root node Set<Integer> nodesWithNoParents = Sets.difference(resultAbstractions.keySet(), abstractionsWithParents); assert nodesWithNoParents.size() <= 1; if (!nodesWithNoParents.isEmpty()) { this.rootAbstractionId = nodesWithNoParents.iterator().next(); } else { this.rootAbstractionId = null; } // Set results this.abstractions = ImmutableMap.copyOf(resultAbstractions); this.abstractionTree = ImmutableMultimap.copyOf(resultTree); }
From source file:org.apache.lens.cube.metadata.timeline.EndsAndHolesPartitionTimeline.java
@Override public boolean initFromProperties(Map<String, String> properties) throws LensException { first = null;/* w ww .jav a 2 s . c o m*/ latest = null; holes.clear(); String firstStr = properties.get("first"); String latestStr = properties.get("latest"); String holesStr = MetastoreUtil.getNamedStringValue(properties, "holes"); if (!Strings.isNullOrEmpty(firstStr)) { first = TimePartition.of(getUpdatePeriod(), firstStr); } if (!Strings.isNullOrEmpty(latestStr)) { latest = TimePartition.of(getUpdatePeriod(), latestStr); } holes = Sets.newTreeSet(); if (!Strings.isNullOrEmpty(holesStr)) { for (String hole : holesStr.split("\\s*,\\s*")) { holes.add(TimePartition.of(getUpdatePeriod(), hole)); } } return isConsistent(); }
From source file:org.locationtech.geogig.model.impl.LegacyTreeBuilder.java
/** * Only useful to {@link #build() build} the named {@link #empty() empty} tree *///from w w w .jav a 2 s. c om private LegacyTreeBuilder() { obStore = null; treeChanges = Maps.newTreeMap(); featureChanges = Maps.newTreeMap(); deletes = Sets.newTreeSet(); bucketTreesByBucket = Maps.newTreeMap(); pendingWritesCache = Maps.newTreeMap(); original = RevTree.EMPTY; }
From source file:com.cloudera.fts.pig.ProcessSession.java
@Override public DataBag exec(Tuple inputTuple) throws IOException { if (inputTuple.size() != 1) { throw new ExecException("Expecting 1 input, found " + inputTuple.size(), PigException.INPUT); }//from w ww . j a v a2 s . c o m if (inputTuple.get(0) == null) { return null; } if (!(inputTuple.get(0) instanceof DataBag)) { throw new ExecException("Usage ProcessSession(DataBag of (timestamp, page) tuples)", PigException.INPUT); } try { DataBag outBag = mBagFactory.newDefaultBag(); Map<String, Long> timesOnPage = Maps.newHashMap(); long nextStamp = 0L; for (Tuple view : (DataBag) inputTuple.get(0)) { Preconditions.checkElementIndex(1, view.size()); try { long timestamp = Long.parseLong(view.get(0).toString()); String page = view.get(1).toString(); if (nextStamp != 0L) { timesOnPage.put(page, timesOnPage.containsKey(page) ? timesOnPage.get(page) + nextStamp - timestamp : nextStamp - timestamp); } nextStamp = timestamp; } catch (NumberFormatException e) { throw new ExecException("The first element of the tuples should be timestamp, got a " + view.get(0).getClass().getCanonicalName() + " with value " + view.get(0).toString(), PigException.INPUT); } } Set<LongStringPair> sortedTimes = Sets.newTreeSet(); for (Map.Entry<String, Long> entry : timesOnPage.entrySet()) { sortedTimes.add(new LongStringPair(entry.getValue(), entry.getKey())); } int rank = 0; for (LongStringPair pair : sortedTimes) { Tuple tup = mTupleFactory.newTuple(3); tup.set(0, new Integer(++rank)); tup.set(1, new Long(pair.lvalue)); tup.set(2, pair.svalue); outBag.add(tup); } return outBag; } catch (Exception e) { String msg = "Encountered error while processing visits in " + this.getClass().getCanonicalName(); throw new ExecException(msg, PigException.BUG, e); } }