Example usage for com.google.common.collect Iterables concat

List of usage examples for com.google.common.collect Iterables concat

Introduction

In this page you can find the example usage for com.google.common.collect Iterables concat.

Prototype

public static <T> Iterable<T> concat(Iterable<? extends T> a, Iterable<? extends T> b) 

Source Link

Document

Combines two iterables into a single iterable.

Usage

From source file:org.summer.dsl.model.xbase.util.XbaseUsageCrossReferencer.java

@Override
protected TreeIterator<Notifier> newContentsIterator() {
    return new ContentTreeIterator<Notifier>(emfObjects) {
        private static final long serialVersionUID = 1L;

        @Override//  w  w  w.  j a v  a 2  s .c om
        protected Iterator<? extends EObject> getEObjectChildren(EObject eObject) {
            if (eObject instanceof XAbstractFeatureCall) {
                Iterable<EObject> result = eObject.eContents();
                XAbstractFeatureCall featureCall = (XAbstractFeatureCall) eObject;
                XExpression implicitReceiver = featureCall.getImplicitReceiver();
                if (implicitReceiver != null)
                    result = Iterables.concat(result, Collections.singleton(implicitReceiver));
                XExpression implicitFirstArgument = featureCall.getImplicitFirstArgument();
                if (implicitFirstArgument != null)
                    result = Iterables.concat(result, Collections.singleton(implicitFirstArgument));
                return result.iterator();
            } else
                return super.getEObjectChildren(eObject);
        }
    };
}

From source file:org.amanzi.awe.render.core.utils.RenderMenuUtils.java

public static Pair<IRenderableModel, Iterable<IDataElement>> getLocationElements(
        final IStructuredSelection selection) {
    IRenderableModel renderableModel = null;
    boolean incorrect = false;

    Iterable<IDataElement> elementsIterable = Iterables.emptyIterable();

    for (final Object element : selection.toArray()) {
        if (element instanceof IUIItem) {
            final IUIItem item = (IUIItem) element;

            final IRenderableModel itemModel = getRenderableModel(item);

            // check UI Item is correct
            if (itemModel == null) {
                incorrect = true;/*  w  w w  .jav  a  2 s  .  c o m*/
                break;
            }

            // check model is same for all elements
            if (renderableModel == null) {
                renderableModel = itemModel;
            } else if (!itemModel.equals(renderableModel)) {
                incorrect = true;
                break;
            }

            // check internal elements
            final Iterable<IDataElement> subIterable = collectDataElements(item, renderableModel);

            if (subIterable != null) {
                elementsIterable = Iterables.concat(elementsIterable, subIterable);
            }

        }
    }

    // check element locations
    if (!incorrect && !Iterables.isEmpty(elementsIterable)) {
        incorrect = Iterables.isEmpty(renderableModel.getElementsLocations(elementsIterable));
    }

    if (!incorrect) {
        return new ImmutablePair<IRenderableModel, Iterable<IDataElement>>(renderableModel, elementsIterable);
    }

    return null;
}

From source file:org.polarsys.reqcycle.utils.iterators.collectors.WidthHarvester.java

/**
 * Width wise collection./* w  w  w  .  j a va2 s .  c  om*/
 * 
 * @param handler
 *            the handler that processes each element.
 * @param element
 *            : the element from which the collection is performed.
 * @throws CollectionAbortedException
 */
protected void collectWidthWise(ResultHandler<Object> handler, Object element)
        throws CollectionAbortedException {
    Iterable<?> currentLayer = Collections.singletonList(element);
    Iterable<?> nextLayer = Collections.EMPTY_LIST;
    while (currentLayer != null && !Iterables.isEmpty(currentLayer)) {
        for (Object currentElement : currentLayer) {
            try {
                handler.handleResult(currentElement);
                // Building the next layer.
                for (IPicker picker : this.getPickers()) {
                    Iterable<?> nexts = picker.getNexts(currentElement); // getting children.
                    if (nexts != null) {
                        nextLayer = Iterables.concat(nextLayer, nexts);
                    }
                }
            } catch (CannotHandleException e) {
                // do nothing
            } catch (Exception e) {
                Activator.logError(e);
            }
        }
        // The current layer has been processed. Going through the next one.
        currentLayer = nextLayer;
        nextLayer = Collections.EMPTY_LIST;
    }
}

From source file:org.killbill.billing.invoice.notification.NextBillingDateNotificationKey.java

