
software.amazon.awssdk.services.textract.model.ExpenseDocument 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.textract.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;
/**
*
* The structure holding all the information returned by AnalyzeExpense
*
*/
@Generated("software.amazon.awssdk:codegen")
public final class ExpenseDocument implements SdkPojo, Serializable, ToCopyableBuilder {
private static final SdkField EXPENSE_INDEX_FIELD = SdkField. builder(MarshallingType.INTEGER)
.memberName("ExpenseIndex").getter(getter(ExpenseDocument::expenseIndex)).setter(setter(Builder::expenseIndex))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("ExpenseIndex").build()).build();
private static final SdkField> SUMMARY_FIELDS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("SummaryFields")
.getter(getter(ExpenseDocument::summaryFields))
.setter(setter(Builder::summaryFields))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("SummaryFields").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(ExpenseField::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> LINE_ITEM_GROUPS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("LineItemGroups")
.getter(getter(ExpenseDocument::lineItemGroups))
.setter(setter(Builder::lineItemGroups))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("LineItemGroups").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(LineItemGroup::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final SdkField> BLOCKS_FIELD = SdkField
.> builder(MarshallingType.LIST)
.memberName("Blocks")
.getter(getter(ExpenseDocument::blocks))
.setter(setter(Builder::blocks))
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD).locationName("Blocks").build(),
ListTrait
.builder()
.memberLocationName(null)
.memberFieldInfo(
SdkField. builder(MarshallingType.SDK_POJO)
.constructor(Block::builder)
.traits(LocationTrait.builder().location(MarshallLocation.PAYLOAD)
.locationName("member").build()).build()).build()).build();
private static final List> SDK_FIELDS = Collections.unmodifiableList(Arrays.asList(EXPENSE_INDEX_FIELD,
SUMMARY_FIELDS_FIELD, LINE_ITEM_GROUPS_FIELD, BLOCKS_FIELD));
private static final long serialVersionUID = 1L;
private final Integer expenseIndex;
private final List summaryFields;
private final List lineItemGroups;
private final List blocks;
private ExpenseDocument(BuilderImpl builder) {
this.expenseIndex = builder.expenseIndex;
this.summaryFields = builder.summaryFields;
this.lineItemGroups = builder.lineItemGroups;
this.blocks = builder.blocks;
}
/**
*
* Denotes which invoice or receipt in the document the information is coming from. First document will be 1, the
* second 2, and so on.
*
*
* @return Denotes which invoice or receipt in the document the information is coming from. First document will be
* 1, the second 2, and so on.
*/
public final Integer expenseIndex() {
return expenseIndex;
}
/**
* For responses, this returns true if the service returned a value for the SummaryFields 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 hasSummaryFields() {
return summaryFields != null && !(summaryFields instanceof SdkAutoConstructList);
}
/**
*
* Any information found outside of a table by Amazon Textract.
*
*
* 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 #hasSummaryFields} method.
*
*
* @return Any information found outside of a table by Amazon Textract.
*/
public final List summaryFields() {
return summaryFields;
}
/**
* For responses, this returns true if the service returned a value for the LineItemGroups 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 hasLineItemGroups() {
return lineItemGroups != null && !(lineItemGroups instanceof SdkAutoConstructList);
}
/**
*
* Information detected on each table of a document, seperated into LineItems
.
*
*
* 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 #hasLineItemGroups} method.
*
*
* @return Information detected on each table of a document, seperated into LineItems
.
*/
public final List lineItemGroups() {
return lineItemGroups;
}
/**
* For responses, this returns true if the service returned a value for the Blocks 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 hasBlocks() {
return blocks != null && !(blocks instanceof SdkAutoConstructList);
}
/**
*
* This is a block object, the same as reported when DetectDocumentText is run on a document. It provides word level
* recognition of text.
*
*
* 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 #hasBlocks} method.
*
*
* @return This is a block object, the same as reported when DetectDocumentText is run on a document. It provides
* word level recognition of text.
*/
public final List blocks() {
return blocks;
}
@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 final int hashCode() {
int hashCode = 1;
hashCode = 31 * hashCode + Objects.hashCode(expenseIndex());
hashCode = 31 * hashCode + Objects.hashCode(hasSummaryFields() ? summaryFields() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasLineItemGroups() ? lineItemGroups() : null);
hashCode = 31 * hashCode + Objects.hashCode(hasBlocks() ? blocks() : 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 ExpenseDocument)) {
return false;
}
ExpenseDocument other = (ExpenseDocument) obj;
return Objects.equals(expenseIndex(), other.expenseIndex()) && hasSummaryFields() == other.hasSummaryFields()
&& Objects.equals(summaryFields(), other.summaryFields()) && hasLineItemGroups() == other.hasLineItemGroups()
&& Objects.equals(lineItemGroups(), other.lineItemGroups()) && hasBlocks() == other.hasBlocks()
&& Objects.equals(blocks(), other.blocks());
}
/**
* 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("ExpenseDocument").add("ExpenseIndex", expenseIndex())
.add("SummaryFields", hasSummaryFields() ? summaryFields() : null)
.add("LineItemGroups", hasLineItemGroups() ? lineItemGroups() : null)
.add("Blocks", hasBlocks() ? blocks() : null).build();
}
public final Optional getValueForField(String fieldName, Class clazz) {
switch (fieldName) {
case "ExpenseIndex":
return Optional.ofNullable(clazz.cast(expenseIndex()));
case "SummaryFields":
return Optional.ofNullable(clazz.cast(summaryFields()));
case "LineItemGroups":
return Optional.ofNullable(clazz.cast(lineItemGroups()));
case "Blocks":
return Optional.ofNullable(clazz.cast(blocks()));
default:
return Optional.empty();
}
}
@Override
public final List> sdkFields() {
return SDK_FIELDS;
}
private static Function