Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 2AB84200B59 for ; Mon, 8 Aug 2016 20:30:57 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 29324160AB5; Mon, 8 Aug 2016 18:30:57 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 20EC2160AB3 for ; Mon, 8 Aug 2016 20:30:54 +0200 (CEST) Received: (qmail 22192 invoked by uid 500); 8 Aug 2016 18:30:54 -0000 Mailing-List: contact commits-help@juneau.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@juneau.incubator.apache.org Delivered-To: mailing list commits@juneau.incubator.apache.org Received: (qmail 22183 invoked by uid 99); 8 Aug 2016 18:30:54 -0000 Received: from pnap-us-west-generic-nat.apache.org (HELO spamd1-us-west.apache.org) (209.188.14.142) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2016 18:30:54 +0000 Received: from localhost (localhost [127.0.0.1]) by spamd1-us-west.apache.org (ASF Mail Server at spamd1-us-west.apache.org) with ESMTP id B21C9C2FBD for ; Mon, 8 Aug 2016 18:30:53 +0000 (UTC) X-Virus-Scanned: Debian amavisd-new at spamd1-us-west.apache.org X-Spam-Flag: NO X-Spam-Score: -4.474 X-Spam-Level: X-Spam-Status: No, score=-4.474 tagged_above=-999 required=6.31 tests=[KAM_LAZY_DOMAIN_SECURITY=1, RCVD_IN_DNSWL_HI=-5, RCVD_IN_MSPIKE_H3=-0.01, RCVD_IN_MSPIKE_WL=-0.01, RP_MATCHES_RCVD=-0.454] autolearn=disabled Received: from mx1-lw-eu.apache.org ([10.40.0.8]) by localhost (spamd1-us-west.apache.org [10.40.0.7]) (amavisd-new, port 10024) with ESMTP id bE1P0eCxbzWe for ; Mon, 8 Aug 2016 18:30:47 +0000 (UTC) Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx1-lw-eu.apache.org (ASF Mail Server at mx1-lw-eu.apache.org) with SMTP id 5318F60E5F for ; Mon, 8 Aug 2016 18:30:31 +0000 (UTC) Received: (qmail 21057 invoked by uid 99); 8 Aug 2016 18:30:30 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 08 Aug 2016 18:30:30 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 0BC31DFC56; Mon, 8 Aug 2016 18:30:30 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jamesbognar@apache.org To: commits@juneau.incubator.apache.org Date: Mon, 08 Aug 2016 18:31:01 -0000 Message-Id: <78d21a4b69194b5a8980e5cfc8ce6f60@git.apache.org> In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [34/51] [partial] incubator-juneau-website git commit: Add missing javadocs archived-at: Mon, 08 Aug 2016 18:30:57 -0000 http://git-wip-us.apache.org/repos/asf/incubator-juneau-website/blob/112b098d/content/api-documentation/org/apache/juneau/ObjectList.html ---------------------------------------------------------------------- diff --git a/content/api-documentation/org/apache/juneau/ObjectList.html b/content/api-documentation/org/apache/juneau/ObjectList.html new file mode 100644 index 0000000..16a51b5 --- /dev/null +++ b/content/api-documentation/org/apache/juneau/ObjectList.html @@ -0,0 +1,1181 @@ + + + + + +ObjectList (Juneau) + + + + + + + + + + + +
+
org.apache.juneau
+

Class ObjectList

