Example usage for com.google.common.collect Iterables getFirst

List of usage examples for com.google.common.collect Iterables getFirst

Introduction

In this page you can find the example usage for com.google.common.collect Iterables getFirst.

Prototype

@Nullable
public static <T> T getFirst(Iterable<? extends T> iterable, @Nullable T defaultValue) 

Source Link

Document

Returns the first element in iterable or defaultValue if the iterable is empty.

Usage

From source file:org.apache.metron.common.writer.WriterToBulkWriter.java

@Override
public void write(String sensorType, WriterConfiguration configurations, Iterable<Tuple> tuples,
        List<MESSAGE_T> messages) throws Exception {
    if (messages.size() > 1) {
        throw new IllegalStateException("WriterToBulkWriter expects a batch of exactly 1");
    }/*from  w ww. j  av  a  2 s .  c o  m*/
    messageWriter.write(sensorType, configurations, Iterables.getFirst(tuples, null),
            Iterables.getFirst(messages, null));
}

From source file:com.android.tools.idea.npw.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.of(importGradle, importEclipse);
    } else if (wizardPath instanceof WrapArchiveWizardPath) {
        ChooseTemplateStep.MetadataListItem template = Iterables.getFirst(templates, null);
        assert template != null;
        return Collections.singleton(new LegacyModuleTemplate(template, "Import .JAR/.AAR Package",
                "Import an existing JAR or AAR package as a new project module",
                AndroidIcons.ModuleTemplates.Android));
    } else {//  w w w  .  j  a  va2s.  com
        ImmutableList.Builder<ModuleTemplate> templatesBuilder = ImmutableList.builder();
        for (ChooseTemplateStep.MetadataListItem template : templates) {
            templatesBuilder.add(new LegacyModuleTemplate(template, null));
        }
        return templatesBuilder.build();
    }
}

From source file:com.github.vbauer.yta.converter.TranslationConverter.java

/**
 * {@inheritDoc}// w w w .j  av a2s  . co  m
 */
@Nonnull
@Override
protected Translation doForward(@Nonnull final TranslationInfo translationInfo) {
    final String text = Strings.nullToEmpty(Iterables.getFirst(translationInfo.text(), null));
    final Direction direction = DirectionConverter.INSTANCE.convert(translationInfo.lang());
    return Translation.of(direction, text);
}

From source file:com.google.idea.blaze.base.run.targetfinder.TargetFinder.java

@Nullable
public TargetIdeInfo firstTargetOfKinds(Project project, Kind... kinds) {
    return Iterables.getFirst(targetsOfKinds(project, kinds), null);
}

From source file:com.google.idea.blaze.android.run.test.BlazeAndroidTestApplicationIdProvider.java

@NotNull
@Override/*from   w  ww. jav a2  s .com*/
public String getPackageName() throws ApkProvisionException {
    BlazeAndroidDeployInfo deployInfo = Futures.get(deployInfoFuture, ApkProvisionException.class);
    Manifest manifest = Iterables.getFirst(deployInfo.getAdditionalMergedManifests(), null);
    if (manifest == null) {
        // The application may not have a separate package,
        // and can instead be in the same package as the tests.
        return getTestPackageName();
    }
    String applicationId = ApplicationManager.getApplication()
            .runReadAction((Computable<String>) () -> manifest.getPackage().getValue());
    if (applicationId == null) {
        throw new ApkProvisionException("No application id in manifest under test");
    }
    return applicationId;
}

From source file:eu.trentorise.opendata.semtext.SemTexts.java

/**
 * Determines the best meaning among the given ones according to their
 * probabilities. If no best meaning is found null is returned.
 *
 * @param meanings a sorted list of meanings, with the first ones being the
 * most important./* w w w.  j  a  va  2s.c o m*/
 * @return the disambiguated meaning or null if no meaning can be clearly
 * identified.
 */
@Nullable
public static Meaning disambiguate(Iterable<Meaning> meanings) {

    if (Iterables.isEmpty(meanings)) {
        return null;
    }

    int size = Iterables.size(meanings);

    if (size == 1) {
        Meaning m = meanings.iterator().next();
        if (m.getId() == null) {
            return null;
        } else {
            return m;
        }
    }

    Meaning first = Iterables.getFirst(meanings, null);

    if (first.getProbability() > DISAMBIGUATION_FACTOR / size && first.getId() != null) {
        return first;
    } else {
        return null;
    }

}

From source file:org.sosy_lab.cpachecker.cpa.singleSuccessorCompactor.SingleSuccessorCompactorTransferRelation.java

@Override
public Collection<? extends AbstractState> getAbstractSuccessors(AbstractState state, Precision precision)
        throws CPATransferException, InterruptedException {

    // this is the main core of this CPA:
    // iterate as long as there is only one successor, abort on target, zero or multiple successors.

    Collection<? extends AbstractState> states;
    do {/*from  w w w .  j  a v a 2s. c  o  m*/
        states = delegate.getAbstractSuccessors(state, precision);
        state = Iterables.getFirst(states, null);
    } while (states.size() == 1 && !AbstractStates.isTargetState(state));
    return states;
}

From source file:com.google.gerrit.server.git.ProjectLevelConfig.java

public Config getWithInheritance() {
    Config cfgWithInheritance = new Config();
    try {//from w w w.  j a v  a  2  s  .c o  m
        cfgWithInheritance.fromText(get().toText());
    } catch (ConfigInvalidException e) {
        // cannot happen
    }
    ProjectState parent = Iterables.getFirst(project.parents(), null);
    if (parent != null) {
        Config parentCfg = parent.getConfig(fileName).getWithInheritance();
        for (String section : parentCfg.getSections()) {
            Set<String> allNames = get().getNames(section);
            for (String name : parentCfg.getNames(section)) {
                if (!allNames.contains(name)) {
                    cfgWithInheritance.setStringList(section, null, name,
                            Arrays.asList(parentCfg.getStringList(section, null, name)));
                }
            }

            for (String subsection : parentCfg.getSubsections(section)) {
                allNames = get().getNames(section, subsection);
                for (String name : parentCfg.getNames(section, subsection)) {
                    if (!allNames.contains(name)) {
                        cfgWithInheritance.setStringList(section, subsection, name,
                                Arrays.asList(parentCfg.getStringList(section, subsection, name)));
                    }
                }
            }
        }
    }
    return cfgWithInheritance;
}

From source file:org.apache.metron.common.csv.CSVConverter.java

public static Map.Entry<String, Integer> getColumnMapEntry(String column, int i) {
    if (column.contains(":")) {
        Iterable<String> tokens = Splitter.on(':').split(column);
        String col = Iterables.getFirst(tokens, null);
        Integer pos = Integer.parseInt(Iterables.getLast(tokens));
        return new AbstractMap.SimpleEntry<>(col, pos);
    } else {/*w  w w .jav a2s  .  co m*/
        return new AbstractMap.SimpleEntry<>(column, i);
    }

}

From source file:org.smartdeveloperhub.vocabulary.publisher.model.Example.java

public static Language language() {
    final Language language = new Language();
    language.setUri(Iterables.getFirst(Languages.getInstance().uri("en"), "Unknown"));
    language.setLabel("en");
    language.setName(Languages.getInstance().localizedName("en", Locale.ENGLISH));
    return language;
}