Example usage for com.google.common.base Optional isPresent

List of usage examples for com.google.common.base Optional isPresent

Introduction

In this page you can find the example usage for com.google.common.base Optional isPresent.

Prototype

public abstract boolean isPresent();

Source Link

Document

Returns true if this holder contains a (non-null) instance.

Usage

From source file:org.locationtech.geogig.test.integration.remoting.RemotesIndexTestSupport.java

public static List<Index> createIndexes(Repository repo, Ref ref) {
    Envelope bounds = new Envelope(-180, 180, -90, 90);
    List<NodeRef> types = repo.command(FindFeatureTypeTrees.class).setRootTreeRef(ref.getName()).call();

    List<Index> indexes = new ArrayList<>();
    for (NodeRef treeRef : types) {
        Map<String, IndexInfo> typeIndexes = getIndexes(repo, treeRef.path());
        if (typeIndexes.containsKey(treeRef.path())) {
            IndexInfo indexInfo = typeIndexes.get(treeRef.path());
            IndexDatabase indexdb = repo.indexDatabase();
            Optional<ObjectId> indexedTree = indexdb.resolveIndexedTree(indexInfo, treeRef.getObjectId());
            if (indexedTree.isPresent()) {
                indexes.add(new Index(indexInfo, indexedTree.get(), indexdb));
            }/*from  w  w w  .java  2s . c om*/
        } else {
            Index index = repo.command(CreateQuadTree.class).setBounds(bounds).setIndexHistory(true)
                    .setTypeTreeRef(treeRef).call();
            log.info("Created index {} before cloning", index);
            indexes.add(index);
        }
    }
    return indexes;
}

From source file:org.eclipse.mylyn.internal.wikitext.commonmark.inlines.InlineParser.java

static List<Inline> secondPass(List<Inline> inlines) {
    List<Inline> processedInlines = ImmutableList.copyOf(inlines);
    Optional<InlinesSubstitution> substitution = Optional.absent();
    do {//from w w  w.  ja v  a 2  s.  c o m
        for (Inline inline : processedInlines) {
            substitution = inline.secondPass(processedInlines);
            if (substitution.isPresent()) {
                processedInlines = substitution.get().apply(processedInlines);
                break;
            }
        }
    } while (substitution.isPresent());
    return processedInlines;
}

From source file:org.apache.lens.server.common.FormDataMultiPartFactory.java

public static FormDataMultiPart createFormDataMultiPartForSession(final Optional<String> username,
        final Optional<String> password, final Optional<LensConf> lensConf, final MediaType mt) {

    final FormDataMultiPart mp = new FormDataMultiPart();

    if (username.isPresent()) {
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("username").build(), username.get()));
    }//from www. j  av  a2  s.  c  o m

    if (password.isPresent()) {
        mp.bodyPart(new FormDataBodyPart(FormDataContentDisposition.name("password").build(), password.get()));
    }

    if (lensConf.isPresent()) {
        mp.bodyPart(getFormDataBodyPart("sessionconf", "sessionconf", lensConf.get(), mt));
    }

    return mp;
}

From source file:org.sonar.server.computation.queue.InternalCeQueueImpl.java

private static void updateTaskResult(CeActivityDto activityDto, @Nullable CeTaskResult taskResult) {
    if (taskResult != null) {
        java.util.Optional<String> analysisUuid = taskResult.getAnalysisUuid();
        if (analysisUuid.isPresent()) {
            activityDto.setAnalysisUuid(analysisUuid.get());
        }//from w w  w .  j a v a  2  s  .c  o  m
    }
}

From source file:org.opendaylight.topology.multitechnology.MultitechnologyLinkCorrelationFieldHandler.java

public static String getCorrelationField(final DataBroker dataProvider, final MlmtOperationProcessor processor,
        final InstanceIdentifier<Topology> topologyInstanceId, final LinkKey linkKey) {
    final Uri uri = new Uri(MlmtInfoOpaqueAttrId.MTINFO_OPAQUE_ATTR_ID_CORRELATION_FIELD);
    final AttributeKey attributeKey = new AttributeKey(uri);
    final InstanceIdentifier<Attribute> instanceAttributeId = topologyInstanceId.child(Link.class, linkKey)
            .augmentation(MtInfoLink.class).child(Attribute.class, attributeKey);

    try {//from   w ww . j  ava2s.c o  m
        final ReadOnlyTransaction rx = dataProvider.newReadOnlyTransaction();
        final Optional<Attribute> sourceAttributeObject = rx
                .read(LogicalDatastoreType.CONFIGURATION, instanceAttributeId).get();
        if (sourceAttributeObject == null || !sourceAttributeObject.isPresent()) {
            return null;
        }
        final Value value = sourceAttributeObject.get().getValue();
        final MtOpaqueLinkAttributeValue mtOpaqueLinkAttributeValue = value
                .getAugmentation(MtOpaqueLinkAttributeValue.class);
        if (mtOpaqueLinkAttributeValue != null) {
            final BasicAttributeTypes basicAttributeTypes = mtOpaqueLinkAttributeValue.getBasicAttributeTypes();
            if (basicAttributeTypes instanceof StringValue) {
                return ((StringValue) basicAttributeTypes).getStringValue();
            }
        }
    } catch (final InterruptedException e) {
        LOG.error("MultitechnologyLinkCorrelationFieldHandler.getCorrelationField interrupted exception", e);
    } catch (final ExecutionException e) {
        LOG.error("MultitechnologyLinkCorrelationFieldHandler.getCorrelationField execution exception", e);
    }

    return null;
}

