1. /*
  2. * Copyright 2003-2004 The Apache Software Foundation
  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. */
  17. package org.apache.tools.ant.types.selectors.modifiedselector;
  18. import java.util.Comparator;
  19. /**
  20. * Simple implementation of Comparator for use in CacheSelector.
  21. * compare() returns '0' (should not be selected) if both parameter
  22. * are equal otherwise '1' (should be selected).
  23. *
  24. * @version 2003-09-13
  25. * @since Ant 1.6
  26. */
  27. public class EqualComparator implements Comparator {
  28. /**
  29. * Implements Comparator.compare().
  30. * @param o1 the first object
  31. * @param o2 the second object
  32. * @return 0, if both are equal, otherwise 1
  33. */
  34. public int compare(Object o1, Object o2) {
  35. if (o1 == null) {
  36. if (o2 == null) {
  37. return 1;
  38. } else {
  39. return 0;
  40. }
  41. } else {
  42. return (o1.equals(o2)) ? 0 : 1;
  43. }
  44. }
  45. /**
  46. * Override Object.toString().
  47. * @return information about this comparator
  48. */
  49. public String toString() {
  50. return "EqualComparator";
  51. }
  52. }