List of usage examples for com.google.common.collect Iterables find
public static <T> T find(Iterable<T> iterable, Predicate<? super T> predicate)
From source file:org.obiba.onyx.quartz.editor.locale.LocaleProperties.java
public KeyValue getKeyValue(IQuestionnaireElement element, Locale locale, final String key) { ListMultimap<Locale, KeyValue> labels = getElementLabels(element); if (labels != null) { List<KeyValue> keyValueList = labels.get(locale); if (keyValueList != null) { try { return Iterables.find(keyValueList, new Predicate<KeyValue>() { @Override// ww w . jav a 2s.c o m public boolean apply(@Nullable KeyValue keyValue) { return keyValue != null && StringUtils.equals(keyValue.getKey(), key); } }); } catch (NoSuchElementException e) { // do nothing } } } return null; }
From source file:org.linagora.linshare.view.tapestry.pages.uploadrequest.Index.java
@Log public Object onActionFromShowContent(String uuid) { content.setMySelected(Iterables.find(requests, UploadRequestVo.equalTo(uuid))); return content; }
From source file:com.eviware.soapui.utils.ContainerWalker.java
public JTextComponent findTextComponent(String componentName) { JTextComponent component = (JTextComponent) Iterables.find(containedComponents, new ComponentClassAndNamePredicate(JTextComponent.class, componentName)); if (component == null) { throw new NoSuchElementException("No text component with name '" + componentName + "' found"); }/*from w w w .j a va 2s . c o m*/ return component; }
From source file:org.linagora.linshare.view.tapestry.components.ListUserThread.java
public void onActionFromAdd(String uuid) throws BusinessException { UserVo u = Iterables.find(users, UserVo.equalTo(uuid)); threadEntryFacade.addMember(userVo, thread, u.getDomainIdentifier(), u.getMail()); }
From source file:org.jclouds.deltacloud.compute.functions.InstanceToNodeMetadata.java
protected OperatingSystem parseOperatingSystem(Instance from) { try {// w w w. j a va2 s .c om return Iterables.find(images.get(), new FindImageForInstance(from)).getOperatingSystem(); } catch (NoSuchElementException e) { logger.warn("could not find a matching image for instance %s", from); } return null; }
From source file:clocker.docker.networking.entity.sdn.util.SdnUtils.java
public static final VirtualNetwork lookupNetwork(final SdnProvider provider, final String networkId) { Task<Boolean> lookup = TaskBuilder.<Boolean>builder() .displayName("Waiting until virtual network is available").body(new Callable<Boolean>() { @Override/*from ww w . ja v a2 s. c o m*/ public Boolean call() throws Exception { return Repeater.create().every(Duration.TEN_SECONDS).until(new Callable<Boolean>() { public Boolean call() { Optional<Entity> found = Iterables.tryFind( provider.sensors().get(SdnProvider.SDN_NETWORKS).getMembers(), EntityPredicates.attributeEqualTo(VirtualNetwork.NETWORK_ID, networkId)); return found.isPresent(); } }).limitTimeTo(Duration.ONE_MINUTE).run(); } }).build(); Boolean result = DynamicTasks.queueIfPossible(lookup).orSubmitAndBlock().andWaitForSuccess(); if (!result) { throw new IllegalStateException(String.format("Cannot find virtual network entity for %s", networkId)); } VirtualNetwork network = (VirtualNetwork) Iterables.find( provider.sensors().get(SdnProvider.SDN_NETWORKS).getMembers(), EntityPredicates.attributeEqualTo(VirtualNetwork.NETWORK_ID, networkId)); return network; }
From source file:org.jclouds.fujitsu.fgcp.compute.functions.VServerMetadataToNodeMetadata.java
protected Image parseImage(VServer from) { try {/* www .j a v a 2 s . co m*/ return Iterables.find(images.get(), new FindImageForVServer(from)); } catch (NoSuchElementException e) { logger.warn("could not find a matching image for server %s", from); } return null; }
From source file:org.linagora.linshare.view.tapestry.pages.uploadrequest.Proposition.java
@Log public void onActionFromReject(String uuid) throws BusinessException { UploadPropositionVo res = Iterables.find(propositions, UploadPropositionVo.equalTo(uuid)); uploadPropositionFacade.reject(userVo, res); }
From source file:broadwick.model.Model.java
/** * Get the value of a parameter for the model given the parameter name (as defined in the config file). * @param name the name of the parameter. * @return a string value of the value for the parameter. *//*from w ww .j a v a 2 s . c om*/ public final String getParameterValue(final String name) { try { return Iterables.find(parameters, new Predicate<Parameter>() { @Override public boolean apply(final Parameter parameter) { return name.equals(parameter.getId()); } }).getValue(); } catch (java.util.NoSuchElementException e) { log.error("{} in is not configured for the model.", name); throw new BroadwickException(String.format("Could not find parameter %s in configuration file.", name)); } }
From source file:cc.kave.commons.pointsto.evaluation.runners.ProjectStoreRunner.java
private static void methodPropabilities(Collection<ICoReTypeName> types, ProjectUsageStore store) throws IOException { ICoReTypeName stringType = Iterables.find(types, t -> t.getClassName().equals("String")); Map<ICoReMethodName, Integer> methods = new HashMap<>(); for (Usage usage : store.load(stringType)) { for (CallSite cs : usage.getReceiverCallsites()) { Integer currentCount = methods.getOrDefault(cs.getMethod(), 0); methods.put(cs.getMethod(), currentCount + 1); }/* w w w . ja va 2 s . c om*/ } double total = methods.values().stream().mapToInt(i -> i).sum(); List<Map.Entry<ICoReMethodName, Integer>> methodEntries = new ArrayList<>(methods.entrySet()); methodEntries .sort(Comparator.<Map.Entry<ICoReMethodName, Integer>>comparingInt(e -> e.getValue()).reversed()); double mrr = 0; double rank = 1.0; for (Map.Entry<ICoReMethodName, Integer> method : methodEntries) { double probability = method.getValue() / total; mrr += probability * (1.0 / rank); ++rank; System.out.printf(Locale.US, "%s\t%.3f\n", method.getKey().getName(), probability); } System.out.println(mrr); }