Search in sources :

Example 91 with TreeSet

use of java.util.TreeSet in project hive by apache.

the class ClassNameCompleter method getClassNames.

public static String[] getClassNames() throws IOException {
    Set urls = new HashSet();
    for (ClassLoader loader = Thread.currentThread().getContextClassLoader(); loader != null; loader = loader.getParent()) {
        if (!(loader instanceof URLClassLoader)) {
            continue;
        }
        urls.addAll(Arrays.asList(((URLClassLoader) loader).getURLs()));
    }
    // Now add the URL that holds java.lang.String. This is because
    // some JVMs do not report the core classes jar in the list of
    // class loaders.
    Class[] systemClasses = new Class[] { String.class, javax.swing.JFrame.class };
    for (int i = 0; i < systemClasses.length; i++) {
        URL classURL = systemClasses[i].getResource("/" + systemClasses[i].getName().replace('.', '/') + clazzFileNameExtension);
        if (classURL != null) {
            URLConnection uc = classURL.openConnection();
            if (uc instanceof JarURLConnection) {
                urls.add(((JarURLConnection) uc).getJarFileURL());
            }
        }
    }
    Set classes = new HashSet();
    for (Iterator i = urls.iterator(); i.hasNext(); ) {
        URL url = (URL) i.next();
        try {
            File file = new File(url.getFile());
            if (file.isDirectory()) {
                Set files = getClassFiles(file.getAbsolutePath(), new HashSet(), file, new int[] { 200 });
                classes.addAll(files);
                continue;
            }
            if (!isJarFile(file)) {
                continue;
            }
            JarFile jf = new JarFile(file);
            for (Enumeration e = jf.entries(); e.hasMoreElements(); ) {
                JarEntry entry = (JarEntry) e.nextElement();
                if (entry == null) {
                    continue;
                }
                String name = entry.getName();
                if (isClazzFile(name)) {
                    /* only use class file */
                    classes.add(name);
                } else if (isJarFile(name)) {
                    classes.addAll(getClassNamesFromJar(name));
                } else {
                    continue;
                }
            }
        } catch (IOException e) {
            throw new IOException(String.format("Error reading classpath entry: %s", url), e);
        }
    }
    // now filter classes by changing "/" to "." and trimming the
    // trailing ".class"
    Set classNames = new TreeSet();
    for (Iterator i = classes.iterator(); i.hasNext(); ) {
        String name = (String) i.next();
        classNames.add(name.replace('/', '.').substring(0, name.length() - 6));
    }
    return (String[]) classNames.toArray(new String[classNames.size()]);
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) Enumeration(java.util.Enumeration) JarURLConnection(java.net.JarURLConnection) IOException(java.io.IOException) JarFile(java.util.jar.JarFile) JarEntry(java.util.jar.JarEntry) URL(java.net.URL) URLConnection(java.net.URLConnection) JarURLConnection(java.net.JarURLConnection) TreeSet(java.util.TreeSet) URLClassLoader(java.net.URLClassLoader) Iterator(java.util.Iterator) URLClassLoader(java.net.URLClassLoader) JarFile(java.util.jar.JarFile) File(java.io.File) HashSet(java.util.HashSet)

Example 92 with TreeSet

use of java.util.TreeSet in project elasticsearch by elastic.

the class SignificantTermsTests method createTestAggregatorBuilder.

