Example usage for com.google.common.base Predicates containsPattern

List of usage examples for com.google.common.base Predicates containsPattern

Introduction

In this page you can find the example usage for com.google.common.base Predicates containsPattern.

Prototype

@GwtIncompatible(value = "java.util.regex.Pattern")
public static Predicate<CharSequence> containsPattern(String pattern) 

Source Link

Document

Returns a predicate that evaluates to true if the CharSequence being tested contains any match for the given regular expression pattern.

Usage

From source file:clocker.docker.location.DockerContainerLocation.java

@Override
public int copyTo(final Map<String, ?> props, final InputStream src, final long filesize,
        final String destination) {
    Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port")));
    boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH));
    boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH));
    if (entitySsh && dockerSsh) {
        return super.copyTo(nonPortProps, src, filesize, destination);
    } else {/*from   w ww.  j av  a 2 s.c  o m*/
        return copyTo(props, src, destination);
    }
}

From source file:clocker.docker.location.DockerContainerLocation.java

@Override
public int copyTo(final Map<String, ?> props, final InputStream src, final String destination) {
    Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port")));
    boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH));
    boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH));
    if (entitySsh && dockerSsh) {
        return super.copyTo(nonPortProps, src, destination);
    } else {/* ww  w. ja  va 2  s.c  o  m*/
        try {
            String tmp = Os.mergePaths("/tmp", Joiner.on('-').join(dockerContainer.getId(),
                    Urls.getBasename(destination), Strings.makeRandomId(4)));
            hostMachine.copyTo(nonPortProps, src, tmp);
            copyFile(tmp, destination);
            src.close();
            return 0;
        } catch (IOException ioe) {
            throw Exceptions.propagate(ioe);
        }
    }
}

From source file:clocker.docker.location.DockerContainerLocation.java

@Override
public int copyTo(Map<String, ?> props, File src, String destination) {
    Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port")));
    boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH));
    boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH));
    if (entitySsh && dockerSsh) {
        return super.copyTo(nonPortProps, src, destination);
    } else {/* w  w w  .j a va 2  s  . c  o  m*/
        String tmp = Os.mergePaths("/tmp", Joiner.on('-').join(dockerContainer.getId(),
                Urls.getBasename(destination), Strings.makeRandomId(4)));
        hostMachine.copyTo(nonPortProps, src, tmp);
        copyFile(tmp, destination);
        return 0;
    }
}

From source file:it.cnr.ilc.lremapasgraph.managedbeans.LremapasgraphManagedBeanView.java

public List<String> completeAuthors(String query) {
    List<String> results = Lists
            .newArrayList(Collections2.filter(getAuthors(), Predicates.containsPattern(query)));

    return results;
}

From source file:clocker.docker.location.DockerContainerLocation.java

@Override
public int copyFrom(final Map<String, ?> props, final String remote, final String local) {
    Map<String, ?> nonPortProps = Maps.filterKeys(props, Predicates.not(Predicates.containsPattern("port")));
    boolean entitySsh = Boolean.TRUE.equals(entity.config().get(DockerContainer.DOCKER_USE_SSH));
    boolean dockerSsh = Boolean.TRUE.equals(getOwner().config().get(DockerContainer.DOCKER_USE_SSH));
    if (entitySsh && dockerSsh) {
        return super.copyFrom(nonPortProps, remote, local);
    } else {/*from w w w . ja  v a  2 s. c  o m*/
        String tmp = Os.mergePaths("/tmp",
                Joiner.on('-').join(dockerContainer.getId(), Urls.getBasename(local), Strings.makeRandomId(4)));
        String cp = String.format("cp %s:%s %s", dockerContainer.getContainerId(), remote, tmp);
        String output = getOwner().getDockerHost().runDockerCommand(cp);
        hostMachine.copyFrom(nonPortProps, tmp, local);
        LOG.info("Copying from {}:{} to {} - result: {}",
                new Object[] { dockerContainer.getContainerId(), remote, local, output });
        return 0;
    }
}

From source file:it.cnr.ilc.lremapasgraph.managedbeans.LremapasgraphManagedBeanView.java

public List<String> completeNames(String query) {
    List<String> results = Lists
            .newArrayList(Collections2.filter(getResourcenames(), Predicates.containsPattern(query)));

    return results;
}

From source file:co.cask.cdap.internal.app.runtime.spark.SparkRuntimeService.java

/**
 * Creates a {@link Runnable} for deleting content for the given directory.
 *///from  ww  w .j  a va  2 s.c  o m
private Runnable createCleanupTask(final File directory) {
    return new Runnable() {

        @Override
        public void run() {
            // Cleanup all system properties setup by SparkSubmit
            Iterable<String> sparkKeys = Iterables.filter(System.getProperties().stringPropertyNames(),
                    Predicates.containsPattern("^spark\\."));
            for (String key : sparkKeys) {
                LOG.debug("Removing Spark system property: {}", key);
                System.clearProperty(key);
            }

            try {
                DirUtils.deleteDirectoryContents(directory);
            } catch (IOException e) {
                LOG.warn("Failed to cleanup directory {}", directory);
            }
        }
    };
}

From source file:es.upm.dit.xsdinferencer.XSDInferenceConfiguration.java

/**
 * Loads a configuration from a properties file. Any value which was not present at the file would remain 
 * at its previous value (which might be the default value) 
 * @param file File object representing the properties file
 * @throws IOException If there is an I/O error related to the properties file.
 * @throws XSDConfigurationException if a value of a parameter is not valid or if a value of any parameter is inconsistent 
 *                                              with the value of another parameter
 *//*from   w w  w  .  jav  a2 s. co  m*/
