Search in sources :

Example 46 with LinkedHashSet

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

the class NativeClient method bulkSpanIndexer.

@Override
protected BulkSpanIndexer bulkSpanIndexer() {
    return new SpanBytesBulkSpanIndexer() {

        final List<IndexRequestBuilder> indexRequests = new LinkedList<>();

        final Set<String> indicesToFlush = new LinkedHashSet<>();

        @Override
        protected void add(String index, byte[] spanBytes) {
            indexRequests.add(client.prepareIndex(index, SPAN).setSource(spanBytes));
            if (flushOnWrites)
                indicesToFlush.add(index);
        }

        // Creates a bulk request when there is more than one span to store
        @Override
        public void execute(final Callback<Void> callback) {
            ActionListener callbackAdapter = new ActionListener() {

                @Override
                public void onResponse(Object input) {
                    callback.onSuccess(null);
                }

                @Override
                public void onFailure(Throwable throwable) {
                    callback.onError(throwable);
                }
            };
            // Conditionally create a bulk action depending on the count of index requests
            ListenableActionFuture<? extends ActionResponse> future;
            if (indexRequests.size() == 1) {
                future = indexRequests.get(0).execute();
            } else {
                BulkRequestBuilder request = client.prepareBulk();
                for (IndexRequestBuilder span : indexRequests) {
                    request.add(span);
                }
                future = request.execute();
            }
            // Unless we are in a unit test, this should always be true
            if (indicesToFlush.isEmpty()) {
                future.addListener(callbackAdapter);
                return;
            }
            // If we are in a unit test, we need to flush so that we can read our writes
            future.addListener(new ActionListener() {

                @Override
                public void onResponse(Object input) {
                    client.admin().indices().prepareFlush(indicesToFlush.toArray(new String[indicesToFlush.size()])).execute().addListener(callbackAdapter);
                }

                @Override
                public void onFailure(Throwable throwable) {
                    callbackAdapter.onFailure(throwable);
                }
            });
        }
    };
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) IndexRequestBuilder(org.elasticsearch.action.index.IndexRequestBuilder) Callback(zipkin.storage.Callback) ActionListener(org.elasticsearch.action.ActionListener) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) LinkedList(java.util.LinkedList) BulkRequestBuilder(org.elasticsearch.action.bulk.BulkRequestBuilder)

Example 47 with LinkedHashSet

use of java.util.LinkedHashSet in project jodd by oblac.

the class MixTest method testCollections.

@Test
public void testCollections() {
    List list1 = TypeConverterManager.convertType(arri(1, 2, 3), List.class);
    assertEquals(listo(1, 2, 3), list1);
    list1 = TypeConverterManager.convertType("1,2,3", List.class);
    assertEquals(listo("1", "2", "3"), list1);
    Set set1 = TypeConverterManager.convertType(arrl(1, 2, 3), LinkedHashSet.class);
    assertTrue(set1 instanceof LinkedHashSet);
    Iterator i = set1.iterator();
    assertEquals(Long.valueOf(1), i.next());
    assertEquals(Long.valueOf(2), i.next());
    assertEquals(Long.valueOf(3), i.next());
    list1 = TypeConverterManager.convertType("hello", List.class);
    assertEquals(listo("hello"), list1);
    list1 = TypeConverterManager.convertType(Long.valueOf(4), List.class);
    assertEquals(listo(Long.valueOf(4)), list1);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) LinkedHashSet(java.util.LinkedHashSet) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 48 with LinkedHashSet

use of java.util.LinkedHashSet in project jodd by oblac.

the class DbOomQuery method listSet.

