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:com.icosilune.fnexample.simple.Example.java

public static void main(String args[]) throws Exception {
    JFrame frame = new JFrame("womp womp");

    NodeGraph graph = new NodeGraph(new TimestampContextFactory());

    List<AbstractFn> fns = ImmutableList
            .copyOf(Iterables.concat(ImmutableList.of(new TimestampFn()), Fn_Index.INSTANCES.values()));

    // need to add constants & sinks
    List<NodeFactory.NodeKey> nodeKeys = new ArrayList<>();
    nodeKeys.add(NodeFactory.ConstantNodeKey.create(FnType.fromString("double"), 0.0));
    nodeKeys.add(NodeFactory.SinkNodeKey.create(FnType.fromString("double")));
    nodeKeys.addAll(NodeFactory.FnNodeKey.fromInstances(fns));
    NodeGraphEvaluatorPanel graphPanel = new NodeGraphEvaluatorPanel(graph, nodeKeys);

    //    AbstractNode node1 = new FnNode(graph, new Fn_Multiply());
    //    AbstractNode node2 = new ConstantNode(graph, FnType.fromString("double"), 10.0);
    //    AbstractNode node3 = new ConstantNode(graph, FnType.fromString("double"), 10.0);
    //    AbstractNode sink = new SinkNode(graph, FnType.fromString("double"));
    //    graph.addNode(node1);
    //    graph.addNode(node2);
    //    graph.addNode(node3);
    //    graph.addNode(sink);
    ///*from w w w.j a  va 2  s .  co  m*/
    //    graph.addConnection(node1, node2, "output", "x");
    //    graph.addConnection(node1, node2, "output", "y");
    //    graph.addConnection(sink, node1, "out", "in");

    graphPanel.setPreferredSize(new Dimension(500, 500));

    frame.add(graphPanel);

    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.pack();
    frame.setVisible(true);
}

From source file:tool.Lst.java

public static <T> Iterable<T> cons(T first, Iterable<T> rest) {
    return Iterables.concat(ImmutableList.of(first), rest);
}

From source file:eu.itesla_project.iidm.eurostag.export.BranchParallelIndexes.java

public static BranchParallelIndexes build(Network network, EurostagEchExportConfig config) {
    Multimap<String, Identifiable> map = HashMultimap.create();
    for (TwoTerminalsConnectable ttc : Iterables.concat(network.getLines(),
            network.getTwoWindingsTransformers())) {
        ConnectionBus bus1 = ConnectionBus.fromTerminal(ttc.getTerminal1(), config, EchUtil.FAKE_NODE_NAME1);
        ConnectionBus bus2 = ConnectionBus.fromTerminal(ttc.getTerminal2(), config, EchUtil.FAKE_NODE_NAME2);
        if (bus1.getId().compareTo(bus2.getId()) < 0) {
            map.put(bus1.getId() + bus2.getId(), ttc);
        } else {/*from   www . j  a va2s.c o  m*/
            map.put(bus2.getId() + bus1.getId(), ttc);
        }
    }
    for (VoltageLevel vl : network.getVoltageLevels()) {
        for (Switch s : EchUtil.getSwitches(vl, config)) {
            Bus bus1 = EchUtil.getBus1(vl, s.getId(), config);
            Bus bus2 = EchUtil.getBus2(vl, s.getId(), config);
            if (bus1.getId().compareTo(bus2.getId()) < 0) {
                map.put(bus1.getId() + bus2.getId(), s);
            } else {
                map.put(bus2.getId() + bus1.getId(), s);
            }
        }
    }
    Map<String, Character> parallelIndexes = new HashMap<>();
    for (Map.Entry<String, Collection<Identifiable>> entry : map.asMap().entrySet()) {
        List<Identifiable> eqs = new ArrayList<>(entry.getValue());
        Collections.sort(eqs, (o1, o2) -> o1.getId().compareTo(o2.getId()));
        if (eqs.size() >= 2) {
            char index = '0';
            for (Identifiable l : eqs) {
                index = incParallelIndex(index);
                parallelIndexes.put(l.getId(), index);
            }
        }
    }
    return new BranchParallelIndexes(parallelIndexes);
}

From source file:org.trancecode.collection.TcLists.java

public static <T> List<T> immutableList(final Iterable<T> elements, final T newElement) {
    return ImmutableList.copyOf(Iterables.concat(elements, ImmutableList.of(newElement)));
}

From source file:ivorius.ivtoolkit.tools.Pairs.java

