List of usage examples for com.google.common.collect Iterables get
public static <T> T get(Iterable<T> iterable, int position)
From source file:org.jclouds.rackspace.cloudloadbalancers.v1.functions.ParseNestedBoolean.java
@Override public Boolean apply(HttpResponse response) { Map<String, Map<String, Boolean>> 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); }
From source file:com.zimbra.client.ZPrefs.java
/** * @param name name of pref to get/*from w w w. j a v a2 s.c om*/ * @return null if unset, or first value in list */ public String get(String name) { Collection<String> values = mPrefs.get(name); if (values == null || values.isEmpty()) { return null; } return Iterables.get(values, 0); }
From source file:org.jclouds.rackspace.cloudloadbalancers.functions.ParseNestedBoolean.java
@Override public Boolean apply(HttpResponse response) { Map<String, Map<String, Boolean>> map = json.apply(response); if (map == null || map.size() == 0) throw new HttpResponseException("Unexpected connection logging format returned.", null, response); return Iterables.get(Iterables.get(map.values(), 0).values(), 0); }
From source file:org.jclouds.virtualbox.util.MachineNameOrIdAndNicSlot.java
public static MachineNameOrIdAndNicSlot fromString(String machineNameOrIdAndNicSlotString) { Iterable<String> splittedString = Splitter.on(SEPARATOR).split(machineNameOrIdAndNicSlotString); checkState(Iterables.size(splittedString) == 2); String machineNameOrId = Strings.nullToEmpty(Iterables.get(splittedString, 0)); String nicSlotString = Strings.nullToEmpty(Iterables.get(splittedString, 1)); checkArgument(!nicSlotString.startsWith("+"), "Unparseable slot number: %s", nicSlotString); try {//from w w w . j a v a 2s .c o m long slot = Long.parseLong(nicSlotString); checkArgument(isValidSlot(slot), "Slot number out of range: %s", nicSlotString); return new MachineNameOrIdAndNicSlot(machineNameOrId, slot); } catch (NumberFormatException e) { throw new IllegalArgumentException("Unparseable slot number: " + nicSlotString); } }
From source file:org.jclouds.s3.blobstore.functions.LocationFromBucketLocation.java
@Inject LocationFromBucketLocation(S3Client client, @Memoized Supplier<Set<? extends Location>> locations) { this.client = client; this.onlyLocation = locations.get().size() == 1 ? Iterables.get(locations.get(), 0) : null; this.locations = locations; }
From source file:org.jclouds.vcloud.compute.util.VCloudComputeUtils.java
public static LoginCredentials getCredentialsFrom(VApp vApp) { return vApp.getChildren().size() > 0 ? getCredentialsFrom(Iterables.get(vApp.getChildren(), 0)) : null; }
From source file:eu.numberfour.n4js.ui.preferences.ExternalLibraryTreeContentProvider.java
@Override public void updateElement(final Object parent, final int index) { if (treeViewerRef.isPresent()) { final TreeViewer treeViewer = treeViewerRef.get(); if (parent instanceof Iterable) { final Object child = Iterables.get((Iterable<?>) parent, index); treeViewer.replace(parent, index, child); if (child instanceof URI) { treeViewer.setChildCount(child, Iterables.size(getProjects((URI) child))); }/*from w w w .ja v a 2 s. com*/ } else if (parent instanceof URI) { final IN4JSProject child = Iterables.get(getProjects((URI) parent), index); treeViewer.replace(parent, index, child); } } }
From source file:com.github.benmanes.caffeine.cache.node.NodeRule.java
protected final Strength keyStrength() { return strengthOf(Iterables.get(context.generateFeatures, 0)); }
From source file:org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.java
public static Invokable<?, ?> getInvokerOfRequestAtIndex(final Collection<HttpCommand> commandsInvoked, int index) { return getInvokerOfRequest(Iterables.get(commandsInvoked, index)); }
From source file:brooklyn.location.basic.Machines.java
public static Maybe<String> getSubnetIp(Location where) { // TODO Too much duplication between the ip and hostname methods String result = null;/*from ww w . j ava2 s.c om*/ if (where instanceof HasSubnetHostname) { result = ((HasSubnetHostname) where).getSubnetIp(); } if (where instanceof HasNetworkAddresses) { Set<String> privateAddrs = ((HasNetworkAddresses) where).getPrivateAddresses(); if (privateAddrs.size() > 0) { result = Iterables.get(privateAddrs, 0); } } if (result == null && where instanceof MachineLocation) { InetAddress addr = ((MachineLocation) where).getAddress(); if (addr != null) result = addr.getHostAddress(); } log.debug("computed hostname {} for {}", result, where); return Maybe.fromNullable(result); }