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.rimuhosting.miro.functions.ParsePricingPlansFromJsonResponse.java
@Override public SortedSet<PricingPlan> apply(HttpResponse arg0) { return Iterables.get(json.apply(arg0).values(), 0).pricing_plan_infos; }
From source file:eu.esdihumboldt.hale.server.security.util.ProxyOpenIDAuthenticationFilter.java
/** * Build a returnTo URL if behind a proxy. * //from www . j a va 2s. co m * @param returnTo the original returnTo URL * @param forwardedFor the X-Forwarded-For header * @return the proxy returnTo URL or <code>null</code> if it could not be * determined */ public static String buildReturnToForProxy(String returnTo, String forwardedFor) { Iterable<String> parts = Splitter.on(',').trimResults().split(forwardedFor); String outwardProxy = null; try { outwardProxy = Iterables.get(parts, 1); // original returnTo URI org = URI.create(returnTo); // build proxy URL, assuming http as scheme URI uri = new URI("http", outwardProxy, org.getPath(), org.getQuery(), org.getFragment()); return uri.toString(); } catch (Exception e) { log.warn("Error building proxy return URL from X-Forwarded-For"); // try HALE base URL system property as fall-back String baseUrl = System.getProperty(SYSTEM_PROPERTY_SERVER_URL); if (baseUrl != null) { try { // original returnTo URI org = URI.create(returnTo); // build proxy URL URI uri = new URI(baseUrl + org.getRawPath()); return uri.toString(); } catch (Exception e1) { log.warn("Error building proxy return URL from " + SYSTEM_PROPERTY_SERVER_URL + " system property", e1); } } } return null; }
From source file:org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.java
public static CIMOperatingSystem toComputeOs(VApp vApp) { // TODO we need to change the design so that it doesn't assume single-vms return vApp.getChildren().getVms().size() > 0 ? toComputeOs(Iterables.get(vApp.getChildren().getVms(), 0)) : null;// w w w . j a v a2 s . co m }
From source file:org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToVLANInfo.java
@Override public VLANInfo apply(HttpResponse response) { Set<VLANInfo> drives = setParser.apply(response); if (drives.size() == 0) return null; return Iterables.get(drives, 0); }
From source file:com.zimbra.client.ZFeatures.java
/** * @param name name of attr to get//from www . j a v a2 s .c o m * @return null if unset, or first value in list */ private String get(String name) { Collection<String> value = mAttrs.get(name); if (value == null || value.isEmpty()) { return null; } return Iterables.get(value, 0); }
From source file:org.nuxeo.ecm.core.query.sql.model.FromClause.java
public String get(int i) { return Iterables.get(elements.values(), i); }
From source file:org.jclouds.azurecompute.compute.functions.internal.OperatingSystems.java
public static Function<OSImage, String> version() { return new Function<OSImage, String>() { @Override/*from ww w .j a v a2s . co m*/ public String apply(final OSImage osImage) { if (osImage.category().matches("Canonical|OpenLogic")) { return Iterables.get(Splitter.on(" ").split(osImage.label()), 2); } else if (osImage.category().matches(SUSE)) { if (osImage.label().startsWith(OPENSUSE)) { return osImage.label().substring(OPENSUSE.length() + 1); } if (osImage.label().startsWith(SUSE)) { return Iterables.get(Splitter.on("-").split(osImage.name()), 4); } } else if (osImage.category().matches(MICROSOFT)) { if (osImage.label().startsWith(WINDOWS_SERVER)) { return osImage.label().substring(WINDOWS_SERVER.length() + 1); } if (osImage.label().startsWith(MICROSOFT_SQL_SERVER)) { return osImage.label().substring(MICROSOFT_SQL_SERVER.length() + 1); } } else if (osImage.category().matches("RightScale with Linux|Public ")) { final Iterable<String> splittedLabel = Splitter.on("-").split(osImage.label()); if (Iterables.size(splittedLabel) > 2) { return Iterables.get(splittedLabel, 2); } } return null; } }; }
From source file:org.jclouds.cloudsigma.functions.KeyValuesDelimitedByBlankLinesToDriveInfo.java
@Override public DriveInfo apply(HttpResponse response) { Set<DriveInfo> drives = setParser.apply(response); if (drives.size() == 0) return null; return Iterables.get(drives, 0); }
From source file:net.sourceforge.cilib.util.selection.weighting.ParticleBehaviorWeighting.java
@Override public <T> Iterable<WeightedObject> weigh(Iterable<T> iterable) { Preconditions.checkArgument(Iterables.get(iterable, 0) instanceof ParticleBehavior); List<WeightedObject> result = Lists.newArrayList(); for (T t : iterable) { double weight = ratio.getRatio((ParticleBehavior) t); result.add(new WeightedObject(t, weight)); }/*w w w. j a v a 2s . com*/ return result; }
From source file:com.tera.gapi.spawn.template.CSpawnData.java
@Override public SpawnTemplate getObject(int npcId) { Collection<SpawnTemplate> spawns = spawnTemplates.get(npcId); return spawns.size() != 0 ? Iterables.get(spawns, 0) : null; }