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.apache.whirr.service.zookeeper.ZooKeeperService.java
private List<String> getHosts(List<NodeMetadata> nodes) { return Lists.transform(Lists.newArrayList(nodes), new Function<NodeMetadata, String>() { @Override/*from w w w. j a va 2 s . co m*/ public String apply(NodeMetadata node) { String publicIp = Iterables.get(node.getPublicAddresses(), 0).getHostName(); return String.format("%s:%d", publicIp, CLIENT_PORT); } }); }
From source file:com.github.benmanes.caffeine.cache.NodeGenerator.java
private void addKey() { if (!isBaseClass()) { return;// w ww . ja v a 2 s .c o m } Strength keyStrength = strengthOf(Iterables.get(generateFeatures, 0)); nodeSubtype.addField(newFieldOffset(className, "key")).addField(newKeyField()) .addMethod(newGetter(keyStrength, kTypeVar, "key", Visibility.LAZY)).addMethod(newGetKeyRef()); addKeyConstructorAssignment(constructorByKey, false); addKeyConstructorAssignment(constructorByKeyRef, true); }
From source file:com.crystal.flexin.record.SmartPoster.java
/** * Returns the first element of {@code elements} which is an instance of * {@code type}, or {@code null} if no such element exists. */// ww w. ja v a 2s.c o m private static <T> T getFirstIfExists(Iterable<?> elements, Class<T> type) { Iterable<T> filtered = Iterables.filter(elements, type); T instance = null; if (!Iterables.isEmpty(filtered)) { instance = Iterables.get(filtered, 0); } return instance; }
From source file:com.google.template.soy.parsepasses.contextautoesc.CheckEscapingSanityVisitor.java
@Override protected void visitCallDelegateNode(CallDelegateNode node) { if (autoescapeMode == AutoescapeMode.NONCONTEXTUAL) { TemplateNode callee;// w w w .j av a2s.c o m Set<DelegateTemplateDivision> divisions = templateRegistry .getDelTemplateDivisionsForAllVariants((node).getDelCalleeName()); if (divisions != null && !divisions.isEmpty()) { // As the callee is required only to know the kind of the content and as all templates in // delPackage are of the same kind it is sufficient to choose only the first template. DelegateTemplateDivision division = Iterables.getFirst(divisions, null); callee = Iterables.get(division.delPackageNameToDelTemplateMap.values(), 0); if (callee.getContentKind() == SanitizedContent.ContentKind.TEXT) { throw SoyAutoescapeException .createWithNode( "Calls to strict templates with 'kind=\"text\"' attribute is not permitted in " + "non-contextually autoescaped templates: " + node.toSourceString(), node); } } } visitChildren(node); }
From source file:com.bigtester.ate.tcg.controller.WebFormUserInputsCollector.java
/** * Collect user inputs./*from w ww .ja v a2 s . co m*/ * * @param cleanedDoc * the cleaned doc * @param originalDoc * the original doc * @throws IOException * Signals that an I/O exception has occurred. */ private void collectUserInputs(Document cleanedDoc) throws IOException { for (int j = 0; j < USER_CHANGABLE_INPUT_TAGS.length; j++) { NodeList htmlInputs = cleanedDoc.getElementsByTagName(USER_CHANGABLE_INPUT_TAGS[j]); for (int i = 0; i < htmlInputs.getLength(); i++) { Node coreNode = htmlInputs.item(i); List<Element> parentsUntilForm = $(coreNode).parentsUntil("form").get();// NOPMD if (null != coreNode && (parentsUntilForm.isEmpty() || !Iterables.get(parentsUntilForm, parentsUntilForm.size() - 1).getNodeName() .equalsIgnoreCase("html")) && isUserChangableInputType(coreNode) && !((Element) coreNode).getAttribute("ate-invisible").equalsIgnoreCase("yes")) { if (parentsUntilForm.isEmpty()) { Node coreNodeParent = coreNode.getParentNode(); userInputs.add(initUserInputDomInsideOfForm(cleanedDoc, coreNode, coreNodeParent)); } else { List<Element> parents = $(coreNode).parentsUntil("form").parent().get(); Node tempNode = parents.get(parents.size() - 1); userInputs.add(initUserInputDomInsideOfForm(cleanedDoc, coreNode, tempNode)); } } else { // TODO collect input out of form element } } } }
From source file:org.jclouds.savvis.vpdc.config.VPDCRestClientModule.java
@Provides @org.jclouds.savvis.vpdc.internal.Org//w ww . j a v a 2 s .co m @Singleton protected Supplier<String> provideDefaultOrgId( @org.jclouds.savvis.vpdc.internal.Org Supplier<Set<org.jclouds.savvis.vpdc.domain.Resource>> orgs) { return Suppliers.compose(new Function<Set<org.jclouds.savvis.vpdc.domain.Resource>, String>() { @Override public String apply(Set<org.jclouds.savvis.vpdc.domain.Resource> input) { return Iterables.get(input, 0).getId(); } }, orgs); }
From source file:org.apache.brooklyn.core.location.dynamic.clocker.StubInfrastructureLocation.java
@Override public MachineLocation obtain(Map<?, ?> flags) throws NoMachinesAvailableException { StubHost host = (StubHost) Iterables.get(infrastructure.getStubHostList(), 0); StubHostLocation hostLocation = host.getDynamicLocation(); StubContainerLocation containerLocation = hostLocation.obtain(flags); containers.put(hostLocation, containerLocation.getId()); return containerLocation; }
From source file:minium.web.internal.ExpressionInvocationHandler.java
@Override protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable { Preconditions.checkArgument(proxy instanceof WebElements); T parent = ((WebElements) proxy).as(typeVariableToken); ExpressionWebElements webElements = factory.as(InternalElementsFactory.class) .createMixin(parent, new DefaultExpressionWebElements<T>(method.getName(), args)) .as(ExpressionWebElements.class); Class<?> returnClazz = method.getReturnType(); if (returnClazz != Object.class && Elements.class.isAssignableFrom(returnClazz)) { return webElements.as(typeVariableToken); }/*w w w . j a va 2 s. c o m*/ JavascriptInvoker javascriptInvoker = parent.as(HasJavascriptInvoker.class).javascriptInvoker(); Object result; if (returnClazz == Void.TYPE) { Iterable<DocumentWebDriver> documentDrivers = parent.as(InternalWebElements.class).documentDrivers(); DocumentDriverInvoker documentDriverInvoker = new DocumentDriverInvoker(javascriptInvoker, webElements.getExpression()); for (DocumentWebDriver documentDriver : documentDrivers) { documentDriverInvoker.apply(documentDriver); } result = null; } else { // materialize document drivers Set<DocumentWebDriver> documentDrivers = Sets .newLinkedHashSet(parent.as(InternalWebElements.class).documentDrivers()); switch (documentDrivers.size()) { case 0: // special case for size, if no document was found then size is // 0 for sure if (method.equals(SIZE_METHOD)) { return 0; } throw new NoDocumentDriverFoundException( String.format("The expression %s has no frame or window to be evaluated to", parent)); case 1: result = getSingleDocumentDriverResult(Iterables.get(documentDrivers, 0), javascriptInvoker, webElements); break; default: Expression parentExpression = parent.as(ExpressionWebElements.class).getExpression(); Expression sizeExpression = new FunctionInvocationExpression(parentExpression, "size"); DocumentWebDriver webDriverWithResults = getCandidateDocumentDriver(javascriptInvoker, sizeExpression, documentDrivers); if (webDriverWithResults != null) { DocumentDriverInvoker documentDriverInvoker = new DocumentDriverInvoker(javascriptInvoker, webElements.getExpression()); result = documentDriverInvoker.apply(webDriverWithResults); } else { result = Defaults.defaultValue(returnClazz); } break; } } return coercer.coerce(result, method.getGenericReturnType()); }
From source file:com.vilt.minium.impl.BaseWebElementsImpl.java
public Object invoke(Method method, Object... args) { if (method.isVarArgs()) { args = expandVarArgs(args);// w ww . j a v a 2 s. c o m } String expression = computeExpression(this, isAsyncMethod(method), method.getName(), args); if (method.getReturnType() != Object.class && method.getReturnType().isAssignableFrom(this.getClass())) { T webElements = WebElementsFactoryHelper.createExpressionWebElements(factory, myself, expression); return webElements; } else { Object result = null; boolean async = isAsyncMethod(method); Iterable<WebElementsDriver<T>> webDrivers = candidateWebDrivers(); if (method.getReturnType() == Void.TYPE) { for (WebElementsDriver<T> wd : webDrivers) { factory.getInvoker().invokeExpression(wd, async, expression); } } else { if (Iterables.size(webDrivers) == 0) { throw new WebElementsException("The expression has no frame or window to be evaluated to"); } else if (Iterables.size(webDrivers) == 1) { WebElementsDriver<T> wd = Iterables.get(webDrivers, 0); result = factory.getInvoker().invokeExpression(wd, async, expression); } else { String sizeExpression = computeExpression(this, false, "size"); WebElementsDriver<T> webDriverWithResults = null; for (WebElementsDriver<T> wd : webDrivers) { long size = (Long) factory.getInvoker().invokeExpression(wd, async, sizeExpression); if (size > 0) { if (webDriverWithResults == null) { webDriverWithResults = wd; } else { throw new WebElementsException( "Several frames or windows match the same expression, so value cannot be computed"); } } } if (webDriverWithResults != null) { result = factory.getInvoker().invokeExpression(webDriverWithResults, async, expression); } } } if (logger.isDebugEnabled()) { String val; if (method.getReturnType() == Void.TYPE) { val = "void"; } else { val = StringUtils.abbreviate(argToStringFunction.apply(result), 40); if (val.startsWith("'") && !val.endsWith("'")) val += "(...)'"; } logger.debug("[Value: {}] {}", argToStringFunction.apply(result), expression); } // let's handle numbers when return type is int if (method.getReturnType() == Integer.TYPE) { return result == null ? 0 : ((Number) result).intValue(); } else { return result; } } }
From source file:controllers.config.Config.java
/** * Overlays the hostclass configuration. * * @param rawHostclass the hostclass// w ww.j a v a 2s. co m * @return a hostclass configuration yaml response */ public F.Promise<Result> hostclass(final String rawHostclass) { final String rollerHostclass = Iterables .get(Splitter.on("-").trimResults().limit(2).omitEmptyStrings().split(rawHostclass), 0); final List<String> splitHostclass = Splitter.on("::").trimResults().limit(2).omitEmptyStrings() .splitToList(rawHostclass); final Optional<String> artemisHostclass = Optional.ofNullable(Iterables.get(splitHostclass, 1, null)); final Optional<String> rollerVersionedHostclass = Optional .ofNullable(Iterables.get(splitHostclass, 0, null)); LOGGER.info(String.format("Request for hostclass; rollerHostclass=%s, artemisHostclass=%s", rollerHostclass, artemisHostclass.orElse("[null]"))); return _configClient.getHostclassData(rollerVersionedHostclass.get()).map(hostclassOutput -> { if (artemisHostclass.isPresent()) { final Hostclass hostclass = Hostclass.getByName(artemisHostclass.get()); if (hostclass == null) { return notFound(); } overlayHostclass(hostclassOutput, hostclass); } return ok(YAML_MAPPER.writeValueAsString(hostclassOutput)); }); }