~ubuntu-branches/ubuntu/trusty/freeguide/trusty

« back to all changes in this revision

Viewing changes to src/freeguide/common/lib/fgspecific/data/TVProgrammeOverlapIsEqualComparator.java

  • Committer: Bazaar Package Importer
  • Author(s): Daniel Watkins
  • Date: 2008-09-07 15:49:32 UTC
  • mfrom: (1.2.6 upstream) (4.1.2 squeeze)
  • Revision ID: james.westby@ubuntu.com-20080907154932-2jvgv76btq068fe0
Tags: 0.10.9-1
* New upstream release. (Closes: #492789)
* Moved package from contrib to main. (Closes: #492544)
* Added lintian override for 'build-depends-without-arch-dep ant', as ant is
  used in the clean target.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
package freeguide.common.lib.fgspecific.data;
 
2
 
 
3
public class TVProgrammeOverlapIsEqualComparator implements java.util.Comparator
 
4
{
 
5
 
 
6
    /**
 
7
     * Compare two programmes by their datetimes.
 
8
     *
 
9
     * @param prog1 A TVProgramme
 
10
     * @param prog2 another TVProgramme
 
11
     *
 
12
     * @return -1 if prog1 comes first,
 
13
     *          1 if prog2 comes first, and
 
14
     *          0 if they overlap.
 
15
     */
 
16
    public int compare( Object prog1, Object prog2 )
 
17
    {
 
18
        TVProgramme p1 = (TVProgramme)( prog1 );
 
19
        TVProgramme p2 = (TVProgramme)( prog2 );
 
20
 
 
21
        // If the end times have not been downloaded, we
 
22
        // must compare purely by start time.
 
23
        // If both end times are valid, we delare them equal if
 
24
        // They overlap at all, so we don't get overlapping
 
25
        // programmes showing.
 
26
        if( p1.getEnd() == 0 || p2.getEnd() == 0 )
 
27
        {
 
28
            if( p1.getStart() < p2.getStart() )
 
29
            {
 
30
                return -1;
 
31
            }
 
32
            else if( p1.getStart() > p2.getStart() )
 
33
            {
 
34
                return 1;
 
35
            }
 
36
            else
 
37
            {
 
38
                // If the start times are the same, they definitely overlap!
 
39
                return 0;
 
40
            }
 
41
        }
 
42
        else if( p1.getEnd() <= p2.getStart() )
 
43
        {
 
44
            return -1;
 
45
        }
 
46
        else if( p2.getEnd() <= p1.getStart() )
 
47
        {
 
48
            return 1;
 
49
        }
 
50
 
 
51
        return 0;
 
52
    }
 
53
 
 
54
}