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

io.vulpine.lib.kalo.ClassUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright ${YEAR} Elizabeth Harper
 *
 * Licensed 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 io.vulpine.lib.kalo;

import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

class ClassUtils
{
  private static final Map < Class, PropertyAggregator >
    MAPPING = Collections.synchronizedMap(new HashMap <>());

  public static PropertyAggregator parse( final Class type )
  {
    if ( MAPPING.containsKey(type) )
      return MAPPING.get(type);

    final PropertyAggregator map = new PropertyAggregator();

    Class temp = type;
    do {
      map.add(temp);
      temp = temp.getSuperclass();

      for ( final Class c : temp.getInterfaces() ) {
        map.add(c);
      }
    } while ( !temp.equals(Object.class) );

    MAPPING.put(type, map);

    return map;
  }

  public static Class dePrimitive( final Class c )
  {
    if ( int.class.equals(c) )
      return Integer.class;
    if ( double.class.equals(c) )
      return Double.class;
    if ( boolean.class.equals(c) )
      return Boolean.class;
    if ( long.class.equals(c) )
      return Long.class;
    if ( float.class.equals(c) )
      return Float.class;
    if ( byte.class.equals(c) )
      return Byte.class;
    if ( char.class.equals(c) )
      return Character.class;
    if ( short.class.equals(c) )
      return Short.class;
    if ( void.class.equals(c) )
      return Void.class;
    return c;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy