List of usage examples for com.google.common.collect ImmutableList forEach
default void forEach(Consumer<? super T> action)
From source file:com.spectralogic.ds3contractcomparator.print.simpleprinter.Ds3TypeDiffSimplePrinter.java
/** * Converts a {@link ImmutableList} of {@link Ds3EnumConstant} into an {@link ImmutableMap} of * enum values (i.e. names) and {@link Ds3EnumConstant} *//* w w w . jav a 2s . co m*/ private static ImmutableMap<String, Ds3EnumConstant> toEnumConstantMap( final ImmutableList<Ds3EnumConstant> enumConstants) { if (isEmpty(enumConstants)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, Ds3EnumConstant> builder = ImmutableMap.builder(); enumConstants.forEach(enumConstant -> builder.put(enumConstant.getName(), enumConstant)); return builder.build(); }
From source file:com.spectralogic.ds3contractcomparator.print.htmlprinter.generators.row.ModifiedHtmlRowGenerator.java
/** * Creates a map between the specified property in string form, and the object containing the property. *//*from w w w . j a v a2 s . c om*/ static <T> ImmutableMap<String, T> toPropertyMap(final ImmutableList<T> objects, final String property) { if (isEmpty(objects)) { return ImmutableMap.of(); } final ImmutableMap.Builder<String, T> builder = ImmutableMap.builder(); objects.forEach(o -> { try { builder.put(BeanUtils.getProperty(o, property), o); } catch (final IllegalAccessException | InvocationTargetException | NoSuchMethodException e) { LOG.warn("Cannot create property map of object from class " + o.getClass().toString() + " using property " + property + ": " + e.getMessage(), e); } }); return builder.build(); }
From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.DeleteService.java
/** * Delete folder(s)/*from w w w. j av a2 s. c om*/ * * @param ds3Common ds3Common object * @param values list of folders to be deleted */ public static void deleteFolders(final Ds3Common ds3Common, final ImmutableList<TreeItem<Ds3TreeTableValue>> values) { LOG.info("Got delete folder event"); final Ds3PanelPresenter ds3PanelPresenter = ds3Common.getDs3PanelPresenter(); final Session currentSession = ds3Common.getCurrentSession(); if (currentSession != null) { final ImmutableMultimap.Builder<String, String> deleteFoldersMap = ImmutableMultimap.builder(); values.forEach(folder -> { deleteFoldersMap.put(folder.getValue().getBucketName(), folder.getValue().getFullName()); }); final Ds3DeleteFoldersTask deleteFolderTask = new Ds3DeleteFoldersTask(currentSession.getClient(), deleteFoldersMap.build()); DeleteFilesPopup.show(deleteFolderTask, ds3Common); ds3PanelPresenter.getDs3PathIndicator().setText(StringConstants.EMPTY_STRING); ds3PanelPresenter.getDs3PathIndicatorTooltip().setText(StringConstants.EMPTY_STRING); } }
From source file:com.spectralogic.dsbrowser.gui.services.tasks.Ds3GetJob.java
public static ImmutableMap<String, Path> getFileMap(final List<Ds3TreeTableValueCustom> selectedItems) { final ImmutableList<Ds3TreeTableValueCustom> fileList = selectedItems.stream() .filter(value -> value.getType().equals(Ds3TreeTableValue.Type.File)) .collect(GuavaCollectors.immutableList()); final ImmutableMap.Builder<String, Path> fileMap = ImmutableMap.builder(); fileList.forEach(file -> { fileMap.put(file.getFullName(), Paths.get(StringConstants.FORWARD_SLASH)); });// ww w. j a v a 2 s. c om return fileMap.build(); }
From source file:com.spectralogic.dsbrowser.gui.services.tasks.Ds3GetJob.java
public static ImmutableMap<String, Path> getFolderMap(final List<Ds3TreeTableValueCustom> selectedItems) { final ImmutableList<Ds3TreeTableValueCustom> folderList = selectedItems.stream() .filter(value -> !value.getType().equals(Ds3TreeTableValue.Type.File)) .collect(GuavaCollectors.immutableList()); final ImmutableMap.Builder<String, Path> fileMap = ImmutableMap.builder(); folderList.forEach(folder -> { fileMap.put(folder.getFullName(), Paths.get(StringConstants.FORWARD_SLASH)); });//from w ww . ja v a 2 s . co m return fileMap.build(); }
From source file:org.ow2.authzforce.core.pdp.io.xacml.json.BaseXacmlJsonResultPostprocessor.java
private static JSONObject convert(final IndividualXacmlJsonRequest request, final DecisionResult result) { assert request != null && result != null; final Map<String, Object> jsonPropertyMap = HashCollections.newUpdatableMap(6); // Decision/*from ww w .ja v a 2 s . c o m*/ jsonPropertyMap.put("Decision", result.getDecision().value()); // Status final Status status = result.getStatus(); if (status != null) { jsonPropertyMap.put("Status", toJson(status)); } // Obligations/Advice final ImmutableList<PepAction> pepActions = result.getPepActions(); assert pepActions != null; if (!pepActions.isEmpty()) { final int numOfPepActions = pepActions.size(); final List<JSONObject> jsonObligations = new ArrayList<>(numOfPepActions); final List<JSONObject> jsonAdvices = new ArrayList<>(numOfPepActions); pepActions.forEach(pepAction -> { final JSONObject pepActionJsonObject = toJson(pepAction.getId(), pepAction.getAttributeAssignments()); final List<JSONObject> pepActionJsonObjects = pepAction.isMandatory() ? jsonObligations : jsonAdvices; pepActionJsonObjects.add(pepActionJsonObject); }); if (!jsonObligations.isEmpty()) { jsonPropertyMap.put("Obligations", new JSONArray(jsonObligations)); } if (!jsonAdvices.isEmpty()) { jsonPropertyMap.put("AssociatedAdvice", new JSONArray(jsonAdvices)); } } // IncludeInResult categories final List<JSONObject> attributesByCategoryToBeReturned = request.getAttributesByCategoryToBeReturned(); if (!attributesByCategoryToBeReturned.isEmpty()) { jsonPropertyMap.put("Category", new JSONArray(attributesByCategoryToBeReturned)); } // PolicyIdentifierList final ImmutableList<PrimaryPolicyMetadata> applicablePolicies = result.getApplicablePolicies(); if (applicablePolicies != null && !applicablePolicies.isEmpty()) { final List<JSONObject> policyRefs = new ArrayList<>(applicablePolicies.size()); final List<JSONObject> policySetRefs = new ArrayList<>(applicablePolicies.size()); for (final PrimaryPolicyMetadata applicablePolicy : applicablePolicies) { final JSONObject ref = new JSONObject(HashCollections.newImmutableMap("Id", applicablePolicy.getId(), "Version", applicablePolicy.getVersion().toString())); final List<JSONObject> refs = applicablePolicy.getType() == TopLevelPolicyElementType.POLICY ? policyRefs : policySetRefs; refs.add(ref); } final Map<String, Object> policyListJsonObjMap = HashCollections.newUpdatableMap(2); if (!policyRefs.isEmpty()) { policyListJsonObjMap.put("PolicyIdReference", new JSONArray(policyRefs)); } if (!policySetRefs.isEmpty()) { policyListJsonObjMap.put("PolicySetIdReference", new JSONArray(policySetRefs)); } jsonPropertyMap.put("PolicyIdentifierList", new JSONObject(policyListJsonObjMap)); } // final Result return new JSONObject(jsonPropertyMap); }
From source file:org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor.java
/** * Convert AuthzForce-specific {@link DecisionResult} to XACML {@link Result} * //from ww w . j av a 2 s.c o m * @param request * request corresponding to result; iff null, some content from it, esp. the list of {@link oasis.names.tc.xacml._3_0.core.schema.wd_17.Attributes}, is included in {@code result} * @param result * @return XACML Result */ public static final Result convert(final IndividualXacmlJaxbRequest request, final DecisionResult result) { final ImmutableList<PepAction> pepActions = result.getPepActions(); assert pepActions != null; final List<Obligation> xacmlObligations; final List<Advice> xacmlAdvices; if (pepActions.isEmpty()) { xacmlObligations = null; xacmlAdvices = null; } else { xacmlObligations = new ArrayList<>(pepActions.size()); xacmlAdvices = new ArrayList<>(pepActions.size()); pepActions.forEach(pepAction -> { final String pepActionId = pepAction.getId(); final List<AttributeAssignment> xacmlAttAssignments = convert(pepAction.getAttributeAssignments()); if (pepAction.isMandatory()) { xacmlObligations.add(new Obligation(xacmlAttAssignments, pepActionId)); } else { xacmlAdvices.add(new Advice(xacmlAttAssignments, pepActionId)); } }); } final ImmutableList<PrimaryPolicyMetadata> applicablePolicies = result.getApplicablePolicies(); final PolicyIdentifierList jaxbPolicyIdentifiers; if (applicablePolicies == null || applicablePolicies.isEmpty()) { jaxbPolicyIdentifiers = null; } else { final List<JAXBElement<IdReferenceType>> jaxbPolicyIdRefs = new ArrayList<>(applicablePolicies.size()); for (final PrimaryPolicyMetadata applicablePolicy : applicablePolicies) { final IdReferenceType jaxbIdRef = new IdReferenceType(applicablePolicy.getId(), applicablePolicy.getVersion().toString(), null, null); final JAXBElement<IdReferenceType> jaxbPolicyIdRef = applicablePolicy .getType() == TopLevelPolicyElementType.POLICY ? Xacml3JaxbHelper.XACML_3_0_OBJECT_FACTORY.createPolicyIdReference(jaxbIdRef) : Xacml3JaxbHelper.XACML_3_0_OBJECT_FACTORY.createPolicySetIdReference(jaxbIdRef); jaxbPolicyIdRefs.add(jaxbPolicyIdRef); } jaxbPolicyIdentifiers = new PolicyIdentifierList(jaxbPolicyIdRefs); } return new Result(result.getDecision(), result.getStatus(), xacmlObligations == null || xacmlObligations.isEmpty() ? null : new Obligations(xacmlObligations), xacmlAdvices == null || xacmlAdvices.isEmpty() ? null : new AssociatedAdvice(xacmlAdvices), request == null ? null : request.getAttributesToBeReturned(), jaxbPolicyIdentifiers); }
From source file:org.spongepowered.api.item.inventory.ItemStackBuilderPopulators.java
/** * Creates a new {@link BiConsumer} that provides a {@link VariableAmount} * of {@link DataManipulator}s from the provided pool. Note that no * validation can be performed, however the builder will ignore unsupported * data. This can be used to provide custom data manipulators. * * @param manipulators The manipulator pool to use * @param rolls The variable amount of manipulators to apply * @return The new biconsumer to apply to an itemstack builder *///from w ww .ja v a 2s . c o m public static BiConsumer<ItemStack.Builder, Random> data(Collection<DataManipulator<?, ?>> manipulators, VariableAmount rolls) { checkNotNull(manipulators, "Manipulators cannot be null!"); checkNotNull(rolls, "VariableAmount cannot be null!"); final ImmutableList<DataManipulator<?, ?>> copied = ImmutableList.copyOf(manipulators); final WeightedTable<DataManipulator<?, ?>> table = new WeightedTable<>(); table.setRolls(rolls); copied.forEach(manipulator1 -> table.add(manipulator1, 1)); return data(table); }
From source file:com.facebook.buck.parser.PythonDslProjectBuildFileParser.java
private static ImmutableMap<String, Map<String, Object>> indexTargetsByName( ImmutableList<Map<String, Object>> targets) { ImmutableMap.Builder<String, Map<String, Object>> builder = ImmutableMap .builderWithExpectedSize(targets.size()); targets.forEach(target -> builder.put((String) target.get("name"), convertSelectableAttributes(target))); return builder.build(); }
From source file:com.facebook.buck.rules.modern.PipelinedModernBuildRule.java
@Override public final ImmutableList<? extends Step> getPipelinedBuildSteps(BuildContext context, BuildableContext buildableContext, State state) { ImmutableList.Builder<Path> outputsBuilder = ImmutableList.builder(); recordOutputs(outputsBuilder::add);// ww w .j a va 2 s . c o m ImmutableList<Path> outputs = outputsBuilder.build(); outputs.forEach(buildableContext::recordArtifact); OutputPathResolver outputPathResolver = getOutputPathResolver(); ImmutableList.Builder<Step> stepsBuilder = ImmutableList.builder(); ModernBuildRule.getSetupStepsForBuildable(context, getProjectFilesystem(), outputs, stepsBuilder, outputPathResolver); stepsBuilder.addAll(getBuildable().getPipelinedBuildSteps(context, getProjectFilesystem(), state, outputPathResolver, getBuildCellPathFactory(context, getProjectFilesystem(), outputPathResolver))); return stepsBuilder.build(); }