1 /*--------------------------------------------------------------------------
2 * Copyright 2010 utgenome.org
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *--------------------------------------------------------------------------*/
16 //--------------------------------------
17 // utgb-core Project
18 //
19 // LongArray.java
20 // Since: 2010/10/27
21 //
22 //--------------------------------------
23 package org.utgenome.util.aligner;
24
25 /**
26 * Uint32 value
27 *
28 * @author leo
29 *
30 */
31 public class UInt32 implements Comparable<UInt32> {
32
33 private final byte[] value;
34
35 public UInt32(long v) {
36 value = new byte[4];
37 value[0] = (byte) ((v >> 24) & 0xFF);
38 value[1] = (byte) ((v >> 16) & 0xFF);
39 value[2] = (byte) ((v >> 8) & 0xFF);
40 value[3] = (byte) (v & 0xFF);
41 }
42
43 public int compareTo(UInt32 o) {
44 for (int i = 0; i < 4; ++i) {
45 int left = value[i] & 0xFF;
46 int right = o.value[i] & 0xFF;
47 int diff = left - right;
48 if (diff != 0)
49 return diff;
50 }
51 return 0;
52 }
53
54 public long toLong() {
55 long v = 0;
56 for (int i = 0; i < 3; i++) {
57 v |= value[i] & 0xFF;
58 v <<= 8;
59 }
60 v |= value[3] & 0xFF;
61 return v;
62 }
63
64 @Override
65 public String toString() {
66 return Long.toString(toLong());
67 }
68
69 }