All Downloads are FREE. Search and download functionalities are using the official Maven repository.

software.amazon.awssdk.services.freetier.model.Expression Maven / Gradle / Ivy

/*
 * Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with
 * the License. A copy of the License is located at
 * 
 * http://aws.amazon.com/apache2.0
 * 
 * or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
 * CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions
 * and limitations under the License.
 */

package software.amazon.awssdk.services.freetier.model;

import java.io.Serializable;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.function.BiConsumer;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import software.amazon.awssdk.annotations.Generated;
import software.amazon.awssdk.core.SdkField;
import software.amazon.awssdk.core.SdkPojo;
import software.amazon.awssdk.core.protocol.MarshallLocation;
import software.amazon.awssdk.core.protocol.MarshallingType;
import software.amazon.awssdk.core.traits.ListTrait;
import software.amazon.awssdk.core.traits.LocationTrait;
import software.amazon.awssdk.core.util.DefaultSdkAutoConstructList;
import software.amazon.awssdk.core.util.SdkAutoConstructList;
import software.amazon.awssdk.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;

/**
 * 

* Use Expression to filter in the GetFreeTierUsage API operation. *

*

* You can use the following patterns: *

*
    *
  • *

    * Simple dimension values (Dimensions root operator) *

    *
  • *
  • *

    * Complex expressions with logical operators (AND, NOT, and OR root operators). *

    *
  • *
*

* For simple dimension values, you can set the dimension name, values, and match type for the filters that you * plan to use. *

*

* Example for simple dimension values *

*

* You can filter to match exactly for REGION==us-east-1 OR REGION==us-west-1. *

*

* The corresponding Expression appears like the following: * { "Dimensions": { "Key": "REGION", "Values": [ "us-east-1", "us-west-1" ], "MatchOptions": ["EQUALS"] } } *

*

* As shown in the previous example, lists of dimension values are combined with OR when you apply the * filter. *

*

* For complex expressions with logical operators, you can have nested expressions to use the logical operators * and specify advanced filtering. *

*

* Example for complex expressions with logical operators *

*

* You can filter by * ((REGION == us-east-1 OR REGION == us-west-1) OR (SERVICE CONTAINS AWSLambda)) AND (USAGE_TYPE !CONTAINS DataTransfer) * . *

*

* The corresponding Expression appears like the following: * { "And": [ {"Or": [ {"Dimensions": { "Key": "REGION", "Values": [ "us-east-1", "us-west-1" ], "MatchOptions": ["EQUALS"] }}, {"Dimensions": { "Key": "SERVICE", "Values": ["AWSLambda"], "MatchOptions": ["CONTAINS"] } } ]}, {"Not": {"Dimensions": { "Key": "USAGE_TYPE", "Values": ["DataTransfer"], "MatchOptions": ["CONTAINS"] }}} ] } *

*

* In the following Contents, you must specify exactly one of the following root operators. *

*/ @Generated("software.amazon.awssdk:codegen") public final class Expression implements SdkPojo, Serializable, ToCopyableBuilder { private static final SdkField> AND_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("And") .getter(getter(Expression::and)) .setter(setter(Builder::and)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("And").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(Expression::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final SdkField DIMENSIONS_FIELD = SdkField . builder(MarshallingType.SDK_POJO).memberName("Dimensions").getter(getter(Expression::dimensions)) .setter(setter(Builder::dimensions)).constructor(DimensionValues::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Dimensions").build()).build(); private static final SdkField NOT_FIELD = SdkField. builder(MarshallingType.SDK_POJO) .memberName("Not").getter(getter(Expression::not)).setter(setter(Builder::not)).constructor(Expression::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Not").build()).build(); private static final SdkField> OR_FIELD = SdkField .> builder(MarshallingType.LIST) .memberName("Or") .getter(getter(Expression::or)) .setter(setter(Builder::or)) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Or").build(), ListTrait .builder() .memberLocationName(null) .memberFieldInfo( SdkField. builder(MarshallingType.SDK_POJO) .constructor(Expression::builder) .traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD) .locationName("member").build()).build()).build()).build(); private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(AND_FIELD, DIMENSIONS_FIELD, NOT_FIELD, OR_FIELD)); private static final long serialVersionUID = 1L; private final List and; private final DimensionValues dimensions; private final Expression not; private final List or; private Expression(BuilderImpl builder) { this.and = builder.and; this.dimensions = builder.dimensions; this.not = builder.not; this.or = builder.or; } /** * For responses, this returns true if the service returned a value for the And property. This DOES NOT check that * the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful * because the SDK will never return a null collection or map, but you may need to differentiate between the service * returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true * if a value for the property was specified in the request builder, and false if a value was not specified. */ public final boolean hasAnd() { return and != null && !(and instanceof SdkAutoConstructList); } /** *

* Return results that match all Expressions that you specified in the array. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasAnd} method. *

* * @return Return results that match all Expressions that you specified in the array. */ public final List and() { return and; } /** *

* The specific dimension, values, and match type to filter objects with. *

* * @return The specific dimension, values, and match type to filter objects with. */ public final DimensionValues dimensions() { return dimensions; } /** *

* Return results that don’t match the Expression that you specified. *

* * @return Return results that don’t match the Expression that you specified. */ public final Expression not() { return not; } /** * For responses, this returns true if the service returned a value for the Or property. This DOES NOT check that * the value is non-empty (for which, you should check the {@code isEmpty()} method on the property). This is useful * because the SDK will never return a null collection or map, but you may need to differentiate between the service * returning nothing (or null) and the service returning an empty collection or map. For requests, this returns true * if a value for the property was specified in the request builder, and false if a value was not specified. */ public final boolean hasOr() { return or != null && !(or instanceof SdkAutoConstructList); } /** *

* Return results that match any of the Expressions that you specified. in the array. *

*

* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException. *

*

* This method will never return null. If you would like to know whether the service returned this field (so that * you can differentiate between null and empty), you can use the {@link #hasOr} method. *

* * @return Return results that match any of the Expressions that you specified. in the array. */ public final List or() { return or; } @Override public Builder toBuilder() { return new BuilderImpl(this); } public static Builder builder() { return new BuilderImpl(); } public static Class serializableBuilderClass() { return BuilderImpl.class; } @Override public final int hashCode() { int hashCode = 1; hashCode = 31 * hashCode + Objects.hashCode(hasAnd() ? and() : null); hashCode = 31 * hashCode + Objects.hashCode(dimensions()); hashCode = 31 * hashCode + Objects.hashCode(not()); hashCode = 31 * hashCode + Objects.hashCode(hasOr() ? or() : null); return hashCode; } @Override public final boolean equals(Object obj) { return equalsBySdkFields(obj); } @Override public final boolean equalsBySdkFields(Object obj) { if (this == obj) { return true; } if (obj == null) { return false; } if (!(obj instanceof Expression)) { return false; } Expression other = (Expression) obj; return hasAnd() == other.hasAnd() && Objects.equals(and(), other.and()) && Objects.equals(dimensions(), other.dimensions()) && Objects.equals(not(), other.not()) && hasOr() == other.hasOr() && Objects.equals(or(), other.or()); } /** * Returns a string representation of this object. This is useful for testing and debugging. Sensitive data will be * redacted from this string using a placeholder value. */ @Override public final String toString() { return ToString.builder("Expression").add("And", hasAnd() ? and() : null).add("Dimensions", dimensions()) .add("Not", not()).add("Or", hasOr() ? or() : null).build(); } public final Optional getValueForField(String fieldName, Class clazz) { switch (fieldName) { case "And": return Optional.ofNullable(clazz.cast(and())); case "Dimensions": return Optional.ofNullable(clazz.cast(dimensions())); case "Not": return Optional.ofNullable(clazz.cast(not())); case "Or": return Optional.ofNullable(clazz.cast(or())); default: return Optional.empty(); } } @Override public final List> sdkFields() { return SDK_FIELDS; } private static Function getter(Function g) { return obj -> g.apply((Expression) obj); } private static BiConsumer setter(BiConsumer s) { return (obj, val) -> s.accept((Builder) obj, val); } public interface Builder extends SdkPojo, CopyableBuilder { /** *

* Return results that match all Expressions that you specified in the array. *

* * @param and * Return results that match all Expressions that you specified in the array. * @return Returns a reference to this object so that method calls can be chained together. */ Builder and(Collection and); /** *

* Return results that match all Expressions that you specified in the array. *

* * @param and * Return results that match all Expressions that you specified in the array. * @return Returns a reference to this object so that method calls can be chained together. */ Builder and(Expression... and); /** *

* Return results that match all Expressions that you specified in the array. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder} avoiding the need to create one * manually via {@link software.amazon.awssdk.services.freetier.model.Expression#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder#build()} is called immediately and * its result is passed to {@link #and(List)}. * * @param and * a consumer that will call methods on * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #and(java.util.Collection) */ Builder and(Consumer... and); /** *

* The specific dimension, values, and match type to filter objects with. *

* * @param dimensions * The specific dimension, values, and match type to filter objects with. * @return Returns a reference to this object so that method calls can be chained together. */ Builder dimensions(DimensionValues dimensions); /** *

* The specific dimension, values, and match type to filter objects with. *

* This is a convenience method that creates an instance of the {@link DimensionValues.Builder} avoiding the * need to create one manually via {@link DimensionValues#builder()}. * *

* When the {@link Consumer} completes, {@link DimensionValues.Builder#build()} is called immediately and its * result is passed to {@link #dimensions(DimensionValues)}. * * @param dimensions * a consumer that will call methods on {@link DimensionValues.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #dimensions(DimensionValues) */ default Builder dimensions(Consumer dimensions) { return dimensions(DimensionValues.builder().applyMutation(dimensions).build()); } /** *

* Return results that don’t match the Expression that you specified. *

* * @param not * Return results that don’t match the Expression that you specified. * @return Returns a reference to this object so that method calls can be chained together. */ Builder not(Expression not); /** *

* Return results that don’t match the Expression that you specified. *

* This is a convenience method that creates an instance of the {@link Expression.Builder} avoiding the need to * create one manually via {@link Expression#builder()}. * *

* When the {@link Consumer} completes, {@link Expression.Builder#build()} is called immediately and its result * is passed to {@link #not(Expression)}. * * @param not * a consumer that will call methods on {@link Expression.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #not(Expression) */ default Builder not(Consumer not) { return not(Expression.builder().applyMutation(not).build()); } /** *

* Return results that match any of the Expressions that you specified. in the array. *

* * @param or * Return results that match any of the Expressions that you specified. in the array. * @return Returns a reference to this object so that method calls can be chained together. */ Builder or(Collection or); /** *

* Return results that match any of the Expressions that you specified. in the array. *

* * @param or * Return results that match any of the Expressions that you specified. in the array. * @return Returns a reference to this object so that method calls can be chained together. */ Builder or(Expression... or); /** *

* Return results that match any of the Expressions that you specified. in the array. *

* This is a convenience method that creates an instance of the * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder} avoiding the need to create one * manually via {@link software.amazon.awssdk.services.freetier.model.Expression#builder()}. * *

* When the {@link Consumer} completes, * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder#build()} is called immediately and * its result is passed to {@link #or(List)}. * * @param or * a consumer that will call methods on * {@link software.amazon.awssdk.services.freetier.model.Expression.Builder} * @return Returns a reference to this object so that method calls can be chained together. * @see #or(java.util.Collection) */ Builder or(Consumer... or); } static final class BuilderImpl implements Builder { private List and = DefaultSdkAutoConstructList.getInstance(); private DimensionValues dimensions; private Expression not; private List or = DefaultSdkAutoConstructList.getInstance(); private BuilderImpl() { } private BuilderImpl(Expression model) { and(model.and); dimensions(model.dimensions); not(model.not); or(model.or); } public final List getAnd() { List result = ExpressionsCopier.copyToBuilder(this.and); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setAnd(Collection and) { this.and = ExpressionsCopier.copyFromBuilder(and); } @Override public final Builder and(Collection and) { this.and = ExpressionsCopier.copy(and); return this; } @Override @SafeVarargs public final Builder and(Expression... and) { and(Arrays.asList(and)); return this; } @Override @SafeVarargs public final Builder and(Consumer... and) { and(Stream.of(and).map(c -> Expression.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } public final DimensionValues.Builder getDimensions() { return dimensions != null ? dimensions.toBuilder() : null; } public final void setDimensions(DimensionValues.BuilderImpl dimensions) { this.dimensions = dimensions != null ? dimensions.build() : null; } @Override public final Builder dimensions(DimensionValues dimensions) { this.dimensions = dimensions; return this; } public final Builder getNot() { return not != null ? not.toBuilder() : null; } public final void setNot(BuilderImpl not) { this.not = not != null ? not.build() : null; } @Override public final Builder not(Expression not) { this.not = not; return this; } public final List getOr() { List result = ExpressionsCopier.copyToBuilder(this.or); if (result instanceof SdkAutoConstructList) { return null; } return result; } public final void setOr(Collection or) { this.or = ExpressionsCopier.copyFromBuilder(or); } @Override public final Builder or(Collection or) { this.or = ExpressionsCopier.copy(or); return this; } @Override @SafeVarargs public final Builder or(Expression... or) { or(Arrays.asList(or)); return this; } @Override @SafeVarargs public final Builder or(Consumer... or) { or(Stream.of(or).map(c -> Expression.builder().applyMutation(c).build()).collect(Collectors.toList())); return this; } @Override public Expression build() { return new Expression(this); } @Override public List> sdkFields() { return SDK_FIELDS; } } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy