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

http://thoughtsite.googlecode.com/ · Java · 48 lines · 12 code · 8 blank · 28 comment · 0 complexity · 8f8a9d464becef40d6e83181f2b91220 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.Tag;
  17. import java.util.Comparator;
  18. /**
  19. * An object that compares {@link Tag} objects with respect to their titles
  20. *
  21. * @author Sachneet
  22. *
  23. */
  24. public final class TagTitleComparator implements Comparator<Tag> {
  25. /**
  26. * A shared default instance of this comparator.This is the only instance
  27. * available for this comparator.
  28. */
  29. public static final TagTitleComparator TAG_TITLE_COMPARATOR = new TagTitleComparator();
  30. @Override
  31. public int compare(Tag tag1, Tag tag2) {
  32. return tag1.getTitle().compareTo(tag2.getTitle());
  33. }
  34. /*
  35. * Suppresses default constructor, ensuring no instance is created from
  36. * outside the class.
  37. */
  38. private TagTitleComparator() {
  39. }
  40. }