X12Simple

public class X12Simple implements EDI, Iterable<Segment>

The X12 class is the object representation of an ANSI X12 transaction. The building block of an X12 transaction is an element. Some elements may be made of sub elements. Elements combine to form segments. Segments are grouped as loops. And a set of loops form an X12 transaction.

Author:Prasad Balan

Constructors

X12Simple

public X12Simple(Context c)

The constructor takes a context object.

Parameters:
  • c – a Context object

Methods

addSegment

public Segment addSegment()

Creates an empty instance of Segment and adds the segment to the end of the X12 transaction. The returned instance can be used to add elements to the segment.

Returns:a new Segment object

addSegment

public Segment addSegment(String segment)

Takes a java.lang.String representation of segment, creates a Segment object and adds the segment to the end of the X12 transaction.

Parameters:
Returns:

a new Segment object

addSegment

public Segment addSegment(Segment segment)

Takes a Segment and adds the segment to the end of the X12 transaction.

Parameters:
  • segmentSegment representation of the Segment.
Returns:

a new Segment object

addSegment

public Segment addSegment(int index)

Creates an empty instance of Segment and inserts the segment at the specified position in the X12 transaction. The returned instance can be used to add elements to the segment.

Parameters:
  • index – position at which to add the segment.
Returns:

a new Segment object

addSegment

public Segment addSegment(int index, String segment)

Takes a java.lang.String representation of segment, creates a Segment object and inserts the segment at the specified position

Parameters:
Returns:

a new Segment object

addSegment

public Segment addSegment(int index, Segment segment)

Takes a java.lang.String representation of segment, creates a Segment object and inserts the segment at the specified position

Parameters:
Returns:

a new Segment object

findSegment

public List<Segment> findSegment(String name)

Get the segments in the X12 transaction.

Parameters:
  • name – name of a segment
Returns:

java.util.List<Segment>

getContext

public Context getContext()

Returns the context of the X12 transaction.

Returns:Context object

getSegment

public Segment getSegment(int index)

Returns the Segment at the specified position.

Parameters:
  • index – the position of the segment to return.
Returns:

Segment at the specified index

getSegments

public List<Segment> getSegments()

Returns the java.util.List<Segment>.

Returns:List of segments

iterator

public Iterator<Segment> iterator()

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

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

removeSegment

public Segment removeSegment(int index)

Removes the segment at the specified position in this list.

Parameters:
  • index – the position of the segment to remove.
Returns:

Segment

setContext

public void setContext(Context context)

Sets the context of the current transaction.

Parameters:
  • context – the context to apply to this object.

setSegment

public Segment setSegment(int index)

Creates an empty instance of Segment and replaces the segment at specified position in the X12 transaction. The returned instance can be used to add elements to the segment.

Parameters:
  • index – position at which to add the segment.
Returns:

a new Segment object

setSegment

public Segment setSegment(int index, String segment)

Takes a java.lang.String representation of segment, creates a Segment object and replaces the segment at the specified position in the X12 transaction.

Parameters:
  • index – position of the segment to be replaced.
  • segmentjava.lang.String representation of the Segment.
Returns:

a new Segment object

setSegment

public Segment setSegment(int index, Segment segment)

Replaces Segment at the specified position in X12 transaction.

Parameters:
  • index – position of the segment to be replaced.
  • segmentSegment
Returns:

a new Segment object

size

public int size()

Returns number of segments in the transaction

Returns:size

toString

public String toString()

Returns the X12 transaction in java.lang.String format. This method is used to convert the X12 object into a X12 transaction.

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:

the segment as an X12 string.

toXML

public String toXML()

Returns the X12 transaction in XML format. This method translates the X12 object into XML format.

Returns:XML string

toXML

public String toXML(boolean bRemoveTrailingEmptyElements)

Returns the X12 transaction in XML format. This method translates the X12 object into XML format.

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

the X12 as an XML string.