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.obm.provisioning.authorization.SubBatchResourceAuthorizationFilter.java
@Override protected String getPathPermission(ServletRequest request) { String pathInfo = ((HttpServletRequest) request).getRequestURI(); Iterable<String> iterable = Splitter.on("/").split(pathInfo); return Iterables.get(iterable, DOMAIN_UID_PATH_INDEX) + ":" + Iterables.get(iterable, SUB_BATCH_PATH_INDEX); }
From source file:org.opendaylight.openflowplugin.openflow.md.core.sal.convertor.PacketOutConvertor.java
/** * @param version openflow version/*from w w w . jav a2 s. c o m*/ * @param inputPacket input packet * @param datapathid datapath id * @param xid tx id * @return PacketOutInput required by OF Library */ public static PacketOutInput toPacketOutInput(final TransmitPacketInput inputPacket, final short version, final Long xid, final BigInteger datapathid) { LOG.trace("toPacketOutInput for datapathId:{}, xid:{}", datapathid, xid); // Build Port ID from TransmitPacketInput.Ingress PortNumber inPortNr = null; Long bufferId = OFConstants.OFP_NO_BUFFER; Iterable<PathArgument> inArgs = null; PacketOutInputBuilder builder = new PacketOutInputBuilder(); if (inputPacket.getIngress() != null) { inArgs = inputPacket.getIngress().getValue().getPathArguments(); } if (inArgs != null && Iterables.size(inArgs) >= 3) { inPortNr = getPortNumber(Iterables.get(inArgs, 2), version); } else { // The packetOut originated from the controller inPortNr = new PortNumber(0xfffffffdL); } // Build Buffer ID to be NO_OFP_NO_BUFFER if (inputPacket.getBufferId() != null) { bufferId = inputPacket.getBufferId(); } PortNumber outPort = null; NodeConnectorRef outRef = inputPacket.getEgress(); Iterable<PathArgument> outArgs = outRef.getValue().getPathArguments(); if (Iterables.size(outArgs) >= 3) { outPort = getPortNumber(Iterables.get(outArgs, 2), version); } else { // TODO : P4 search for some normal exception new Exception("PORT NR not exist in Egress"); } List<Action> actions = null; List<org.opendaylight.yang.gen.v1.urn.opendaylight.action.types.rev131112.action.list.Action> inputActions = inputPacket .getAction(); if (inputActions != null) { actions = ActionConvertor.getActions(inputActions, version, datapathid, null); } else { actions = new ArrayList<>(); // TODO VD P! wait for way to move Actions (e.g. augmentation) ActionBuilder aBuild = new ActionBuilder(); OutputActionCaseBuilder outputActionCaseBuilder = new OutputActionCaseBuilder(); OutputActionBuilder outputActionBuilder = new OutputActionBuilder(); outputActionBuilder.setPort(outPort); outputActionBuilder.setMaxLength(OFConstants.OFPCML_NO_BUFFER); outputActionCaseBuilder.setOutputAction(outputActionBuilder.build()); aBuild.setActionChoice(outputActionCaseBuilder.build()); actions.add(aBuild.build()); } builder.setAction(actions); builder.setData(inputPacket.getPayload()); builder.setVersion(version); builder.setXid(xid); builder.setInPort(inPortNr); builder.setBufferId(bufferId); // -------------------------------------------------------- return builder.build(); }
From source file:br.com.caelum.vraptor.http.route.JavaEvaluator.java
private Object access(Object current, int position) { if (current.getClass().isArray()) { return Array.get(current, position); } else if (Collection.class.isAssignableFrom(current.getClass())) { return Iterables.get((Collection<?>) current, position); }//from w ww . j ava 2 s . c o m throw new VRaptorException("Unable to access position of a" + current.getClass().getName() + "."); }
From source file:org.jclouds.vcloud.director.v1_5.compute.util.VCloudDirectorComputeUtils.java
public static String getVirtualSystemIdentifierOfFirstVMIn(VApp vApp) { return vApp.getChildren().getVms().size() > 0 ? getVirtualSystemIdentifierOf(Iterables.get(vApp.getChildren().getVms(), 0)) : null;// w w w . java2 s . c o m }
From source file:org.jclouds.http.internal.TrackingJavaUrlHttpCommandExecutorService.java
public static List<Object> getArgsForRequestAtIndex(final Collection<HttpCommand> commandsInvoked, int index) { return GeneratedHttpRequest.class.cast(Iterables.get(commandsInvoked, index).getCurrentRequest()) .getInvocation().getArgs();/*w ww. j a va 2 s . co m*/ }
From source file:com.na.install.InstallationWizard.java
/** Loads instance of Integrator using reflection. */ public InstallationWizard() throws InstantiationException, IllegalAccessException { String packageToScan = "com.na.install"; Set<Class<? extends Integrator>> implementations = new Reflections(packageToScan) .getSubTypesOf(Integrator.class); if (implementations == null || implementations.size() == 0) { throw new RuntimeException(String.format("Didn't find implementation of %s in package %s.", Integrator.class.getName(), packageToScan)); }/*www .j a v a 2 s . c o m*/ if (implementations.size() > 1) { log.warn("There are several implementations of " + Integrator.class.getName()); } this.integrator = Iterables.get(implementations, 0).newInstance(); }
From source file:org.icgc.dcc.portal.util.ElasticsearchResponseUtils.java
/** * Returns first value of the list as a String *//*from w w w .jav a2 s .c o m*/ public static String getString(Object values) { if (values == null) { return null; } if (values instanceof Iterable<?>) { val iterable = (Iterable<?>) values; return Iterables.isEmpty(iterable) ? null : Iterables.get(iterable, 0).toString(); } if (values instanceof String) { return values.toString(); } return null; }
From source file:org.jclouds.trmk.vcloud_0_8.functions.OrgNameCatalogNameVAppTemplateNameToEndpoint.java
@SuppressWarnings("unchecked") public URI apply(Object from) { Iterable<Object> orgCatalog = (Iterable<Object>) checkNotNull(from, "args"); Object org = Iterables.get(orgCatalog, 0); Object catalog = Iterables.get(orgCatalog, 1); Object catalogItem = Iterables.get(orgCatalog, 2); if (org == null) org = defaultOrg.get().getName(); if (catalog == null) catalog = defaultCatalog.get().getName(); Map<String, Map<String, Map<String, ? extends CatalogItem>>> orgCatalogItemMap = this.orgCatalogItemMap .get();/*from w ww . j av a 2 s.c o m*/ if (!orgCatalogItemMap.containsKey(org)) throw new NoSuchElementException("org: " + org + " not found in " + orgCatalogItemMap.keySet()); Map<String, Map<String, ? extends CatalogItem>> catalogs = orgCatalogItemMap.get(org); if (!catalogs.containsKey(catalog)) throw new NoSuchElementException( "catalog: " + org + "/" + catalog + " not found in " + catalogs.keySet()); Map<String, ? extends CatalogItem> catalogMap = catalogs.get(catalog); if (!catalogMap.containsKey(catalogItem)) throw new NoSuchElementException( "item: " + org + "/" + catalog + "/" + catalogItem + " not found in " + catalogMap.keySet()); CatalogItem item = catalogMap.get(catalogItem); return checkNotNull(item.getEntity(), "item: " + org + "/" + catalog + "/" + catalogItem + " has no entity") .getHref(); }
From source file:com.spotify.helios.servicescommon.RiemannSupport.java
public RiemannSupport(final MetricRegistry metricsRegistry, final String hostPort, final String hostName, final String serviceName) { this.metricsRegistry = metricsRegistry; this.serviceName = serviceName; this.hostName = hostName; if (Strings.isNullOrEmpty(hostPort)) { host = null;/*w ww. jav a 2 s. c o m*/ port = 0; proto = null; return; } final Iterable<String> parts = Splitter.on(":").split(hostPort); final int size = Iterables.size(parts); if (size > 3 || size < 2) { throw new RuntimeException("specification of riemann host port has wrong number of parts. Should be" + " [proto:]host:port, where proto is udp or tcp"); } if (size == 3) { this.proto = Iterables.get(parts, 0); } else { this.proto = "udp"; } checkState("udp".equals(this.proto) || "tcp".equals(this.proto)); host = Iterables.get(parts, size - 2); port = Integer.valueOf(Iterables.get(parts, size - 1)); }
From source file:org.icgc.dcc.download.job.core.DefaultDownloadJob.java
private static void setJobName(TaskContext taskContext) { val jobId = taskContext.getJobId(); val dataTypes = taskContext.getDataTypes(); val dataType = DownloadDataType.hasClinicalDataTypes(dataTypes) ? DownloadDataType.DONOR : Iterables.get(dataTypes, 0); val jobName = DownloadJobs.getJobName(jobId, dataType); setJobGroupName(taskContext.getSparkContext(), jobName); }