View Javadoc

1   /*--------------------------------------------------------------------------
2    *  Copyright 2007 utgenome.org
3    *
4    *  Licensed under the Apache License, Version 2.0 (the "License");
5    *  you may not use this file except in compliance with the License.
6    *  You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   *  Unless required by applicable law or agreed to in writing, software
11   *  distributed under the License is distributed on an "AS IS" BASIS,
12   *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   *  See the License for the specific language governing permissions and
14   *  limitations under the License.
15   *--------------------------------------------------------------------------*/
16  //--------------------------------------
17  // GenomeBrowser Project
18  //
19  // TrackComparator.java
20  // Since: 2007/06/20
21  //
22  // $URL$ 
23  // $Author$ ssksn
24  //--------------------------------------
25  package org.utgenome.gwt.utgb.client.track;
26  
27  import java.util.Comparator;
28  
29  /**
30   * @author ssksn
31   * 
32   */
33  public class TrackComparator implements Comparator<TrackEntry> {
34  
35  	private static final TrackComparator _comparator = new TrackComparator();
36  
37  	public static TrackComparator getComparator() {
38  		return _comparator;
39  	}
40  
41  	public int compare(TrackEntry arg0, TrackEntry arg1) {
42  		if (arg0 instanceof TrackGroup) {
43  			final TrackGroup trackGroup0 = (TrackGroup) arg0;
44  
45  			if (arg1 instanceof TrackGroup) {
46  				final TrackGroup trackGroup1 = (TrackGroup) arg1;
47  
48  				return trackGroup0.compareTo(trackGroup1);
49  			}
50  			else if (arg1 instanceof Track) {
51  				return 1;
52  			}
53  		}
54  		else if (arg0 instanceof Track) {
55  			final Track track0 = (Track) arg0;
56  
57  			if (arg1 instanceof TrackGroup) {
58  				return -1;
59  			}
60  			else if (arg1 instanceof Track) {
61  				final Track track1 = (Track) arg1;
62  
63  				final TrackInfo trackInfo0 = track0.getTrackInfo();
64  				final TrackInfo trackInfo1 = track1.getTrackInfo();
65  
66  				final String trackName0 = trackInfo0.getTrackName();
67  				final String trackName1 = trackInfo1.getTrackName();
68  
69  				return trackName0.compareTo(trackName1);
70  			}
71  		}
72  
73  		throw new ClassCastException();
74  	}
75  
76  }