Subversion Repositories SmartDukaan

Rev

Rev 30 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
30 ashish 1
/**
2
 * Licensed to the Apache Software Foundation (ASF) under one
3
 * or more contributor license agreements.  See the NOTICE file
4
 * distributed with this work for additional information
5
 * regarding copyright ownership.  The ASF licenses this file
6
 * to you under the Apache License, Version 2.0 (the
7
 * "License"); you may not use this file except in compliance
8
 * with the License.  You may obtain a copy of the License at
9
 *
10
 *     http://www.apache.org/licenses/LICENSE-2.0
11
 *
12
 * Unless required by applicable law or agreed to in writing, software
13
 * distributed under the License is distributed on an "AS IS" BASIS,
14
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
 * See the License for the specific language governing permissions and
16
 * limitations under the License.
17
 */
18
package org.apache.thrift;
19
 
20
import java.util.List;
21
 
22
public class TBaseHelper {
23
 
24
  public static int compareTo(boolean a, boolean b) {
25
    return Boolean.valueOf(a).compareTo(b);
26
  }
27
 
28
  public static int compareTo(byte a, byte b) {
29
    if (a < b) {
30
      return -1;
31
    } else if (b < a) {
32
      return 1;
33
    } else {
34
      return 0;
35
    }
36
  }
37
 
38
  public static int compareTo(short a, short b) {
39
    if (a < b) {
40
      return -1;
41
    } else if (b < a) {
42
      return 1;
43
    } else {
44
      return 0;
45
    }
46
  }
47
 
48
  public static int compareTo(int a, int b) {
49
    if (a < b) {
50
      return -1;
51
    } else if (b < a) {
52
      return 1;
53
    } else {
54
      return 0;
55
    }
56
  }
57
 
58
  public static int compareTo(long a, long b) {
59
    if (a < b) {
60
      return -1;
61
    } else if (b < a) {
62
      return 1;
63
    } else {
64
      return 0;
65
    }
66
  }
67
 
68
  public static int compareTo(double a, double b) {
69
    if (a < b) {
70
      return -1;
71
    } else if (b < a) {
72
      return 1;
73
    } else {
74
      return 0;
75
    }
76
  }
77
 
78
  public static int compareTo(String a, String b) {
79
    return a.compareTo(b);
80
  }
81
 
82
  public static int compareTo(byte[] a, byte[] b) {
83
    int sizeCompare = compareTo(a.length, b.length);
84
    if (sizeCompare != 0) {
85
      return sizeCompare;
86
    }
87
    for (int i = 0; i < a.length; i++) {
88
      int byteCompare = compareTo(a[i], b[i]);
89
      if (byteCompare != 0) {
90
        return byteCompare;
91
      }
92
    }
93
    return 0;
94
  }
95
 
96
  public static int compareTo(Comparable a, Comparable b) {
97
    return a.compareTo(b);
98
  }
99
 
100
  public static int compareTo(List a, List b) {
101
    int lastComparison = compareTo(a.size(), b.size());
102
    if (lastComparison != 0) {
103
      return lastComparison;
104
    }
105
    for (int i = 0; i < a.size(); i++) {
106
      Object oA = a.get(i);
107
      Object oB = b.get(i);
108
      if (oA instanceof List) {
109
        lastComparison = compareTo((List)oA, (List)oB);
110
      } else {
111
        lastComparison = compareTo((Comparable)oA, (Comparable)oB);
112
      }
113
      if (lastComparison != 0) {
114
        return lastComparison;
115
      }
116
    }
117
    return 0;
118
  }
119
}