1 /** 2 * Copyright 2009 The Apache Software Foundation 3 * 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, software 15 * distributed under the License is distributed on an "AS IS" BASIS, 16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17 * See the License for the specific language governing permissions and 18 * limitations under the License. 19 */ 20 21 package org.apache.hadoop.hbase.io; 22 23 import java.util.*; 24 25 /** 26 * A Static Interface. 27 * Instead of having this code in the the HbaseMapWritable code, where it 28 * blocks the possibility of altering the variables and changing their types, 29 * it is put here in this static interface where the static final Maps are 30 * loaded one time. Only byte[] and Cell are supported at this time. 31 */ 32 public interface CodeToClassAndBack { 33 /** 34 * Static map that contains mapping from code to class 35 */ 36 public static final Map<Byte, Class<?>> CODE_TO_CLASS = 37 new HashMap<Byte, Class<?>>(); 38 39 /** 40 * Static map that contains mapping from class to code 41 */ 42 public static final Map<Class<?>, Byte> CLASS_TO_CODE = 43 new HashMap<Class<?>, Byte>(); 44 45 /** 46 * Class list for supported classes 47 */ 48 public Class<?>[] classList = {byte[].class}; 49 50 /** 51 * The static loader that is used instead of the static constructor in 52 * HbaseMapWritable. 53 */ 54 public InternalStaticLoader sl = 55 new InternalStaticLoader(classList, CODE_TO_CLASS, CLASS_TO_CODE); 56 57 /** 58 * Class that loads the static maps with their values. 59 */ 60 public class InternalStaticLoader{ 61 InternalStaticLoader(Class<?>[] classList, 62 Map<Byte,Class<?>> CODE_TO_CLASS, Map<Class<?>, Byte> CLASS_TO_CODE){ 63 byte code = 1; 64 for(int i=0; i<classList.length; i++){ 65 CLASS_TO_CODE.put(classList[i], code); 66 CODE_TO_CLASS.put(code, classList[i]); 67 code++; 68 } 69 } 70 } 71 }