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

org.yamcs.yarch.RawTuple Maven / Gradle / Ivy

There is a newer version: 5.10.9
Show newest version
package org.yamcs.yarch;

import java.util.Comparator;

import com.google.common.primitives.UnsignedBytes;


public abstract class RawTuple implements Comparable{
    protected int index; //used for sorting tuples with equals keys
    protected abstract byte[] getKey();
    protected abstract byte[] getValue();
    
    static Comparator bytesComparator=UnsignedBytes.lexicographicalComparator();

    public static Comparator reverseComparator = new Comparator() {
        @Override
        public int compare(RawTuple o1, RawTuple o2) {
            return -o1.compareTo(o2);
        }
    };

    public RawTuple(int index) {
        this.index=index;
    }

    @Override
    public int compareTo(RawTuple o) {
        int c = bytesComparator.compare(getKey(), o.getKey());
        if(c!=0) return c;
        return (index-o.index);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy