All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.softicar.platform.common.container.comparator.ByteArrayComparator Maven / Gradle / Ivy

Go to download

The SoftiCAR Platform is a lightweight, Java-based library to create interactive business web applications.

There is a newer version: 50.0.0
Show newest version
package com.softicar.platform.common.container.comparator;

import java.util.Comparator;

/**
 * This is a simple comparator for byte arrays.
 * 

* The given arrays are compared lexicographically to produce an ascending * order. * * @author Oliver Richers */ public class ByteArrayComparator implements Comparator { private static ByteArrayComparator singleton = new ByteArrayComparator(); /** * Returns the singleton instance of this comparator. * * @return comparator singleton */ public static ByteArrayComparator get() { return singleton; } /** * Compares the byte arrays using the * {@link #compareArraysAscending(byte[], byte[])} method. */ @Override public int compare(byte[] left, byte[] right) { return compareArraysAscending(left, right); } /** * Compares the given byte arrays to produce an ascending order. *

* The arrays are compared lexicographically. * * @param left * the first byte * @param right * the second byte * @return negative if left is less than right, positive if right is less * than left, zero if left equals right */ public static int compareArraysAscending(byte[] left, byte[] right) { int n = Math.min(left.length, right.length); for (int i = 0; i < n; ++i) { int cmp = ByteComparator.compareBytesAscending(left[i], right[i]); if (cmp != 0) { return cmp; } } return left.length - right.length; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy