1 /**
2 * Copyright 2011-2012 The Kuali Foundation Licensed under the Educational
3 * Community License, Version 2.0 (the "License"); you may not use this file
4 * except in compliance with the License. You may obtain a copy of the License
5 * at
6 *
7 * http://www.osedu.org/licenses/ECL-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12 * License for the specific language governing permissions and limitations under
13 * the License.
14 */
15 package org.kuali.mobility.news.util;
16
17 import org.kuali.mobility.news.entity.NewsSource;
18
19 import java.util.Comparator;
20
21 /**
22 * An interface for a contract for interacting with the news entity objects.
23 *
24 * @author Kuali Mobility Team (mobility.dev@kuali.org)
25 */
26 public class NewsServiceSort implements Comparator<NewsSource> {
27 @Override
28 public int compare(NewsSource a, NewsSource b) {
29 int comp;
30 if( null == a ) {
31 comp = -42;
32 } else if( null == b ) {
33 comp = 42;
34 } else {
35 comp = a.getOrder() - b.getOrder();
36 if( comp == 0 && a.getTitle() != null && b.getTitle() != null) {
37 comp = a.getTitle().compareTo(b.getTitle());
38 }
39 }
40 return comp;
41 }
42 }