protected void loadFromFile(File file) throws IOException, XSDConfigurationException {
    FileInputStream fis = new FileInputStream(file);
    Properties properties = new Properties();
    properties.load(fis);
    String readMainNamespace = properties.getProperty(KEY_MAIN_NAMESPACE);
    if (readMainNamespace != null) {
        mainNamespace = readMainNamespace;
    }

    Set<String> foundSkipNamespacesKeys = Sets.filter(properties.stringPropertyNames(),
            Predicates.containsPattern("^\\Q" + KEY_MULTIPLE_SKIP_NAMESPACES + "\\E.*$"));
    if (!foundSkipNamespacesKeys.isEmpty()) {
        skipNamespaces.clear();
    }
    for (String skipNamespace : foundSkipNamespacesKeys) {
        skipNamespaces.add(properties.getProperty(skipNamespace));
    }

    String readTypeInferencer = properties.getProperty(KEY_TYPE_NAME_INFERENCER);
    String localityStr = properties.getProperty(KEY_TYPE_NAME_INFERENCER_LOCALITY);

    if (readTypeInferencer != null) {
        setTypeInferencer(readTypeInferencer, localityStr);
    }

    String readGenerateEnumerations = properties.getProperty(KEY_GENERATE_ENUMERATIONS);
    if (readGenerateEnumerations != null) {
        setGenerateEnumerations(readGenerateEnumerations);
    }

    String readWorkingFormat = properties.getProperty(KEY_WORKING_FORMAT);
    if (readWorkingFormat != null) {
        setWorkingFormat(readWorkingFormat);
    }

    String readMinNumberOfDistinctValuesToEnum = properties
            .getProperty(KEY_MIN_NUMBER_OF_DISTINCT_VALUES_TO_ENUM);
    if (readMinNumberOfDistinctValuesToEnum != null) {
        minNumberOfDistinctValuesToEnum = Integer.parseInt(readMinNumberOfDistinctValuesToEnum);
    }

    String readMaxNumberOfDistinctValuesToEnum = properties
            .getProperty(KEY_MAX_NUMBER_OF_DISTINCT_VALUES_TO_ENUM);
    if (readMaxNumberOfDistinctValuesToEnum != null) {
        maxNumberOfDistinctValuesToEnum = Integer.parseInt(readMaxNumberOfDistinctValuesToEnum);
    }

    String readSimpleTypeInferencer = properties.getProperty(KEY_SIMPLE_TYPE_INFERENCER);
    if (readSimpleTypeInferencer != null) {
        setSimpleTypeInferencer(readSimpleTypeInferencer);
    }

    String readAttributeListInferencer = properties.getProperty(KEY_ATTRIBUTE_LIST_INFERENCER);
    if (readAttributeListInferencer != null) {
        setAttributeListInferencer(readAttributeListInferencer);
    }

    String readChildrenPatternComparator = properties.getProperty(KEY_CHILDREN_PATTERN_COMPARATOR);
    String readAttributeListComparator = properties.getProperty(KEY_ATTRIBUTE_LIST_COMPARATOR);
    String readReduceThreshold = properties.getProperty(KEY_CHILDREN_PATTERN_COMPARATOR_REDUCE_THRESHOLD,
            DEFAULT_REDUCE_THRESHOLD);

    if ((readChildrenPatternComparator == null && readAttributeListComparator != null)
            || (readChildrenPatternComparator != null && readAttributeListComparator == null)) {
        throw new InconsistentXSDConfigurationParametersException(
                "If a 'childrenPatternComparator' is specified, an 'attributeListComparator' must be specified as well and vice versa");
    } else if (readChildrenPatternComparator != null && readAttributeListComparator != null) {
        if ((readChildrenPatternComparator.equalsIgnoreCase(VALUE_CHILDREN_PATTERN_COMPARATOR_NO)
                && !readAttributeListComparator.equals(VALUE_ATTRIBUTE_LIST_COMPARATOR_NO))
                || (!readChildrenPatternComparator.equalsIgnoreCase(VALUE_CHILDREN_PATTERN_COMPARATOR_NO)
                        && readAttributeListComparator.equals(VALUE_ATTRIBUTE_LIST_COMPARATOR_NO))) {
            throw new InconsistentXSDConfigurationParametersException(
                    "If a 'childrenPatternComparator' is specified to no, 'attributeListComparator' must be specified as well to no and vice versa");
        }
        setChildrenPatternComparator(readChildrenPatternComparator, readReduceThreshold);
        setAttributeListComparator(readAttributeListComparator);
    }

    String snReadChildrenPatternComparator = properties.getProperty(KEY_SAME_NAME_CHILDREN_PATTERN_COMPARATOR);
    String snReadAttributeListComparator = properties.getProperty(KEY_SAME_NAME_ATTRIBUTE_LIST_COMPARATOR);
    String snReadReduceThreshold = properties
            .getProperty(KEY_SAME_NAME_CHILDREN_PATTERN_COMPARATOR_REDUCE_THRESHOLD, DEFAULT_REDUCE_THRESHOLD);
    if (snReadChildrenPatternComparator != null || snReadAttributeListComparator != null) {

        if ((readAttributeListComparator == null || attributeListComparator == null)
                && !(snReadChildrenPatternComparator != null && snReadAttributeListComparator != null)) {
            throw new InconsistentXSDConfigurationParametersException(
                    "If same name comparators are defined when normal comparators are not defined, both same name comparators must be defined");
        }
        setSnChildrenPatternComparator(snReadChildrenPatternComparator, snReadReduceThreshold);
        setSnAttributeListComparator(snReadAttributeListComparator);
    }

    String readEnumsComparator = properties.getProperty(KEY_ENUMS_COMPARATOR);
    String readEnumComparatorThreshold = properties.getProperty(KEY_ENUMS_COMPARATOR_THRESHOLD,
            DEFAULT_ENUM_COMPARATORS_THRESHOLD);
    if (readEnumsComparator != null) {
        setEnumsComparator(readEnumsComparator, readEnumComparatorThreshold);
    }

    String readSnEnumsComparator = properties.getProperty(KEY_SAME_NAME_ENUMS_COMPARATOR);
    String readSnEnumComparatorThreshold = properties.getProperty(KEY_SAME_NAME_ENUMS_COMPARATOR_THRESHOLD,
            DEFAULT_ENUM_COMPARATORS_THRESHOLD);
    if (readSnEnumsComparator != null) {
        setSnEnumsComparator(readSnEnumsComparator, readSnEnumComparatorThreshold);
    }

    String readAvoidSore = properties.getProperty(KEY_AVOID_SORE);
    if (readAvoidSore != null) {
        setAvoidSORE(readAvoidSore);
    }

    String readTryECHARE = properties.getProperty(KEY_TRY_ECHARE);
    if (readTryECHARE != null) {
        setTryECHARE(readTryECHARE);
    }

    Set<String> foundOptimizersKeys = Sets.filter(properties.stringPropertyNames(),
            Predicates.containsPattern("^\\Q" + KEY_MULTIPLE_OPTIMIZERS + "\\E.*$"));

    if (!foundOptimizersKeys.isEmpty()) {
        optimizers.clear();
        Set<String> foundOptimizersValues = new HashSet<String>(foundOptimizersKeys.size());
        for (String foundOptimizerKey : foundOptimizersKeys) {
            foundOptimizersValues.add(properties.getProperty(foundOptimizerKey));
        }
        addOptimizersFromStringsSet(foundOptimizersValues);
    }

    String readStrictValidRootDefinitionWorkaround = properties
            .getProperty(KEY_STRICT_VALID_ROOT_DEFINITION_WORKAROUND);
    if (readStrictValidRootDefinitionWorkaround != null) {
        setStrictValidRootDefinitionWorkaround(readStrictValidRootDefinitionWorkaround);
    }

    String readElementsGlobal = properties.getProperty(KEY_ELEMENTS_GLOBAL);
    if (readElementsGlobal != null) {
        setElementsGlobal(readElementsGlobal);
    }

    String readComplexTypesGlobal = properties.getProperty(KEY_COMPLEX_TYPES_GLOBAL);
    if (readComplexTypesGlobal != null) {
        setComplexTypesGlobal(readComplexTypesGlobal);
    }

    String readSimpleTypesGlobal = properties.getProperty(KEY_SIMPLE_TYPES_GLOBAL);
    if (readSimpleTypesGlobal != null) {
        setSimpleTypesGlobal(readSimpleTypesGlobal);
    }

    String readTypeNamesAncestorSeparator = properties.getProperty(KEY_TYPE_NAMES_ANCESTORS_SEPARATOR);
    if (readTypeNamesAncestorSeparator != null) {
        setTypeNamesAncestorsSeparator(readTypeNamesAncestorSeparator);
    }

    String readMergedTypesSeparator = properties.getProperty(KEY_MERGED_TYPES_SEPARATOR);
    if (readMergedTypesSeparator != null) {
        setMergedTypesSeparator(readMergedTypesSeparator);
    }

}

