Christian Lavoie | afc6d8f | 2011-02-20 02:39:19 +0000 | [diff] [blame] | 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, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | |
| 20 | |
| 21 | package thrift |
| 22 | |
| 23 | func CompareInt(i, j int) int { |
| 24 | if i > j { |
| 25 | return 1 |
| 26 | } |
| 27 | if i < j { |
| 28 | return -1 |
| 29 | } |
| 30 | return 0 |
| 31 | } |
| 32 | |
| 33 | func CompareInt16(i, j int16) int { |
| 34 | if i > j { |
| 35 | return 1 |
| 36 | } |
| 37 | if i < j { |
| 38 | return -1 |
| 39 | } |
| 40 | return 0 |
| 41 | } |
| 42 | |
| 43 | func CompareInt32(i, j int32) int { |
| 44 | if i > j { |
| 45 | return 1 |
| 46 | } |
| 47 | if i < j { |
| 48 | return -1 |
| 49 | } |
| 50 | return 0 |
| 51 | } |
| 52 | |
| 53 | func CompareInt64(i, j int32) int { |
| 54 | if i > j { |
| 55 | return 1 |
| 56 | } |
| 57 | if i < j { |
| 58 | return -1 |
| 59 | } |
| 60 | return 0 |
| 61 | } |
| 62 | |
| 63 | func CompareStringArray(i, j []string) int { |
| 64 | if cmp := CompareInt(len(i), len(j)); cmp != 0 { |
| 65 | return cmp |
| 66 | } |
| 67 | size := len(i) |
| 68 | for k := 0; k < size; k++ { |
| 69 | if cmp := CompareString(i[k], j[k]); cmp != 0 { |
| 70 | return cmp |
| 71 | } |
| 72 | } |
| 73 | return 0 |
| 74 | } |
| 75 | |
| 76 | func CompareString(i, j string) int { |
| 77 | if i > j { |
| 78 | return 1 |
| 79 | } |
| 80 | if i < j { |
| 81 | return -1 |
| 82 | } |
| 83 | return 0 |
| 84 | } |
| 85 | |
| 86 | func CompareFloat(i, j float32) int { |
| 87 | if i > j { |
| 88 | return 1 |
| 89 | } |
| 90 | if i < j { |
| 91 | return -1 |
| 92 | } |
| 93 | return 0 |
| 94 | } |
| 95 | |
| 96 | func CompareDouble(i, j float64) int { |
| 97 | if i > j { |
| 98 | return 1 |
| 99 | } |
| 100 | if i < j { |
| 101 | return -1 |
| 102 | } |
| 103 | return 0 |
| 104 | } |
| 105 | |
| 106 | func CompareByte(i, j byte) int { |
| 107 | if i > j { |
| 108 | return 1 |
| 109 | } |
| 110 | if i < j { |
| 111 | return -1 |
| 112 | } |
| 113 | return 0 |
| 114 | } |
| 115 | |
| 116 | func CompareBool(i, j bool) int { |
| 117 | if i { |
| 118 | if j { |
| 119 | return 0 |
| 120 | } |
| 121 | return 1 |
| 122 | } |
| 123 | if j { |
| 124 | return -1 |
| 125 | } |
| 126 | return 0 |
| 127 | } |