org.jmythapi.protocol.utils
Class PropertyAwareUtils
java.lang.Object
org.jmythapi.protocol.utils.PropertyAwareUtils
public class PropertyAwareUtils
- extends Object
Method Summary |
static
|
compare(IPropertyAware<P> source,
IPropertyAware<P> target)
Compares two property-aware objects. |
static
|
groupListByProperty(Iterable<E> list,
P prop)
Usage example:
IProgramInfoList allRecordings = backend.queryRecordings();
Map<Object,List<IProgramInfo>> recordingsByCategory = PropertyAwareUtils.groupListByProperty(allRecordings,IProgramInfo.Props.CATEGORY);
for(Entry<Object,List<IProgramInfo>> entry : recordingsByCategory.entrySet()) {
System.out.println(String.format(
"\r\nCATEGORY '%s': %02d recordings",
entry.getKey(),
entry.getValue().size()
));
for(IProgramInfo program : entry.getValue()) {
System.out.println(String.format(
"- %s",
program.getFullTitle()
));
}
}
|
static
|
groupListByProperty(Iterable<E> list,
P prop,
IFilter<P,E> filter)
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
PropertyAwareUtils
public PropertyAwareUtils()
groupListByProperty
public static <P extends Enum<P>,E extends IPropertyAware<P>> Map<Object,List<E>> groupListByProperty(Iterable<E> list,
P prop)
Usage example:
IProgramInfoList allRecordings = backend.queryRecordings();
Map<Object,List<IProgramInfo>> recordingsByCategory = PropertyAwareUtils.groupListByProperty(allRecordings,IProgramInfo.Props.CATEGORY);
for(Entry<Object,List<IProgramInfo>> entry : recordingsByCategory.entrySet()) {
System.out.println(String.format(
"\r\nCATEGORY '%s': %02d recordings",
entry.getKey(),
entry.getValue().size()
));
for(IProgramInfo program : entry.getValue()) {
System.out.println(String.format(
"- %s",
program.getFullTitle()
));
}
}
- Type Parameters:
P
- The class of the enumeration property used for groupingE
- The class of the property-aware object- Parameters:
list
- A list of property-aware objectsprop
- The property to use for grouping
- Returns:
- the grouped lists
groupListByProperty
public static <P extends Enum<P>,E extends IPropertyAware<P>> Map<Object,List<E>> groupListByProperty(Iterable<E> list,
P prop,
IFilter<P,E> filter)
compare
public static <P extends Enum<P>,E extends IPropertyAware<P>> EnumMap<P,Object[]> compare(IPropertyAware<P> source,
IPropertyAware<P> target)
- Compares two property-aware objects.
This function compares two property-aware objects and determines those properties,
whose values are not equal in the compared objects. As a result a enumeration map is
returned containing the constants and values of all different properties.
Usage Example:
IProgramInfo recording1 = ...;
IProgramInfo recording2 = ...;
EnumMap<IProgramInfo.Props,Object[]> diffMap = PropertyAwareUtils.compare(recording1,recording2);
for(Entry<IProgramInfo.Props,Object[]> entry : diffMap.entrySet()){
IProgramInfo.Props property = entry.getKey();
Object[] values = entry.getValue();
System.out.println(String.format(
"Property %s is different: %s != %s",
property, values[0],values[1]
));
}
- Type Parameters:
P
- the type of the propertyE
- the type of the objects- Parameters:
source
- the source objecttarget
- the target object
- Returns:
- a map containing all properties that are different
Copyright © 2008-2013. All Rights Reserved.