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

net.openhft.chronicle.algo.bytes.Accessor Maven / Gradle / Ivy

There is a newer version: 2.27ea0
Show newest version
/*
 *     Copyright (C) 2015  higherfrequencytrading.com
 *
 *     This program is free software: you can redistribute it and/or modify
 *     it under the terms of the GNU Lesser General Public License as published by
 *     the Free Software Foundation, either version 3 of the License.
 *
 *     This program is distributed in the hope that it will be useful,
 *     but WITHOUT ANY WARRANTY; without even the implied warranty of
 *     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *     GNU Lesser General Public License for more details.
 *
 *     You should have received a copy of the GNU Lesser General Public License
 *     along with this program.  If not, see .
 */

package net.openhft.chronicle.algo.bytes;

import net.openhft.chronicle.bytes.BytesStore;

import java.nio.ByteBuffer;
import java.nio.ByteOrder;

public interface Accessor> {

    static , U> Accessor.Full checkedBytesStoreAccessor() {
        return BytesAccessors.Generic.INSTANCE;
    }

    static Accessor.Full uncheckedByteBufferAccessor(
            ByteBuffer buffer) {
        return ByteBufferAccessor.unchecked(buffer);
    }

    static Accessor.Full booleanArrayAccessor() {
        return ArrayAccessors.Boolean.INSTANCE;
    }

    static Accessor.Full byteArrayAccessor() {
        return ArrayAccessors.Byte.INSTANCE;
    }

    static Accessor.Full charArrayAccessor() {
        return ArrayAccessors.Char.INSTANCE;
    }

    static Accessor.Full shortArrayAccessor() {
        return ArrayAccessors.Short.INSTANCE;
    }

    static Accessor.Full intArrayAccessor() {
        return ArrayAccessors.Int.INSTANCE;
    }

    static Accessor.Full longArrayAccessor() {
        return ArrayAccessors.Long.INSTANCE;
    }

    static Accessor.Read stringAccessor() {
        return (Read) CharSequenceAccessor.stringAccessor;
    }

    static Accessor.Read checkedNativeCharSequenceAccessor() {
        return CharSequenceAccessor.nativeCharSequenceAccessor();
    }

    static Accessor.Read checkedCharSequenceAccess(ByteOrder order) {
        return order == ByteOrder.LITTLE_ENDIAN ? CharSequenceAccessor.LITTLE_ENDIAN :
                CharSequenceAccessor.BIG_ENDIAN;
    }

    /**
     * Returns {@code Access} for the given source.
     *
     * @return {@code Access} for the given source
     */
    A access();

    /**
     * Returns handle for {@code Access} to the given source.
     *
     * @param source the source
     * @return handle for {@code Access} to the given source
     */
    T handle(S source);

    /**
     * Convert index in the source domain to {@code Access} offset.
     *
     * @param source the source
     * @param index  index in the source type domain
     * @return offset for {@code Access}, corresponding to the given index
     */
    long offset(S source, long index);

    /**
     * Convert size (length) in the source domain to size in bytes.
     * 

* The default implementation returns the given {@code size} back, i. e. assuming * byte-indexed source. * * @param size size (length) in the source type domain * @return number of bytes, corresponding to the given size in the source type domain */ default long size(long size) { return size; } interface Read extends Accessor> { } interface Full extends Accessor> { } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy