HBASE-26921 Rewrite the counting cells part in TestMultiVersions (#4316)
[hbase.git] / hbase-common / src / main / java / org / apache / hadoop / hbase / util / Classes.java
blobc52a09c8a6f3acdf205f4378bc22a3459305cb87
1 /*
2 * Copyright The Apache Software Foundation
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
12 * http://www.apache.org/licenses/LICENSE-2.0
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.
20 package org.apache.hadoop.hbase.util;
22 import org.apache.yetus.audience.InterfaceAudience;
24 /**
25 * Utilities for class manipulation.
27 @InterfaceAudience.Private
28 public class Classes {
30 /**
31 * Equivalent of {@link Class#forName(String)} which also returns classes for
32 * primitives like <code>boolean</code>, etc.
34 * @param className
35 * The name of the class to retrieve. Can be either a normal class or
36 * a primitive class.
37 * @return The class specified by <code>className</code>
38 * @throws ClassNotFoundException
39 * If the requested class can not be found.
41 public static Class<?> extendedForName(String className)
42 throws ClassNotFoundException {
43 Class<?> valueType;
44 if (className.equals("boolean")) {
45 valueType = boolean.class;
46 } else if (className.equals("byte")) {
47 valueType = byte.class;
48 } else if (className.equals("short")) {
49 valueType = short.class;
50 } else if (className.equals("int")) {
51 valueType = int.class;
52 } else if (className.equals("long")) {
53 valueType = long.class;
54 } else if (className.equals("float")) {
55 valueType = float.class;
56 } else if (className.equals("double")) {
57 valueType = double.class;
58 } else if (className.equals("char")) {
59 valueType = char.class;
60 } else {
61 valueType = Class.forName(className);
63 return valueType;
66 public static String stringify(Class<?>[] classes) {
67 StringBuilder buf = new StringBuilder();
68 if (classes != null) {
69 for (Class<?> c : classes) {
70 if (buf.length() > 0) {
71 buf.append(",");
73 buf.append(c.getName());
75 } else {
76 buf.append("NULL");
78 return buf.toString();
81 @SuppressWarnings("unchecked")
82 public static <T> Class<T> cast(Class<?> clazz) {
83 return (Class<T>) clazz;