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