/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

  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. */
  16. package org.b3log.solo.util.comparator;
  17. import java.util.Comparator;
  18. import java.util.Date;
  19. import org.b3log.solo.model.Article;
  20. import org.json.JSONObject;
  21. /**
  22. * Article comparator by update date.
  23. *
  24. * @author <a href="mailto:DL88250@gmail.com">Liang Ding</a>
  25. * @version 1.0.0.1, Dec 30, 2010
  26. */
  27. public final class ArticleUpdateDateComparator
  28. implements Comparator<JSONObject> {
  29. /**
  30. * Package default constructor.
  31. */
  32. ArticleUpdateDateComparator() {
  33. }
  34. @Override
  35. public int compare(final JSONObject article1, final JSONObject article2) {
  36. try {
  37. final Date date1 = (Date) article1.get(Article.ARTICLE_UPDATE_DATE);
  38. final Date date2 = (Date) article2.get(Article.ARTICLE_UPDATE_DATE);
  39. return date2.compareTo(date1);
  40. } catch (final Exception e) {
  41. throw new IllegalStateException(e);
  42. }
  43. }
  44. }