com.github.jknack.extend
Class Extend

java.lang.Object
  extended by com.github.jknack.extend.Extend

public final class Extend
extends Object

Extends JavaBean or convert them to Map and add new properties at runtime.

Usage:

 import static com.github.jknack.extend.Extend.*;

 ...

 MyObject extended =
   extend(object,
     $("propertyA", value),
     $("propertyB", value),
     ...
   );

 

Derived Properties:

 import static com.github.jknack.extend.Extend.*;

 ...

 MyObject extended =
   extend(object,
     $("propertyA", new Function() {
       public Integer apply(MyObject object) {
         return ...;
       }
     })
   );

 

Convert a JavaBean to a Map:

 import static com.github.jknack.extend.Extend.*;

 ...

 Map extended =
   map(object,
     $("propertyA", value)
   );

 

Since:
0.1.0
Author:
edgar.espina

Nested Class Summary
static class Extend.Property
          Helper class for simplify object property creation.
 
Method Summary
static Extend.Property $(String name, Object value)
          Factory method for Extend.Property.
static
<T> List<T>
extend(Iterable<T> sources, Extend.Property... properties)
          Extends each object with the given properties.
static
<T> List<T>
extend(Iterable<T> sources, Map<String,Object> properties)
          Extends each object with the given properties.
static
<T> T
extend(T source, Extend.Property... properties)
          Extends an object with the given properties.
static
<T> T
extend(T source, Map<String,Object> properties)
          Extends an object with the given properties.
static
<T> List<Map<String,Object>>
map(Iterable<T> sources, Extend.Property... properties)
          Converts each object to a Map.
static
<T> List<Map<String,Object>>
map(Iterable<T> sources, Map<String,Object> properties)
          Converts each object to a Map.
static
<T> Map<String,Object>
map(T source, Extend.Property... properties)
          Converts an object to a Map.
static
<T> Map<String,Object>
map(T source, Map<String,Object> properties)
          Converts an object to a Map.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

$

public static Extend.Property $(String name,
                                Object value)
Factory method for Extend.Property.

Parameters:
name - The property's name. Required.
value - The property's value. Required.
Returns:
A new Extend.Property.

extend

public static <T> List<T> extend(Iterable<T> sources,
                                 Extend.Property... properties)
Extends each object with the given properties.

Type Parameters:
T - The source type.
Parameters:
sources - The objects to extend. Required.
properties - The extra property set. Required.
Returns:
A list of extended and immutable objects.

extend

public static <T> T extend(T source,
                           Extend.Property... properties)
Extends an object with the given properties.

Type Parameters:
T - The source type.
Parameters:
source - The object to extend. Required.
properties - The extra property set. Required.
Returns:
A new extended and immutable object.

extend

public static <T> List<T> extend(Iterable<T> sources,
                                 Map<String,Object> properties)
Extends each object with the given properties.

Type Parameters:
T - The source type.
Parameters:
sources - The objects to extend. Required.
properties - The extra property set. Required.
Returns:
A list of extended and immutable objects.

extend

public static <T> T extend(T source,
                           Map<String,Object> properties)
Extends an object with the given properties.

Type Parameters:
T - The source type.
Parameters:
source - The object to extend. Required.
properties - The extra property set. Required.
Returns:
A new extended and immutable object.

map

public static <T> Map<String,Object> map(T source,
                                         Extend.Property... properties)
Converts an object to a Map. The resulting map is the union of the bean properties and all the extra properties.

Type Parameters:
T - The source type.
Parameters:
source - The object to extend. Required.
properties - The extra property set. Required.
Returns:
A new immutable map.

map

public static <T> List<Map<String,Object>> map(Iterable<T> sources,
                                               Extend.Property... properties)
Converts each object to a Map. The resulting map is the union of the bean properties and all the extra properties.

Type Parameters:
T - The source type.
Parameters:
sources - The objects to extend. Required.
properties - The extra property set. Required.
Returns:
A new immutable map.

map

public static <T> List<Map<String,Object>> map(Iterable<T> sources,
                                               Map<String,Object> properties)
Converts each object to a Map. The resulting map is the union of the bean properties and all the extra properties.

Type Parameters:
T - The source type.
Parameters:
sources - The objects to extend. Required.
properties - The extra property set. Required.
Returns:
A new immutable map.

map

public static <T> Map<String,Object> map(T source,
                                         Map<String,Object> properties)
Converts an object to a Map. The resulting map is the union of the bean properties and all the extra properties.

Type Parameters:
T - The source type.
Parameters:
source - The object to extend. Required.
properties - The extra property set. Required.
Returns:
A new immutable map.


Copyright © 2013. All Rights Reserved.