@SuppressWarnings({ "unchecked" })
protected <T> Set<T> listSet(Class[] types, int max, boolean close) {
    Set<T> result = new LinkedHashSet<>(initialCollectionSize(max));
    ResultSetMapper rsm = executeAndBuildResultSetMapper();
    if (types == null) {
        types = rsm.resolveTables();
    }
    Object previousElement = null;
    while (rsm.next()) {
        Object[] objects = rsm.parseObjects(types);
        Object row = resolveRowResults(objects);
        int size = result.size();
        T newElement = (T) row;
        if (entityAwareMode && size > 0) {
            if (previousElement != null && newElement != null) {
                boolean equals;
                if (newElement.getClass().isArray()) {
                    equals = Arrays.equals((Object[]) previousElement, (Object[]) newElement);
                } else {
                    equals = previousElement.equals(newElement);
                }
                if (equals) {
                    continue;
                }
            }
        }
        if (size == max) {
            break;
        }
        result.add(newElement);
        previousElement = newElement;
    }
    close(rsm, close);
    return result;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ResultSetMapper(jodd.db.oom.mapper.ResultSetMapper) DefaultResultSetMapper(jodd.db.oom.mapper.DefaultResultSetMapper)

Example 49 with LinkedHashSet

use of java.util.LinkedHashSet in project OpenAM by OpenRock.

the class UpgradeStepProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    if (!roundEnv.processingOver()) {
        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(UpgradeStepInfo.class);
        for (Element element : elements) {
            Set<DependencyInfo> depends = new LinkedHashSet<DependencyInfo>(2);
            String annotatedType = element.asType().toString();
            UpgradeStepInfo annotation = element.getAnnotation(UpgradeStepInfo.class);
            for (String name : annotation.dependsOn()) {
                DependencyInfo depInfo = stepMappings.get(name);
                if (depInfo == null) {
                    depInfo = new DependencyInfo(name);
                    stepMappings.put(name, depInfo);
                }
                depends.add(depInfo);
            }
            DependencyInfo depInfo = stepMappings.get(annotatedType);
            if (depInfo == null) {
                depInfo = new DependencyInfo(annotatedType);
                stepMappings.put(annotatedType, depInfo);
            }
            for (DependencyInfo dep : depends) {
                depInfo.dependencies.add(dep);
            }
        }
        createDAG();
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Element(javax.lang.model.element.Element) TypeElement(javax.lang.model.element.TypeElement) UpgradeStepInfo(org.forgerock.openam.upgrade.UpgradeStepInfo)

Example 50 with LinkedHashSet

use of java.util.LinkedHashSet in project OpenAM by OpenRock.

the class SiteConfiguration method getSiteInfo.

private static Set getSiteInfo(ServiceConfig rootNode, String name) throws SMSException, SSOException {
    Set info = new LinkedHashSet();
    ServiceConfig sc = rootNode.getSubConfig(name);
    ServiceConfig accessPoint = sc.getSubConfig(SUBCONFIG_ACCESS_URL);
    Map map = accessPoint.getAttributes();
    Set setId = (Set) map.get(ATTR_PRIMARY_SITE_ID);
    Set setURL = (Set) map.get(ATTR_PRIMARY_SITE_URL);
    if ((setId != null) && (!setId.isEmpty()) && (setURL != null) && (!setURL.isEmpty())) {
        info.add(NormalizedURL.normalize((String) setURL.iterator().next()) + "|" + (String) setId.iterator().next());
    }
    Set secURLs = accessPoint.getSubConfigNames("*");
    if ((secURLs != null) && !secURLs.isEmpty()) {
        for (Iterator i = secURLs.iterator(); i.hasNext(); ) {
            String secName = (String) i.next();
            ServiceConfig s = accessPoint.getSubConfig(secName);
            Map mapValues = s.getAttributes();
            setId = (Set) mapValues.get(ATTR_SEC_ID);
            info.add(NormalizedURL.normalize(secName) + "|" + (String) setId.iterator().next());
        }
    }
    return info;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Set(java.util.Set) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) ServiceConfig(com.sun.identity.sm.ServiceConfig) Iterator(java.util.Iterator) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

LinkedHashSet (java.util.LinkedHashSet)3111 ArrayList (java.util.ArrayList)632 Set (java.util.Set)410 HashSet (java.util.HashSet)334 HashMap (java.util.HashMap)312 Map (java.util.Map)284 List (java.util.List)269 File (java.io.File)266 LinkedHashMap (java.util.LinkedHashMap)257 IOException (java.io.IOException)240 Test (org.junit.Test)239 LinkedList (java.util.LinkedList)139 Collection (java.util.Collection)103 URL (java.net.URL)83 ProcessResult (org.asqatasun.entity.audit.ProcessResult)76 Iterator (java.util.Iterator)73 SourceCodeRemark (org.asqatasun.entity.audit.SourceCodeRemark)73 TreeMap (java.util.TreeMap)70 TreeSet (java.util.TreeSet)70 Collectors (java.util.stream.Collectors)69