Package aQute.libg.dtos
Class DTOsImpl
- java.lang.Object
-
- aQute.libg.dtos.DTOsImpl
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
DTOsImpl.Diff
(package private) static class
DTOsImpl.Link
-
Nested classes/interfaces inherited from interface aQute.libg.dtos.DTOs
DTOs.Difference, DTOs.Reason
-
-
Field Summary
Fields Modifier and Type Field Description private java.util.Map<java.lang.Class<?>,java.lang.reflect.Field[]>
cache
private java.lang.reflect.Field[]
EMPTY_FIELDS
(package private) static java.util.regex.Pattern
ESCAPE_P
private static org.slf4j.Logger
logger
private DTOsImpl.Link
root
(package private) static java.util.regex.Pattern
UNESCAPE_P
-
Constructor Summary
Constructors Constructor Description DTOsImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.util.Map<java.lang.String,java.lang.Object>
asMap(java.lang.Object dto)
Return a partially read only Map object that maps directly to a DTO.(package private) int
bsearch(java.lang.reflect.Field[] a, int fromIndex, int toIndex, java.lang.String key)
<T> T
deepCopy(T source)
Deep copy(package private) <T> T
deepCopy(T source, DTOsImpl.Link link)
boolean
deepEquals(java.lang.Object a, java.lang.Object b)
Check if two DTOs fields are equal.java.util.List<DTOs.Difference>
diff(java.lang.Object older, java.lang.Object newer)
Return a list of paths where the two objects differ.private boolean
diff(java.util.List<DTOs.Difference> diffs, DTOsImpl.Link link, java.lang.Object older, java.lang.Object newer)
boolean
equals(java.lang.Object a, java.lang.Object b)
Check if two dtos fields are equal.java.lang.String
escape(java.lang.String unescaped)
Escape a string to be used in a path.java.lang.String[]
fromPathToSegments(java.lang.String path)
Takes a path with escaped '.'and '\' and then turns it into an array of unescaped keys(package private) java.lang.String[]
fromPathToSegments(java.lang.String path, int start, int n)
java.lang.String
fromSegmentsToPath(java.lang.String[] segments)
Takes a path with unescaped keys and turns it into a string path where the \ and .java.util.Optional<java.lang.Object>
get(java.lang.Object dto, java.lang.String path)
Access a DTO with a path.java.util.Optional<java.lang.Object>
get(java.lang.Object dto, java.lang.String... path)
Access a DTO with a path that consists of an array with segments.private java.util.Optional<java.lang.Object>
get(java.lang.Object dto, java.lang.String[] path, int i, int max)
(package private) java.lang.reflect.Field
getField(java.lang.reflect.Field[] fields, java.lang.String name)
(package private) java.lang.reflect.Field[]
getFields(java.lang.Class<?> c)
(package private) java.lang.reflect.Field[]
getFields(java.lang.Object o)
int
hashCode(java.lang.Object dto)
Calculate a hash Code for the fields in this DTO.boolean
isComplex(java.lang.Object a)
Return true if the give dto is complex (either Map, Collection, Array, or has public fields.boolean
isDTO(java.lang.Object o)
An object with public non-static non-synthetic fields.<T> T
shallowCopy(T source)
Shallow copyjava.lang.String
toString(java.lang.Object dto)
Convert a DTO to a human readable string presentation.java.lang.String
unescape(java.lang.String unescaped)
Unescapes a string to be used in a path.
-
-
-
Field Detail
-
logger
private static final org.slf4j.Logger logger
-
EMPTY_FIELDS
private final java.lang.reflect.Field[] EMPTY_FIELDS
-
cache
private final java.util.Map<java.lang.Class<?>,java.lang.reflect.Field[]> cache
-
root
private final DTOsImpl.Link root
-
ESCAPE_P
static java.util.regex.Pattern ESCAPE_P
-
UNESCAPE_P
static java.util.regex.Pattern UNESCAPE_P
-
-
Method Detail
-
asMap
public java.util.Map<java.lang.String,java.lang.Object> asMap(java.lang.Object dto)
Description copied from interface:DTOs
Return a partially read only Map object that maps directly to a DTO. I.e. changes are reflected in the DTO. If a field is a DTO, then this field will also become a Map.
-
getFields
java.lang.reflect.Field[] getFields(java.lang.Object o)
-
getFields
java.lang.reflect.Field[] getFields(java.lang.Class<?> c)
-
bsearch
int bsearch(java.lang.reflect.Field[] a, int fromIndex, int toIndex, java.lang.String key)
-
getField
java.lang.reflect.Field getField(java.lang.reflect.Field[] fields, java.lang.String name)
-
shallowCopy
public <T> T shallowCopy(T source)
Shallow copy- Specified by:
shallowCopy
in interfaceDTOs
- Parameters:
source
- the source object- Returns:
- a shallow copy of object
-
deepCopy
public <T> T deepCopy(T source)
Deep copy
-
deepCopy
<T> T deepCopy(T source, DTOsImpl.Link link)
-
fromPathToSegments
public java.lang.String[] fromPathToSegments(java.lang.String path)
Description copied from interface:DTOs
Takes a path with escaped '.'and '\' and then turns it into an array of unescaped keys- Specified by:
fromPathToSegments
in interfaceDTOs
- Parameters:
path
- the path with escaped \ and .- Returns:
- a path array with unescaped segments
-
fromPathToSegments
java.lang.String[] fromPathToSegments(java.lang.String path, int start, int n)
-
fromSegmentsToPath
public java.lang.String fromSegmentsToPath(java.lang.String[] segments)
Description copied from interface:DTOs
Takes a path with unescaped keys and turns it into a string path where the \ and . are escaped.- Specified by:
fromSegmentsToPath
in interfaceDTOs
- Parameters:
segments
- The unescaped segments of the path- Returns:
- a string path where the . and \ are escaped.
-
deepEquals
public boolean deepEquals(java.lang.Object a, java.lang.Object b)
Description copied from interface:DTOs
Check if two DTOs fields are equal. This is deep equal, that is the fields of this DTO are using this method is the object at a field is a DTO, recursively.- Specified by:
deepEquals
in interfaceDTOs
- Parameters:
a
- the first objectb
- the second object- Returns:
- true if both are null or the DTO's primary fields are equal
-
toString
public java.lang.String toString(java.lang.Object dto)
Description copied from interface:DTOs
Convert a DTO to a human readable string presentation. This is primarily for debugging since the toString can truncate fields. This method must print all public fields, also non primary. Output formats can vary (e.g. YAML like) so the actual output should NOT be treated as standard.
-
equals
public boolean equals(java.lang.Object a, java.lang.Object b)
Description copied from interface:DTOs
Check if two dtos fields are equal. This is shallow equal, that is the fields of this DTO are using the equals() instance method.
-
hashCode
public int hashCode(java.lang.Object dto)
Description copied from interface:DTOs
Calculate a hash Code for the fields in this DTO. The dto must have at least one public field.
-
get
public java.util.Optional<java.lang.Object> get(java.lang.Object dto, java.lang.String path)
Description copied from interface:DTOs
Access a DTO with a path. A path is a '.' separated string. Each part in the path is either a field name, key in a map, or an index in a list. If the path segments contain dots or backslashes, then these must be escaped
-
get
public java.util.Optional<java.lang.Object> get(java.lang.Object dto, java.lang.String... path)
Description copied from interface:DTOs
Access a DTO with a path that consists of an array with segments. Each segment in the path is either a field name, key in a map, or an index in a list.
-
get
private java.util.Optional<java.lang.Object> get(java.lang.Object dto, java.lang.String[] path, int i, int max)
-
diff
public java.util.List<DTOs.Difference> diff(java.lang.Object older, java.lang.Object newer)
Description copied from interface:DTOs
Return a list of paths where the two objects differ. The objects must be of the same class.
-
diff
private boolean diff(java.util.List<DTOs.Difference> diffs, DTOsImpl.Link link, java.lang.Object older, java.lang.Object newer)
-
escape
public java.lang.String escape(java.lang.String unescaped)
Description copied from interface:DTOs
Escape a string to be used in a path. This will put a backslash ('\') in front of full stops ('.') and the backslash ('\').
-
unescape
public java.lang.String unescape(java.lang.String unescaped)
Description copied from interface:DTOs
Unescapes a string to be used in a path. This will remove a backslash ('\') in front of full stops ('.') and the backslash ('\').
-
isComplex
public boolean isComplex(java.lang.Object a)
Description copied from interface:DTOs
Return true if the give dto is complex (either Map, Collection, Array, or has public fields.
-
-