Skip to content
This repository has been archived by the owner on Mar 27, 2024. It is now read-only.

Commit

Permalink
Add documentation to Fields
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Bluhm <bluhmdj@ornl.gov>
  • Loading branch information
dbluhm committed May 28, 2020
1 parent 1a3cb63 commit 127ff86
Showing 1 changed file with 40 additions and 10 deletions.
Expand Up @@ -4,7 +4,10 @@
import java.util.List;

/**
* A simple container for fields discovered on a DataElement.
* A container for fields discovered on a DataElement.
*
* Fields can create and hold onto an instance of FieldBuilder to assist in
* constructing new Fields while visiting an AnnotationValue tree.
*/
class Fields {
protected List<Field> fields;
Expand All @@ -15,10 +18,16 @@ public Fields() {
this.building = null;
}

/**
* Begin construction of a new Field.
*/
public void begin() {
this.building = Field.builder();
}

/**
* Finish the under construction Field and append to fields list.
*/
public void finish() {
this.fields.add(this.building.build());
this.building = null;
Expand All @@ -28,23 +37,41 @@ public List<Field> getFields() {
return fields;
}

/**
* @return true if there is an instance of Field currently under construction.
*/
public boolean isBuilding() {
return this.building != null;
}

/**
* @return true if the currently under construction Field is ready to be finished.
*/
public boolean isComplete() {
Field partial = this.building.build();
return (partial.getType() != null) && (partial.getName() != null);
}

/**
* Shortcut to FieldBuilder.type().
* @param type
*/
public void setType(final String type) {
this.building.type(Field.raw(type));
}

/**
* Shortcut to FieldBuilder.name().
* @param name
*/
public void setName(final String name) {
this.building.name(name);
}

/**
* Shortcut to FieldBuilder.primitive().
* @param primitive
*/
public void setPrimitive(boolean primitive) {
this.building.primitive(primitive);
}
Expand All @@ -54,24 +81,27 @@ public String toString() {
return fields.toString();
}

/**
* Append field to fields list.
* @param field
*/
public void add(Field field) {
this.fields.add(field);
}

/**
* Extend fields with the contents of another Fields object.
* @param fields
*/
public void addAll(Fields fields) {
this.fields.addAll(fields.getFields());
}

/**
* Extend fields with a list of Field objects.
* @param fields
*/
public void addAll(List<Field> fields) {
this.fields.addAll(fields);
}

public void addAll(Field[] fields) {
if (fields == null) {
return;
}
for (int i = 0; i < fields.length; i++) {
this.fields.add(fields[i]);
}
}
}

0 comments on commit 127ff86

Please sign in to comment.