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:jp.xet.uncommons.wicket.model.SingleSelectModel.java

@Override
public T getObject() {
    return Iterables.getFirst(Iterables.filter(delegate.getObject(), predicate), null);
}

From source file:com.kolich.blog.entities.feed.AbstractFeedEntity.java

/**
 * Returns the first entry in the list of entries, or null if there was no first entry.
 *//*  w w  w .  j a  v a 2 s  . c  o m*/
public final Entry getFirst() {
    return Iterables.getFirst(entries_, null);
}

From source file:org.jclouds.cloudtransformer.openstack.DevstackNodeToOpenstack.java

@Override
public ComputeServiceContext apply(NodeMetadata input) {

    String address = Iterables.getFirst(input.getPublicAddresses(), null);

    Properties overrides = new Properties();
    overrides.setProperty(Constants.PROPERTY_ENDPOINT, "http://" + address + ":5000");
    overrides.setProperty(KeystoneProperties.CREDENTIAL_TYPE, CredentialType.PASSWORD_CREDENTIALS.toString());
    overrides.setProperty(KeystoneProperties.VERSION, "2.0");

    return new ComputeServiceContextFactory().createContext("openstack-nova", "admin:admin", "password",
            ImmutableSet.<Module>of(new SLF4JLoggingModule(), new SshjSshClientModule()), overrides);
}

From source file:org.apache.metron.common.field.transformation.RegexSelectTransformation.java

@Override
public Map<String, Object> map(Map<String, Object> input, List<String> outputField,
        LinkedHashMap<String, Object> fieldMappingConfig, Context context,
        Map<String, Object>... sensorConfig) {
    String outField = null;//from ww  w  .  jav  a2 s . c  om
    if (!(outputField == null || outputField.isEmpty())) {
        outField = outputField.get(0);
    }
    String inVal = null;
    if (!(input == null || input.isEmpty() || input.size() > 1)) {
        Object inValObj = Iterables.getFirst(input.entrySet(), null).getValue();
        if (inValObj != null) {
            inVal = inValObj.toString();
        }
    }
    Map<String, Object> ret = new HashMap<>(1);
    if (outField == null || inVal == null) {
        //in the situation where we don't have valid input or output, then we want to do nothing
        return ret;
    }
    for (Map.Entry<String, Object> valToRegex : fieldMappingConfig.entrySet()) {
        if (isMatch(valToRegex.getValue(), inVal)) {
            ret.put(outField, valToRegex.getKey());
            break;
        }
    }
    return ret;
}

From source file:it.f2informatica.core.validator.utils.ErrorMessageResolver.java

public List<ErrorMessage> resolveErrorCodes(List<FieldError> fieldErrors, final Locale locale) {
    return Lists.newArrayList(Iterables.transform(fieldErrors, new Function<FieldError, ErrorMessage>() {
        @Override//w  w  w .jav a  2 s .  c  o m
        public ErrorMessage apply(FieldError input) {
            String errorCode = input.getCode();
            String errorMessage = messageSource.getMessage(errorCode, input.getArguments(), locale);
            String field = Iterables.getFirst(Arrays.asList(input.getField().split("\\.")), "");
            return new ErrorMessage(field, errorCode, errorMessage);
        }
    }));
}

From source file:io.druid.server.router.PriorityTieredBrokerSelectorStrategy.java

@Override
public Optional<String> getBrokerServiceName(TieredBrokerConfig tierConfig, Query query) {
    final int priority = query.getContextPriority(0);

    if (priority < minPriority) {
        return Optional.of(Iterables.getLast(tierConfig.getTierToBrokerMap().values(),
                tierConfig.getDefaultBrokerServiceName()));
    } else if (priority >= maxPriority) {
        return Optional.of(Iterables.getFirst(tierConfig.getTierToBrokerMap().values(),
                tierConfig.getDefaultBrokerServiceName()));
    }/* ww w. j  ava 2  s . c  o  m*/

    return Optional.absent();
}

From source file:org.apache.metron.dataloads.extractor.csv.CSVExtractor.java

private 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 {/*from   w ww .  j a  v  a 2  s.  c  o m*/
        return new AbstractMap.SimpleEntry<>(column, i);
    }

}

From source file:ezbake.publisher.service.PublisherBroadcaster.java

@Override
protected Optional<byte[]> receiveImpl(String topic) throws IOException {
    Collection<byte[]> dataForTopic = broadcasted.get(topic);
    byte[] first = Iterables.getFirst(dataForTopic, null);
    if (first == null) {
        return Optional.absent();
    }//w w w  .  j av  a  2  s . co m
    dataForTopic.remove(first);
    return Optional.of(first);
}

From source file:org.jclouds.docker.compute.functions.ImageToImage.java

@Override
public Image apply(org.jclouds.docker.domain.Image from) {
    checkNotNull(from, "image");

    String firstRepoTag = Iterables.getFirst(from.repoTags(), "<none>");
    final int versionSeparatorPos = firstRepoTag.lastIndexOf(':');

    final String name;
    final String osVersion;
    if (versionSeparatorPos > -1) {
        name = firstRepoTag.substring(0, versionSeparatorPos);
        osVersion = firstRepoTag.substring(versionSeparatorPos + 1);
    } else {/*from  w w w . j av a 2s.  c om*/
        name = firstRepoTag;
        osVersion = firstRepoTag;
    }
    logger.debug("os version for item: %s is %s", firstRepoTag, osVersion);

    OsFamily osFamily = osFamily().apply(firstRepoTag);

    OperatingSystem os = OperatingSystem.builder().description(firstRepoTag).family(osFamily).version(osVersion)
            .is64Bit(is64bit(from)).build();

    return new ImageBuilder().ids(from.id()).name(name).description(firstRepoTag).operatingSystem(os)
            .status(Image.Status.AVAILABLE).build();
}

From source file:org.eclipse.viatra.query.patternlanguage.emf.ui.builder.configuration.EMFPatternLanguageGeneratorEclipseConfigProvider.java

@Override
public EMFPatternLanguageGeneratorConfig get(EObject context) {
    EMFPatternLanguageGeneratorConfig result = new EMFPatternLanguageGeneratorConfig();
    IProject project = null;//from  ww w . jav a  2s.  c  om
    if (context.eResource() != null) {
        Pair<IStorage, IProject> pair = Iterables
                .getFirst(storage2UriMapper.getStorages(context.eResource().getURI()), null);
        if (pair != null) {
            project = pair.getSecond();
        }
    }
    builderPreferenceAccess.loadBuilderPreferences(result, project);
    return result;
}