org.jmythapi.protocol.response.impl
Class ProgramInfoList

java.lang.Object
  extended by org.jmythapi.impl.AData<E>
      extended by org.jmythapi.protocol.response.impl.AMythResponse<IProgramInfoList.Props>
          extended by org.jmythapi.protocol.response.impl.ProgramInfoList
All Implemented Interfaces:
Cloneable, Iterable<IProgramInfo>, IPropertyAware<IProgramInfoList.Props>, IVersionable, ISendable, IMythResponse<IProgramInfoList.Props>, IProgramInfoList

public class ProgramInfoList
extends AMythResponse<IProgramInfoList.Props>
implements Iterable<IProgramInfo>, IProgramInfoList


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jmythapi.protocol.response.IProgramInfoList
IProgramInfoList.MapKey, IProgramInfoList.Props
 
Field Summary
 
Fields inherited from class org.jmythapi.impl.AData
logger, propsClass, protoVersion, respArgs
 
Constructor Summary
ProgramInfoList(IMythPacket packet)
           
ProgramInfoList(ProtocolVersion protoVersion, List<String> responseArgs)
           
 
Method Summary
 List<IProgramInfo> asList()
          Returns a list of programs.
 List<IProgramInfo> asList(IProgramInfoFilter filter)
          Returns a list of programs.
 Map<String,IProgramInfo> asMap(IProgramInfoList.MapKey mapKey)
          Returns a map containing the unique-id of each program as key and the program as value.
static ProgramInfoList emptyList(ProtocolVersion protoVersion)
          Creates an empty program-info list
 IProgramInfoList filter(IProgramInfoFilter filter)
          Returns a new program list containing only programs that are accepted by the given filter.
 IProgramInfo get(int idx)
          Gets the program-info object at the given index.
protected  int getExpectedSize(List<String> responseArgs)
          This function returns the expected size of the response-argument-list.
 Map<String,Integer> getIndexMap(IProgramInfoList.MapKey mapKey)
          Returns a map containing the unique-id of each program as key and the program-index as value.
 long getTotalDuration()
          Gets the sum of all recording durations.
static long getTotalDuration(Iterable<IProgramInfo> programs, boolean checkCurrentTime)
           
static long getTotalFileSize(Iterable<IProgramInfo> programs)
           
 long getTotalFilesSize()
          Gets the sum of all file sizes.
 Map<Object,IProgramInfoList> groupBy(IProgramInfo.Props prop)
          Groups the list of program-infos by the specified program-info property.
 Map<Object,IProgramInfoList> groupBy(IProgramInfo.Props prop, IProgramInfoFilter filter)
          Groups the list of program-infos by the specified program-info property.
 boolean isEmpty()
          Checks if the program list is empty.
 Iterator<IProgramInfo> iterator()
           
 Iterator<IProgramInfo> iterator(IProgramInfoFilter filter)
           
 IProgramInfoList[] multiFilter(IProgramInfoFilter... filters)
          Allows to filter the program list, using multiple filters.
 int size()
          Returns the number of programs contained in this list
 String toString()
          Returns the content of this data object as a formatted string.
static ProgramInfoList valueOf(ProtocolVersion protoVersion, Collection<IProgramInfo> programs)
          Converts a collection of program-info objects into a program-info list.
 
Methods inherited from class org.jmythapi.protocol.response.impl.AMythResponse
checkSize, decodeProperty, encodeProperty, getPacket, getProperties, getProperty, getPropertyIndex
 
Methods inherited from class org.jmythapi.impl.AData
clone, equals, getPropertyClass, getPropertyCount, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValueObject, getPropertyValues, getVersionNr, hashCode, init, postProcessArguments, setPropertyValue, setPropertyValue, setPropertyValueObject
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.jmythapi.protocol.response.IProgramInfoList
clone
 
Methods inherited from interface org.jmythapi.IVersionable
getVersionNr
 
Methods inherited from interface org.jmythapi.IPropertyAware
getProperties, getProperty, getPropertyClass, getPropertyCount, getPropertyIndex, getPropertyMap, getPropertyValue, getPropertyValue, getPropertyValueObject, getPropertyValues, setPropertyValue, setPropertyValue, setPropertyValueObject
 

Constructor Detail

ProgramInfoList

public ProgramInfoList(IMythPacket packet)

