com.mindee.parsing.generated.GeneratedFeature Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mindee-api-java Show documentation
Show all versions of mindee-api-java Show documentation
Java Library to call Mindee's Off-The-Shelf and Custom APIs
The newest version!
package com.mindee.parsing.generated;
import com.mindee.MindeeException;
import com.mindee.parsing.standard.AmountField;
import com.mindee.parsing.standard.ClassificationField;
import com.mindee.parsing.standard.DateField;
import com.mindee.parsing.standard.StringField;
import java.util.ArrayList;
import lombok.Getter;
/**
*
* A generic feature which can represent any OTS Mindee return prediction.
*
*
* The Mindee API can return either lists or objects.
* Here we represent all features as a list, to simplify any code that interacts with this class.
*
*
* If you want, you can "cast" the raw hashmap into one of the standard Mindee fields:
*
*
* - StringField - asStringField()
* - AmountField - asAmountField()
* - DateField - asDateField()
* - ClassificationField - asClassificationField()
*
* This will not work for any feature which is a list in the Mindee return.
*
*/
@Getter
public class GeneratedFeature extends ArrayList {
private final boolean isList;
/**
* Whether the original feature is a list.
*/
public GeneratedFeature(boolean isList) {
this.isList = isList;
}
/**
* Represent the feature as a standard {@link StringField}.
* Only works for non-list features.
*/
public StringField asStringField() {
if (this.isList) {
throw new MindeeException("Cannot convert a list feature into a StringField.");
}
return this.get(0).asStringField();
}
/**
* Represent the feature as a standard {@link AmountField}.
* Only works for non-list features.
*/
public AmountField asAmountField() {
if (this.isList) {
throw new MindeeException("Cannot convert a list feature into an AmountField.");
}
return this.get(0).asAmountField();
}
/**
* Represent the feature as a standard {@link DateField}.
* Only works for non-list features.
*/
public DateField asDateField() {
if (this.isList) {
throw new MindeeException("Cannot convert a list feature into a DateField.");
}
return this.get(0).asDateField();
}
/**
* Represent the feature as a standard {@link ClassificationField}.
* Only works for non-list features.
*/
public ClassificationField asClassificationField() {
if (this.isList) {
throw new MindeeException("Cannot convert a list feature into a ClassificationField.");
}
return this.get(0).asClassificationField();
}
}