List of usage examples for com.google.common.collect Iterables getLast
public static <T> T getLast(Iterable<T> iterable)
From source file:org.sonar.javascript.checks.DuplicateBranchImplementationCheck.java
private static boolean isCaseEndingWithoutJumpStmt(SwitchClauseTree caseTree) { return caseTree.is(Kind.CASE_CLAUSE) && !isJumpStatement(Iterables.getLast(caseTree.statements())); }
From source file:org.jclouds.openstack.nova.v1_1.compute.functions.AllocateAndAddFloatingIpToNode.java
@Override public AtomicReference<NodeMetadata> apply(AtomicReference<NodeMetadata> input) { checkState(nodeRunning.apply(input), "node never achieved state running %s", input.get()); NodeMetadata node = input.get();//from w w w. ja v a 2 s.co m // node's location is a host String zoneId = node.getLocation().getParent().getId(); FloatingIPClient floatingIpClient = novaClient.getFloatingIPExtensionForZone(zoneId).get(); FloatingIP ip = null; try { logger.debug(">> allocating or reassigning floating ip for node(%s)", node.getId()); ip = floatingIpClient.allocate(); } catch (InsufficientResourcesException e) { logger.trace("<< [%s] allocating a new floating ip for node(%s)", e.getMessage(), node.getId()); logger.trace(">> searching for existing, unassigned floating ip for node(%s)", node.getId()); ArrayList<FloatingIP> unassignedIps = Lists .newArrayList(Iterables.filter(floatingIpClient.listFloatingIPs(), new Predicate<FloatingIP>() { @Override public boolean apply(FloatingIP arg0) { return arg0.getFixedIp() == null; } })); // try to prevent multiple parallel launches from choosing the same ip. Collections.shuffle(unassignedIps); ip = Iterables.getLast(unassignedIps); } logger.debug(">> adding floatingIp(%s) to node(%s)", ip.getIp(), node.getId()); floatingIpClient.addFloatingIPToServer(ip.getIp(), node.getProviderId()); input.set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getIp())).build()); floatingIpCache.invalidate(ZoneAndId.fromSlashEncoded(node.getId())); return input; }
From source file:org.diqube.plan.planner.RemoteColumnManager.java
@Override public void wireOutputOfColumnIfAvailable(String colName, RExecutionPlanStep targetStep) { if (functionRemoteSteps.containsKey(colName)) { RExecutionPlanStep previousStep = Iterables.getLast(functionRemoteSteps.get(colName)); remoteWireManager.wire(ColumnBuiltConsumer.class, previousStep, targetStep); }/*from w w w .j av a 2 s . c om*/ }
From source file:org.eclipse.xtend.core.scoping.NestedTypesScope.java
protected IEObjectDescription doGetSingleElement(JvmDeclaredType declarator, QualifiedName name, String firstSegment, int dollarIndex) { if (declarator.isLocal()) { JvmTypeReference superTypeReference = Iterables.getLast(declarator.getSuperTypes()); if (InferredTypeIndicator.isInferred(superTypeReference)) return findNestedTypeInLocalTypeNonResolving(declarator, name, firstSegment, dollarIndex); }/* ww w . j a v a 2s .c om*/ Iterable<JvmDeclaredType> nestedTypes = declarator.findAllNestedTypesByName(firstSegment); for (JvmDeclaredType nested : nestedTypes) { JvmType nestedType = findNestedType(nested, 0, name); if (nestedType != null) { return toDescription(name, nestedType, dollarIndex, 0); } } return null; }
From source file:org.opendaylight.sfc.scfofrenderer.SfcNshHeader.java
public static SfcNshHeader getSfcNshHeader(RspName rspName) { if (rspName == null) { LOG.error("getSfcNshHeader: rspName is null\n"); return null; }/*from w w w . j a v a 2s . c o m*/ RenderedServicePath renderedServicePath = SfcProviderRenderedPathAPI.readRenderedServicePath(rspName); if (renderedServicePath == null) { LOG.error("getSfcNshHeader: rsp is null\n"); return null; } RenderedServicePathFirstHop rspFirstHop = SfcProviderRenderedPathAPI .readRenderedServicePathFirstHop(rspName); if (rspFirstHop == null) { LOG.error("getSfcNshHeader: rsp first hop is null\n"); return null; } if (rspFirstHop.getIp() == null) { LOG.error("getSfcNshHeader: ip address of rsp first hop is null\n"); return null; } if (renderedServicePath.getRenderedServicePathHop() == null) { LOG.error("getSfcNshHeader: getRenderedServicePathHop is null\n"); return null; } RenderedServicePathHop lastRspHop = Iterables.getLast(renderedServicePath.getRenderedServicePathHop()); if (lastRspHop == null) { LOG.error("getSfcNshHeader: last rsp hop is null\n"); return null; } SffName sffName = lastRspHop.getServiceFunctionForwarder(); SfcNshHeader sfcNshHeader = new SfcNshHeader().setVxlanIpDst(rspFirstHop.getIp().getIpv4Address()) .setVxlanUdpPort(rspFirstHop.getPort()).setNshNsp(renderedServicePath.getPathId()) .setNshStartNsi(rspFirstHop.getStartingIndex()) .setNshEndNsi((short) (lastRspHop.getServiceIndex().intValue() - 1)) .setSffName(lastRspHop.getServiceFunctionForwarder()); String context = renderedServicePath.getContextMetadata(); if (context == null) { LOG.error("getSfcNshHeader: context is null\n"); } ContextMetadata md = SfcProviderServiceFunctionMetadataAPI.readContextMetadata(context); if (md == null) { LOG.error("getSfcNshHeader: metadata is null\n"); } else { sfcNshHeader.setNshMetaC1(md.getContextHeader1()).setNshMetaC2(md.getContextHeader2()) .setNshMetaC3(md.getContextHeader3()).setNshMetaC4(md.getContextHeader4()); } return sfcNshHeader; }
From source file:stormy.pythian.features.web.support.WebConnector.java
public WebElement retrieve_last(By by) { try {/*w ww. j av a2 s . c om*/ return Iterables.getLast(driver.findElements(by)); } catch (NoSuchElementException ex) { return null; } }
From source file:org.jclouds.gogrid.GoGridLiveTestDisabled.java
@Test(enabled = true) public void testDescriptionIs500Characters() { final String nameOfServer = "Description" + String.valueOf(new Date().getTime()).substring(6); serversToDeleteAfterTheTests.add(nameOfServer); Set<Ip> availableIps = api.getIpServices().getUnassignedPublicIpList(); Ip availableIp = Iterables.getLast(availableIps); String ram = Iterables.get(api.getServerServices().getRamSizes(), 0).getName(); StringBuilder builder = new StringBuilder(); for (int i = 0; i < 500; i++) builder.append('a'); String description = builder.toString(); Server createdServer = api.getServerServices().addServer(nameOfServer, "GSI-f8979644-e646-4711-ad58-d98a5fa3612c", ram, availableIp.getIp(), new AddServerOptions().withDescription(description)); assertNotNull(createdServer);/*from www . ja va 2 s. c o m*/ assert serverLatestJobCompleted.apply(createdServer); assertEquals(Iterables.getLast(api.getServerServices().getServersByName(nameOfServer)).getDescription(), description); }
From source file:com.haulmont.cuba.web.exception.RowLevelSecurityExceptionHandler.java
@Override protected void doHandle(App app, String className, String message, @Nullable Throwable throwable) { try {/*from ww w . ja va 2s. co m*/ // we may show two or more dialogs if user pressed F5 and we have no valid user session // just remove previous dialog and show new if (dialog != null) { app.getAppUI().removeWindow(dialog); } Messages messages = AppBeans.get(Messages.NAME); String userCaption = messages.getMessage("com.haulmont.cuba.gui", "rowLevelSecurity.caption"); String userMessage = null; if (throwable != null) { Throwable rootCause = ExceptionUtils.getRootCause(throwable); RowLevelSecurityException rowLevelSecurityException = null; if (throwable instanceof RowLevelSecurityException) { rowLevelSecurityException = (RowLevelSecurityException) throwable; } else if (rootCause instanceof RowLevelSecurityException) { rowLevelSecurityException = (RowLevelSecurityException) rootCause; } if (rowLevelSecurityException != null) { String entity = rowLevelSecurityException.getEntity(); MetaClass entityClass = AppBeans.get(Metadata.NAME, Metadata.class).getClassNN(entity); String entityCaption = messages.getTools().getEntityCaption(entityClass, locale); ConstraintOperationType operationType = rowLevelSecurityException.getOperationType(); if (operationType != null) { userMessage = messages.formatMessage("com.haulmont.cuba.gui", "rowLevelSecurity.entityAndOperationMessage", locale, messages.getMessage(operationType), entityCaption); } else if (entity != null) { userMessage = messages.formatMessage("com.haulmont.cuba.gui", "rowLevelSecurity.entityMessage", locale, entityCaption); } } } WebWindowManager wm = app.getWindowManager(); wm.showNotification(userCaption, userMessage, Frame.NotificationType.ERROR); Collection<Window> windows = app.getAppUI().getWindows(); if (!windows.isEmpty()) { dialog = Iterables.getLast(windows); } } catch (Throwable th) { log.error("Unable to handle RowLevelSecurityException", throwable); log.error("Exception in RowLevelSecurityExceptionHandler", th); } }
From source file:org.jclouds.openstack.nova.v2_0.compute.functions.AllocateAndAddFloatingIpToNode.java
@Override public AtomicReference<NodeMetadata> apply(AtomicReference<NodeMetadata> input) { checkState(nodeRunning.apply(input), "node never achieved state running %s", input.get()); NodeMetadata node = input.get();// w ww .j av a2 s .c o m // node's location is a host String zoneId = node.getLocation().getParent().getId(); FloatingIPApi floatingIpApi = novaApi.getFloatingIPExtensionForZone(zoneId).get(); FloatingIP ip = null; try { logger.debug(">> allocating or reassigning floating ip for node(%s)", node.getId()); ip = floatingIpApi.create(); } catch (InsufficientResourcesException e) { logger.trace("<< [%s] allocating a new floating ip for node(%s)", e.getMessage(), node.getId()); logger.trace(">> searching for existing, unassigned floating ip for node(%s)", node.getId()); ArrayList<FloatingIP> unassignedIps = Lists .newArrayList(Iterables.filter(floatingIpApi.list(), new Predicate<FloatingIP>() { @Override public boolean apply(FloatingIP arg0) { return arg0.getFixedIp() == null; } })); // try to prevent multiple parallel launches from choosing the same ip. Collections.shuffle(unassignedIps); ip = Iterables.getLast(unassignedIps); } logger.debug(">> adding floatingIp(%s) to node(%s)", ip.getIp(), node.getId()); floatingIpApi.addToServer(ip.getIp(), node.getProviderId()); input.set(NodeMetadataBuilder.fromNodeMetadata(node).publicAddresses(ImmutableSet.of(ip.getIp())).build()); floatingIpCache.invalidate(ZoneAndId.fromSlashEncoded(node.getId())); return input; }
From source file:eu.artist.reusevol.repo.common.model.RepoCategory.java
private String getNameFromCategoryName(CategoryName name) { if (name == null) return null; if (name.getSegments().size() > 0) { return Iterables.getLast(name.getSegments()); } else {/*www.ja v a2s. c o m*/ return "root"; } }