ProgramInfoList

public ProgramInfoList(ProtocolVersion protoVersion,
                       List<String> responseArgs)
Method Detail

getExpectedSize

protected int getExpectedSize(List<String> responseArgs)
Description copied from class: AMythResponse

This function returns the expected size of the response-argument-list.

The expected size may be different depending on the current MythTV-protocol-version.
The default implementation of this function uses EnumUtils#getEnumLength(Class, int) to determine the expected size of the argument-list.

Overrides:
getExpectedSize in class AMythResponse<IProgramInfoList.Props>
Parameters:
responseArgs - the response-argument-list

size

public int size()
Description copied from interface: IProgramInfoList
Returns the number of programs contained in this list

Specified by:
size in interface IProgramInfoList
Returns:
the list size

isEmpty

public boolean isEmpty()
Description copied from interface: IProgramInfoList
Checks if the program list is empty.

Specified by:
isEmpty in interface IProgramInfoList
Returns:
true if the list is empty.

asList

public List<IProgramInfo> asList()
Description copied from interface: IProgramInfoList
Returns a list of programs.

Use IProgramInfoList.asList(IProgramInfoFilter) if you want to filter out unwanted programs.

Specified by:
asList in interface IProgramInfoList
Returns:
a list of program-info objects

asList

public List<IProgramInfo> asList(IProgramInfoFilter filter)
Description copied from interface: IProgramInfoList
Returns a list of programs. Only programs accepted by the given filter are returned.

Specified by:
asList in interface IProgramInfoList
Parameters:
filter - the filter to apply to the list of programs
Returns:
a list of program-info objects

filter

public IProgramInfoList filter(IProgramInfoFilter filter)
Description copied from interface: IProgramInfoList
Returns a new program list containing only programs that are accepted by the given filter.

Usage example:


The following example shows how to filter a list of programs by the programs recording-status.

    // our list of programs
    IProgramInfoList programs = ...; 
 
    // creating the program filter
    IProgramInfoFilter filter = ProgramInfoFilters.recordingStatus(IProgramRecordingStatus.Status.WILL_RECORD);
 
    // filter programs
    IProgramInfoList filteredPrograms = programs.filter(filter);
 
    // loop through the filtered list 
    for (IProgramInfo program : filteredPrograms) {
       System.out.println(String.format(
          "%1$tF %1$tT- %2$s (%3$s)",
          program.getStartTime(),
          program.getFullTitle(),
          program.getChannelSign()
       ));
    }
 

See ProgramInfoFilters for a list of predefined filters.

Specified by:
filter in interface IProgramInfoList
Parameters:
filter - the program filter to use or null if no filtering should be done
Returns:
a list of filtered program-info objects

multiFilter

public IProgramInfoList[] multiFilter(IProgramInfoFilter... filters)
Description copied from interface: IProgramInfoList
Allows to filter the program list, using multiple filters.

For each filter a list of matching program-info objects is returned.

Specified by:
multiFilter in interface IProgramInfoList
Parameters:
filters - a list of filters
Returns:
an array with the same length as the amount of filters.

get

public IProgramInfo get(int idx)
Description copied from interface: IProgramInfoList
Gets the program-info object at the given index.

Specified by:
get in interface IProgramInfoList
Parameters:
idx - the index
Returns:
the found program

iterator

public Iterator<IProgramInfo> iterator()
Specified by:
iterator in interface Iterable<IProgramInfo>
See Also:
Iterable.iterator()

iterator

public Iterator<IProgramInfo> iterator(IProgramInfoFilter filter)

toString

public String toString()
Description copied from class: AData

Returns the content of this data object as a formatted string.

E.g.
 <0>TOTAL_RAM_MB: 1002 | <1>FREE_RAM_MB: 474 | <2>TOTAL_VM_MB: 853 | <3>FREE_VM_MB: 853
 

Overrides:
toString in class AData<IProgramInfoList.Props>

asMap

public Map<String,IProgramInfo> asMap(IProgramInfoList.MapKey mapKey)
Description copied from interface: IProgramInfoList
Returns a map containing the unique-id of each program as key and the program as value.

The input parameter specifies if the unique program-id or recording-id should be used as key.
Please note that multiple different recordings may have the same program-id but different recording-ids.

