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

edu.isi.nlp.ClassUtils Maven / Gradle / Ivy

The newest version!
package edu.isi.nlp;

import com.google.common.base.Function;

/** Utility methods for working with Class objects */
public final class ClassUtils {

  private ClassUtils() {
    throw new UnsupportedOperationException();
  }

  /** A Guava {@link Function} to convert classes to their names. Does not accept {@code null}. */
  public static Function nameFunction() {
    return ClassUtils.ClassNameFunction.INSTANCE;
  }

  private enum ClassNameFunction implements Function {
    INSTANCE;

    @Override
    public String apply(final Class input) {
      return input.getName();
    }
  }

  /** A {@link Function} mapping objects to their {@link Class}. Does not accept {@code null}. */
  public static Function> classFunction() {
    return ClassFunction.INSTANCE;
  }

  private enum ClassFunction implements Function> {
    INSTANCE;

    @Override
    public Class apply(final Object input) {
      return input.getClass();
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy