Segment

public class Segment implements Iterable<String>

This class represents an X12 segment.

Author:Prasad Balan

Constructors

Segment

public Segment(Context c)

The constructor takes a Context object as input. The context object represents the delimiters in a X12 transaction.

Parameters:
  • c – the context object

Methods

addCompositeElement

public boolean addCompositeElement(String... ces)

Adds strings as a composite element to the end of the segment.

Parameters:
  • ces – sub-elements of a composite element
Returns:

boolean

addCompositeElement

public void addCompositeElement(int index, String... ces)

Inserts strings as a composite element to segment at specified position

Parameters:
  • ces – sub-elements of a composite element
  • index – a int.

addElement

public boolean addElement(String e)

Adds java.lang.String element to the segment. The element is added at the end of the elements in the current segment.

Parameters:
  • e – the element to be added
Returns:

boolean

addElement

public boolean addElement(int index, String e)

Inserts java.lang.String element to the segment at the specified position

Parameters:
  • e – the element to be added
  • index – a int.
Returns:

boolean true if element matches the element at the index provided.

addElements

public boolean addElements(String s)

Adds java.lang.String with elements to the segment. The elements are added at the end of the elements in the current segment. e.g. addElements("ISA*ISA01*ISA02");

Parameters:
  • s – the element to add.
Returns:

boolean

addElements

public boolean addElements(String... es)

Adds java.lang.String elements to the segment. The elements are added at the end of the elements in the current segment. e.g. addElements("ISA", "ISA01", "ISA02");

Parameters:
  • es – elements to add.
Returns:

boolean

getContext

public Context getContext()

Returns the context object

Returns:Context object

getElement

public String getElement(int index)

Returns the java.lang.String element at the specified position.

Parameters:
  • index – position
Returns:

the element at the specified position.

getElements

public List<String> getElements()

Getter for the field java.util.List<java.lang.String>

Returns:List of elements

iterator

public Iterator<String> iterator()

Returns and java.util.Iterator<java.lang.String> to the elements in the segment.

Returns:java.util.Iterator<java.lang.String>

removeElement

public String removeElement(int index)

Removes the element at the specified position in this list.

Parameters:
  • index – the index at which to remove the element.
Returns:

String element that was removed.

setCompositeElement

public void setCompositeElement(int index, String... ces)

Replaces composite element at the specified position in segment.

Parameters:
  • ces – sub-elements of a composite element
  • index – a int.

setContext

public void setContext(Context context)

Sets the context of the segment

Parameters:
  • context – context object

setElement

public void setElement(int index, String s)

Replaces element at the specified position with the specified java.lang.String

Parameters:
  • index – position of the element to be replaced
  • s – new element with which to replace

size

public int size()

Returns number of elements in the segment.

Returns:size

toString

public String toString()

Returns the X12 representation of the segment.

Returns:a java.lang.String object.

toString

public String toString(boolean bRemoveTrailingEmptyElements)

Returns the X12 representation of the segment.

Parameters:
  • bRemoveTrailingEmptyElements – a flag for whether or not empty trailing elements should be removed.
Returns:

java.lang.String

toXML

public String toXML()

Returns the XML representation of the segment.

Returns:java.lang.String XML representation of the segment.

toXML

public String toXML(boolean bRemoveTrailingEmptyElements)

Returns the XML representation of the segment.

Parameters:
  • bRemoveTrailingEmptyElements – a flag for whether or not empty trailing elements should be removed.
Returns:

java.lang.String XML representation of the segment.