source: release-kits/lirk3/bin/ant-installer/src/org/tp23/antinstaller/runtime/logic/StringLengthComparator.java@ 14982

Last change on this file since 14982 was 14982, checked in by oranfry, 16 years ago

initial import of LiRK3

File size: 1.3 KB
Line 
1/*
2 * Licensed under the Apache License, Version 2.0 (the "License");
3 * you may not use this file except in compliance with the License.
4 * You may obtain a copy of the License at
5 *
6 * http://www.apache.org/licenses/LICENSE-2.0
7 *
8 * Unless required by applicable law or agreed to in writing, software
9 * distributed under the License is distributed on an "AS IS" BASIS,
10 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11 * See the License for the specific language governing permissions and
12 * limitations under the License.
13 */
14
15package org.tp23.antinstaller.runtime.logic;
16
17import java.util.Comparator;
18
19import org.apache.tools.ant.taskdefs.Length;
20
21/**
22 * Compare strings based on their length. Used by ExpressionBuilder to ensure
23 * that longest match is attempted first.
24 *
25 * @author mwilson
26 * @version $Id: StringLengthComparator.java,v 1.1 2006/09/08 19:16:31
27 * anothermwilson Exp $
28 * @since 0.7.4 patch 2
29 */
30
31public class StringLengthComparator implements Comparator {
32
33 /**
34 * Sort by descending String length
35 *
36 * @param o1 first string
37 * @param o2 second string
38 * @return difference between the length of o2 and o1
39 */
40 public int compare(Object o1, Object o2) {
41 String str1 = (String) o1;
42 String str2 = (String) o2;
43 return (str2.length() - str1.length());
44 }
45
46}
Note: See TracBrowser for help on using the repository browser.