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:forge.game.spellability.TargetChoices.java

public final Card getFirstTargetedCard() {
    return Iterables.getFirst(targetCards, null);
}

From source file:com.jive.myco.seyren.core.service.notification.SlackNotificationService.java

private String formatContent(List<String> emojis, Check check, Subscription subscription, List<Alert> alerts) {
    String url = String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getId());
    String alertsString = Joiner.on(", ").join(transform(alerts, new Function<Alert, String>() {
        @Override/*from  www. j a  va2  s.c o m*/
        public String apply(Alert input) {
            return String.format("%s: %s", input.getTarget(), input.getValue().toString());
        }
    }));
    return String.format("[%s] %s %s has entered its %s state - [%s] - %s",
            Iterables.getFirst(alerts, null).getTimestamp(),
            Iterables.get(emojis, check.getState().ordinal(), ""), check.getName(), check.getState().toString(),
            alertsString, url);
}

From source file:org.jclouds.abiquo.domain.infrastructure.Tier.java

/**
 * Retrieve the first storage pool matching the filter within the list of
 * pools in this tier./*  w  w  w.j a  v  a2  s .  com*/
 * 
 * @param filter
 *           Filter to be applied to the list.
 * @see API: <a href=
 *      "http://community.abiquo.com/display/ABI20/StoragePoolResource#StoragePoolResource-Retrievestoragepools"
 *      > http://community.abiquo.com/display/ABI20/StoragePoolResource#
 *      StoragePoolResource- Retrievestoragepools</a>
 * @return First storage pool matching the filter or <code>null</code> if
 *         there is none.
 */
public StoragePool findStoragePool(final Predicate<StoragePool> filter) {
    return Iterables.getFirst(filter(listStoragePools(), filter), null);
}

From source file:org.sonar.java.se.checks.RedundantAssignmentsCheck.java

@Override
public void checkEndOfExecution(CheckerContext context) {
    for (Map.Entry<AssignmentExpressionTree, Collection<AssignmentDataHolder>> assignmentForTree : assignmentsByMethod
            .pop().asMap().entrySet()) {
        Collection<AssignmentDataHolder> allAssignments = assignmentForTree.getValue();
        if (allAssignments.stream().allMatch(AssignmentDataHolder::isRedundant)) {
            Set<Flow> flows = allAssignments.stream().map(AssignmentDataHolder::flows).flatMap(Set::stream)
                    .collect(Collectors.toSet());
            reportIssue(assignmentForTree.getKey(), String.format(
                    "Remove this useless assignment; \"%s\" already holds the assigned value along all execution paths.",
                    Iterables.getFirst(allAssignments, null).assignedSymbol.name()), flows);
        }/*from w  w  w. jav  a 2  s  .com*/
    }
}

From source file:forge.game.spellability.TargetChoices.java

public final Player getFirstTargetedPlayer() {
    return Iterables.getFirst(targetPlayers, null);
}

From source file:com.jive.myco.seyren.core.service.notification.FlowdockNotificationService.java

private String formatContent(List<String> emojis, Check check, Subscription subscription, List<Alert> alerts) {
    String url = String.format("%s/#/checks/%s", seyrenConfig.getBaseUrl(), check.getId());
    String alertsString = Joiner.on(", ").join(transform(alerts, new Function<Alert, String>() {
        @Override/*  ww  w  . ja v  a  2 s. c  om*/
        public String apply(Alert input) {
            return String.format("%s: %s", input.getTarget(), input.getValue().toString());
        }
    }));
    return String.format("%s %s has entered its %s state - [%s] - %s - %s",
            Iterables.get(emojis, check.getState().ordinal(), ""), check.getName(), check.getState().toString(),
            alertsString, Iterables.getFirst(alerts, null).getTimestamp(), url);
}

From source file:org.loadui.testfx.service.finder.impl.NodeFinderImpl.java

public Node node(String query, Node parentNode) {
    Set<Node> resultNodes = nodes(query, parentNode);
    return Iterables.getFirst(resultNodes, null);
}

From source file:org.splevo.ui.dashboard.ConfigurationTab.java

private Group buildFeatureModelBuilderGroup(Composite composite) {

    Group group = new Group(composite, SWT.FILL);
    group.setText("FeatureModel Builders");
    group.setLayout(new GridLayout(columnNum, true));
    group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));

    Label configLabel = new Label(group, SWT.NONE);
    configLabel.setText("Feature Model Builder:");
    //configLabel.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_CENTER));

    GridData gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL);
    gridData.horizontalSpan = columnNum - 1;

    final Combo fmBuilderCombo = new Combo(group, SWT.READ_ONLY | SWT.DROP_DOWN);
    fmBuilderCombo.setLayoutData(gridData);
    for (FeatureModelBuilder<?> fmBuilder : FeatureModelBuilderRegistry.getInstance().getElements()) {
        fmBuilderCombo.add(fmBuilder.getLabel());
    }/*from  w ww .  j ava 2 s.c om*/

    FeatureModelBuilder<Object> firstFmBuilderInRegistry = Iterables
            .getFirst(FeatureModelBuilderRegistry.getInstance().getElements(), null);
    FeatureModelBuilder<Object> defaultFMBuilderInProject = FeatureModelBuilderRegistry.getInstance()
            .getElementById(getSPLevoProject().getFmBuilderId());
    final FeatureModelBuilder<Object> activeFmBuilder = defaultFMBuilderInProject == null
            ? firstFmBuilderInRegistry
            : defaultFMBuilderInProject;
    if (activeFmBuilder != null) {
        int index = Iterables.indexOf(Lists.newArrayList(fmBuilderCombo.getItems()), new Predicate<String>() {
            @Override
            public boolean apply(String itemLabel) {
                return itemLabel.equals(activeFmBuilder.getLabel());
            }
        });
        fmBuilderCombo.select(index);
        getSPLevoProject().setFmBuilderId(activeFmBuilder.getId());
    }

    fmBuilderCombo.addSelectionListener(new SelectionAdapter() {
        @Override
        public void widgetSelected(SelectionEvent arg0) {
            String fmBuilderId = FeatureModelBuilderRegistry.getInstance()
                    .getIdByLabel(fmBuilderCombo.getText());
            if (fmBuilderId != null && !getSPLevoProject().getFmBuilderId().equals(fmBuilderId)) {
                getSPLevoProject().setFmBuilderId(fmBuilderId);
                getSplevoProjectEditor().markAsDirty();
            }
        }
    });

    return group;
}

From source file:com.palantir.atlasdb.shell.AtlasShellConnectionDialogModel.java

public void removeSavedDbConnections(String nameToRemove) {
    savedDbConnections.remove(nameToRemove);
    if (Objects.equal(selectedItem, nameToRemove)) {
        setSelectedItem(Iterables.getFirst(savedDbConnections, null));
    }/*from   w w  w  . j a v a2s  . co  m*/
    this.update();
}

From source file:com.google.devtools.build.lib.util.GroupedList.java

public void appendGroup(Collection<T> group) {
    // Do a check to make sure we don't have lists here. Note that if group is empty,
    // Iterables.getFirst will return null, and null is not instanceof List.
    Preconditions.checkState(!(Iterables.getFirst(group, null) instanceof List),
            "Cannot make grouped list of lists: %s", group);
    switch (group.size()) {
    case 0:/*w  w w.jav a  2  s  .  co m*/
        return;
    case 1:
        elements.add(Iterables.getOnlyElement(group));
        break;
    default:
        elements.add(group);
        break;
    }
    size += group.size();
}