Search in sources :

Example 36 with Collection

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

the class NeededCoverageSpecTypeCoercer method coerce.

@Override
public NeededCoverageSpec coerce(CellPathResolver cellRoots, ProjectFilesystem filesystem, Path pathRelativeToProjectRoot, Object object) throws CoerceFailedException {
    if (object instanceof NeededCoverageSpec) {
        return (NeededCoverageSpec) object;
    }
    if (object instanceof Collection<?>) {
        Collection<?> collection = (Collection<?>) object;
        if (collection.size() == 2 || collection.size() == 3) {
            Iterator<?> iter = collection.iterator();
            Float neededRatio = floatTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
            if (neededRatio < 0 || neededRatio > 1) {
                throw CoerceFailedException.simple(object, getOutputClass(), "the needed coverage ratio should be in range [0; 1]");
            }
            BuildTarget buildTarget = buildTargetTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next());
            Optional<String> pathName = Optional.empty();
            if (iter.hasNext()) {
                pathName = Optional.of(pathNameTypeCoercer.coerce(cellRoots, filesystem, pathRelativeToProjectRoot, iter.next()));
            }
            return NeededCoverageSpec.of(neededRatio, buildTarget, pathName);
        }
    }
    throw CoerceFailedException.simple(object, getOutputClass(), "input should be a tuple of needed coverage ratio, a build target, and optionally a path");
}
Also used : BuildTarget(com.facebook.buck.model.BuildTarget) Collection(java.util.Collection) NeededCoverageSpec(com.facebook.buck.python.NeededCoverageSpec)

Example 37 with Collection

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

the class SmartDexingStep method execute.

