KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > types > resources > comparators > ResourceComparator


1 /*
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  */

18 package org.apache.tools.ant.types.resources.comparators;
19
20 import java.util.Comparator JavaDoc;
21
22 import org.apache.tools.ant.types.DataType;
23 import org.apache.tools.ant.types.Resource;
24
25 /**
26  * Abstract Resource Comparator.
27  * @since Ant 1.7
28  */

29 public abstract class ResourceComparator extends DataType implements Comparator JavaDoc {
30
31     /**
32      * Compare two objects.
33      * @param foo the first Object.
34      * @param bar the second Object.
35      * @return a negative integer, zero, or a positive integer as the first
36      * argument is less than, equal to, or greater than the second.
37      * @throws ClassCastException if either argument is null.
38      */

39     public final int compare(Object JavaDoc foo, Object JavaDoc bar) {
40         dieOnCircularReference();
41         ResourceComparator c =
42             isReference() ? (ResourceComparator) getCheckedRef() : this;
43         return c.resourceCompare((Resource) foo, (Resource) bar);
44     }
45
46     /**
47      * Test for equality with this ResourceComparator.
48      * @param o the Object to compare against.
49      * @return true if the specified Object equals this one.
50      */

51     public boolean equals(Object JavaDoc o) {
52         if (isReference()) {
53             return getCheckedRef().equals(o);
54         }
55         if (o == null) {
56             return false;
57         }
58         return o == this || o.getClass().equals(getClass());
59     }
60
61     /**
62      * Hashcode based on the rules for equality.
63      * @return a hashcode.
64      */

65     public synchronized int hashCode() {
66         if (isReference()) {
67             return getCheckedRef().hashCode();
68         }
69         return getClass().hashCode();
70     }
71
72     /**
73      * Compare two Resources.
74      * @param foo the first Resource.
75      * @param bar the second Resource.
76      * @return a negative integer, zero, or a positive integer as the first
77      * argument is less than, equal to, or greater than the second.
78      */

79     protected abstract int resourceCompare(Resource foo, Resource bar);
80
81 }
82
Popular Tags