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 package org.apache.directory.mavibot.btree.comparator; 21 22 23 import java.util.Comparator; 24 25 26 /** 27 * Compares Longs 28 * 29 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a> 30 */ 31 public class LongComparator implements Comparator<Long> 32 { 33 /** A static instance of a LongComparator */ 34 public static final LongComparator INSTANCE = new LongComparator(); 35 36 /** 37 * A private constructor of the BooleanArrayComparator class 38 */ 39 private LongComparator() 40 { 41 } 42 /** 43 * Compare two longs. 44 * 45 * @param long1 First long 46 * @param long2 Second long 47 * @return 1 if long1 > long2, 0 if long1 == long2, -1 if long1 < long2 48 */ 49 public int compare( Long long1, Long long2 ) 50 { 51 if ( long1 == long2 ) 52 { 53 return 0; 54 } 55 56 if ( long1 == null ) 57 { 58 if ( long2 == null ) 59 { 60 return 0; 61 } 62 else 63 { 64 return -1; 65 } 66 } 67 else 68 { 69 if ( long2 == null ) 70 { 71 return 1; 72 } 73 else 74 { 75 if ( long1 < long2 ) 76 { 77 return -1; 78 } 79 else if ( long1 > long2 ) 80 { 81 return 1; 82 } 83 else 84 { 85 return 0; 86 } 87 } 88 } 89 } 90 }