software.amazon.awssdk.services.costexplorer.model.Expression Maven / Gradle / Ivy
Show all versions of costexplorer Show documentation
/*
* Copyright 2014-2019 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.costexplorer.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.utils.ToString;
import software.amazon.awssdk.utils.builder.CopyableBuilder;
import software.amazon.awssdk.utils.builder.ToCopyableBuilder;
/**
*
* Use Expression
to filter by cost or by usage. There are two patterns:
*
*
* -
*
* Simple dimension values - You can set the dimension name and values for the filters that you plan to use. For
* example, you can filter for REGION==us-east-1 OR REGION==us-west-1
. The Expression
for that
* looks like this:
*
*
* { "Dimensions": { "Key": "REGION", "Values": [ "us-east-1", “us-west-1” ] } }
*
*
* The list of dimension values are OR'd together to retrieve cost or usage data. You can create Expression
* and DimensionValues
objects using either with*
methods or set*
methods in
* multiple lines.
*
*
* -
*
* Compound dimension values with logical operations - You can use multiple Expression
types and the
* logical operators AND/OR/NOT
to create a list of one or more Expression
objects. This
* allows you to filter on more advanced options. For example, you can filter on
* ((REGION == us-east-1 OR REGION == us-west-1) OR (TAG.Type == Type1)) AND (USAGE_TYPE != DataTransfer)
.
* The Expression
for that looks like this:
*
*
* { "And": [ {"Or": [ {"Dimensions": { "Key": "REGION", "Values": [ "us-east-1", "us-west-1" ] }}, {"Tags": { "Key": "TagName", "Values": ["Value1"] } } ]}, {"Not": {"Dimensions": { "Key": "USAGE_TYPE", "Values": ["DataTransfer"] }}} ] }
*
*
*
* Because each Expression
can have only one operator, the service returns an error if more than one is
* specified. The following example shows an Expression
object that creates an error.
*
*
*
* { "And": [ ... ], "DimensionValues": { "Dimension": "USAGE_TYPE", "Values": [ "DataTransfer" ] } }
*
*
*
*
*
* For GetRightsizingRecommendation
action, a combination of OR and NOT is not supported. OR is not
* supported between different dimensions, or dimensions and tags. NOT operators aren't supported. Dimentions are also
* limited to LINKED_ACCOUNT
, REGION
, or RIGHTSIZING_TYPE
.
*
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class Expression implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField> OR_FIELD = SdkField
.> builder(MarshallingType.LIST)
.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 SdkField> AND_FIELD = SdkField
.> builder(MarshallingType.LIST)
.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 NOT_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.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 DIMENSIONS_FIELD = SdkField
. builder(MarshallingType.SDK_POJO).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 TAGS_FIELD = SdkField. builder(MarshallingType.SDK_POJO)
.getter(getter(Expression::tags)).setter(setter(Builder::tags)).constructor(TagValues::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Tags").build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(OR_FIELD, AND_FIELD,
NOT_FIELD, DIMENSIONS_FIELD, TAGS_FIELD));
private static final long serialVersionUID = 1L;
private final List or;
private final List and;
private final Expression not;
private final DimensionValues dimensions;
private final TagValues tags;
private Expression(BuilderImpl builder) {
this.or = builder.or;
this.and = builder.and;
this.not = builder.not;
this.dimensions = builder.dimensions;
this.tags = builder.tags;
}
/**
*
* Return results that match either Dimension
object.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return Return results that match either Dimension
object.
*/
public List or() {
return or;
}
/**
*
* Return results that match both Dimension
objects.
*
*
* Attempts to modify the collection returned by this method will result in an UnsupportedOperationException.
*
*
* @return Return results that match both Dimension
objects.
*/
public List and() {
return and;
}
/**
*
* Return results that don't match a Dimension
object.
*
*
* @return Return results that don't match a Dimension
object.
*/
public Expression not() {
return not;
}
/**
*
* The specific Dimension
to use for Expression
.
*
*
* @return The specific Dimension
to use for Expression
.
*/
public DimensionValues dimensions() {
return dimensions;
}
/**
*
* The specific Tag
to use for Expression
.
*
*
* @return The specific Tag
to use for Expression
.
*/
public TagValues tags() {
return tags;
}
@Override
public Builder toBuilder() {
return new BuilderImpl(this);
}
public static Builder builder() {
return new BuilderImpl();
}
public static Class extends Builder> serializableBuilderClass() {
return BuilderImpl.class;
}
@Override
public int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(or());
hashCode = 31 * hashCode + Objects.hashCode(and());
hashCode = 31 * hashCode + Objects.hashCode(not());
hashCode = 31 * hashCode + Objects.hashCode(dimensions());
hashCode = 31 * hashCode + Objects.hashCode(tags());
return hashCode;
}
@Override
public boolean equals(Object obj) {
return equalsBySdkFields(obj);
}
@Override
public 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 Objects.equals(or(), other.or()) && Objects.equals(and(), other.and()) && Objects.equals(not(), other.not())
&& Objects.equals(dimensions(), other.dimensions()) && Objects.equals(tags(), other.tags());
}
/**
* 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 String toString() {
return ToString.builder("Expression").add("Or", or()).add("And", and()).add("Not", not()).add("Dimensions", dimensions())
.add("Tags", tags()).build();
}
public Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "Or":
return Optional.ofNullable(clazz.cast(or()));
case "And":
return Optional.ofNullable(clazz.cast(and()));
case "Not":
return Optional.ofNullable(clazz.cast(not()));
case "Dimensions":
return Optional.ofNullable(clazz.cast(dimensions()));
case "Tags":
return Optional.ofNullable(clazz.cast(tags()));
default:
return Optional.empty();
}
}
@Override
public List> sdkFields() {
return SDK_FIELDS;
}
private static Function