+
+
+ +
+
    +
  • +
    +
    All Implemented Interfaces:
    +
    Serializable, Cloneable, Iterable<Object>, Collection<Object>, Deque<Object>, List<Object>, Queue<Object>
    +
    +
    +
    +
    public class ObjectList
    +extends LinkedList<Object>
    +
    Java implementation of a JSON array. +

    + An extension of LinkedList, so all methods available to in that class are also available + to this class. +

    + Note that the use of this class is optional. The serializers will accept any objects that implement + the Collection interface. But this class provides some useful additional functionality + when working with JSON models constructed from Java Collections Framework objects. For example, a + constructor is provided for converting a JSON array string directly into a List. It also contains + accessor methods for to avoid common typecasting when accessing elements in a list. + +

    Examples
    +

    + // Construct an empty List + List l = new ObjectList(); + + // Construct a list of objects using various methods + l = new ObjectList().append("foo").append(123).append(true); + l = new ObjectList().append("foo", 123, true); // Equivalent + l = new ObjectList("foo", 123, true); // Equivalent + + // Construct a list of integers from JSON + l = new ObjectList("[1,2,3]"); + + // Construct a list of generic ObjectMap objects from JSON + l = new ObjectList("[{foo:'bar'},{baz:'bing'}]"); + + // Construct a list of integers from XML + String xml = "<array><number>1</number><number>2</number><number>3</number></array>"; + l = new ObjectList(xml, DataFormat.XML); + l = (List)XmlParser.DEFAULT.parse(xml); // Equivalent + l = (List)XmlParser.DEFAULT.parse(Object.class, xml); // Equivalent + l = XmlParser.DEFAULT.parse(List.class, xml); // Equivalent + l = XmlParser.DEFAULT.parse(ObjectList.class, xml); // Equivalent + + // Construct JSON from ObjectList + l = new ObjectList("[{foo:'bar'},{baz:'bing'}]"); + String json = l.toString(); // Produces "[{foo:'bar'},{baz:'bing'}]" + json = l.toString(JsonSerializer.DEFAULT_CONDENSED); // Equivalent + json = JsonSerializer.DEFAULT_CONDENSED.serialize(l); // Equivalent + + // Get one of the entries in the list as an Integer + l = new ObjectList("[1,2,3]"); + Integer i = l.getInt(1); + i = l.get(Integer.class, 1); // Equivalent + + // Get one of the entries in the list as an Float + l = new ObjectList("[1,2,3]"); + Float f = l.getFloat(1); // Returns 2f + f = l.get(Float.class, 1); // Equivalent + + // Same as above, except converted to a String + l = new ObjectList("[1,2,3]"); + String s = l.getString(1); // Returns "2" + s = l.get(String.class, 1); // Equivalent + + // Get one of the entries in the list as a bean (converted to a bean if it isn't already one) + l = new ObjectList("[{name:'John Smith',age:45}]"); + Person p = l.get(Person.class, 0); + + // Iterate over a list of beans using the elements() method + ObjectList ObjectList = new ObjectList("[{name:'John Smith',age:45}]"); + for (Person p : ObjectList.elements(Person.class) { + // Do something with p + } +

    +

    + This class is not thread safe. +

    +
    +
    Author:
    +
    James Bognar (james.bognar@salesforce.com)
    +
    See Also:
    +
    Serialized Form
    +
    +
  • +
