List of usage examples for com.google.common.collect Iterators addAll
public static <T> boolean addAll(Collection<T> addTo, Iterator<? extends T> iterator)
From source file:org.sosy_lab.cpachecker.util.expressions.ExpressionTrees.java
public static <LeafType> ExpressionTree<LeafType> toDNF(ExpressionTree<LeafType> pExpressionTree) { if (isInDNF(pExpressionTree)) { return pExpressionTree; }/*w ww. ja v a 2 s . co m*/ if (isOr(pExpressionTree)) { return Or.of(getChildren(pExpressionTree) .transform(new Function<ExpressionTree<LeafType>, ExpressionTree<LeafType>>() { @Override public ExpressionTree<LeafType> apply(ExpressionTree<LeafType> pExpressionTree) { return toDNF(pExpressionTree); } })); } assert isAnd(pExpressionTree); Iterator<ExpressionTree<LeafType>> elementIterator = getChildren(pExpressionTree).iterator(); if (!elementIterator.hasNext()) { return ExpressionTrees.getTrue(); } ExpressionTree<LeafType> first = elementIterator.next(); if (!elementIterator.hasNext()) { return first; } Collection<ExpressionTree<LeafType>> rest = new ArrayList<>(); Iterators.addAll(rest, elementIterator); ExpressionTree<LeafType> firstDNF = toDNF(first); ExpressionTree<LeafType> restDNF = toDNF(And.of(rest)); final Iterable<ExpressionTree<LeafType>> combinatorsA; if (isLeaf(firstDNF)) { combinatorsA = Collections.singleton(firstDNF); } else { combinatorsA = getChildren(firstDNF); } final Iterable<ExpressionTree<LeafType>> combinatorsB; if (isLeaf(restDNF)) { combinatorsB = Collections.singleton(restDNF); } else { combinatorsB = getChildren(restDNF); } Collection<ExpressionTree<LeafType>> newClauses = new ArrayList<>(); for (ExpressionTree<LeafType> combinatorA : combinatorsA) { for (ExpressionTree<LeafType> combinatorB : combinatorsB) { newClauses.add(And.of(ImmutableList.<ExpressionTree<LeafType>>of(combinatorA, combinatorB))); } } return Or.of(newClauses); }
From source file:org.obeonetwork.dsl.sysml.design.tests.plugin.manual.ServiceTestsUtils.java
private static List<String> getAllSysmlOperations() { // Obtain a new resource set ResourceSet resSet = new ResourceSetImpl(); // Create a resource Resource res = resSet.getResource(URI.createURI("http://www.eclipse.org/papyrus/0.7.0/SysML"), true); EObject root = res.getContents().get(0); // Get all eOperations List<EObject> sysmlOperations = Lists.newArrayList(); Iterators.addAll(sysmlOperations, Iterators.filter(root.eAllContents(), Predicates.instanceOf(EOperation.class))); // Get eOperation names List<String> result = Lists.newArrayList(); for (EObject sysmlOperation : sysmlOperations) { result.add(((EOperation) sysmlOperation).getName()); }//www. ja v a2 s. c o m return result; }
From source file:com.google.googlejavaformat.java.Formatter.java
/** * Converts zero-indexed, [closed, open) line ranges in the given source file to character ranges. */// w ww . ja v a 2s . c o m public static RangeSet<Integer> lineRangesToCharRanges(String input, RangeSet<Integer> lineRanges) { List<Integer> lines = new ArrayList<>(); Iterators.addAll(lines, Newlines.lineOffsetIterator(input)); lines.add(input.length() + 1); final RangeSet<Integer> characterRanges = TreeRangeSet.create(); for (Range<Integer> lineRange : lineRanges.subRangeSet(Range.closedOpen(0, lines.size() - 1)).asRanges()) { int lineStart = lines.get(lineRange.lowerEndpoint()); // Exclude the trailing newline. This isn't strictly necessary, but handling blank lines // as empty ranges is convenient. int lineEnd = lines.get(lineRange.upperEndpoint()) - 1; Range<Integer> range = Range.closedOpen(lineStart, lineEnd); characterRanges.add(range); } return characterRanges; }
From source file:org.eclipse.sirius.business.internal.session.danalysis.DanglingRefRemovalTrigger.java
/** * Return the EObjects which have been changed by the given notifications * and their children.//from www . jav a2 s. c o m * * @param notifications * notifications to process. * @param notifierToIgnore * a predicate indicating if a given notification should be * ignored regarding its EObject notifier or not (can be null if * all notifications should be considered) * @return the EObjects which have been changed by the given notifications * and their children. */ protected Set<EObject> getChangedEObjectsAndChildren(Iterable<Notification> notifications, Predicate<EObject> notifierToIgnore) { final Set<EObject> changedEObjects = Sets.newLinkedHashSet(); for (Notification notification : notifications) { if (notifierToIgnore == null || notification.getNotifier() instanceof EObject && !notifierToIgnore.apply((EObject) notification.getNotifier())) { for (EObject root : getNotificationValues(notification)) { // Add the element and all its contents to the // changedEObjects set only once. if (!changedEObjects.contains(root)) { changedEObjects.add(root); Iterators.addAll(changedEObjects, root.eAllContents()); } } } } return changedEObjects; }
From source file:org.locationtech.geogig.test.integration.RepositoryTestCase.java
public <E> List<E> toList(Iterator<E> logs) { List<E> logged = new ArrayList<E>(); Iterators.addAll(logged, logs); return logged; }
From source file:org.sosy_lab.cpachecker.util.expressions.ExpressionTrees.java
public static <LeafType> ExpressionTree<LeafType> toCNF(ExpressionTree<LeafType> pExpressionTree) { if (isInCNF(pExpressionTree)) { return pExpressionTree; }/* w w w .j a v a 2s .c om*/ if (isAnd(pExpressionTree)) { return And.of(getChildren(pExpressionTree) .transform(new Function<ExpressionTree<LeafType>, ExpressionTree<LeafType>>() { @Override public ExpressionTree<LeafType> apply(ExpressionTree<LeafType> pExpressionTree) { return toCNF(pExpressionTree); } })); } assert isOr(pExpressionTree); Iterator<ExpressionTree<LeafType>> elementIterator = getChildren(pExpressionTree).iterator(); if (!elementIterator.hasNext()) { return ExpressionTrees.getFalse(); } ExpressionTree<LeafType> first = elementIterator.next(); if (!elementIterator.hasNext()) { return first; } Collection<ExpressionTree<LeafType>> rest = new ArrayList<>(); Iterators.addAll(rest, elementIterator); ExpressionTree<LeafType> firstCNF = toCNF(first); ExpressionTree<LeafType> restCNF = toCNF(And.of(rest)); final Iterable<ExpressionTree<LeafType>> combinatorsA; if (isLeaf(firstCNF)) { combinatorsA = Collections.singleton(firstCNF); } else { combinatorsA = getChildren(firstCNF); } final Iterable<ExpressionTree<LeafType>> combinatorsB; if (isLeaf(restCNF)) { combinatorsB = Collections.singleton(restCNF); } else { combinatorsB = getChildren(restCNF); } Collection<ExpressionTree<LeafType>> newClauses = new ArrayList<>(); for (ExpressionTree<LeafType> combinatorA : combinatorsA) { for (ExpressionTree<LeafType> combinatorB : combinatorsB) { newClauses.add(Or.of(ImmutableList.<ExpressionTree<LeafType>>of(combinatorA, combinatorB))); } } return And.of(newClauses); }
From source file:de.learnlib.algorithms.ttt.base.AbstractTTTLearner.java
protected Set<TTTState<I, D>> getNondetSuccessors(Collection<? extends TTTState<I, D>> states, I sym) { Set<TTTState<I, D>> result = new HashSet<>(); int symIdx = alphabet.getSymbolIndex(sym); for (TTTState<I, D> state : states) { TTTTransition<I, D> trans = state.getTransition(symIdx); if (trans.isTree()) { result.add(trans.getTreeTarget()); } else {// www . ja v a2 s. c om AbstractBaseDTNode<I, D> tgtNode = trans.getNonTreeTarget(); Iterators.addAll(result, tgtNode.subtreeStatesIterator()); } } return result; }
From source file:org.eclipse.emf.ecoretools.design.service.DesignServices.java
private List<EObject> allValidSessionElements(EObject cur, Predicate<EObject> validForClassDiagram) { Session found = SessionManager.INSTANCE.getSession(cur); List<EObject> result = Lists.newArrayList(); if (found != null) { for (Resource res : found.getSemanticResources()) { if (res.getURI().isPlatformResource() || res.getURI().isPlatformPlugin()) { Iterators.addAll(result, Iterators.filter(res.getAllContents(), validForClassDiagram)); }//w ww.j av a 2s . c o m } } return result; }
From source file:org.locationtech.geogig.remote.RemoteRepositoryTestCase.java
protected <E> List<E> toList(Iterator<E> logs) { List<E> logged = new ArrayList<E>(); Iterators.addAll(logged, logs); return logged; }
From source file:org.dswarm.graph.xml.read.PropertyGraphXMLReader.java
private static Iterable<Relationship> getSortedOutgoings(final Node node) { final Iterable<Relationship> relationships = node.getRelationships(Direction.OUTGOING); if (relationships == null) { return Collections.emptyList(); }/*from w w w .j ava 2s . co m*/ final Iterator<Relationship> relationshipIterator = relationships.iterator(); final List<Relationship> sortedRels = new ArrayList<>(); Iterators.addAll(sortedRels, relationshipIterator); // sort rels by index value // TODO: what should we do, if index is null (currently, the case for import via RDF) Collections.sort(sortedRels, BY_INDEX_PROPERTY); return sortedRels; }