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