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

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

Introduction

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

Prototype

@Nullable
public static <T> T get(Iterable<? extends T> iterable, int position, @Nullable T defaultValue) 

Source Link

Document

Returns the element at the specified position in an iterable or a default value otherwise.

Usage

From source file:com.palantir.common.collect.IterableView.java

public T get(int position, @Nullable T defaultValue) {
    return Iterables.get(castAsIterable(), position, defaultValue);
}

From source file:brooklyn.entity.basic.SoftwareProcessImpl.java

protected MachineLocation getMachineOrNull() {
    return Iterables.get(Iterables.filter(getLocations(), MachineLocation.class), 0, null);
}

From source file:com.flaptor.indextank.storage.IndexLog.java

public Segment getFirstSortedSegment() {
    return Iterables.get(Segment.iterateSegments(root, getSegmentsPath(), true), 0, null);
}

From source file:com.flaptor.indextank.storage.IndexLog.java

public Segment getFirstSegment() {
    return Iterables.get(Segment.iterateSegments(root, getSegmentsPath()), 0, null);
}

From source file:com.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("\n").join(transform(alerts, new Function<Alert, String>() {
        @Override//www.  j  av a 2s .c om
        public String apply(Alert input) {
            return String.format("%s = %s (%s to %s)", input.getTarget(), input.getValue().toString(),
                    input.getFromType(), input.getToType());
        }
    }));

    String channel = subscription.getTarget().contains("!") ? "<!channel>" : "";

    String description;
    if (StringUtils.isNotBlank(check.getDescription())) {
        description = String.format("\n> %s", check.getDescription());
    } else {
        description = "";
    }

    final String state = check.getState().toString();

    return String.format("%s*%s* %s [%s]%s\n```\n%s\n```\n#%s %s",
            Iterables.get(emojis, check.getState().ordinal(), ""), state, check.getName(), url, description,
            alertsString, state.toLowerCase(Locale.getDefault()), channel);
}

From source file:brooklyn.entity.database.postgresql.PostgreSqlNodeSaltImpl.java

protected void connectSensors() {
    setAttribute(DATASTORE_URL,/*  w  w  w .  ja va2s . c  om*/
            String.format("postgresql://%s:%s/", getAttribute(HOSTNAME), getAttribute(POSTGRESQL_PORT)));

    Location machine = Iterables.get(getLocations(), 0, null);

    if (machine instanceof SshMachineLocation) {
        feed = SshFeed.builder().entity(this).machine((SshMachineLocation) machine)
                .poll(new SshPollConfig<Boolean>(SERVICE_UP).command("ps -ef | grep [p]ostgres")
                        .setOnSuccess(true).setOnFailureOrException(false))
                .build();
    } else {
        LOG.warn(
                "Location(s) %s not an ssh-machine location, so not polling for status; setting serviceUp immediately",
                getLocations());
    }
}

From source file:org.polymap.wbv.model.Waldbesitzer.java

public Kontakt besitzer() {
    return Iterables.get(kontakte(), besitzerIndex.get(), null);
}

From source file:org.apache.brooklyn.entity.database.postgresql.PostgreSqlNodeSaltImpl.java

protected void connectSensors() {
    sensors().set(DATASTORE_URL,//from   ww  w .j av  a 2s  .  c o m
            String.format("postgresql://%s:%s/", getAttribute(HOSTNAME), getAttribute(POSTGRESQL_PORT)));

    Location machine = Iterables.get(getLocations(), 0, null);

    if (machine instanceof SshMachineLocation) {
        feed = SshFeed.builder().entity(this).machine((SshMachineLocation) machine)
                .poll(new SshPollConfig<Boolean>(SERVICE_UP).command("ps -ef | grep [p]ostgres")
                        .setOnSuccess(true).setOnFailureOrException(false))
                .build();
    } else {
        LOG.warn(
                "Location(s) %s not an ssh-machine location, so not polling for status; setting serviceUp immediately",
                getLocations());
    }
}

From source file:fr.aliacom.obm.utils.HelperServiceImpl.java

private String getEmailWithoutDomain(String email) {
    if (email != null) {
        Iterable<String> it = Splitter.on('@').omitEmptyStrings().split(email);
        return Iterables.get(it, 0, "");
    }/*from  www .  j a v a2s.  c om*/
    return email;
}

From source file:org.apache.brooklyn.cloudfoundry.entity.CloudFoundryEntityImpl.java

private Optional<CloudFoundryPaasLocation> tryLocation() {
    return Optional.fromNullable(
            Iterables.get(Iterables.filter(getLocations(), CloudFoundryPaasLocation.class), 0, null));
}