Package com.salesforce.phoenix.schema

Source Code of com.salesforce.phoenix.schema.PNameImpl$PNameImplData

/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements.  See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership.  The ASF licenses this file
* to you 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.salesforce.phoenix.schema;

import org.apache.hadoop.hbase.util.Bytes;
import org.apache.http.annotation.Immutable;

import com.salesforce.hbase.index.util.ImmutableBytesPtr;

@Immutable
public class PNameImpl implements PName {
    /**
     */
    private static class PNameImplData {
        /**  */
        public String stringName;
        /**  */
        public byte[] bytesName;
        /**  */
        public ImmutableBytesPtr ptr;

        /**
         *
         */
        public PNameImplData() {
        }
    }
    private PNameImplData data = new PNameImplData();

    PNameImpl(String name) {
        this.data.stringName = name;
        this.data.bytesName = Bytes.toBytes(name);
    }

    PNameImpl(byte[] name) {
        this.data.stringName = Bytes.toString(name);
        this.data.bytesName = name;
    }

    @Override
    public String getString() {
        return data.stringName;
    }

    @Override
    public byte[] getBytes() {
        return data.bytesName;
    }

    @Override
    public ImmutableBytesPtr getBytesPtr() {
        if (data.ptr == null) {
            synchronized (data.bytesName) {
                if (data.ptr == null) {
                    this.data.ptr = new ImmutableBytesPtr(data.bytesName);
                }
            }
        }
        return this.data.ptr;
    }

    @Override
    public int hashCode() {
        final int prime = 31;
        int result = 1;
        result = prime * result + data.stringName.hashCode();
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if (this == obj) return true;
        if (obj == null) return false;
        if (getClass() != obj.getClass()) return false;
        PNameImpl other = (PNameImpl) obj;
        // Compare normalized stringName for equality, since bytesName
        // may differ since it remains case sensitive.
        if (!data.stringName.equals(other.data.stringName)) return false;
        return true;
    }

    @Override
    public String toString() {
        return data.stringName;
    }
}
TOP

Related Classes of com.salesforce.phoenix.schema.PNameImpl$PNameImplData

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.