From source file:jcomposition.processor.utils.AnnotationUtils.java

public static String getCompositionName(TypeElement element, ProcessingEnvironment env) {
    Optional<AnnotationValue> value = getParameterFrom(element, Composition.class, "name", env);
    String defaultName = element.getSimpleName() + "_Generated";

    if (value.isPresent()) {
        String name = (String) value.get().getValue();

        if (!Const.UNDEFINED.equals(name)) {
            return name;
        }/*w ww . j  av  a  2s. c  o  m*/
    }

    return defaultName;
}

From source file:org.dswarm.common.model.util.AttributePathUtil.java

private static Attribute getOrCreateAttribute(final String uri,
        final Optional<Map<String, Attribute>> optionalAttributeMap) {

    if (!optionalAttributeMap.isPresent()) {

        return new Attribute(uri);
    }/*from w w  w .  jav  a  2s  .  c o  m*/

    if (!optionalAttributeMap.get().containsKey(uri)) {

        optionalAttributeMap.get().put(uri, new Attribute(uri));
    }

    return optionalAttributeMap.get().get(uri);
}

From source file:org.apache.gobblin.data.management.copy.hive.WhitelistBlacklist.java

private static boolean multimapContains(SetMultimap<Pattern, Pattern> multimap, String database,
        Optional<String> table, boolean blacklist) {
    for (Pattern dbPattern : multimap.keySet()) {
        if (dbPattern.matcher(database).matches()) {
            if (!table.isPresent()) {
                // if we are only matching database
                return !blacklist || multimap.get(dbPattern).contains(ALL_TABLES);
            }/*www .j a v  a2 s.  c om*/

            for (Pattern tablePattern : multimap.get(dbPattern)) {
                if (tablePattern.matcher(table.get()).matches()) {
                    return true;
                }
            }
        }
    }

    return false;
}

From source file:gobblin.util.test.RetentionTestHelper.java

/**
*
* Does gobblin retention for test data. {@link DatasetCleaner} which does retention in production can not be directly called as we need to resolve some
* runtime properties like ${testNameTempPath}. This directory contains all the setup data created for a test by {@link RetentionTestDataGenerator#setup()}.
* It is unique for each test.//  ww w  .j ava 2 s. c o m
* The default {@link ConfigClient} used by {@link DatasetCleaner} connects to config store configs. We need to provide a
* mock {@link ConfigClient} since the configs are in classpath and not on config store.
*
* @param retentionConfigClasspathResource this is the same jobProps/config files used while running a real retention job
* @param testNameTempPath temp path for this test where test data is generated
*/
public static void clean(FileSystem fs, Path retentionConfigClasspathResource,
        Optional<Path> additionalJobPropsClasspathResource, Path testNameTempPath) throws Exception {

    Properties additionalJobProps = new Properties();
    if (additionalJobPropsClasspathResource.isPresent()) {
        try (final InputStream stream = RetentionTestHelper.class.getClassLoader()
                .getResourceAsStream(additionalJobPropsClasspathResource.get().toString())) {
            additionalJobProps.load(stream);
        }
    }

    if (retentionConfigClasspathResource.getName().endsWith(".job")) {

        Properties jobProps = new Properties();
        try (final InputStream stream = RetentionTestHelper.class.getClassLoader()
                .getResourceAsStream(retentionConfigClasspathResource.toString())) {
            jobProps.load(stream);
            for (Entry<Object, Object> entry : jobProps.entrySet()) {
                jobProps.put(entry.getKey(), StringUtils.replace((String) entry.getValue(),
                        "${testNameTempPath}", testNameTempPath.toString()));
            }
        }

        MultiCleanableDatasetFinder finder = new MultiCleanableDatasetFinder(fs, jobProps);
        for (Dataset dataset : finder.findDatasets()) {
            ((CleanableDataset) dataset).clean();
        }
    } else {
        Config testConfig = ConfigFactory.parseResources(retentionConfigClasspathResource.toString())
                .withFallback(ConfigFactory.parseMap(ImmutableMap.of("testNameTempPath",
                        PathUtils.getPathWithoutSchemeAndAuthority(testNameTempPath).toString())))
                .resolve();

        ConfigClient client = mock(ConfigClient.class);
        when(client.getConfig(any(String.class))).thenReturn(testConfig);
        Properties jobProps = new Properties();
        jobProps.setProperty(CleanableDatasetBase.SKIP_TRASH_KEY, Boolean.toString(true));
        jobProps.setProperty(ConfigurationKeys.CONFIG_MANAGEMENT_STORE_URI, "dummy");

        jobProps.putAll(additionalJobProps);

        @SuppressWarnings("unchecked")
        DatasetsFinder<CleanableDataset> finder = (DatasetsFinder<CleanableDataset>) GobblinConstructorUtils
                .invokeFirstConstructor(
                        Class.forName(
                                testConfig.getString(MultiCleanableDatasetFinder.DATASET_FINDER_CLASS_KEY)),
                        ImmutableList.of(fs, jobProps, testConfig, client),
                        ImmutableList.of(fs, jobProps, client));

        for (CleanableDataset dataset : finder.findDatasets()) {
            dataset.clean();
        }
    }
}