Specified by:
asMap in interface IProgramInfoList
Returns:
a mapping between the program-ids and programs

getIndexMap

public Map<String,Integer> getIndexMap(IProgramInfoList.MapKey mapKey)
Description copied from interface: IProgramInfoList
Returns a map containing the unique-id of each program as key and the program-index as value.

The result of this function can be used to determine the index of a program within the program-list.

The input parameter specifies if the unique program-id or recording-id should be used as key.
Please note that multiple different recordings may have the same program-id but different recording-ids.

Specified by:
getIndexMap in interface IProgramInfoList
Returns:
an index list

groupBy

public Map<Object,IProgramInfoList> groupBy(IProgramInfo.Props prop)
Description copied from interface: IProgramInfoList
Groups the list of program-infos by the specified program-info property.

Usage example:

The following example groups all recordings by their storage group.

    // get a list of all recordings
    IProgramInfoList allRecordings = backend.queryRecordings();
    
    // group recordings by storage group
    Map<Object,IProgramInfoList> recordingsByStorageGroup = allRecordings.groupBy(IProgramInfo.Props.STORAGE_GROUP);
    for(Entry<Object,IProgramInfoList> entry : recordingsByStorageGroup.entrySet()) {
       System.out.println(String.format(
          "\r\nSTORAGE-GROUP '%s': %02d recordings",
          entry.getKey(),
          entry.getValue().size()
       ));
       
       for(IProgramInfo program : entry.getValue()) {
          System.out.println(String.format(
             "- %s",
             program.getFullTitle()
          ));
       }
    }
 

Specified by:
groupBy in interface IProgramInfoList
Parameters:
prop - the program-info property that is used for grouping
Returns:
a map containing the found property values as keys and the grouped lists of programs as values

groupBy

public Map<Object,IProgramInfoList> groupBy(IProgramInfo.Props prop,
                                            IProgramInfoFilter filter)
Description copied from interface: IProgramInfoList
Groups the list of program-infos by the specified program-info property. Only programs matching the given program-filter are returned.

Usage example:

The following example groups all recordings by their categories.

    // get a list of all recordings
    IProgramInfoList allRecordings = backend.queryRecordings();
 
    // optionally define a filter
    IProgramInfoFilter filter = null;
    
    // group recordings by category
    Map<Object,IProgramInfoList> recordingsByCategory = allRecordings.groupBy(IProgramInfo.Props.CATEGORY, filter);
    for(Entry<Object,IProgramInfoList> entry : recordingsByCategory.entrySet()) {
       System.out.println(String.format(
          "\r\nCATEGORY '%s': ",
          entry.getKey()
       ));
       			
       for(IProgramInfo program : entry.getValue()) {
          System.out.println(String.format(
             "- %s",
             program.getFullTitle()
          ));
       }
    }
 

Specified by:
groupBy in interface IProgramInfoList
Parameters:
prop - the program-info property that is used for grouping
filter - the program filter to use or null if no filtering should be done
Returns:
a map containing the found property values as keys and the grouped lists of programs as values

getTotalFilesSize

public long getTotalFilesSize()
Description copied from interface: IProgramInfoList
Gets the sum of all file sizes.

Specified by:
getTotalFilesSize in interface IProgramInfoList
Returns:
the total size of all recording files
See Also:
IProgramInfo.getFileSize()

getTotalDuration

public long getTotalDuration()
Description copied from interface: IProgramInfoList
Gets the sum of all recording durations.

Specified by:
getTotalDuration in interface IProgramInfoList
Returns:
the total duration of all recordings
See Also:
IBasicProgramInfo.getDuration()

getTotalFileSize

public static final long getTotalFileSize(Iterable<IProgramInfo> programs)

getTotalDuration

public static final long getTotalDuration(Iterable<IProgramInfo> programs,
                                          boolean checkCurrentTime)

valueOf

public static final ProgramInfoList valueOf(ProtocolVersion protoVersion,
                                            Collection<IProgramInfo> programs)
Converts a collection of program-info objects into a program-info list.

Parameters:
programs - the collection of programs.
Returns:
the created program-info list

emptyList

public static final ProgramInfoList emptyList(ProtocolVersion protoVersion)
Creates an empty program-info list

Parameters:
protoVersion - the protocol version
Returns:
the empty list


Copyright © 2008-2013. All Rights Reserved.