Search in sources :

Example 1 with Collection

use of java.util.Collection in project cas by apereo.

the class AbstractServicesManager method load.

/**
 * For the duration of the read, the cache store should not remain empty.
 * Otherwise, lookup operations during that loading time window might produce
 * unauthorized failure errors. Invalidation attempts must happen after the load
 * to minimize chances of failures.
 */
@Override
public synchronized Collection<RegisteredService> load() {
    LOGGER.trace("Loading services from [{}]", configurationContext.getServiceRegistry().getName());
    val servicesMap = configurationContext.getServiceRegistry().load().stream().filter(this::supports).filter(this::validateAndFilterServiceByEnvironment).peek(this::loadInternal).collect(Collectors.toMap(r -> {
        LOGGER.trace("Adding registered service [{}] with name [{}] and internal identifier [{}]", r.getServiceId(), r.getName(), r.getId());
        return r.getId();
    }, Function.identity(), (r, s) -> s));
    configurationContext.getServicesCache().invalidateAll();
    configurationContext.getServicesCache().putAll(servicesMap);
    loadInternal();
    publishEvent(new CasRegisteredServicesLoadedEvent(this, getAllServices()));
    evaluateExpiredServiceDefinitions();
    LOGGER.info("Loaded [{}] service(s) from [{}].", configurationContext.getServicesCache().asMap().size(), configurationContext.getServiceRegistry().getName());
    return configurationContext.getServicesCache().asMap().values();
}
Also used : lombok.val(lombok.val) Getter(lombok.Getter) Predicate(java.util.function.Predicate) Collection(java.util.Collection) RequiredArgsConstructor(lombok.RequiredArgsConstructor) lombok.val(lombok.val) CasRegisteredServiceExpiredEvent(org.apereo.cas.support.events.service.CasRegisteredServiceExpiredEvent) StringUtils(org.apache.commons.lang3.StringUtils) Function(java.util.function.Function) Supplier(java.util.function.Supplier) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) CasRegisteredServiceDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceDeletedEvent) CasRegisteredServicePreDeleteEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreDeleteEvent) CasRegisteredServicesDeletedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesDeletedEvent) ApplicationEvent(org.springframework.context.ApplicationEvent) Consumer(java.util.function.Consumer) Slf4j(lombok.extern.slf4j.Slf4j) AccessLevel(lombok.AccessLevel) Stream(java.util.stream.Stream) Service(org.apereo.cas.authentication.principal.Service) Optional(java.util.Optional) CasRegisteredServiceSavedEvent(org.apereo.cas.support.events.service.CasRegisteredServiceSavedEvent) CasRegisteredServicePreSaveEvent(org.apereo.cas.support.events.service.CasRegisteredServicePreSaveEvent) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent) CasRegisteredServicesLoadedEvent(org.apereo.cas.support.events.service.CasRegisteredServicesLoadedEvent)

Example 2 with Collection

use of java.util.Collection in project buck by facebook.

the class ApkBuilderStep method getDescription.

@Override
public String getDescription(ExecutionContext context) {
    ImmutableList.Builder<String> args = ImmutableList.builder();
    args.add(javaRuntimeLauncher.getCommand(), "-classpath", // accessible via an AndroidPlatformTarget and insert that here in place of "$ANDROID_HOME".
    "$ANDROID_HOME/tools/lib/sdklib.jar", "com.android.sdklib.build.ApkBuilderMain");
    args.add(String.valueOf(pathToOutputApkFile));
    args.add("-v");
    if (debugMode) {
        args.add("-d");
    }
    // Unfortunately, ApkBuilderMain does not have CLI args to set the keystore,
    // so these member variables are left out of the command:
    // pathToKeystore, pathToKeystorePropertiesFile
    Multimap<String, Collection<Path>> groups = ImmutableMultimap.<String, Collection<Path>>builder().put("-z", ImmutableList.of(resourceApk)).put("-f", ImmutableList.of(dexFile)).put("-rf", assetDirectories).put("-nf", nativeLibraryDirectories).put("-z", zipFiles).put("-rj", jarFilesThatMayContainResources).build();
    for (Map.Entry<String, Collection<Path>> group : groups.entries()) {
        String prefix = group.getKey();
        for (Path path : group.getValue()) {
            args.add(prefix, String.valueOf(path));
        }
    }
    return Joiner.on(' ').join(args.build());
}
Also used : Path(java.nio.file.Path) ImmutableList(com.google.common.collect.ImmutableList) Collection(java.util.Collection) Map(java.util.Map)

