/*
 * Copyright (c) 2013-2021 Cinchapi Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.cinchapi.concourse.util;

import java.nio.ByteBuffer;

import com.cinchapi.concourse.server.model.Text;

/**
 * Utilities for dealing with generic arrays.
 * 
 * @author Jeff Nelson
 */
public final class TArrays {

    /**
     * Convert an array of objects (possibly of mixed types) to a ByteBuffer.
     * This method, in some sense, is akin to returning a hash of the objects,
     * except the size of the returned buffer will vary depending upon the
     * number of objects that are in the array.
     * <p>
     * This method assumes that the hashCode of the objects in the array are
     * defined in a manner that will yield the same value between JVM sessions.
     * There are no guarantees made about the content of returned ByteBuffer
     * except that objects that are considered equal will always returned byte
     * buffers that are equal.
     * </p>
     * 
     * @param objects
     * @return the hash for the objects
     */
    public static ByteBuffer hash(Object... objects) {
        ByteBuffer bytes = ByteBuffer.allocate(8 * objects.length);
        for (Object object : objects) {
            // We make a best effort to "uniquely" identify each object in
            // the array by that object's hashcode and the name of the
            // object's class.
            bytes.putInt(object.hashCode());

            Class<?> clazz;
            if(object instanceof Text) {
                // Backwards compatibility for versions prior to 0.10.6 that
                // didn't have multiple kinds of Text
                clazz = Text.class;
            }
            else {
                clazz = object.getClass();
            }
            bytes.putInt(clazz.getName().hashCode());
        }
        bytes.rewind();
        return bytes;
    }

}

@@ -662,16 +662,71 @@
 uffer;%0A%0A
+import com.cinchapi.concourse.server.model.Identifier;%0A
 import c
@@ -2013,16 +2013,14 @@
     
-Class%3C?%3E
+String
  cla
@@ -2229,16 +2229,294 @@
 xt.class
+.getName();%0A            %7D%0A            else if(object instanceof Identifier) %7B%0A                // Backwards compatibility for versions prior to 0.11.0 when%0A                // Identifier was named PrimaryKey%0A                clazz = %22com.cinchapi.concourse.server.model.PrimaryKey%22
 ;%0A      
@@ -2583,16 +2583,26 @@
 tClass()
+.getName()
 ;%0A      
@@ -2644,18 +2644,8 @@
 azz.
-getName().
 hash
@@ -2717,9 +2717,8 @@
     %7D%0A%0A%7D
-%0A

fix bug