public NextBillingDateNotificationKey(final NextBillingDateNotificationKey existing,
        final Iterable<UUID> newUUIDKeys) {
    super(null);//from  w ww.jav a2s. co m
    this.uuidKeys = ImmutableSet.copyOf(Iterables.concat(existing.getUuidKeys(), newUUIDKeys));
    this.targetDate = existing.getTargetDate();
    this.isDryRunForInvoiceNotification = existing.isDryRunForInvoiceNotification();
    this.isRescheduled = existing.isRescheduled();
}

From source file:org.eclipse.sirius.diagram.ui.business.internal.command.ViewDeleteCommand.java

@Override
protected CommandResult doExecuteWithResult(IProgressMonitor progressMonitor, IAdaptable info)
        throws ExecutionException {
    // Prevents GMF to install its CrossReferencerAdapter by not calling
    // ViewUtil.destroy(View)

    // Remove incoming or outgoing NoteAttachment links
    for (Edge edge : Iterables.filter(Iterables.concat(getView().getSourceEdges(), getView().getTargetEdges()),
            Edge.class)) {
        if (ViewType.NOTEATTACHMENT.equals(edge.getType())) {
            EcoreUtil.remove(edge);/*from  w  w w .  ja  va 2 s  .c o m*/
        }
    }
    EcoreUtil.remove(getView());
    return CommandResult.newOKCommandResult();
}

From source file:io.jare.tk.TkRelay.java

/**
 * The request to send.//from  w  w  w. ja  v a 2s. c  o  m
 * @param req Original request
 * @param path Destination path
 * @return Request
 */
private static Request request(final Request req, final String path) {
    return new Request() {
        @Override
        public Iterable<String> head() throws IOException {
            return Iterables.concat(Collections.singleton(String.format("GET %s HTTP/1.1", path)),
                    Iterables.skip(req.head(), 1));
        }

        @Override
        public InputStream body() throws IOException {
            return req.body();
        }
    };
}

From source file:org.janusgraph.diskstorage.configuration.TransactionalConfiguration.java

@Override
public Iterable<String> getKeys(final String prefix) {
    return Iterables.concat(Iterables.filter(writtenValues.keySet(), new Predicate<String>() {
        @Override/*from   www . j  a  v a  2  s  . c om*/
        public boolean apply(@Nullable String s) {
            return s.startsWith(prefix);
        }
    }), Iterables.filter(config.getKeys(prefix), new Predicate<String>() {
        @Override
        public boolean apply(@Nullable String s) {
            return !writtenValues.containsKey(s);
        }
    }));
}

From source file:org.sonar.java.model.statement.CaseGroupTreeImpl.java

@Override
public Iterable<Tree> children() {
    return Iterables.concat(labels, body);
}

From source file:org.richfaces.cdk.templatecompiler.statements.IfStatement.java

@Override
public Iterable<JavaImport> getRequiredImports() {
    return Iterables.concat(super.getRequiredImports(), testStatement.getRequiredImports());
}

From source file:com.facebook.buck.rules.BuckPyFunction.java

public String toPythonFunction(BuildRuleType type, ConstructorArg dto) {
    Preconditions.checkNotNull(type);//w  w  w.  j a  va2 s.  c om
    Preconditions.checkNotNull(dto);

    StringBuilder builder = new StringBuilder();

    SortedSet<ParamInfo> mandatory = Sets.newTreeSet();
    SortedSet<ParamInfo> optional = Sets.newTreeSet();

    for (ParamInfo param : argMarshaller.getAllParamInfo(dto)) {
        if (isSkippable(param)) {
            continue;
        }

        if (param.isOptional()) {
            optional.add(param);
        } else {
            mandatory.add(param);
        }
    }

    @Nullable
    TargetName defaultName = dto.getClass().getAnnotation(TargetName.class);

    builder.append("@provide_for_build\n").append("def ").append(type.getName()).append("(");

    if (defaultName == null) {
        builder.append("name, ");
    }

    // Construct the args.
    for (ParamInfo param : Iterables.concat(mandatory, optional)) {
        appendPythonParameter(builder, param);
    }
    builder.append("visibility=[], build_env=None):\n")

            // Define the rule.
            .append("  add_rule({\n").append("    'type' : '").append(type.getName()).append("',\n");

    if (defaultName != null) {
        builder.append("    'name' : '").append(defaultName.name()).append("',\n");
    } else {
        builder.append("    'name' : name,\n");
    }

    // Iterate over args.
    for (ParamInfo param : Iterables.concat(mandatory, optional)) {
        builder.append("    '").append(param.getName()).append("' : ").append(param.getPythonName())
                .append(",\n");
    }

    builder.append("    'visibility' : visibility,\n");
    builder.append("  }, build_env)\n\n");

    return builder.toString();
}