Java ByteBuffer Set equals(final ByteBuffer keyValue, final int offset, final int keyLen, final byte[] otherKey)

Here you can find the source of equals(final ByteBuffer keyValue, final int offset, final int keyLen, final byte[] otherKey)

Description

Equals.

License

Open Source License

Parameter

Parameter Description
keyValue the key value
offset the offset
keyLen the key len
otherKey the other key

Return

true, if successful

Declaration

public static boolean equals(final ByteBuffer keyValue, final int offset, final int keyLen,
        final byte[] otherKey) 

Method Source Code

//package com.java2s;
/*******************************************************************************
* Copyright (c) 2013 Vladimir Rodionov. All Rights Reserved
*
* This code is released under the GNU Affero General Public License.
*
* See: http://www.fsf.org/licensing/licenses/agpl-3.0.html
*
* VLADIMIR RODIONOV MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY
* OF THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
* IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR
* NON-INFRINGEMENT. Vladimir Rodionov SHALL NOT BE LIABLE FOR ANY DAMAGES SUFFERED
* BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING THIS SOFTWARE OR
* ITS DERIVATIVES.//from  www  .  j  av a  2s .  c  o m
*
* Author: Vladimir Rodionov
*
*******************************************************************************/

import java.nio.ByteBuffer;

public class Main {
    /**
     * Equals.
     *
     * @param s the s
     * @param key the key
     * @return true, if successful
     */
    public final static boolean equals(final byte[] s, final byte[] key) {
        if (key.length != s.length)
            return false;
        for (int i = 0; i < s.length; i++) {
            if (s[i] != key[i]) {
                System.out.println("Failed at " + i + " of " + s.length);
                return false;
            }
        }
        return true;
    }

    /**
     * Equals.
     *
     * @param keyValue the key value
     * @param offset the offset
     * @param keyLen the key len
     * @param otherKey the other key
     * @return true, if successful
     */
    public static boolean equals(final ByteBuffer keyValue, final int offset, final int keyLen,
            final byte[] otherKey) {
        for (int i = offset; i < offset + keyLen; i++) {
            if (keyValue.get(i) != otherKey[i - offset])
                return false;
        }
        return true;
    }
}

Related

  1. byteBuffersToString(ByteBuffer[] bufs, Charset cs)
  2. byteIndexOf(ByteBuffer buffer, byte[] temp, int offset)
  3. c_memset(ByteBuffer b, int c_, int size)
  4. charSequence2ByteBuffer(CharSequence cs, Charset charset)
  5. charstoUTF8Bytes(char[] srcBuf, int srcOffset, int srcLength, ByteBuffer dest, int destOffset)
  6. find(ByteBuffer buffer, int offset, byte searchKey)
  7. findCommonPrefix(ByteBuffer buffer, int offsetLeft, int offsetRight, int limit)
  8. from(ByteBuffer buffer, int offset)
  9. fromListToSetByteArray(List list)