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());
}
}
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);
});
}
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);
}
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();
}
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");
}
Aggregations