@Override
public StepExecutionResult execute(ExecutionContext context) throws InterruptedException {
    try {
        Multimap<Path, Path> outputToInputs = outputToInputsSupplier.get();
        runDxCommands(context, outputToInputs);
        if (secondaryOutputDir.isPresent()) {
            removeExtraneousSecondaryArtifacts(secondaryOutputDir.get(), outputToInputs.keySet(), filesystem);
            // Concatenate if solid compression is specified.
            // create a mapping of the xzs file target and the dex.jar files that go into it
            ImmutableMultimap.Builder<Path, Path> secondaryDexJarsMultimapBuilder = ImmutableMultimap.builder();
            for (Path p : outputToInputs.keySet()) {
                if (DexStore.XZS.matchesPath(p)) {
                    String[] matches = p.getFileName().toString().split("-");
                    Path output = p.getParent().resolve(matches[0].concat(SECONDARY_SOLID_DEX_EXTENSION));
                    secondaryDexJarsMultimapBuilder.put(output, p);
                }
            }
            ImmutableMultimap<Path, Path> secondaryDexJarsMultimap = secondaryDexJarsMultimapBuilder.build();
            if (!secondaryDexJarsMultimap.isEmpty()) {
                for (Map.Entry<Path, Collection<Path>> entry : secondaryDexJarsMultimap.asMap().entrySet()) {
                    Path store = entry.getKey();
                    Collection<Path> secondaryDexJars = entry.getValue();
                    // Construct the output path for our solid blob and its compressed form.
                    Path secondaryBlobOutput = store.getParent().resolve("uncompressed.dex.blob");
                    Path secondaryCompressedBlobOutput = store;
                    // Concatenate the jars into a blob and compress it.
                    StepRunner stepRunner = new DefaultStepRunner();
                    Step concatStep = new ConcatStep(filesystem, ImmutableList.copyOf(secondaryDexJars), secondaryBlobOutput);
                    Step xzStep;
                    if (xzCompressionLevel.isPresent()) {
                        xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput, xzCompressionLevel.get().intValue());
                    } else {
                        xzStep = new XzStep(filesystem, secondaryBlobOutput, secondaryCompressedBlobOutput);
                    }
                    stepRunner.runStepForBuildTarget(context, concatStep, Optional.empty());
                    stepRunner.runStepForBuildTarget(context, xzStep, Optional.empty());
                }
            }
        }
    } catch (StepFailedException | IOException e) {
        context.logError(e, "There was an error in smart dexing step.");
        return StepExecutionResult.ERROR;
    }
    return StepExecutionResult.SUCCESS;
}
Also used : Path(java.nio.file.Path) XzStep(com.facebook.buck.step.fs.XzStep) StepRunner(com.facebook.buck.step.StepRunner) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) RmStep(com.facebook.buck.step.fs.RmStep) Step(com.facebook.buck.step.Step) RepackZipEntriesStep(com.facebook.buck.zip.RepackZipEntriesStep) CompositeStep(com.facebook.buck.step.CompositeStep) XzStep(com.facebook.buck.step.fs.XzStep) WriteFileStep(com.facebook.buck.step.fs.WriteFileStep) IOException(java.io.IOException) StepFailedException(com.facebook.buck.step.StepFailedException) DefaultStepRunner(com.facebook.buck.step.DefaultStepRunner) Collection(java.util.Collection) ImmutableMultimap(com.google.common.collect.ImmutableMultimap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 38 with Collection

use of java.util.Collection in project head by mifos.

the class MifosSelect method doEndTag.

/**
     * Function to render the tag in jsp
     */
@Override
public int doEndTag() throws JspException {
    Collection inColl = (Collection) pageContext.getRequest().getAttribute(this.input);
    Collection outColl = null;
    if (this.output != null) {
        outColl = (Collection) pageContext.getRequest().getAttribute(this.output);
    }
    String html = render(inColl, outColl);
    TagUtils.getInstance().write(pageContext, html);
    return super.doEndTag();
}
Also used : Collection(java.util.Collection)

Example 39 with Collection

use of java.util.Collection in project pinot by linkedin.

the class JSONUtil method toJSON.

@SuppressWarnings("unchecked")
public static Object toJSON(Object javaObject) {
    if (javaObject == null) {
        return null;
    }
    if (javaObject instanceof JSON) {
        return javaObject;
    }
    if (javaObject instanceof FastJSONObject) {
        return ((FastJSONObject) javaObject).getInnerJSONObject();
    }
    if (javaObject instanceof FastJSONArray) {
        return ((FastJSONArray) javaObject).getInnerJSONArray();
    }
    if (javaObject instanceof Map) {
        Map<Object, Object> map = (Map<Object, Object>) javaObject;
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject(map.size());
        for (Map.Entry<Object, Object> entry : map.entrySet()) {
            Object key = entry.getKey();
            String jsonKey = TypeUtils.castToString(key);
            Object jsonValue = toJSON(entry.getValue());
            json.put(jsonKey, jsonValue);
        }
        return json;
    }
    if (javaObject instanceof Collection) {
        Collection<Object> collection = (Collection<Object>) javaObject;
        com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray(collection.size());
        for (Object item : collection) {
            Object jsonValue = toJSON(item);
            array.add(jsonValue);
        }
        return array;
    }
    Class<?> clazz = javaObject.getClass();
    if (clazz.isEnum()) {
        return ((Enum<?>) javaObject).name();
    }
    if (clazz.isArray()) {
        int len = Array.getLength(javaObject);
        com.alibaba.fastjson.JSONArray array = new com.alibaba.fastjson.JSONArray(len);
        for (int i = 0; i < len; ++i) {
            Object item = Array.get(javaObject, i);
            Object jsonValue = toJSON(item);
            array.add(jsonValue);
        }
        return array;
    }
    if (ParserConfig.getGlobalInstance().isPrimitive(clazz)) {
        return javaObject;
    }
    try {
        List<FieldInfo> getters = TypeUtils.computeGetters(clazz, null);
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject(getters.size());
        for (FieldInfo field : getters) {
            Object value = field.get(javaObject);
            Object jsonValue = toJSON(value);
            json.put(field.getName(), jsonValue);
        }
        return json;
    } catch (Exception e) {
        throw new com.alibaba.fastjson.JSONException("toJSON error", e);
    }
}
Also used : JSONArray(org.json.JSONArray) JSON(com.alibaba.fastjson.JSON) JSONException(org.json.JSONException) JSONObject(org.json.JSONObject) Collection(java.util.Collection) JSONObject(org.json.JSONObject) Map(java.util.Map) FieldInfo(com.alibaba.fastjson.util.FieldInfo)

Example 40 with Collection

use of java.util.Collection in project head by mifos.

the class BranchReportStaffingLevelSummaryHelperIntegrationTest method assertStaffingLevelSummaries.

private void assertStaffingLevelSummaries(BranchReportBO branchReport) {
    Set<BranchReportStaffingLevelSummaryBO> staffingLevelSummaries = branchReport.getStaffingLevelSummaries();
    Assert.assertEquals(1, staffingLevelSummaries.size());
    Collection retrievedRolenames = CollectionUtils.collect(staffingLevelSummaries, new Transformer() {

        @Override
        public Object transform(Object input) {
            return ((BranchReportStaffingLevelSummaryBO) input).getTitleName();
        }
    });
    Assert.assertEquals(1, retrievedRolenames.size());
    Assert.assertTrue(retrievedRolenames.contains(BranchReportStaffingLevelSummaryBO.TOTAL_STAFF_ROLE_NAME));
}
Also used : Transformer(org.apache.commons.collections.Transformer) Collection(java.util.Collection) BranchReportStaffingLevelSummaryBO(org.mifos.reports.branchreport.BranchReportStaffingLevelSummaryBO)

Aggregations

Collection (java.util.Collection)8532 ArrayList (java.util.ArrayList)2646 Map (java.util.Map)2119 List (java.util.List)1956 HashMap (java.util.HashMap)1657 Test (org.junit.Test)1476 Set (java.util.Set)1137 Iterator (java.util.Iterator)1090 HashSet (java.util.HashSet)1085 Collectors (java.util.stream.Collectors)951 IOException (java.io.IOException)823 Collections (java.util.Collections)660 Arrays (java.util.Arrays)446 Optional (java.util.Optional)423 File (java.io.File)386 Logger (org.slf4j.Logger)344 LoggerFactory (org.slf4j.LoggerFactory)330 PersistenceManager (javax.jdo.PersistenceManager)309 LinkedHashMap (java.util.LinkedHashMap)299 Query (javax.jdo.Query)294