Example 3 with Collection

use of java.util.Collection in project deeplearning4j by deeplearning4j.

the class TestRecordReaders method testClassIndexOutsideOfRangeRRMDSI_MultipleReaders.

@Test
public void testClassIndexOutsideOfRangeRRMDSI_MultipleReaders() {
    Collection<Collection<Collection<Writable>>> c1 = new ArrayList<>();
    Collection<Collection<Writable>> seq1 = new ArrayList<>();
    seq1.add(Arrays.<Writable>asList(new DoubleWritable(0.0)));
    seq1.add(Arrays.<Writable>asList(new DoubleWritable(0.0)));
    c1.add(seq1);
    Collection<Collection<Writable>> seq2 = new ArrayList<>();
    seq2.add(Arrays.<Writable>asList(new DoubleWritable(0.0)));
    seq2.add(Arrays.<Writable>asList(new DoubleWritable(0.0)));
    c1.add(seq2);
    Collection<Collection<Collection<Writable>>> c2 = new ArrayList<>();
    Collection<Collection<Writable>> seq1a = new ArrayList<>();
    seq1a.add(Arrays.<Writable>asList(new IntWritable(0)));
    seq1a.add(Arrays.<Writable>asList(new IntWritable(1)));
    c2.add(seq1a);
    Collection<Collection<Writable>> seq2a = new ArrayList<>();
    seq2a.add(Arrays.<Writable>asList(new IntWritable(0)));
    seq2a.add(Arrays.<Writable>asList(new IntWritable(2)));
    c2.add(seq2a);
    CollectionSequenceRecordReader csrr = new CollectionSequenceRecordReader(c1);
    CollectionSequenceRecordReader csrrLabels = new CollectionSequenceRecordReader(c2);
    DataSetIterator dsi = new SequenceRecordReaderDataSetIterator(csrr, csrrLabels, 2, 2);
    try {
        DataSet ds = dsi.next();
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testClassIndexOutsideOfRangeRRMDSI_MultipleReaders(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : SequenceRecordReaderDataSetIterator(org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator) DataSet(org.nd4j.linalg.dataset.api.DataSet) ArrayList(java.util.ArrayList) CollectionSequenceRecordReader(org.datavec.api.records.reader.impl.collection.CollectionSequenceRecordReader) IntWritable(org.datavec.api.writable.IntWritable) Writable(org.datavec.api.writable.Writable) DoubleWritable(org.datavec.api.writable.DoubleWritable) DoubleWritable(org.datavec.api.writable.DoubleWritable) DL4JException(org.deeplearning4j.exception.DL4JException) DL4JException(org.deeplearning4j.exception.DL4JException) Collection(java.util.Collection) IntWritable(org.datavec.api.writable.IntWritable) SequenceRecordReaderDataSetIterator(org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator) DataSetIterator(org.nd4j.linalg.dataset.api.iterator.DataSetIterator) RecordReaderDataSetIterator(org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator) Test(org.junit.Test)

Example 4 with Collection

use of java.util.Collection in project deeplearning4j by deeplearning4j.

the class TestRecordReaders method testClassIndexOutsideOfRangeRRDSI.

@Test
public void testClassIndexOutsideOfRangeRRDSI() {
    Collection<Collection<Writable>> c = new ArrayList<>();
    c.add(Arrays.<Writable>asList(new DoubleWritable(0.0), new IntWritable(0)));
    c.add(Arrays.<Writable>asList(new DoubleWritable(0.0), new IntWritable(2)));
    CollectionRecordReader crr = new CollectionRecordReader(c);
    RecordReaderDataSetIterator iter = new RecordReaderDataSetIterator(crr, 2, 1, 2);
    try {
        DataSet ds = iter.next();
        fail("Expected exception");
    } catch (DL4JException e) {
        System.out.println("testClassIndexOutsideOfRange(): " + e.getMessage());
    } catch (Exception e) {
        e.printStackTrace();
        fail();
    }
}
Also used : DataSet(org.nd4j.linalg.dataset.api.DataSet) ArrayList(java.util.ArrayList) Collection(java.util.Collection) CollectionRecordReader(org.datavec.api.records.reader.impl.collection.CollectionRecordReader) DoubleWritable(org.datavec.api.writable.DoubleWritable) SequenceRecordReaderDataSetIterator(org.deeplearning4j.datasets.datavec.SequenceRecordReaderDataSetIterator) RecordReaderDataSetIterator(org.deeplearning4j.datasets.datavec.RecordReaderDataSetIterator) DL4JException(org.deeplearning4j.exception.DL4JException) IntWritable(org.datavec.api.writable.IntWritable) DL4JException(org.deeplearning4j.exception.DL4JException) Test(org.junit.Test)

Example 5 with Collection

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

the class ScriptFieldsFetchSubPhase method hitExecute.

@Override
public void hitExecute(SearchContext context, HitContext hitContext) {
    if (context.hasScriptFields() == false) {
        return;
    }
    for (ScriptFieldsContext.ScriptField scriptField : context.scriptFields().fields()) {
        /* Because this is called once per document we end up creating new ScriptDocValues for every document which is important because
             * the values inside ScriptDocValues might be reused for different documents (Dates do this). */
        LeafSearchScript leafScript;
        try {
            leafScript = scriptField.script().getLeafSearchScript(hitContext.readerContext());
        } catch (IOException e1) {
            throw new IllegalStateException("Failed to load script", e1);
        }
        leafScript.setDocument(hitContext.docId());
        final Object value;
        try {
            value = leafScript.unwrap(leafScript.run());
        } catch (RuntimeException e) {
            if (scriptField.ignoreException()) {
                continue;
            }
            throw e;
        }
        if (hitContext.hit().fieldsOrNull() == null) {
            hitContext.hit().fields(new HashMap<>(2));
        }
        SearchHitField hitField = hitContext.hit().getFields().get(scriptField.name());
        if (hitField == null) {
            final List<Object> values;
            if (value instanceof Collection) {
                // TODO: use diamond operator once JI-9019884 is fixed
                values = new ArrayList<>((Collection<?>) value);
            } else {
                values = Collections.singletonList(value);
            }
            hitField = new SearchHitField(scriptField.name(), values);
            hitContext.hit().getFields().put(scriptField.name(), hitField);
        }
    }
}
Also used : LeafSearchScript(org.elasticsearch.script.LeafSearchScript) Collection(java.util.Collection) SearchHitField(org.elasticsearch.search.SearchHitField) IOException(java.io.IOException)

Aggregations

Collection (java.util.Collection)8527 ArrayList (java.util.ArrayList)2642 Map (java.util.Map)2118 List (java.util.List)1950 HashMap (java.util.HashMap)1655 Test (org.junit.Test)1473 Set (java.util.Set)1137 Iterator (java.util.Iterator)1090 HashSet (java.util.HashSet)1085 Collectors (java.util.stream.Collectors)948 IOException (java.io.IOException)821 Collections (java.util.Collections)659 Arrays (java.util.Arrays)445 Optional (java.util.Optional)422 File (java.io.File)386 Logger (org.slf4j.Logger)342 LoggerFactory (org.slf4j.LoggerFactory)330 PersistenceManager (javax.jdo.PersistenceManager)309 LinkedHashMap (java.util.LinkedHashMap)299 Query (javax.jdo.Query)294