List of usage examples for com.google.common.collect ImmutableList isEmpty
boolean isEmpty();
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/* w w w . j a v a2s . co 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.apache.calcite.plan.RelOptPredicateList.java
/** Creates a RelOptPredicateList for a join. * * @param rexBuilder Rex builder/* w w w . j av a2 s. com*/ * @param pulledUpPredicates Predicates that apply to the rows returned by the * relational expression * @param leftInferredPredicates Predicates that were inferred from the right * input * @param rightInferredPredicates Predicates that were inferred from the left * input */ public static RelOptPredicateList of(RexBuilder rexBuilder, Iterable<RexNode> pulledUpPredicates, Iterable<RexNode> leftInferredPredicates, Iterable<RexNode> rightInferredPredicates) { final ImmutableList<RexNode> pulledUpPredicatesList = ImmutableList.copyOf(pulledUpPredicates); final ImmutableList<RexNode> leftInferredPredicateList = ImmutableList.copyOf(leftInferredPredicates); final ImmutableList<RexNode> rightInferredPredicatesList = ImmutableList.copyOf(rightInferredPredicates); if (pulledUpPredicatesList.isEmpty() && leftInferredPredicateList.isEmpty() && rightInferredPredicatesList.isEmpty()) { return EMPTY; } final ImmutableMap<RexNode, RexNode> constantMap = RexUtil.predicateConstants(RexNode.class, rexBuilder, pulledUpPredicatesList); return new RelOptPredicateList(pulledUpPredicatesList, leftInferredPredicateList, rightInferredPredicatesList, constantMap); }
From source file:com.google.javascript.jscomp.Promises.java
/** * Synthesizes a type representing the legal types of a return expression within async code * (i.e.`Promise` callbacks, async functions) based on the expected return type of that code. * * <p>The return type will generally be a union but may not be in the case of top-like types. If * the expected return type is a union, any synchronous elements will be dropped, since they can * never occur. For example:/*from w w w .ja v a2 s .c o m*/ * * <ul> * <li>`!Promise<number>` => `number|!IThenable<number>` * <li>`number` => `?` * <li>`number|!Promise<string>` => `string|!IThenable<string>` * <li>`!IThenable<number>|!Promise<string>` => `number|string|!IThenable<number|string>` * <li>`!IThenable<number|string>` => `number|string|!IThenable<number|string>` * <li>`?` => `?` * <li>`*` => `?` * </ul> */ static final JSType createAsyncReturnableType(JSTypeRegistry registry, JSType maybeThenable) { JSType unknownType = registry.getNativeType(JSTypeNative.UNKNOWN_TYPE); ObjectType iThenableType = registry.getNativeObjectType(JSTypeNative.I_THENABLE_TYPE); JSType iThenableOfUnknownType = registry.createTemplatizedType(iThenableType, unknownType); ImmutableList<JSType> alternates = maybeThenable.isUnionType() ? maybeThenable.toMaybeUnionType().getAlternates() : ImmutableList.of(maybeThenable); ImmutableList<JSType> asyncTemplateAlternates = alternates.stream() .filter((t) -> t.isSubtypeOf(iThenableOfUnknownType)) // Discard "synchronous" types. .map((t) -> getTemplateTypeOfThenable(registry, t)) // Unwrap "asynchronous" types. .collect(toImmutableList()); if (asyncTemplateAlternates.isEmpty()) { return unknownType; } JSType asyncTemplateUnion = registry.createUnionType(asyncTemplateAlternates); return registry.createUnionType(asyncTemplateUnion, registry.createTemplatizedType(iThenableType, asyncTemplateUnion)); }
From source file:com.google.devtools.build.lib.rules.android.ProguardHelper.java
/** * Retrieves the full set of proguard specs that should be applied to this binary, including the * specs passed in, if Proguard should run on the given rule. {@link #createProguardAction} * relies on this method returning an empty list if the given rule doesn't declare specs in * --java_optimization_mode=legacy./* w w w .j a v a 2 s.co m*/ * * <p>If Proguard shouldn't be applied, or the legacy link mode is used and there are no * proguard_specs on this rule, an empty list will be returned, regardless of any given specs or * specs from dependencies. {@link AndroidBinary#createAndroidBinary} relies on that behavior. */ public static ImmutableList<Artifact> collectTransitiveProguardSpecs(RuleContext ruleContext, Artifact... specsToInclude) { JavaOptimizationMode optMode = getJavaOptimizationMode(ruleContext); if (optMode == JavaOptimizationMode.NOOP) { return ImmutableList.of(); } ImmutableList<Artifact> proguardSpecs = ruleContext.attributes().has(PROGUARD_SPECS, BuildType.LABEL_LIST) ? ruleContext.getPrerequisiteArtifacts(PROGUARD_SPECS, Mode.TARGET).list() : ImmutableList.<Artifact>of(); if (optMode == JavaOptimizationMode.LEGACY && proguardSpecs.isEmpty()) { return ImmutableList.of(); } // TODO(bazel-team): In modes except LEGACY verify that proguard specs don't include -dont... // flags since those flags would override the desired optMode ImmutableSortedSet.Builder<Artifact> builder = ImmutableSortedSet.orderedBy(Artifact.EXEC_PATH_COMPARATOR) .addAll(proguardSpecs).add(specsToInclude) .addAll(ruleContext.getPrerequisiteArtifacts(":extra_proguard_specs", Mode.TARGET).list()); for (ProguardSpecProvider dep : ruleContext.getPrerequisites("deps", Mode.TARGET, ProguardSpecProvider.class)) { builder.addAll(dep.getTransitiveProguardSpecs()); } // Generate and include implicit Proguard spec for requested mode. if (!optMode.getImplicitProguardDirectives().isEmpty()) { Artifact implicitDirectives = getProguardConfigArtifact(ruleContext, optMode.name().toLowerCase()); ruleContext.registerAction(new FileWriteAction(ruleContext.getActionOwner(), implicitDirectives, optMode.getImplicitProguardDirectives(), /*executable*/ false)); builder.add(implicitDirectives); } return builder.build().asList(); }
From source file:org.ow2.authzforce.core.pdp.api.DecisionResults.java
/** * Instantiates a Permit decision with optional PEP actions (obligations and advice). * // w w w . j ava 2 s. co m * * @param status * status; even if decision is Permit/Deny, there may be a status "ok" (standard status in XACML 3.0) or internal error on attribute resolution but not resulting in Indeterminate * because of special combining algorithm ignoring such results (like deny-unless-permit) or MustBePresent="false" * @param pepActions * PEP actions (obligations/advices) * @param applicablePolicyIdList * list of identifiers of applicable policies that contributed to this result. If not null, the created instance uses only an immutable copy of this list. * @return permit result, more particularly {@link #SIMPLE_PERMIT} iff {@code status == null && pepActions == null}. */ public static DecisionResult getPermit(final Status status, final ImmutableList<PepAction> pepActions, final ImmutableList<PrimaryPolicyMetadata> applicablePolicyIdList) { if (status == null && (pepActions == null || pepActions.isEmpty()) && (applicablePolicyIdList == null || applicablePolicyIdList.isEmpty())) { return SIMPLE_PERMIT; } return new ImmutableDPResult(DecisionType.PERMIT, status, pepActions, applicablePolicyIdList); }
From source file:org.ow2.authzforce.core.pdp.api.DecisionResults.java
/** * Instantiates a Deny decision with optional PEP actions (obligations and advice). * //from ww w. ja v a2s .com * * @param status * status; even if decision is Permit/Deny, there may be a status "ok" (standard status in XACML 3.0) or internal error on attribute resolution but not resulting in Indeterminate * because of special combining algorithm ignoring such results (like deny-unless-permit) or MustBePresent="false" * @param pepActions * PEP actions (obligations/advices) * @param applicablePolicyIdList * list of identifiers of applicable policies that contributed to this result. If not null, the created instance uses only an immutable copy of this list. * @return deny result, more particularly {@link #SIMPLE_DENY} iff {@code status == null && pepActions == null}. */ public static DecisionResult getDeny(final Status status, final ImmutableList<PepAction> pepActions, final ImmutableList<PrimaryPolicyMetadata> applicablePolicyIdList) { if (status == null && (pepActions == null || pepActions.isEmpty()) && (applicablePolicyIdList == null || applicablePolicyIdList.isEmpty())) { return SIMPLE_DENY; } return new ImmutableDPResult(DecisionType.DENY, status, pepActions, applicablePolicyIdList); }
From source file:com.spectralogic.dsbrowser.gui.services.ds3Panel.Ds3PanelService.java
@SuppressWarnings("unchecked") public static void showMetadata(final Ds3Common ds3Common, final Workers workers, final ResourceBundle resourceBundle) { final TreeTableView ds3TreeTableView = ds3Common.getDs3TreeTableView(); final ImmutableList<TreeItem<Ds3TreeTableValue>> values = (ImmutableList<TreeItem<Ds3TreeTableValue>>) ds3TreeTableView .getSelectionModel().getSelectedItems().stream().collect(GuavaCollectors.immutableList()); if (values.isEmpty()) { LOG.info(resourceBundle.getString("noFiles")); new LazyAlert(resourceBundle).info(resourceBundle.getString("noFiles")); return;//from w w w .j av a2 s . c o m } if (values.size() > 1) { LOG.info(resourceBundle.getString("onlySingleObjectSelectForMetadata")); new LazyAlert(resourceBundle).info(resourceBundle.getString("onlySingleObjectSelectForMetadata")); return; } final MetadataTask getMetadata = new MetadataTask(ds3Common, values); workers.execute(getMetadata); getMetadata.setOnSucceeded(SafeHandler.logHandle(event -> Platform.runLater(() -> { LOG.info("Launching metadata popup"); final MetadataView metadataView = new MetadataView((Ds3Metadata) getMetadata.getValue()); Popup.show(metadataView.getView(), resourceBundle.getString("metaDataContextMenu")); }))); }
From source file:org.ow2.authzforce.core.pdp.api.io.BaseXacmlJaxbResultPostprocessor.java
/** * Convert AuthzForce-specific {@link DecisionResult} to XACML {@link Result} * //w w w.ja v a2 s . co 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:io.mesosphere.mesos.util.CassandraFrameworkProtosUtils.java
public static Optional<Long> maxResourceValueLong(@NotNull final List<Resource> resource) { ImmutableList<Long> values = from(resource).transform(toLongResourceValue()).toList(); if (values.isEmpty()) { return Optional.absent(); } else {//from w w w . j a v a 2 s .c o m return Optional.of(Collections.max(values)); } }
From source file:com.github.rinde.opt.localsearch.Swaps.java
/** * Moves the occurrences of <code>item</code> to their new positions. This * does not change the relative ordering of any other items in the list. * @param originalList The original list that will be swapped. * @param insertionIndices The indices where item should be inserted relative * to the positions of the <code>originalList</code> <b>without</b> * <code>item</code>. The number of indices must equal the number of * occurrences of item in the original list. * @param item The item to swap./*from www . j av a 2 s .c o m*/ * @return The swapped list. * @throws IllegalArgumentException if an attempt is made to move the item to * the previous location(s), this would have no effect and is * therefore considered a bug. */ static <T> ImmutableList<T> inListSwap(ImmutableList<T> originalList, IntList insertionIndices, T item) { checkArgument(!originalList.isEmpty(), "The list may not be empty."); final List<T> newList = newArrayList(originalList); final IntList indices = removeAll(newList, item); checkArgument(newList.size() == originalList.size() - insertionIndices.size(), "The number of occurrences (%s) of item should equal the number of " + "insertionIndices (%s), original list: %s, item %s, " + "insertionIndices %s.", indices.size(), insertionIndices.size(), originalList, item, insertionIndices); checkArgument(!indices.equals(insertionIndices), "Attempt to move the item to exactly the same locations as the input. " + "Indices in original list %s, insertion indices %s.", indices, insertionIndices); return Insertions.insert(newList, insertionIndices, item); }