@Override
protected SignificantTermsAggregationBuilder createTestAggregatorBuilder() {
    String name = randomAsciiOfLengthBetween(3, 20);
    SignificantTermsAggregationBuilder factory = new SignificantTermsAggregationBuilder(name, null);
    String field = randomAsciiOfLengthBetween(3, 20);
    int randomFieldBranch = randomInt(2);
    switch(randomFieldBranch) {
        case 0:
            factory.field(field);
            break;
        case 1:
            factory.field(field);
            factory.script(new Script("_value + 1"));
            break;
        case 2:
            factory.script(new Script("doc[" + field + "] + 1"));
            break;
        default:
            fail();
    }
    if (randomBoolean()) {
        factory.missing("MISSING");
    }
    if (randomBoolean()) {
        factory.bucketCountThresholds().setRequiredSize(randomIntBetween(1, Integer.MAX_VALUE));
    }
    if (randomBoolean()) {
        factory.bucketCountThresholds().setShardSize(randomIntBetween(1, Integer.MAX_VALUE));
    }
    if (randomBoolean()) {
        int minDocCount = randomInt(4);
        switch(minDocCount) {
            case 0:
                break;
            case 1:
            case 2:
            case 3:
            case 4:
                minDocCount = randomIntBetween(0, Integer.MAX_VALUE);
                break;
        }
        factory.bucketCountThresholds().setMinDocCount(minDocCount);
    }
    if (randomBoolean()) {
        int shardMinDocCount = randomInt(4);
        switch(shardMinDocCount) {
            case 0:
                break;
            case 1:
            case 2:
            case 3:
            case 4:
                shardMinDocCount = randomIntBetween(0, Integer.MAX_VALUE);
                break;
            default:
                fail();
        }
        factory.bucketCountThresholds().setShardMinDocCount(shardMinDocCount);
    }
    if (randomBoolean()) {
        factory.executionHint(randomFrom(executionHints));
    }
    if (randomBoolean()) {
        factory.format("###.##");
    }
    if (randomBoolean()) {
        IncludeExclude incExc = null;
        switch(randomInt(5)) {
            case 0:
                incExc = new IncludeExclude(new RegExp("foobar"), null);
                break;
            case 1:
                incExc = new IncludeExclude(null, new RegExp("foobaz"));
                break;
            case 2:
                incExc = new IncludeExclude(new RegExp("foobar"), new RegExp("foobaz"));
                break;
            case 3:
                SortedSet<BytesRef> includeValues = new TreeSet<>();
                int numIncs = randomIntBetween(1, 20);
                for (int i = 0; i < numIncs; i++) {
                    includeValues.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
                }
                SortedSet<BytesRef> excludeValues = null;
                incExc = new IncludeExclude(includeValues, excludeValues);
                break;
            case 4:
                SortedSet<BytesRef> includeValues2 = null;
                SortedSet<BytesRef> excludeValues2 = new TreeSet<>();
                int numExcs2 = randomIntBetween(1, 20);
                for (int i = 0; i < numExcs2; i++) {
                    excludeValues2.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
                }
                incExc = new IncludeExclude(includeValues2, excludeValues2);
                break;
            case 5:
                SortedSet<BytesRef> includeValues3 = new TreeSet<>();
                int numIncs3 = randomIntBetween(1, 20);
                for (int i = 0; i < numIncs3; i++) {
                    includeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
                }
                SortedSet<BytesRef> excludeValues3 = new TreeSet<>();
                int numExcs3 = randomIntBetween(1, 20);
                for (int i = 0; i < numExcs3; i++) {
                    excludeValues3.add(new BytesRef(randomAsciiOfLengthBetween(1, 30)));
                }
                incExc = new IncludeExclude(includeValues3, excludeValues3);
                break;
            default:
                fail();
        }
        factory.includeExclude(incExc);
    }
    if (randomBoolean()) {
        SignificanceHeuristic significanceHeuristic = null;
        switch(randomInt(5)) {
            case 0:
                significanceHeuristic = new PercentageScore();
                break;
            case 1:
                significanceHeuristic = new ChiSquare(randomBoolean(), randomBoolean());
                break;
            case 2:
                significanceHeuristic = new GND(randomBoolean());
                break;
            case 3:
                significanceHeuristic = new MutualInformation(randomBoolean(), randomBoolean());
                break;
            case 4:
                significanceHeuristic = new ScriptHeuristic(new Script("foo"));
                break;
            case 5:
                significanceHeuristic = new JLHScore();
                break;
            default:
                fail();
        }
        factory.significanceHeuristic(significanceHeuristic);
    }
    if (randomBoolean()) {
        factory.backgroundFilter(QueryBuilders.termsQuery("foo", "bar"));
    }
    return factory;
}
Also used : Script(org.elasticsearch.script.Script) JLHScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.JLHScore) ChiSquare(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ChiSquare) RegExp(org.apache.lucene.util.automaton.RegExp) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) PercentageScore(org.elasticsearch.search.aggregations.bucket.significant.heuristics.PercentageScore) TreeSet(java.util.TreeSet) ScriptHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.ScriptHeuristic) SignificanceHeuristic(org.elasticsearch.search.aggregations.bucket.significant.heuristics.SignificanceHeuristic) MutualInformation(org.elasticsearch.search.aggregations.bucket.significant.heuristics.MutualInformation) SignificantTermsAggregationBuilder(org.elasticsearch.search.aggregations.bucket.significant.SignificantTermsAggregationBuilder) GND(org.elasticsearch.search.aggregations.bucket.significant.heuristics.GND) BytesRef(org.apache.lucene.util.BytesRef)

Example 93 with TreeSet

use of java.util.TreeSet in project elasticsearch by elastic.

the class IncludeExcludeTests method testEmptyTermsWithOrds.

