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

com.softicar.platform.common.container.comparator.ByteComparator 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;

/**
 * Compares primitive bytes.
 * 

* All integral types can easily be compared using subtraction, but some * developers have problems to quickly determine how to produce an ascending or * descending order. By default an ascending order is used. * * @author Oliver Richers */ public class ByteComparator implements Comparator { private static ByteComparator singleton = new ByteComparator(); /** * Returns the singleton instance of this comparator. * * @return comparator singleton */ public static ByteComparator get() { return singleton; } /** * Compares the bytes using the {@link #compareBytesAscending(byte, byte)} * method. */ @Override public int compare(Byte left, Byte right) { return compareBytesAscending(left, right); } /** * Compares the given bytes to produce an ascending order. * * @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 compareBytesAscending(byte left, byte right) { return left - right; } /** * Compares the given bytes to produce a descending order. * * @param left * the first byte * @param right * the second byte * @return positive if left is less than right, negative if right is less * than left, zero if left equals right */ public static int compareBytesDescending(byte left, byte right) { return right - left; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy