Search in sources :

Example 26 with SortedSet

use of java.util.SortedSet in project lucene-solr by apache.

the class GetMavenDependenciesTask method setInternalDependencyProperties.

/**
   * Sets the internal dependencies compile and test properties to be inserted 
   * into modules' POMs.
   * 
   * Also collects shared external dependencies, 
   * e.g. solr-core wants all of solrj's external dependencies 
   */
private void setInternalDependencyProperties() {
    log("Loading module dependencies from: " + moduleDependenciesPropertiesFile, verboseLevel);
    Properties moduleDependencies = new Properties();
    try (InputStream inputStream = new FileInputStream(moduleDependenciesPropertiesFile);
        Reader reader = new InputStreamReader(inputStream, StandardCharsets.UTF_8)) {
        moduleDependencies.load(reader);
    } catch (FileNotFoundException e) {
        throw new BuildException("Properties file does not exist: " + moduleDependenciesPropertiesFile.getPath());
    } catch (IOException e) {
        throw new BuildException("Exception reading properties file " + moduleDependenciesPropertiesFile.getPath(), e);
    }
    Map<String, SortedSet<String>> testScopeDependencies = new HashMap<>();
    Map<String, String> testScopePropertyKeys = new HashMap<>();
    for (Map.Entry<?, ?> entry : moduleDependencies.entrySet()) {
        String newPropertyKey = (String) entry.getKey();
        StringBuilder newPropertyValue = new StringBuilder();
        String value = (String) entry.getValue();
        Matcher matcher = MODULE_DEPENDENCIES_COORDINATE_KEY_PATTERN.matcher(newPropertyKey);
        if (!matcher.matches()) {
            throw new BuildException("Malformed module dependencies property key: '" + newPropertyKey + "'");
        }
        String antProjectName = matcher.group(1);
        boolean isTest = null != matcher.group(2);
        String artifactName = antProjectToArtifactName(antProjectName);
        // Add ".internal"
        newPropertyKey = artifactName + (isTest ? ".internal.test" : ".internal") + ".dependencies";
        if (isTest) {
            testScopePropertyKeys.put(artifactName, newPropertyKey);
        }
        if (null == value || value.isEmpty()) {
            allProperties.setProperty(newPropertyKey, "");
            Map<String, SortedSet<String>> scopedDependencies = isTest ? testScopeDependencies : internalCompileScopeDependencies;
            scopedDependencies.put(artifactName, new TreeSet<String>());
        } else {
            // Lucene analysis modules' build dirs do not include hyphens, but Solr contribs' build dirs do
            String origModuleDir = antProjectName.replace("analyzers-", "analysis/");
            // Exclude the module's own build output, in addition to UNWANTED_INTERNAL_DEPENDENCIES
            Pattern unwantedInternalDependencies = Pattern.compile(// require dir separator 
            "(?:lucene/build/|solr/build/(?:contrib/)?)" + origModuleDir + "/" + "|" + UNWANTED_INTERNAL_DEPENDENCIES);
            SortedSet<String> sortedDeps = new TreeSet<>();
            for (String dependency : value.split(",")) {
                matcher = SHARED_EXTERNAL_DEPENDENCIES_PATTERN.matcher(dependency);
                if (matcher.find()) {
                    String otherArtifactName = matcher.group(1);
                    boolean isTestScope = null != matcher.group(2) && matcher.group(2).length() > 0;
                    otherArtifactName = otherArtifactName.replace('/', '-');
                    otherArtifactName = otherArtifactName.replace("lucene-analysis", "lucene-analyzers");
                    otherArtifactName = otherArtifactName.replace("solr-contrib-solr-", "solr-");
                    otherArtifactName = otherArtifactName.replace("solr-contrib-", "solr-");
                    if (!otherArtifactName.equals(artifactName)) {
                        Map<String, Set<String>> sharedDeps = isTest ? interModuleExternalTestScopeDependencies : interModuleExternalCompileScopeDependencies;
                        Set<String> sharedSet = sharedDeps.get(artifactName);
                        if (null == sharedSet) {
                            sharedSet = new HashSet<>();
                            sharedDeps.put(artifactName, sharedSet);
                        }
                        if (isTestScope) {
                            otherArtifactName += ":test";
                        }
                        sharedSet.add(otherArtifactName);
                    }
                }
                matcher = unwantedInternalDependencies.matcher(dependency);
                if (matcher.find()) {
                    // skip external (/(test-)lib/), and non-jar and unwanted (self) internal deps
                    continue;
                }
                String artifactId = dependencyToArtifactId(newPropertyKey, dependency);
                String groupId = ivyModuleInfo.get(artifactId);
                String coordinate = groupId + ':' + artifactId;
                sortedDeps.add(coordinate);
            }
            if (isTest) {
                // Don't set test-scope properties until all compile-scope deps have been seen
                testScopeDependencies.put(artifactName, sortedDeps);
            } else {
                internalCompileScopeDependencies.put(artifactName, sortedDeps);
                for (String dependency : sortedDeps) {
                    int splitPos = dependency.indexOf(':');
                    String groupId = dependency.substring(0, splitPos);
                    String artifactId = dependency.substring(splitPos + 1);
                    appendDependencyXml(newPropertyValue, groupId, artifactId, "    ", null, false, false, null, null);
                }
                if (newPropertyValue.length() > 0) {
                    // drop trailing newline
                    newPropertyValue.setLength(newPropertyValue.length() - 1);
                }
                allProperties.setProperty(newPropertyKey, newPropertyValue.toString());
            }
        }
    }
    // dependencies that are not also compile-scope dependencies.
    for (Map.Entry<String, SortedSet<String>> entry : testScopeDependencies.entrySet()) {
        String module = entry.getKey();
        SortedSet<String> testDeps = entry.getValue();
        SortedSet<String> compileDeps = internalCompileScopeDependencies.get(module);
        if (null == compileDeps) {
            throw new BuildException("Can't find compile scope dependencies for module " + module);
        }
        StringBuilder newPropertyValue = new StringBuilder();
        for (String dependency : testDeps) {
            // included in their test-scope deps.
            if (modulesWithSeparateCompileAndTestPOMs.contains(module) || !compileDeps.contains(dependency)) {
                int splitPos = dependency.indexOf(':');
                String groupId = dependency.substring(0, splitPos);
                String artifactId = dependency.substring(splitPos + 1);
                appendDependencyXml(newPropertyValue, groupId, artifactId, "    ", null, true, false, null, null);
            }
        }
        if (newPropertyValue.length() > 0) {
            // drop trailing newline
            newPropertyValue.setLength(newPropertyValue.length() - 1);
        }
        allProperties.setProperty(testScopePropertyKeys.get(module), newPropertyValue.toString());
    }
}
Also used : SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) FileNotFoundException(java.io.FileNotFoundException) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) Properties(java.util.Properties) SortedSet(java.util.SortedSet) TreeSet(java.util.TreeSet) Pattern(java.util.regex.Pattern) InputStreamReader(java.io.InputStreamReader) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) BuildException(org.apache.tools.ant.BuildException) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Example 27 with SortedSet

use of java.util.SortedSet in project lucene-solr by apache.

the class MetricUtils method toMaps.

/**
   * Convert selected metrics to maps or to flattened objects.
   * @param registry source of metrics
   * @param shouldMatchFilters metrics must match any of these filters
   * @param mustMatchFilter metrics must match this filter
   * @param propertyFilter limit what properties of a metric are returned
   * @param skipHistograms discard any {@link Histogram}-s and histogram parts of {@link Timer}-s.
   * @param skipAggregateValues discard internal values of {@link AggregateMetric}-s.
   * @param compact use compact representation for counters and gauges.
   * @param simple use simplified representation for complex metrics - instead of a (name, map)
   *             only the selected (name "." key, value) pairs will be produced.
   * @param consumer consumer that accepts produced objects
   */
public static void toMaps(MetricRegistry registry, List<MetricFilter> shouldMatchFilters, MetricFilter mustMatchFilter, PropertyFilter propertyFilter, boolean skipHistograms, boolean skipAggregateValues, boolean compact, boolean simple, BiConsumer<String, Object> consumer) {
    final Map<String, Metric> metrics = registry.getMetrics();
    final SortedSet<String> names = registry.getNames();
    names.stream().filter(s -> shouldMatchFilters.stream().anyMatch(metricFilter -> metricFilter.matches(s, metrics.get(s)))).filter(s -> mustMatchFilter.matches(s, metrics.get(s))).forEach(n -> {
        Metric metric = metrics.get(n);
        convertMetric(n, metric, propertyFilter, skipHistograms, skipAggregateValues, compact, simple, consumer);
    });
}
Also used : Histogram(com.codahale.metrics.Histogram) SortedSet(java.util.SortedSet) LoggerFactory(org.slf4j.LoggerFactory) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Introspector(java.beans.Introspector) Meter(com.codahale.metrics.Meter) InstrumentedExecutorService(com.codahale.metrics.InstrumentedExecutorService) BeanInfo(java.beans.BeanInfo) Map(java.util.Map) BiConsumer(java.util.function.BiConsumer) Counter(com.codahale.metrics.Counter) PlatformManagedObject(java.lang.management.PlatformManagedObject) MetricFilter(com.codahale.metrics.MetricFilter) OperatingSystemMXBean(java.lang.management.OperatingSystemMXBean) ExecutorService(java.util.concurrent.ExecutorService) AggregateMetric(org.apache.solr.metrics.AggregateMetric) MetricRegistry(com.codahale.metrics.MetricRegistry) Logger(org.slf4j.Logger) MethodHandles(java.lang.invoke.MethodHandles) Collection(java.util.Collection) Metric(com.codahale.metrics.Metric) Snapshot(com.codahale.metrics.Snapshot) NamedList(org.apache.solr.common.util.NamedList) IntrospectionException(java.beans.IntrospectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) TimeUnit(java.util.concurrent.TimeUnit) Consumer(java.util.function.Consumer) List(java.util.List) PropertyDescriptor(java.beans.PropertyDescriptor) SolrInfoBean(org.apache.solr.core.SolrInfoBean) Timer(com.codahale.metrics.Timer) Gauge(com.codahale.metrics.Gauge) Collections(java.util.Collections) SolrInputDocument(org.apache.solr.common.SolrInputDocument) AggregateMetric(org.apache.solr.metrics.AggregateMetric) Metric(com.codahale.metrics.Metric)

