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.ivy.plugins.latest;
19:
20: import java.util.Comparator;
21:
22: public class LatestLexicographicStrategy extends
23: ComparatorLatestStrategy {
24: /**
25: * Compares two revisions. Revisions are compared lexicographically unless a 'latest' revision
26: * is found. If the latest revision found is an absolute latest (latest. like), then it is
27: * assumed to be the greater. If a partial latest is found, then it is assumed to be greater
28: * than any matching fixed revision.
29: */
30: private static final Comparator COMPARATOR = new Comparator() {
31: public int compare(Object o1, Object o2) {
32: String rev1 = ((ArtifactInfo) o1).getRevision();
33: String rev2 = ((ArtifactInfo) o2).getRevision();
34: if (rev1.startsWith("latest")) {
35: return 1;
36: }
37: if (rev1.endsWith("+")
38: && rev2.startsWith(rev1.substring(0,
39: rev1.length() - 1))) {
40: return 1;
41: }
42: if (rev2.startsWith("latest")) {
43: return -1;
44: }
45: if (rev2.endsWith("+")
46: && rev1.startsWith(rev2.substring(0,
47: rev2.length() - 1))) {
48: return -1;
49: }
50: return rev1.compareTo(rev2);
51: }
52:
53: };
54:
55: public LatestLexicographicStrategy() {
56: super (COMPARATOR);
57: setName("latest-lexico");
58: }
59:
60: }
|