/src/main/java/com/google/ie/common/comparator/ProjectCreationDateComparator.java

http://thoughtsite.googlecode.com/ · Java · 41 lines · 12 code · 7 blank · 22 comment · 0 complexity · 02a6f76c46855769c4c7e950db12ad8c MD5 · raw file

  1. /* Copyright 2010 Google Inc.
  2. *
  3. * Licensed under the Apache License, Version 2.0 (the "License");
  4. * you may not use this file except in compliance with the License.
  5. * You may obtain a copy of the License at
  6. *
  7. * http://www.apache.org/licenses/LICENSE-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.
  11. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. * See the License for the specific language governing permissions and
  13. * limitations under the License
  14. */
  15. package com.google.ie.common.comparator;
  16. import com.google.ie.business.domain.Project;
  17. import java.util.Comparator;
  18. import java.util.Date;
  19. /**
  20. * Comparator class to compare the project based on their creation date.
  21. *
  22. * @author Charanjeet singh
  23. *
  24. */
  25. public class ProjectCreationDateComparator implements Comparator<Project> {
  26. @Override
  27. public int compare(Project project1, Project project2) {
  28. Date creationDate1 = project1.getCreatedOn();
  29. Date creationDate2 = project2.getCreatedOn();
  30. // Multiplying the result of date comparison to sort the dates in
  31. // descending order.
  32. return (-1 * creationDate1.compareTo(creationDate2));
  33. }
  34. }