+
+
+ +
+
+
    +
  • + + + +
      +
    • + + +

      Constructor Detail

      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(CharSequence s,
        +                  Parser p)
        +           throws ParseException
        +
        Construct a JSON array directly from text using the specified parser.
        +
        +
        Parameters:
        +
        s - The string being parsed.
        +
        p - The parser to use to parse the input.
        +
        Throws:
        +
        ParseException - If the input contains a syntax error or is malformed.
        +
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(CharSequence s)
        +           throws ParseException
        +
        Shortcut for new ObjectList(String,JsonParser.DEFAULT);
        +
        +
        Parameters:
        +
        s - The string being parsed.
        +
        Throws:
        +
        ParseException - If the input contains a syntax error or is malformed.
        +
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(Reader r,
        +                  Parser p)
        +           throws ParseException,
        +                  IOException
        +
        Construct a JSON array directly from a reader using the specified parser.
        +
        +
        Parameters:
        +
        r - The reader to read from. Will automatically be wrapped in a BufferedReader if it isn't already a BufferedReader.
        +
        p - The parser to use to parse the input.
        +
        Throws:
        +
        ParseException - If the input contains a syntax error or is malformed.
        +
        IOException - If a problem occurred trying to read from the reader.
        +
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList()
        +
        Construct an empty JSON array. (i.e. an empty LinkedList).
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(BeanContext beanContext)
        +
        Construct an empty JSON array with the specified bean context. (i.e. an empty LinkedList).
        +
        +
        Parameters:
        +
        beanContext - The bean context to associate with this object list for creating beans.
        +
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(Object... o)
        +
        Construct a JSON array and fill it with the specified objects.
        +
        +
        Parameters:
        +
        o - A list of objects to add to this list.
        +
        +
      • +
      + + + +
        +
      • +

        ObjectList

        +
        public ObjectList(Collection<?> c)
        +
        Construct a JSON array and fill it with the specified collection of objects.
        +
        +
        Parameters:
        +
        c - A list of objects to add to this list.
        +
        +
      • +
      +
    • +
    + +
      +
    • + + +

      Method Detail

      + + + +
        +
      • +

        setBeanContext

        +
        public ObjectList setBeanContext(BeanContext beanContext)
        +
        Override the default bean context used for converting POJOs. +

        + Default is BeanContext.DEFAULT, which is sufficient in most cases. +

        + Useful if you're serializing/parsing beans with transforms defined.

        +
        +
        Parameters:
        +
        beanContext - The new bean context.
        +
        Returns:
        +
        This object (for method chaining).
        +
        +
      • +
      + + + +
        +
      • +

        append

        +
        public ObjectList append(Object... o)
        +
        Convenience method for adding multiple objects to this list.
        +
        +
        Parameters:
        +
        o - The objects to add to the list.
        +
        Returns:
        +
        This object (for method chaining).
        +
        +
      • +
      + + + +
        +
      • +

        get

        +
        public <T> T get(Class<T> type,
        +                 int index)
        +
        Get the entry at the specified index, converted to the specified type (if possible). +

        + See BeanContext.convertToType(Object, ClassMeta) for the list of valid data conversions.

        +
        +
        Type Parameters:
        +
        T - The type of object to convert the entry to.
        +
        Parameters:
        +
        type - The type of object to convert the entry to.
        +
        index - The index into this list.
        +
        Returns:
        +
        The converted entry.
        +
        +
      • +
      + + + +
        +
      • +

        getString

        +
        public String getString(int index)
        +
        Shortcut for calling get(String.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        +
      • +
      + + + +
        +
      • +

        getInt

        +
        public Integer getInt(int index)
        +
        Shortcut for calling get(Integer.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + +
        +
      • +

        getBoolean

        +
        public Boolean getBoolean(int index)
        +
        Shortcut for calling get(Boolean.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + +
        +
      • +

        getLong

        +
        public Long getLong(int index)
        +
        Shortcut for calling get(Long.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + +
        +
      • +

        getMap

        +
        public Map<?,?> getMap(int index)
        +
        Shortcut for calling get(Map.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + +
        +
      • +

        getList

        +
        public List<?> getList(int index)
        +
        Shortcut for calling get(List.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + +
        +
      • +

        getObjectMap

        +
        public ObjectMap getObjectMap(int index)
        +
        Shortcut for calling get(ObjectMap.class, index).
        +
        +
        Parameters:
        +
        index - The index.
        +
        Returns:
        +
        The converted value.
        +
        Throws:
        +
        InvalidDataConversionException - If value cannot be converted.
        +
        +
      • +
      + + + + + + + +
        +
      • +

        getAt

        +
        public <T> T getAt(Class<T> type,
        +                   String path)
        +
        Same as get(Class,int), but the key is a slash-delimited + path used to traverse entries in this POJO. +

        + For example, the following code is equivalent: +

        +

        + ObjectMap m = getObjectMap(); + + // Long way + long l = m.getObjectMap("foo").getObjectList("bar").getObjectMap("0").getLong("baz"); + + // Using this method + long l = m.getAt(long.class, "foo/bar/0/baz"); +

        +

        + This method uses the PojoRest class to perform the lookup, so the map can contain + any of the various class types that the PojoRest class supports (e.g. beans, collections, arrays). +

        +
        +
        Type Parameters:
        +
        T - The class type.
        +
        Parameters:
        +
        type - The class type.
        +
        path - The path to the entry.
        +
        Returns:
        +
        The value, or null if the entry doesn't exist.
        +
        +
      • +
      + + + +
        +
      • +

        putAt

        +
        public Object putAt(String path,
        +                    Object o)
        +
        Same as set(int,Object), but the key is a slash-delimited + path used to traverse entries in this POJO. +

        + For example, the following code is equivalent: +

        +

        + ObjectMap m = getObjectMap(); + + // Long way + m.getObjectMap("foo").getObjectList("bar").getObjectMap("0").put("baz", 123); + + // Using this method + m.putAt("foo/bar/0/baz", 123); +

        +

        + This method uses the PojoRest class to perform the lookup, so the map can contain + any of the various class types that the PojoRest class supports (e.g. beans, collections, arrays). +

        +
        +
        Parameters:
        +
        path - The path to the entry.
        +
        o - The new value.
        +
        Returns:
        +
        The previous value, or null if the entry doesn't exist.
        +
        +
      • +
      + + + +
        +
      • +

        postAt

        +
        public Object postAt(String path,
        +                     Object o)
        +
        Similar to putAt(String,Object), but used to append + to collections and arrays. +

        + For example, the following code is equivalent: +

        +

        + ObjectMap m = getObjectMap(); + + // Long way + m.getObjectMap("foo").getObjectList("bar").append(123); + + // Using this method + m.postAt("foo/bar", 123); +

        +

        + This method uses the PojoRest class to perform the lookup, so the map can contain + any of the various class types that the PojoRest class supports (e.g. beans, collections, arrays). +

        +
        +
        Parameters:
        +
        path - The path to the entry.
        +
        o - The new value.
        +
        Returns:
        +
        The previous value, or null if the entry doesn't exist.
        +
        +
      • +
      + + + +
        +
      • +

        deleteAt

        +
        public Object deleteAt(String path)
        +
        Similar to remove(int),but the key is a slash-delimited + path used to traverse entries in this POJO. +

        + For example, the following code is equivalent: +

        +

        + ObjectMap m = getObjectMap(); + + // Long way + m.getObjectMap("foo").getObjectList("bar").getObjectMap(1).remove("baz"); + + // Using this method + m.deleteAt("foo/bar/0/baz"); +

        +

        + This method uses the PojoRest class to perform the lookup, so the map can contain + any of the various class types that the PojoRest class supports (e.g. beans, collections, arrays). +

        +
        +
        Parameters:
        +
        path - The path to the entry.
        +
        Returns:
        +
        The previous value, or null if the entry doesn't exist.
        +
        +
      • +
      + + + +
        +
      • +

        elements

        +
        public <E> Iterable<E> elements(Class<E> childType)
        +
        Creates an Iterable with elements of the specified child type. +

        + Attempts to convert the child objects to the correct type if they aren't already the correct type. +

        + The next() method on the returned iterator may throw a InvalidDataConversionException if + the next element cannot be converted to the specified type. +

        + See BeanContext.convertToType(Object, ClassMeta) for a description of valid conversions. + +

        +
        Example:
        +
        +

        + // Iterate over a list of ObjectMaps. + ObjectList l = new ObjectList("[{foo:'bar'},{baz:123}]"); + for (ObjectMap m : l.elements(ObjectMap.class)) { + // Do something with m. + } + + // Iterate over a list of ints. + ObjectList l = new ObjectList("[1,2,3]"); + for (Integer i : l.elements(Integer.class)) { + // Do something with i. + } + + // Iterate over a list of beans. + // Automatically converts to beans. + ObjectList l = new ObjectList("[{name:'John Smith',age:45}]"); + for (Person p : l.elements(Person.class)) { + // Do something with p. + } +

        +
        +
        +
        +
        Type Parameters:
        +
        E - The child object type.
        +
        Parameters:
        +
        childType - The child object type.
        +
        Returns:
        +
        A new Iterable object over this list.
        +
        +
      • +
      + + + +
        +
      • +

        getClassMeta

        +
        public ClassMeta<?> getClassMeta(int index)
        +
        Returns the ClassMeta of the class of the object at the specified index.
        +
        +
        Parameters:
        +
        index - An index into this list, zero-based.
        +
        Returns:
        +
        The data type of the object at the specified index, or null if the value is null.
        +
        +
      • +
      + + + +
        +
      • +

        toString

        +
        public String toString(WriterSerializer serializer)
        +                throws SerializeException
        +
        Serialize this array to a string using the specified serializer.
        +
        +
        Parameters:
        +
        serializer - The serializer to use to convert this object to a string.
        +
        Returns:
        +
        This object as a serialized string.
        +
        Throws:
        +
        SerializeException - If a problem occurred trying to convert the output.
        +
        +
      • +
      + + + + + + + +
        +
      • +

        serializeTo

        +
        public void serializeTo(Writer w)
        +                 throws IOException,
        +                        SerializeException
        +
        Convenience method for serializing this ObjectList to the specified Writer using + the JsonSerializer.DEFAULT serializer.
        +
        +
        Parameters:
        +
        w - The writer to send the serialized contents of this object.
        +
        Throws:
        +
        IOException - If a problem occurred trying to write to the writer.
        +
        SerializeException - If a problem occurred trying to convert the output.
        +
        +
      • +
      +
    • +
    +
  • +
+
+
+ + + + + + +