/* * Copyright 2010-2023 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 com.amazonaws.services.comprehend.model; import java.io.Serializable; /** *

* Information about each word or line of text in the input document. *

*

* For additional information, see Block in the Amazon Textract API reference. *

*/ public class Block implements Serializable { /** *

* Unique identifier for the block. *

*

* Constraints:
* Length: 1 -
*/ private String id; /** *

* The block represents a line of text or one word of text. *

* *

* Constraints:
* Allowed Values: LINE, WORD */ private String blockType; /** *

* The word or line of text extracted from the block. *

*

* Constraints:
* Length: 1 -
*/ private String text; /** *

* Page number where the block appears. *

*/ private Integer page; /** *

* Co-ordinates of the rectangle or polygon that contains the text. *

*/ private Geometry geometry; /** *

* A list of child blocks of the current block. For example, a LINE object * has child blocks for each WORD block that's part of the line of text. *

*/ private java.util.List relationships; /** *

* Unique identifier for the block. *

*

* Constraints:
* Length: 1 -
* * @return

* Unique identifier for the block. *

*/ public String getId() { return id; } /** *

* Unique identifier for the block. *

*

* Constraints:
* Length: 1 -
* * @param id

* Unique identifier for the block. *

*/ public void setId(String id) { this.id = id; } /** *

* Unique identifier for the block. *

*

* Returns a reference to this object so that method calls can be chained * together. *

* Constraints:
* Length: 1 -
* * @param id

* Unique identifier for the block. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withId(String id) { this.id = id; return this; } /** *

* The block represents a line of text or one word of text. *

* *

* Constraints:
* Allowed Values: LINE, WORD * * @return

* The block represents a line of text or one word of text. *

* * @see BlockType */ public String getBlockType() { return blockType; } /** *

* The block represents a line of text or one word of text. *

* *

* Constraints:
* Allowed Values: LINE, WORD * * @param blockType

* The block represents a line of text or one word of text. *

* * @see BlockType */ public void setBlockType(String blockType) { this.blockType = blockType; } /** *

* The block represents a line of text or one word of text. *

* *

* Returns a reference to this object so that method calls can be chained * together. *

* Constraints:
* Allowed Values: LINE, WORD * * @param blockType

* The block represents a line of text or one word of text. *

* * @return A reference to this updated object so that method calls can be * chained together. * @see BlockType */ public Block withBlockType(String blockType) { this.blockType = blockType; return this; } /** *

* The block represents a line of text or one word of text. *

* *

* Constraints:
* Allowed Values: LINE, WORD * * @param blockType

* The block represents a line of text or one word of text. *

* * @see BlockType */ public void setBlockType(BlockType blockType) { this.blockType = blockType.toString(); } /** *

* The block represents a line of text or one word of text. *

* *

* Returns a reference to this object so that method calls can be chained * together. *

* Constraints:
* Allowed Values: LINE, WORD * * @param blockType

* The block represents a line of text or one word of text. *

* * @return A reference to this updated object so that method calls can be * chained together. * @see BlockType */ public Block withBlockType(BlockType blockType) { this.blockType = blockType.toString(); return this; } /** *

* The word or line of text extracted from the block. *

*

* Constraints:
* Length: 1 -
* * @return

* The word or line of text extracted from the block. *

*/ public String getText() { return text; } /** *

* The word or line of text extracted from the block. *

*

* Constraints:
* Length: 1 -
* * @param text

* The word or line of text extracted from the block. *

*/ public void setText(String text) { this.text = text; } /** *

* The word or line of text extracted from the block. *

*

* Returns a reference to this object so that method calls can be chained * together. *

* Constraints:
* Length: 1 -
* * @param text

* The word or line of text extracted from the block. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withText(String text) { this.text = text; return this; } /** *

* Page number where the block appears. *

* * @return

* Page number where the block appears. *

*/ public Integer getPage() { return page; } /** *

* Page number where the block appears. *

* * @param page

* Page number where the block appears. *

*/ public void setPage(Integer page) { this.page = page; } /** *

* Page number where the block appears. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param page

* Page number where the block appears. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withPage(Integer page) { this.page = page; return this; } /** *

* Co-ordinates of the rectangle or polygon that contains the text. *

* * @return

* Co-ordinates of the rectangle or polygon that contains the text. *

*/ public Geometry getGeometry() { return geometry; } /** *

* Co-ordinates of the rectangle or polygon that contains the text. *

* * @param geometry

* Co-ordinates of the rectangle or polygon that contains the * text. *

*/ public void setGeometry(Geometry geometry) { this.geometry = geometry; } /** *

* Co-ordinates of the rectangle or polygon that contains the text. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param geometry

* Co-ordinates of the rectangle or polygon that contains the * text. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withGeometry(Geometry geometry) { this.geometry = geometry; return this; } /** *

* A list of child blocks of the current block. For example, a LINE object * has child blocks for each WORD block that's part of the line of text. *

* * @return

* A list of child blocks of the current block. For example, a LINE * object has child blocks for each WORD block that's part of the * line of text. *

*/ public java.util.List getRelationships() { return relationships; } /** *

* A list of child blocks of the current block. For example, a LINE object * has child blocks for each WORD block that's part of the line of text. *

* * @param relationships

* A list of child blocks of the current block. For example, a * LINE object has child blocks for each WORD block that's part * of the line of text. *

*/ public void setRelationships(java.util.Collection relationships) { if (relationships == null) { this.relationships = null; return; } this.relationships = new java.util.ArrayList(relationships); } /** *

* A list of child blocks of the current block. For example, a LINE object * has child blocks for each WORD block that's part of the line of text. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param relationships

* A list of child blocks of the current block. For example, a * LINE object has child blocks for each WORD block that's part * of the line of text. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withRelationships(RelationshipsListItem... relationships) { if (getRelationships() == null) { this.relationships = new java.util.ArrayList( relationships.length); } for (RelationshipsListItem value : relationships) { this.relationships.add(value); } return this; } /** *

* A list of child blocks of the current block. For example, a LINE object * has child blocks for each WORD block that's part of the line of text. *

*

* Returns a reference to this object so that method calls can be chained * together. * * @param relationships

* A list of child blocks of the current block. For example, a * LINE object has child blocks for each WORD block that's part * of the line of text. *

* @return A reference to this updated object so that method calls can be * chained together. */ public Block withRelationships(java.util.Collection relationships) { setRelationships(relationships); return this; } /** * Returns a string representation of this object; useful for testing and * debugging. * * @return A string representation of this object. * @see java.lang.Object#toString() */ @Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append("{"); if (getId() != null) sb.append("Id: " + getId() + ","); if (getBlockType() != null) sb.append("BlockType: " + getBlockType() + ","); if (getText() != null) sb.append("Text: " + getText() + ","); if (getPage() != null) sb.append("Page: " + getPage() + ","); if (getGeometry() != null) sb.append("Geometry: " + getGeometry() + ","); if (getRelationships() != null) sb.append("Relationships: " + getRelationships()); sb.append("}"); return sb.toString(); } @Override public int hashCode() { final int prime = 31; int hashCode = 1; hashCode = prime * hashCode + ((getId() == null) ? 0 : getId().hashCode()); hashCode = prime * hashCode + ((getBlockType() == null) ? 0 : getBlockType().hashCode()); hashCode = prime * hashCode + ((getText() == null) ? 0 : getText().hashCode()); hashCode = prime * hashCode + ((getPage() == null) ? 0 : getPage().hashCode()); hashCode = prime * hashCode + ((getGeometry() == null) ? 0 : getGeometry().hashCode()); hashCode = prime * hashCode + ((getRelationships() == null) ? 0 : getRelationships().hashCode()); return hashCode; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (obj instanceof Block == false) return false; Block other = (Block) obj; if (other.getId() == null ^ this.getId() == null) return false; if (other.getId() != null && other.getId().equals(this.getId()) == false) return false; if (other.getBlockType() == null ^ this.getBlockType() == null) return false; if (other.getBlockType() != null && other.getBlockType().equals(this.getBlockType()) == false) return false; if (other.getText() == null ^ this.getText() == null) return false; if (other.getText() != null && other.getText().equals(this.getText()) == false) return false; if (other.getPage() == null ^ this.getPage() == null) return false; if (other.getPage() != null && other.getPage().equals(this.getPage()) == false) return false; if (other.getGeometry() == null ^ this.getGeometry() == null) return false; if (other.getGeometry() != null && other.getGeometry().equals(this.getGeometry()) == false) return false; if (other.getRelationships() == null ^ this.getRelationships() == null) return false; if (other.getRelationships() != null && other.getRelationships().equals(this.getRelationships()) == false) return false; return true; } }