01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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 org.apache.tools.ant.BuildException;
21: import org.apache.tools.ant.types.Resource;
22:
23: /**
24: * Reverses another ResourceComparator. If no nested ResourceComparator
25: * is supplied, the compared Resources' natural order will be reversed.
26: * @since Ant 1.7
27: */
28: public class Reverse extends ResourceComparator {
29: private static final String ONE_NESTED = "You must not nest more than one ResourceComparator for reversal.";
30:
31: private ResourceComparator nested;
32:
33: /**
34: * Default constructor.
35: */
36: public Reverse() {
37: }
38:
39: /**
40: * Construct a new Reverse, supplying the ResourceComparator to be reversed.
41: * @param c the ResourceComparator to reverse.
42: */
43: public Reverse(ResourceComparator c) {
44: add(c);
45: }
46:
47: /**
48: * Add the ResourceComparator to reverse.
49: * @param c the ResourceComparator to add.
50: */
51: public void add(ResourceComparator c) {
52: if (nested != null) {
53: throw new BuildException(ONE_NESTED);
54: }
55: nested = c;
56: }
57:
58: /**
59: * Compare two Resources.
60: * @param foo the first Resource.
61: * @param bar the second Resource.
62: * @return a negative integer, zero, or a positive integer as the first
63: * argument is greater than, equal to, or less than the second.
64: */
65: protected int resourceCompare(Resource foo, Resource bar) {
66: return -1
67: * (nested == null ? foo.compareTo(bar) : nested
68: .compare(foo, bar));
69: }
70:
71: }
|