Example 28 with SortedSet

use of java.util.SortedSet in project lucene-solr by apache.

the class LastFieldValueUpdateProcessorFactory method pickSubset.

@Override
public Collection<Object> pickSubset(Collection<Object> values) {
    Object result = null;
    if (values instanceof List) {
        // optimize index lookup
        List l = (List) values;
        result = l.get(l.size() - 1);
    } else if (values instanceof SortedSet) {
        // optimize tail lookup
        result = ((SortedSet) values).last();
    } else {
        // trust the iterator
        for (Object o : values) {
            result = o;
        }
    }
    return Collections.singletonList(result);
}
Also used : List(java.util.List) SortedSet(java.util.SortedSet)

Example 29 with SortedSet

use of java.util.SortedSet in project geode by apache.

the class InternalDistributedSystem method canonicalizeLocators.

/**
   * Canonicalizes a locators string so that they may be compared.
   * 
   * @since GemFire 4.0
   */
private static String canonicalizeLocators(String locators) {
    SortedSet sorted = new TreeSet();
    StringTokenizer st = new StringTokenizer(locators, ",");
    while (st.hasMoreTokens()) {
        String l = st.nextToken();
        StringBuilder canonical = new StringBuilder();
        DistributionLocatorId locId = new DistributionLocatorId(l);
        String addr = locId.getBindAddress();
        if (addr != null && addr.trim().length() > 0) {
            canonical.append(addr);
        } else {
            canonical.append(locId.getHost().getHostAddress());
        }
        canonical.append("[");
        canonical.append(String.valueOf(locId.getPort()));
        canonical.append("]");
        sorted.add(canonical.toString());
    }
    StringBuilder sb = new StringBuilder();
    for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
        sb.append((String) iter.next());
        if (iter.hasNext()) {
            sb.append(",");
        }
    }
    return sb.toString();
}
Also used : StringTokenizer(java.util.StringTokenizer) DistributionLocatorId(org.apache.geode.internal.admin.remote.DistributionLocatorId) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Example 30 with SortedSet

use of java.util.SortedSet in project robovm by robovm.

the class CollectionsTest method test_unmodifiableSortedSetLjava_util_SortedSet.

/**
     * java.util.Collections#unmodifiableSortedSet(java.util.SortedSet)
     */
public void test_unmodifiableSortedSetLjava_util_SortedSet() {
    // Test for method java.util.SortedSet
    // java.util.Collections.unmodifiableSortedSet(java.util.SortedSet)
    boolean exception = false;
    SortedSet ss = new TreeSet();
    ss.addAll(s);
    SortedSet c = Collections.unmodifiableSortedSet(ss);
    assertTrue("Returned set is of incorrect size", c.size() == ss.size());
    Iterator i = ll.iterator();
    while (i.hasNext()) assertTrue("Returned set missing elements", c.contains(i.next()));
    try {
        c.add(new Object());
    } catch (UnsupportedOperationException e) {
        exception = true;
    // Correct
    }
    if (!exception) {
        fail("Allowed modification of set");
    }
    try {
        c.remove(new Object());
    } catch (UnsupportedOperationException e) {
        // Correct
        return;
    }
    fail("Allowed modification of set");
}
Also used : TreeSet(java.util.TreeSet) ListIterator(java.util.ListIterator) Iterator(java.util.Iterator) SortedSet(java.util.SortedSet)

Aggregations

SortedSet (java.util.SortedSet)377 TreeSet (java.util.TreeSet)174 Iterator (java.util.Iterator)116 HashMap (java.util.HashMap)94 Map (java.util.Map)94 Set (java.util.Set)90 ArrayList (java.util.ArrayList)78 List (java.util.List)78 TreeMap (java.util.TreeMap)61 HashSet (java.util.HashSet)60 IOException (java.io.IOException)58 NavigableSet (java.util.NavigableSet)56 Test (org.junit.Test)50 Collectors (java.util.stream.Collectors)35 Collections (java.util.Collections)34 SortedMap (java.util.SortedMap)31 ImmutableSortedSet (com.google.common.collect.ImmutableSortedSet)30 Comparator (java.util.Comparator)30 File (java.io.File)28 Collection (java.util.Collection)28