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

com.hazelcast.query.impl.AbstractIndex Maven / Gradle / Ivy

The newest version!
/*
 * Copyright (c) 2008-2024, Hazelcast, Inc. All Rights Reserved.
 *
 * 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.hazelcast.query.impl;

import com.hazelcast.nio.ObjectDataInput;
import com.hazelcast.nio.ObjectDataOutput;
import com.hazelcast.query.impl.predicates.PredicateDataSerializerHook;

import static com.hazelcast.query.impl.CompositeValue.NEGATIVE_INFINITY;

/**
 * Provides an abstract base for indexes.
 */
@SuppressWarnings({"rawtypes", "methodcount"})
public abstract class AbstractIndex {

    /**
     * Represents a null-like value that is equal to itself and less than any
     * other value except {@link CompositeValue#NEGATIVE_INFINITY}. The latter
     * is needed to establish the ordering of keys for composite indexes.
     */
    public static final ComparableIdentifiedDataSerializable NULL = new NullObject();

    private static final class NullObject implements ComparableIdentifiedDataSerializable {

        @SuppressWarnings("NullableProblems")
        @Override
        public int compareTo(Object o) {
            if (this == o) {
                return 0;
            }
            return o == NEGATIVE_INFINITY ? +1 : -1;
        }

        @Override
        public int hashCode() {
            return 0;
        }

        @Override
        public boolean equals(Object obj) {
            return this == obj;
        }

        @Override
        public String toString() {
            return "NULL";
        }

        @Override
        public void writeData(ObjectDataOutput out) {
            // nothing to serialize
        }

        @Override
        public void readData(ObjectDataInput in) {
            // nothing to deserialize
        }

        @Override
        public int getFactoryId() {
            return PredicateDataSerializerHook.F_ID;
        }

        @Override
        public int getClassId() {
            return PredicateDataSerializerHook.NULL_OBJECT;
        }

    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy