info.bioinfweb.jphyloio.objecttranslation.implementations

## Class ListTranslator

- java.lang.Object
- - info.bioinfweb.jphyloio.objecttranslation.implementations.AbstractObjectTranslator<O>
  - - info.bioinfweb.jphyloio.objecttranslation.implementations.SimpleValueTranslator<java.util.List<java.lang.Object>>
    - - info.bioinfweb.jphyloio.objecttranslation.implementations.ListTranslator

- All Implemented Interfaces:
    NewickConstants, ObjectTranslator<java.util.List<java.lang.Object>>

      public class ListTranslator
      extends SimpleValueTranslator<java.util.List<java.lang.Object>>
      implements NewickConstants

  Reads and writes string representations of simple values as used in Newick or Nexus. Elements can either be strings or numeric values.

  Example:

      {18.2, 'AB C', 22}

  For a possible format independent use, the data type `ReadWriteConstants.DATA_TYPE_SIMPLE_VALUE_LIST` allows to use this translator also in NeXML, although it primarily meant for Newick and Nexus.
  Author:
    Ben Stöver
  See Also:
    `ReadWriteConstants.DATA_TYPE_SIMPLE_VALUE_LIST`, `ObjectTranslatorFactory.addJPhyloIOTranslators(boolean)`

- - ### Field Summary

    - ### Fields inherited from class info.bioinfweb.jphyloio.objecttranslation.implementations.SimpleValueTranslator

      `MAX_STRING_REPRESENTATION_LENGTH`

    - ### Fields inherited from interface info.bioinfweb.jphyloio.formats.newick.NewickConstants

      `ALLOCATION_SEPARATOR_SYMBOL, ALLOCATION_SYMBOL, ALTERNATIVE_NAME_DELIMITER, COMMENT_END, COMMENT_START, DATA_TYPE_NEWICK_ARRAY, E_NEWICK_EDGE_TYPE_HYBRIDIZATION, E_NEWICK_EDGE_TYPE_LATERAL_GENE_TRANSFER, E_NEWICK_EDGE_TYPE_RECOMBINATION, E_NEWICK_NAMESPACE_PREFIX, E_NEWICK_NETWORK_DATA_SEPARATOR, ELEMENT_SEPERATOR, FIELD_END_SYMBOL, FIELD_START_SYMBOL, FIELD_VALUE_SEPARATOR_SYMBOL, FREE_NAME_BLANK, HOT_COMMENT_START_SYMBOL, INDEX_END_SYMBOL, INDEX_START_SYMBOL, LENGTH_SEPERATOR, NAME_DELIMITER, NEWICK_DATA_TYPE_NAMESPACE, NEWICK_FORMAT_NAME, NEWICK_NAMESPACE_PREFIX, NHX_KEY_CONFIDENCE, NHX_KEY_EVENT, NHX_KEY_GENE_NAME, NHX_KEY_PREFIX, NHX_KEY_SCIENTIFIC_NAME, NHX_KEY_SEQUENCE_ACCESSION, NHX_KEY_TAXONOMY_ID, NHX_START, NHX_VALUE_SEPARATOR_SYMBOL, PREDICATE_E_NEWICK_EDGE_TYPE, ROOTED_HOT_COMMENT, SUBTREE_END, SUBTREE_START, TERMINAL_SYMBOL, UNROOTED_HOT_COMMENT`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `ListTranslator()`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.Class<java.util.List<java.lang.Object>>` | `getObjectClass()` Returns the Java class of object instances created by this translator.
    `java.lang.String` | `javaToRepresentation(java.lang.Object object, WriterStreamDataProvider<?> streamDataProvider)` Creates the string representation of a simple value list from any object that implements `Iterable`.
    `static java.lang.String` | `listToString(java.lang.Iterable<?> list)`
    `static java.util.List<java.lang.Object>` | `parseList(java.lang.String representation)` Reads a string representation of a simple value list into an implementation of `List`.
    `java.util.List<java.lang.Object>` | `representationToJava(java.lang.String representation, ReaderStreamDataProvider<?> streamDataProvider)` Reads a string representation of a simple value list into an implementation of `List`.

    - ### Methods inherited from class info.bioinfweb.jphyloio.objecttranslation.implementations.SimpleValueTranslator

      `hasStringRepresentation, readXMLRepresentation, writeXMLRepresentation`

    - ### Methods inherited from class info.bioinfweb.jphyloio.objecttranslation.implementations.AbstractObjectTranslator

      `equals, hashCode`

    - ### Methods inherited from class java.lang.Object

      `clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### ListTranslator

          public ListTranslator()

  - ### Method Detail

    - #### getObjectClass

          public java.lang.Class<java.util.List<java.lang.Object>> getObjectClass()

      Description copied from interface: `ObjectTranslator`
      Returns the Java class of object instances created by this translator.

      Note that `ObjectTranslator.javaToRepresentation(Object, WriterStreamDataProvider)` and `ObjectTranslator.writeXMLRepresentation(XMLStreamWriter, Object, WriterStreamDataProvider)` may also accept instances of other classes. This is independent from the return value here.

      Specified by:
        `getObjectClass` in interface `ObjectTranslator<java.util.List<java.lang.Object>>`
      Returns:
        the class of the handled objects

    - #### parseList

          public static java.util.List<java.lang.Object> parseList(java.lang.String representation)
                                                            throws InvalidObjectSourceDataException

      Reads a string representation of a simple value list into an implementation of `List`. The single elements are either instances of `String` or any implementation of `Number`. `Double` will be used by default, for values having a higher precision, `BigDecimal` will be used instead.
      Parameters:
        `representation` - the string representation of the list
      Returns:
        a list instance
      Throws:
        `InvalidObjectSourceDataException`

    - #### representationToJava

          public java.util.List<java.lang.Object> representationToJava(java.lang.String representation,
                                                                       ReaderStreamDataProvider<?> streamDataProvider)
                                                                throws InvalidObjectSourceDataException,
                                                                       java.lang.UnsupportedOperationException

      Reads a string representation of a simple value list into an implementation of `List`. The single elements are either instances of `String` or any implementation of `Number`. `Double` will be used by default, for values having a higher precision, `BigDecimal` will be used instead.
      Specified by:
        `representationToJava` in interface `ObjectTranslator<java.util.List<java.lang.Object>>`
      Parameters:
        `representation` - the string representation of the object to be created
        `streamDataProvider` - the stream data provider of the calling reader (Maybe `null`. Some translators will use it to gain additional status information required for translating, e.g. prefix to namespace mapping for creating QNames.)
      Returns:
        the new object
      Throws:
        `InvalidObjectSourceDataException` - if the specified string representation cannot be parsed to a supported object
        `java.lang.UnsupportedOperationException` - if objects handled by this instance can only be represented as XML
      See Also:
        `ObjectTranslator.representationToJava(java.lang.String, info.bioinfweb.jphyloio.ReaderStreamDataProvider)`

    - #### listToString

          public static java.lang.String listToString(java.lang.Iterable<?> list)
                                               throws java.lang.ClassCastException

      Throws:
        `java.lang.ClassCastException`

    - #### javaToRepresentation

          public java.lang.String javaToRepresentation(java.lang.Object object,
                                                       WriterStreamDataProvider<?> streamDataProvider)
                                                throws java.lang.ClassCastException

      Creates the string representation of a simple value list from any object that implements `Iterable`.
      Specified by:
        `javaToRepresentation` in interface `ObjectTranslator<java.util.List<java.lang.Object>>`
      Overrides:
        `javaToRepresentation` in class `SimpleValueTranslator<java.util.List<java.lang.Object>>`
      Parameters:
        `object` - the `Iterable` to be converted
        `streamDataProvider` - TODO
      Returns:
        the string representation of the list
      Throws:
        `java.lang.ClassCastException` - if `object` does not implement `Iterable`
      See Also:
        `ObjectTranslator.javaToRepresentation(java.lang.Object, WriterStreamDataProvider)`