Class Bean<B>
- java.lang.Object
-
- org.perfectable.introspection.bean.Bean<B>
-
- Type Parameters:
B
- type of instance contained in this bean
public final class Bean<B> extends Object
Represents a view of an instance as its property values, typically containing a proper Java Bean.Instances are created using
from(X)
.Allows access to properties either by name (using
property(java.lang.String)
) or by listing them (eg.fieldProperties()
). Properties are defined as either getter and/or setter or field.
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description B
contents()
Extracts instance that is backing this bean.Bean<B>
copy()
Creates new bean with contained instance copied field-by-field from this bean backing instance.boolean
equals(Object obj)
com.google.common.collect.ImmutableSet<Property<B,?>>
fieldProperties()
Lists all properties that are backed by a field.static <X> Bean<X>
from(X instance)
Creates bean from Java Bean object.int
hashCode()
Property<B,Object>
property(String name)
Finds property by name.com.google.common.collect.ImmutableSet<Object>
related()
Finds all object that backing instance has reference to.Class<B>
type()
Extracts actual type of backing instance.
-
-
-
Method Detail
-
from
public static <X> Bean<X> from(X instance)
Creates bean from Java Bean object.- Type Parameters:
X
- Instance type- Parameters:
instance
- a non-null object that this bean will allow introspection into- Returns:
- Bean containing specified instance
-
contents
public B contents()
Extracts instance that is backing this bean.- Returns:
- instance that is backing this bean.
-
type
public Class<B> type()
Extracts actual type of backing instance.- Returns:
- actual type of backing instance.
-
property
public Property<B,Object> property(String name)
Finds property by name.- Parameters:
name
- name of the property to look for.- Returns:
- property with provided name
- Throws:
IllegalArgumentException
- when there is no property with provided name
-
copy
public Bean<B> copy()
Creates new bean with contained instance copied field-by-field from this bean backing instance.Copy is created by default constructor.
- Returns:
- copy of this bean.
-
fieldProperties
public com.google.common.collect.ImmutableSet<Property<B,?>> fieldProperties()
Lists all properties that are backed by a field.- Returns:
- all properties backed by a field.
-
related
public com.google.common.collect.ImmutableSet<Object> related()
Finds all object that backing instance has reference to.- Returns:
- all objects that backing instance has reference to.
-
-