public static <T> Iterable<T> both(Iterable<? extends Pair<T, T>> set) {
    return Sets.newHashSet(Iterables.concat(Iterables.transform(set, Pairs.<T>leftFunction()),
            Iterables.transform(set, Pairs.<T>rightFunction())));
}

From source file:com.google.idea.blaze.base.rulemaps.ReverseDependencyMap.java

public static ImmutableMultimap<Label, Label> createRdepsMap(Map<Label, RuleIdeInfo> ruleMap) {
    ImmutableMultimap.Builder<Label, Label> builder = ImmutableMultimap.builder();
    for (Map.Entry<Label, RuleIdeInfo> entry : ruleMap.entrySet()) {
        Label label = entry.getKey();
        RuleIdeInfo ruleIdeInfo = entry.getValue();
        for (Label dep : Iterables.concat(ruleIdeInfo.dependencies, ruleIdeInfo.runtimeDeps)) {
            if (ruleMap.containsKey(dep)) {
                builder.put(dep, label);
            }//from   ww w. j a v a  2 s .c o  m
        }
    }
    return builder.build();
}

From source file:com.spotify.heroic.common.Optionals.java

public static <T> Optional<List<T>> mergeOptionalList(final Optional<List<T>> a, Optional<List<T>> b) {
    return mergeOptional(a, b, (al, bl) -> ImmutableList.copyOf(Iterables.concat(al, bl)));
}

From source file:com.spotify.heroic.common.Optionals.java

public static <T> Optional<Set<T>> mergeOptionalSet(final Optional<Set<T>> a, Optional<Set<T>> b) {
    return mergeOptional(a, b, (al, bl) -> ImmutableSet.copyOf(Iterables.concat(al, bl)));
}

From source file:eu.itesla_project.iidm.xml.BusFilter.java

static BusFilter create(Network n, XMLExportOptions options) {
    Set<String> buses = null;
    if (options.isOnlyMainCc()) {
        buses = new HashSet<>();
        // keep bus of main cc
        if (options.isForceBusBranchTopo()) {
            for (Bus b : n.getBusView().getBuses()) {
                if (b.isInMainConnectedComponent()) {
                    buses.add(b.getId());
                }//from   w  w  w  .  ja v  a  2s .  c o  m
            }
        } else {
            for (Bus b : n.getBusBreakerView().getBuses()) {
                if (b.isInMainConnectedComponent()) {
                    buses.add(b.getId());
                }
            }
        }
        // and also bus at the other side of open branches
        for (TwoTerminalsConnectable branch : Iterables.concat(n.getLines(), n.getTwoWindingsTransformers())) {
            Terminal t1 = branch.getTerminal1();
            Terminal t2 = branch.getTerminal2();
            if (options.isForceBusBranchTopo()) {
                Bus b1 = t1.getBusView().getConnectableBus();
                Bus b2 = t2.getBusView().getConnectableBus();
                if ((b1 != null && b1.isInMainConnectedComponent()) && b2 != null
                        && !b2.isInMainConnectedComponent()) {
                    buses.add(b2.getId());
                } else if (b1 != null && !b1.isInMainConnectedComponent() && b2 != null
                        && b2.isInMainConnectedComponent()) {
                    buses.add(b1.getId());
                }
            } else {
                Bus b1 = t1.getBusBreakerView().getConnectableBus();
                Bus b2 = t2.getBusBreakerView().getConnectableBus();
                if (b1.isInMainConnectedComponent() && !b2.isInMainConnectedComponent()) {
                    buses.add(b2.getId());
                } else if (!b1.isInMainConnectedComponent() && b2.isInMainConnectedComponent()) {
                    buses.add(b1.getId());
                }
            }
        }
        for (ThreeWindingsTransformer twt : n.getThreeWindingsTransformers()) {
            throw new AssertionError("TODO");
        }
    }
    return new BusFilter(buses, options);
}

From source file:com.hubrick.raml.mojo.util.RamlUtil.java

public static String toJavaMethodName(Action action) {
    final List<String> nameElements = stream(spliterator(action.getResource().getUri().split("\\/")), false)
            .filter(path -> !path.matches(".*\\{[^\\}]*\\}.*"))
            .map(path -> stream(spliterator(path.split("(?i:[^a-z0-9])")), false).map(StringUtils::capitalize)
                    .collect(toList()))/*www. j  ava 2s . c  o m*/
            .flatMap(tokens -> tokens.stream()).collect(toList());

    return Joiner.on("")
            .join(Iterables.concat(Collections.singleton(action.getType().name().toLowerCase()), nameElements));
}