5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * The contents of this file are subject to the terms
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * of the Common Development and Distribution License
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * (the License). You may not use this file except in
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * compliance with the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * You can obtain a copy of the License at
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * See the License for the specific language governing
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * permission and limitations under the License.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * When distributing Covered Code, include this CDDL
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Header Notice in each file and include the License file
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * If applicable, add the following below the CDDL Header,
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * with the fields enclosed by brackets [] replaced by
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * your own identifying information:
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * $Id: ByteArrayTagOrder.java,v 1.2 2008/06/25 05:52:43 qcheng Exp $
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Fosterpublic class ByteArrayTagOrder implements Comparator {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * Compare two byte arrays, by the order of their tags, as defined in ITU-T
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * X.680, sec. 6.4. (First compare tag classes, then tag numbers, ignoring
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * the constructivity bit.)
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param obj1
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * first byte array to compare.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @param obj2
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * second byte array to compare.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @return negative number if obj1 < obj2, 0 if obj1 == obj2, positive
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * number if obj1 > obj2.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * @exception <code>ClassCastException</code> if either argument is not a
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster * byte array.
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster public final int compare(Object obj1, Object obj2) {
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // tag order is same as byte order ignoring any difference in
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster // the constructivity bit (0x02)
5c099afa7c9361afc2f4477fec0e3018588d7840Allan Foster return (bytes1[0] | 0x20) - (bytes2[0] | 0x20);