Example usage for org.apache.hadoop.conf Configuration getClasses

List of usage examples for org.apache.hadoop.conf Configuration getClasses

Introduction

In this page you can find the example usage for org.apache.hadoop.conf Configuration getClasses.

Prototype

public Class<?>[] getClasses(String name, Class<?>... defaultValue) 

Source Link

Document

Get the value of the name property as an array of Class.

Usage

From source file:com.facebook.hiveio.conf.ClassConfOption.java

License:Apache License

/**
 * Get classes from a property that all implement a given interface.
 *
 * @param conf Configuration//  w ww  .  j  a  va2  s  . c o  m
 * @param name String name of property to fetch.
 * @param xface interface classes must implement.
 * @param defaultValue If not found, return this
 * @param <T> Generic type of interface class
 * @return array of Classes implementing interface specified.
 */
public static <T> Class<? extends T>[] getClassesOfType(Configuration conf, String name, Class<T> xface,
        Class<? extends T>... defaultValue) {
    Class<?>[] klasses = conf.getClasses(name, defaultValue);
    for (Class<?> klass : klasses) {
        if (!xface.isAssignableFrom(klass)) {
            throw new RuntimeException(klass + " is not assignable from " + xface.getName());
        }
    }
    return (Class<? extends T>[]) klasses;
}

From source file:com.topsoft.botspider.io.UnionData.java

License:Apache License

@Override
@SuppressWarnings("rawtypes")
public Schema getSchema(Configuration conf) {

    Class[] parseClass = null;//from   w w w .  j a v a2s . co  m
    if (conf != null) {
        parseClass = conf.getClasses(UNION_CLASS, null);
    }

    List<Schema> branches = new ArrayList<Schema>();
    branches.add(Schema.create(Schema.Type.NULL));
    if (parseClass != null) {
        for (Class branch : parseClass) {
            branches.add(ReflectData.get().getSchema(branch));
        }

    }
    Schema field = Schema.createUnion(branches);
    Schema schema = Schema.createRecord(UnionData.class.getName(), null, null, false);
    ArrayList<Field> fields = new ArrayList<Field>();
    fields.add(new Field("datum", field, null, null));
    schema.setFields(fields);
    return schema;
}