PageRenderTime 20ms CodeModel.GetById 16ms app.highlight 2ms RepoModel.GetById 0ms app.codeStats 0ms

/core/src/main/java/org/b3log/solo/util/comparator/ArticleUpdateDateComparator.java

http://github.com/b3log/b3log-solo
Java | 49 lines | 20 code | 5 blank | 24 comment | 0 complexity | 4c25f75fc3af5d31fa3515f66c0ebf04 MD5 | raw file
Possible License(s): Apache-2.0, LGPL-2.1
 1/*
 2 * Copyright (c) 2009, 2010, 2011, 2012, B3log Team
 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 */
16package org.b3log.solo.util.comparator;
17
18import java.util.Comparator;
19import java.util.Date;
20import org.b3log.solo.model.Article;
21import org.json.JSONObject;
22
23/**
24 * Article comparator by update date.
25 *
26 * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
27 * @version 1.0.0.1, Dec 30, 2010
28 */
29public final class ArticleUpdateDateComparator
30        implements Comparator<JSONObject> {
31
32    /**
33     * Package default constructor.
34     */
35    ArticleUpdateDateComparator() {
36    }
37
38    @Override
39    public int compare(final JSONObject article1, final JSONObject article2) {
40        try {
41            final Date date1 = (Date) article1.get(Article.ARTICLE_UPDATE_DATE);
42            final Date date2 = (Date) article2.get(Article.ARTICLE_UPDATE_DATE);
43
44            return date2.compareTo(date1);
45        } catch (final Exception e) {
46            throw new IllegalStateException(e);
47        }
48    }
49}