From source file:co.cask.cdap.app.runtime.spark.SparkRuntimeService.java

/**
 * Creates a {@link Runnable} to be executed to cleanup resources after executing the spark program.
 *
 * @param directory The directory to be deleted
 * @param properties The set of system {@link Properties} prior to the job execution.
 *//* www  . j av  a2s.  com*/
private Runnable createCleanupTask(final File directory, Properties properties) {
    final Map<String, String> retainingProperties = new HashMap<>();
    for (String key : properties.stringPropertyNames()) {
        if (key.startsWith("spark.")) {
            retainingProperties.put(key, properties.getProperty(key));
        }
    }

    return new Runnable() {

        @Override
        public void run() {
            cleanupShutdownHooks();
            invalidateBeanIntrospectorCache();

            // Cleanup all system properties setup by SparkSubmit
            Iterable<String> sparkKeys = Iterables.filter(System.getProperties().stringPropertyNames(),
                    Predicates.containsPattern("^spark\\."));
            for (String key : sparkKeys) {
                if (retainingProperties.containsKey(key)) {
                    String value = retainingProperties.get(key);
                    LOG.debug("Restoring Spark system property: {} -> {}", key, value);
                    System.setProperty(key, value);
                } else {
                    LOG.debug("Removing Spark system property: {}", key);
                    System.clearProperty(key);
                }
            }

            try {
                DirUtils.deleteDirectoryContents(directory);
            } catch (IOException e) {
                LOG.warn("Failed to cleanup directory {}", directory);
            }
        }
    };
}