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

org.apache.metamodel.hbase.HBaseFamilyMap Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/**
 * 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 org.apache.metamodel.hbase;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;
import java.util.NavigableMap;
import java.util.Set;

public class HBaseFamilyMap implements Map {

    private final NavigableMap _map;

    public HBaseFamilyMap(NavigableMap map) {
        _map = map;
    }

    @Override
    public int size() {
        return _map.size();
    }

    @Override
    public boolean isEmpty() {
        return _map.isEmpty();
    }

    @Override
    public boolean containsKey(Object key) {
        return _map.containsKey(ByteUtils.toBytes(key));
    }

    @Override
    public boolean containsValue(Object value) {
        return _map.containsValue(ByteUtils.toBytes(value));
    }

    @Override
    public Object get(Object key) {
        return _map.get(ByteUtils.toBytes(key));
    }

    @Override
    public Object put(Object key, Object value) {
        throw new UnsupportedOperationException("HBase row value map is immutable");
    }

    @Override
    public Object remove(Object key) {
        throw new UnsupportedOperationException("HBase row value map is immutable");
    }

    @Override
    public void putAll(Map m) {
        throw new UnsupportedOperationException("HBase row value map is immutable");
    }

    @Override
    public void clear() {
        throw new UnsupportedOperationException("HBase row value map is immutable");
    }

    @SuppressWarnings("unchecked")
    @Override
    public Set keySet() {
        Set keySet = _map.keySet();
        return (Set) keySet;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Collection values() {
        Collection values = _map.values();
        return (Collection) values;
    }

    @SuppressWarnings("unchecked")
    @Override
    public Set> entrySet() {
        final Set entrySet = _map.entrySet();
        return (Set>) entrySet;
    }

    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        sb.append('{');
        for (java.util.Map.Entry entry : _map.entrySet()) {
            if (sb.length() > 1) {
                sb.append(',');
            }
            sb.append(Arrays.toString(entry.getKey()));
            sb.append('=');
            sb.append(Arrays.toString(entry.getValue()));
        }
        sb.append('}');
        return sb.toString();
    }
}