public void testEmptyTermsWithOrds() throws IOException {
    IncludeExclude inexcl = new IncludeExclude(new TreeSet<>(Collections.singleton(new BytesRef("foo"))), null);
    OrdinalsFilter filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
    LongBitSet acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());
    inexcl = new IncludeExclude(null, new TreeSet<>(Collections.singleton(new BytesRef("foo"))));
    filter = inexcl.convertToOrdinalsFilter(DocValueFormat.RAW);
    acceptedOrds = filter.acceptedGlobalOrdinals(DocValues.emptySortedSet());
    assertEquals(0, acceptedOrds.length());
}
Also used : TreeSet(java.util.TreeSet) IncludeExclude(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude) OrdinalsFilter(org.elasticsearch.search.aggregations.bucket.terms.support.IncludeExclude.OrdinalsFilter) LongBitSet(org.apache.lucene.util.LongBitSet) BytesRef(org.apache.lucene.util.BytesRef)

Example 94 with TreeSet

use of java.util.TreeSet in project elasticsearch by elastic.

the class TransportTwoNodesSearchIT method testQueryThenFetchWithFrom.

public void testQueryThenFetchWithFrom() throws Exception {
    Set<String> fullExpectedIds = prepareData();
    SearchSourceBuilder source = searchSource().query(matchAllQuery()).explain(true);
    Set<String> collectedIds = new TreeSet<>();
    SearchResponse searchResponse = client().search(searchRequest("test").source(source.from(0).size(60)).searchType(QUERY_THEN_FETCH)).actionGet();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
    assertThat(searchResponse.getHits().getHits().length, equalTo(60));
    for (int i = 0; i < 60; i++) {
        SearchHit hit = searchResponse.getHits().getHits()[i];
        collectedIds.add(hit.getId());
    }
    searchResponse = client().search(searchRequest("test").source(source.from(60).size(60)).searchType(QUERY_THEN_FETCH)).actionGet();
    assertNoFailures(searchResponse);
    assertThat(searchResponse.getHits().getTotalHits(), equalTo(100L));
    assertThat(searchResponse.getHits().getHits().length, equalTo(40));
    for (int i = 0; i < 40; i++) {
        SearchHit hit = searchResponse.getHits().getHits()[i];
        collectedIds.add(hit.getId());
    }
    assertThat(collectedIds, equalTo(fullExpectedIds));
}
Also used : SearchHit(org.elasticsearch.search.SearchHit) TreeSet(java.util.TreeSet) SearchSourceBuilder(org.elasticsearch.search.builder.SearchSourceBuilder) SearchResponse(org.elasticsearch.action.search.SearchResponse) MultiSearchResponse(org.elasticsearch.action.search.MultiSearchResponse)

Example 95 with TreeSet

use of java.util.TreeSet in project zipkin by openzipkin.

the class SpanStoreTest method getTraces_mergesSpans.

/**
   * It is expected that [[com.twitter.zipkin.storage.SpanStore.apply]] will receive the same span
   * id multiple times with different annotations. At query time, these must be merged.
   */
@Test
public void getTraces_mergesSpans() {
    // span4, span5 have the same span id
    accept(span1, span4, span5);
    SortedSet<Annotation> mergedAnnotations = new TreeSet<>(span4.annotations);
    mergedAnnotations.addAll(span5.annotations);
    Span merged = span4.toBuilder().timestamp(mergedAnnotations.first().timestamp).duration(mergedAnnotations.last().timestamp - mergedAnnotations.first().timestamp).annotations(mergedAnnotations).binaryAnnotations(span5.binaryAnnotations).build();
    assertThat(store().getTraces(QueryRequest.builder().serviceName("service").build())).containsExactly(asList(merged), asList(span1));
}
Also used : TreeSet(java.util.TreeSet) Span(zipkin.Span) Annotation(zipkin.Annotation) BinaryAnnotation(zipkin.BinaryAnnotation) Test(org.junit.Test)

Aggregations

TreeSet (java.util.TreeSet)3785 ArrayList (java.util.ArrayList)833 Test (org.junit.Test)544 HashMap (java.util.HashMap)500 HashSet (java.util.HashSet)428 Set (java.util.Set)422 Map (java.util.Map)401 IOException (java.io.IOException)374 File (java.io.File)339 List (java.util.List)320 TreeMap (java.util.TreeMap)229 Iterator (java.util.Iterator)189 SortedSet (java.util.SortedSet)186 LinkedList (java.util.LinkedList)110 LinkedHashSet (java.util.LinkedHashSet)106 Date (java.util.Date)94 Collection (java.util.Collection)90 Comparator (java.util.Comparator)85 Test (org.testng.annotations.Test)81 Text (org.apache.hadoop.io.Text)79