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:com.eucalyptus.auth.util.Identifiers.java
private static String getRegionAccountNumberPartition() { return Iterables.getFirst(Partition.supplier.getAccountNumberPartitions(), "000"); }
From source file:com.ngdata.hbaseindexer.phoenix.AbstractUniqueKeyFormatter.java
@Override public final String formatRow(byte[] row) { Object formatted = Iterables.getFirst(byteArrayValueMapper.map(row), null); if (formatted == null) { throw new IllegalStateException("Formatted row was null from " + Arrays.toString(row)); }/* w w w . j ava2 s . c o m*/ return String.valueOf(formatted); }
From source file:net.caseif.ttt.util.helper.platform.BungeeHelper.java
public static void initialize() { checkState(!startedInitializing, "BungeeHelper initialization cannot be called more than once"); startedInitializing = true;//ww w.ja v a 2 s .c o m if (TTTCore.config.get(ConfigKey.RETURN_SERVER).isEmpty()) { return; } registerBungeeChannel(); sendPluginMessage("GetServers", null, Iterables.getFirst(Bukkit.getOnlinePlayers(), null)); }
From source file:org.apache.metron.indexing.dao.IndexDaoFactory.java
public static IndexDao combine(Iterable<IndexDao> daos, Function<IndexDao, IndexDao> daoTransformation) throws ClassNotFoundException, NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {/* www . j ava2 s. co m*/ int numDaos = Iterables.size(daos); if (numDaos == 0) { throw new IllegalArgumentException( "Trying to combine 0 dao's into a DAO is not a supported configuration."); } if (numDaos == 1) { return daoTransformation.apply(Iterables.getFirst(daos, null)); } return new MultiIndexDao(daos, daoTransformation); }
From source file:uk.gov.gchq.koryphe.impl.function.FirstItem.java
@Override @SuppressFBWarnings(value = "DE_MIGHT_IGNORE", justification = "Any exceptions are to be ignored") public T apply(final Iterable<T> input) { if (null == input) { throw new IllegalArgumentException("Input cannot be null"); }/*from w ww . j a va 2s. c o m*/ try { return Iterables.getFirst(input, null); } finally { CloseableUtil.close(input); } }
From source file:com.vilt.minium.impl.FrozenWindowWebElementsImpl.java
@Override public Iterable<WebElementsDriver<T>> candidateWebDrivers() { if (frozenWebElementsDriver == null) { WebElementsDriver<T> driver = null; Iterable<WebElementsDriver<T>> candidateHandles = super.candidateWebDrivers(); int size = size(candidateHandles); if (size == 1) { driver = Iterables.getFirst(candidateHandles, null); } else if (size > 1) { throw new WebElementsException("Cannot freeze window because more than one window matched"); }/* w ww . j av a 2s. co m*/ if (driver != null) { frozenWebElementsDriver = new WindowWebElementsDriver<T>(rootWebDriver(), factory, driver.getWindowHandle()); } } if (frozenWebElementsDriver == null) { return Collections.emptyList(); } return Collections.singletonList(frozenWebElementsDriver); }
From source file:com.android.tools.idea.wizard.LegacyPathWrapper.java
static Iterable<ModuleTemplate> getModuleTemplates(@NotNull WizardPath wizardPath) { Collection<ChooseTemplateStep.MetadataListItem> templates = wizardPath.getBuiltInTemplates(); if (wizardPath instanceof ImportSourceModulePath) { ChooseTemplateStep.MetadataListItem template = Iterables.getFirst(templates, null); assert template != null; LegacyModuleTemplate importEclipse = new LegacyModuleTemplate(template, "Import Eclipse ADT Project", "Import an existing Eclipse ADT project as a module", AndroidIcons.ModuleTemplates.EclipseModule); LegacyModuleTemplate importGradle = new LegacyModuleTemplate(template, "Import Gradle Project", "Import an existing Gradle project as a module", AndroidIcons.ModuleTemplates.GradleModule); return ImmutableList.<ModuleTemplate>of(importGradle, importEclipse); } else if (wizardPath instanceof WrapArchiveWizardPath) { ChooseTemplateStep.MetadataListItem template = Iterables.getFirst(templates, null); assert template != null; return Collections.<ModuleTemplate>singleton(new LegacyModuleTemplate(template, "Import .JAR/.AAR Package", "Import an existing JAR or AAR package as a new project module", AndroidIcons.ModuleTemplates.Android)); } else {/*from w w w. j a va 2s . co m*/ ImmutableList.Builder<ModuleTemplate> templatesBuilder = ImmutableList.builder(); for (ChooseTemplateStep.MetadataListItem template : templates) { templatesBuilder.add(new LegacyModuleTemplate(template, null)); } return templatesBuilder.build(); } }
From source file:org.apache.metron.performance.sampler.BiasedSampler.java
public static List<Map.Entry<Integer, Integer>> readDistribution(BufferedReader distrFile, boolean quiet) throws IOException { List<Map.Entry<Integer, Integer>> ret = new ArrayList<>(); if (!quiet) { System.out.println("Using biased sampler with the following biases:"); }/*ww w.jav a 2 s . com*/ int sumLeft = 0; int sumRight = 0; for (String line = null; (line = distrFile.readLine()) != null;) { if (line.startsWith("#")) { continue; } Iterable<String> it = Splitter.on(",").split(line.trim()); if (Iterables.size(it) != 2) { throw new IllegalArgumentException( line + " should be a comma separated pair of integers, but was not."); } int left = Integer.parseInt(Iterables.getFirst(it, null)); int right = Integer.parseInt(Iterables.getLast(it, null)); if (left <= 0 || left > 100) { throw new IllegalArgumentException( line + ": " + (left < 0 ? left : right) + " must a positive integer in (0, 100]"); } if (right <= 0 || right > 100) { throw new IllegalArgumentException(line + ": " + right + " must a positive integer in (0, 100]"); } if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); sumLeft += left; sumRight += right; } if (sumLeft > 100 || sumRight > 100) { throw new IllegalStateException( "Neither columns must sum to beyond 100. " + "The first column is the % of templates. " + "The second column is the % of the sample that % of template occupies."); } else if (sumLeft < 100 && sumRight < 100) { int left = 100 - sumLeft; int right = 100 - sumRight; if (!quiet) { System.out.println( "\t" + left + "% of templates will comprise roughly " + right + "% of sample output"); } ret.add(new AbstractMap.SimpleEntry<>(left, right)); } return ret; }
From source file:com.slimgears.slimapt.AnnotationProcessingTestBase.java
protected void testAnnotationProcessing(Iterable<AbstractProcessor> processor, Iterable<JavaFileObject> inputs, Iterable<JavaFileObject> expectedOutputs) { assert_().about(javaSources()).that(inputs).processedWith(processor).compilesWithoutError().and() .generatesSources(Iterables.getFirst(expectedOutputs, null), toArray(skip(expectedOutputs, 1), JavaFileObject.class)); }
From source file:com.eucalyptus.auth.util.Identifiers.java
private static String getRegionIdentifierPartition() { return Iterables.getFirst(Partition.supplier.getIdentifierPartitions(), "AA"); }