List of usage examples for com.google.common.collect Iterables getFirst
@Nullable public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue)
From source file:alluxio.collections.NonUniqueFieldIndex.java
@Override public T getFirst(Object value) { Set<T> all = mIndexMap.get(value); return all == null ? null : Iterables.getFirst(all, null); }
From source file:org.jpmml.evaluator.MatrixUtil.java
static private Number getMatCellValue(List<MatCell> matCells, final int row, final int column) { Predicate<MatCell> filter = new Predicate<MatCell>() { @Override/*w w w .jav a 2 s.c o m*/ public boolean apply(MatCell matCell) { return (getRow(matCell) == row) && (getColumn(matCell) == column); } }; MatCell matCell = Iterables.getFirst(Iterables.filter(matCells, filter), null); if (matCell != null) { String value = matCell.getValue(); return Double.valueOf(value); } return null; }
From source file:org.jclouds.vcloud.director.v1_5.domain.dmtf.Envelope.java
public VirtualSystem getVirtualSystem() { if (virtualSystem != null) { return virtualSystem; } else if (virtualSystemCollection == null || virtualSystemCollection.getVirtualSystems() == null) { return null; } else {/*from w w w . j av a2 s . c o m*/ return Iterables.getFirst(virtualSystemCollection.getVirtualSystems(), null); } }
From source file:org.javabits.yar.guice.CacheContainer.java
@Nullable @Override public V getFirst(Type key) { return Iterables.getFirst(getAll(key), null); }
From source file:com.google.security.zynamics.binnavi.debug.helpers.EchoBreakpointCollector.java
@Override public IterationMode next(final NaviNode node) { final INaviViewNode viewNode = node.getRawNode(); if (viewNode instanceof INaviCodeNode) { final INaviCodeNode codeNode = (INaviCodeNode) viewNode; final INaviInstruction instruction = Iterables.getFirst(codeNode.getInstructions(), null); final INaviModule module = instruction.getModule(); final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(instruction.getAddress())); if (isBlocked(manager, address)) { return IterationMode.CONTINUE; }// w w w . ja v a2 s .c o m NaviLogger.info("Adding Echo breakpoint %s to the active list", address.getAddress().getAddress().toHexString()); // Add the echo breakpoint to the list of active echo breakpoints echoBreakpointAbleAddresses.add(address); } else if (viewNode instanceof INaviFunctionNode) { final INaviFunctionNode functionNode = (INaviFunctionNode) viewNode; final INaviModule module = functionNode.getFunction().getModule(); final BreakpointAddress address = new BreakpointAddress(module, new UnrelocatedAddress(functionNode.getFunction().getAddress())); if (isBlocked(manager, address)) { return IterationMode.CONTINUE; } NaviLogger.info("Adding Echo breakpoint %s to the active list", address.getAddress().getAddress().toHexString()); // Add the echo breakpoint to the list of active echo breakpoints echoBreakpointAbleAddresses.add(address); } return IterationMode.CONTINUE; }
From source file:com.palantir.typescript.TypeScriptProjects.java
public static IContainer getOutputFolder(IProject project) { checkNotNull(project);/*from w ww . j a v a 2 s . c o m*/ return Iterables.getFirst(getFoldersFromPreference(project, IPreferenceConstants.COMPILER_OUT_DIR), null); }
From source file:org.apache.beam.runners.spark.translation.SparkKeyedCombineFn.java
/** * Implements Spark's createCombiner function in: * <p>//from www . j a v a 2 s .com * {@link org.apache.spark.rdd.PairRDDFunctions#combineByKey}. * </p> */ Iterable<WindowedValue<KV<K, AccumT>>> createCombiner(WindowedValue<KV<K, InputT>> wkvi) { // sort exploded inputs. Iterable<WindowedValue<KV<K, InputT>>> sortedInputs = sortByWindows(wkvi.explodeWindows()); TimestampCombiner timestampCombiner = windowingStrategy.getTimestampCombiner(); WindowFn<?, BoundedWindow> windowFn = windowingStrategy.getWindowFn(); //--- inputs iterator, by window order. final Iterator<WindowedValue<KV<K, InputT>>> iterator = sortedInputs.iterator(); WindowedValue<KV<K, InputT>> currentInput = iterator.next(); BoundedWindow currentWindow = Iterables.getFirst(currentInput.getWindows(), null); // first create the accumulator and accumulate first input. K key = currentInput.getValue().getKey(); AccumT accumulator = combineFn.createAccumulator(ctxtForInput(currentInput)); accumulator = combineFn.addInput(accumulator, currentInput.getValue().getValue(), ctxtForInput(currentInput)); // keep track of the timestamps assigned by the TimestampCombiner. Instant windowTimestamp = timestampCombiner.assign(currentWindow, windowingStrategy.getWindowFn().getOutputTime(currentInput.getTimestamp(), currentWindow)); // accumulate the next windows, or output. List<WindowedValue<KV<K, AccumT>>> output = Lists.newArrayList(); // if merging, merge overlapping windows, e.g. Sessions. final boolean merging = !windowingStrategy.getWindowFn().isNonMerging(); while (iterator.hasNext()) { WindowedValue<KV<K, InputT>> nextValue = iterator.next(); BoundedWindow nextWindow = Iterables.getOnlyElement(nextValue.getWindows()); boolean mergingAndIntersecting = merging && isIntersecting((IntervalWindow) currentWindow, (IntervalWindow) nextWindow); if (mergingAndIntersecting || nextWindow.equals(currentWindow)) { if (mergingAndIntersecting) { // merge intersecting windows. currentWindow = merge((IntervalWindow) currentWindow, (IntervalWindow) nextWindow); } // keep accumulating and carry on ;-) accumulator = combineFn.addInput(accumulator, nextValue.getValue().getValue(), ctxtForInput(nextValue)); windowTimestamp = timestampCombiner.combine(windowTimestamp, timestampCombiner.assign(currentWindow, windowFn.getOutputTime(nextValue.getTimestamp(), currentWindow))); } else { // moving to the next window, first add the current accumulation to output // and initialize the accumulator. output.add(WindowedValue.of(KV.of(key, accumulator), windowTimestamp, currentWindow, PaneInfo.NO_FIRING)); // re-init accumulator, window and timestamp. accumulator = combineFn.createAccumulator(ctxtForInput(nextValue)); accumulator = combineFn.addInput(accumulator, nextValue.getValue().getValue(), ctxtForInput(nextValue)); currentWindow = nextWindow; windowTimestamp = timestampCombiner.assign(currentWindow, windowFn.getOutputTime(nextValue.getTimestamp(), currentWindow)); } } // add last accumulator to the output. output.add(WindowedValue.of(KV.of(key, accumulator), windowTimestamp, currentWindow, PaneInfo.NO_FIRING)); return output; }
From source file:org.obm.satellite.client.ConnectionImpl.java
@Override public void updateIMAPServer() throws SatteliteClientException, ConnectionException { if (!configuration.isIMAPServerManaged()) { return;/* w ww . j a v a 2 s . com*/ } ObmHost imapHost = Iterables.getFirst(domain.getHosts().get(ServiceProperty.IMAP), null); if (imapHost == null) { throw new SatteliteClientException( String.format("Domain %s doesn't have a linked mail/imap host", domain.getName())); } post(imapHost.getName(), imapHost.getIp(), SATELLITE_IMAP_PATH); }
From source file:com.opengamma.integration.viewer.status.impl.SimpleViewStatusModel.java
@Override public int getColumnCount() { return Iterables.getFirst(_columnHeaders, Lists.newArrayList()).size(); }
From source file:org.opendaylight.controller.config.yangjmxgenerator.plugin.gofactory.AbsModuleGeneratedObjectFactory.java
public GeneratedObject toGeneratedObject(ModuleMXBeanEntry mbe, Optional<String> copyright) { FullyQualifiedName abstractFQN = new FullyQualifiedName(mbe.getPackageName(), mbe.getAbstractModuleName()); Optional<String> classJavaDoc = Optional.fromNullable(mbe.getNullableDescription()); AbstractModuleTemplate abstractModuleTemplate = TemplateFactory.abstractModuleTemplateFromMbe(mbe); Optional<String> header = abstractModuleTemplate.getHeaderString(); List<FullyQualifiedName> implementedInterfaces = Lists.transform( abstractModuleTemplate.getTypeDeclaration().getImplemented(), FULLY_QUALIFIED_NAME_FUNCTION); Optional<FullyQualifiedName> extended = Optional.fromNullable(Iterables.getFirst(Collections2.transform( abstractModuleTemplate.getTypeDeclaration().getExtended(), FULLY_QUALIFIED_NAME_FUNCTION), null)); Optional<FullyQualifiedName> maybeRegistratorType; if (abstractModuleTemplate.isRuntime()) { maybeRegistratorType = Optional .of(FullyQualifiedName.fromString(abstractModuleTemplate.getRegistratorType())); } else {//from ww w. j a v a 2s. c om maybeRegistratorType = Optional.absent(); } return toGeneratedObject(abstractFQN, copyright, header, classJavaDoc, extended, implementedInterfaces, abstractModuleTemplate.getModuleFields(), maybeRegistratorType, abstractModuleTemplate.getMethods(), mbe.getYangModuleQName()); }