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

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

Introduction

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

Prototype

public static <T> T get(Iterable<T> iterable, int position) 

Source Link

Document

Returns the element at the specified position in an iterable.

Usage

From source file:com.google.security.zynamics.binnavi.Gui.Debug.ToolbarPanel.Implementations.CStepOverHelper.java

/**
 * Adds the addresses of a instructions that follow another instruction to a list when
 * single-stepping in a code node.// w ww.  ja  v a2s . co  m
 * 
 * @param node The code node where the step over operation happens.
 * @param address The address in question.
 * @param instructions List to extend with the successor instructions.
 */
private static void stepInCodeNode(final INaviCodeNode node, final UnrelocatedAddress address,
        final Set<BreakpointAddress> instructions) {
    final int instructionIndex = CCodeNodeHelpers.getInstruction(node, address.getAddress());

    if (instructionIndex != -1) {
        // The instruction to search for is in the current basic block ...

        if (instructionIndex < node.instructionCount() - 1) {
            // ... and the basic block is large enough that the following
            // instruction is also part of the basic block.

            final INaviInstruction instruction = Iterables.get(node.getInstructions(), instructionIndex + 1);

            instructions.add(new BreakpointAddress(instruction.getModule(),
                    new UnrelocatedAddress(instruction.getAddress())));
        } else {
            // ... but the instruction is the last instruction of the basic block,
            // so we have to look into the child nodes of the basic block.

            instructions.addAll(CSteppingHelper.getSuccessors(node));
        }
    }
}

From source file:org.spongepowered.common.data.processor.common.SkullUtils.java

public static SkullType getSkullType(int skullType) {
    return Iterables.get(SpongeImpl.getRegistry().getAllOf(SkullType.class), skullType);
}

From source file:org.nuxeo.ecm.core.query.sql.model.FromClause.java

public String getAlias(int i) {
    return Iterables.get(elements.keySet(), i);
}

From source file:org.apache.brooklyn.util.exceptions.CompoundRuntimeException.java

public CompoundRuntimeException(String message, Iterable<? extends Throwable> causes) {
    this(message, (Iterables.isEmpty(causes) ? null : Iterables.get(causes, 0)), causes);
}

From source file:com.bennavetta.aeneas.mesos.slave.docker.Daemon.java

private static void mountFilesystems() throws IOException {
    Path cgroup = Paths.get("/sys/fs/cgroup");
    if (!Files.isDirectory(cgroup))
        Files.createDirectory(cgroup);

    LOG.debug("Creating '{}' tmpfs", cgroup);
    if (!isMountpoint(cgroup)) {
        try {//w ww . j av  a  2 s . c om
            mount(cgroup, "cgroup", "tmpfs", "uid=0,gid=0,mode=0755", false);
        } catch (IOException e) {
            throw new IOException("Could not make a tmpfs mount. Was the --privileged flag used?", e);
        }
    }

    Path security = Paths.get("/sys/kernel/security");
    LOG.debug("Creating security file system in '{}'", security);
    if (Files.isDirectory(security) && !isMountpoint(security)) {
        try {
            mount(security, "none", "securityfs", null, true);
        } catch (IOException e) {
            LOG.warn("Could not mount {}. AppArmor detection and --privileged mode might break.", security);
        }
    }

    String cgroupsText = new String(Files.readAllBytes(Paths.get("/proc/1/cgroup")));
    List<String> cgroups = StreamSupport.stream(Splitter.on('\n').split(cgroupsText).spliterator(), false)
            .filter(s -> !s.trim().isEmpty()).map(s -> Splitter.on(':').split(s)).map(i -> Iterables.get(i, 1))
            .collect(Collectors.toList());
    for (String subsystem : cgroups) {
        LOG.debug("Creating '{}' cgroup", subsystem);
        Path subsysPath = cgroup.resolve(subsystem);
        if (!Files.isDirectory(subsysPath))
            Files.createDirectory(subsysPath);
        if (!isMountpoint(subsysPath)) {
            mount(subsysPath, "cgroup", "cgroup", subsystem, false);
        }

        /*
         * Address some bugs
         * See https://github.com/jpetazzo/dind/blob/master/wrapdocker
          */
        if (subsystem.startsWith("name=")) {
            String name = subsystem.substring(6);
            Files.createSymbolicLink(cgroup.resolve(name), Paths.get(subsystem));
        }

        if (subsystem.equals("cpuacct,cpu")) {
            Files.createSymbolicLink(cgroup.resolve("cpu,cpuacct"), Paths.get(subsystem));
        }
    }

    if (!cgroupsText.contains(":devices:")) {
        LOG.warn("The 'devices' cgroup should be in its own hierarchy.");
    }

    if (!Iterables.contains(Splitter.on(CharMatcher.BREAKING_WHITESPACE).split(cgroupsText), "devices")) {
        LOG.warn("The 'devices' cgroup does not appear to be mounted.");
    }
}

From source file:org.jclouds.rackspace.cloudloadbalancers.v1.domain.HistoricalUsage.java

public Iterable<AccountUsage> getAccountUsage() {
    return Iterables.get(accountUsage.values(), 0);
}

From source file:com.google.code.jgntp.internal.message.read.GntpMessageResponseParser.java

public GntpMessageResponse parse(String s) {
    Iterable<String> splitted = separatorSplitter.split(s);
    Preconditions.checkState(!Iterables.isEmpty(splitted), "Empty message received from Growl");

    Iterator<String> iter = splitted.iterator();
    String statusLine = iter.next();
    Preconditions.checkState(//from  w  w w . j  a  v  a  2 s .  c o m
            statusLine.startsWith(GntpMessage.PROTOCOL_ID + "/" + GntpVersion.ONE_DOT_ZERO.toString()),
            "Unknown protocol version");

    Iterable<String> statusLineIterable = statusLineSplitter.split(statusLine);
    String messageTypeText = Iterables.get(statusLineIterable, 1).substring(1);
    GntpMessageType messageType = GntpMessageType.valueOf(messageTypeText);

    Map<String, String> headers = Maps.newHashMap();
    while (iter.hasNext()) {
        String[] splittedHeader = iter.next().split(":", 2);
        headers.put(splittedHeader[0], splittedHeader[1].trim());
    }

    switch (messageType) {
    case OK:
        return createOkMessage(headers);
    case CALLBACK:
        return createCallbackMessage(headers);
    case ERROR:
        return createErrorMessage(headers);
    default:
        throw new IllegalStateException("Unknown response message type: " + messageType);
    }
}

From source file:org.jclouds.cloudloadbalancers.functions.UnwrapLoadBalancers.java

@Override
public Set<LoadBalancer> apply(HttpResponse arg0) {
    Map<String, Set<LB>> map = json.apply(arg0);
    if (map.size() == 0)
        return ImmutableSet.<LoadBalancer>of();
    ;//from www.  j  av  a 2 s. co  m
    return ImmutableSet.copyOf(Iterables.transform(Iterables.get(map.values(), 0), convertLB));
}

From source file:com.replaymod.replaystudio.pathing.TimelineTestsBase.java

protected Keyframe actualKeyframe(int index) {
    return Iterables.get(path.getKeyframes(), index);
}

From source file:org.jclouds.rackspace.cloudloadbalancers.v1.functions.ParseNestedString.java

@Override
public String apply(HttpResponse response) {
    Map<String, Map<String, String>> map = json.apply(response);

    if (map == null || map.size() == 0)
        throw new HttpResponseException("Unexpected JSON format returned.", null, response);

    return Iterables.get(Iterables.get(map.values(), 0).values(), 0);
}