/** Construct a new {@link WritableComparable} instance. */ public WritableComparable newKey() { return ReflectionUtils.newInstance(keyClass, null); }
/** Construct a new {@link WritableComparable} instance. */ public WritableComparable newKey() { return ReflectionUtils.newInstance(keyClass, null); }
/** * Make a copy of a writable object using serialization to a buffer. * @param orig The object to copy * @return The copied object */ public static <T extends Writable> T clone(T orig, Configuration conf) { try { @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T> T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf); ReflectionUtils.copy(conf, orig, newInst); return newInst; } catch (IOException e) { throw new RuntimeException("Error writing/reading clone buffer", e); } }
/** * Make a copy of a writable object using serialization to a buffer. * @param orig The object to copy * @return The copied object */ public static <T extends Writable> T clone(T orig, Configuration conf) { try { @SuppressWarnings("unchecked") // Unchecked cast from Class to Class<T> T newInst = ReflectionUtils.newInstance((Class<T>) orig.getClass(), conf); ReflectionUtils.copy(conf, orig, newInst); return newInst; } catch (IOException e) { throw new RuntimeException("Error writing/reading clone buffer", e); } }
/** * Get the value of the <code>name</code> property as a <code>List</code> * of objects implementing the interface specified by <code>xface</code>. * * An exception is thrown if any of the classes does not exist, or if it does * not implement the named interface. * * @param name the property name. * @param xface the interface implemented by the classes named by * <code>name</code>. * @return a <code>List</code> of objects implementing <code>xface</code>. */ @SuppressWarnings("unchecked") public <U> List<U> getInstances(String name, Class<U> xface) { List<U> ret = new ArrayList<>(); Class<?>[] classes = getClasses(name); for (Class<?> cl: classes) { if (!xface.isAssignableFrom(cl)) { throw new RuntimeException(cl + " does not implement " + xface); } ret.add((U) ReflectionUtils.newInstance(cl, this)); } return ret; }
/** * Get the value of the <code>name</code> property as a <code>List</code> * of objects implementing the interface specified by <code>xface</code>. * * An exception is thrown if any of the classes does not exist, or if it does * not implement the named interface. * * @param name the property name. * @param xface the interface implemented by the classes named by * <code>name</code>. * @return a <code>List</code> of objects implementing <code>xface</code>. */ @SuppressWarnings("unchecked") public <U> List<U> getInstances(String name, Class<U> xface) { List<U> ret = new ArrayList<U>(); Class<?>[] classes = getClasses(name); for (Class<?> cl: classes) { if (!xface.isAssignableFrom(cl)) { throw new RuntimeException(cl + " does not implement " + xface); } ret.add((U) ReflectionUtils.newInstance(cl, this)); } return ret; }
@SuppressWarnings("unchecked") private void add(Configuration conf, String serializationName) { try { Class<? extends Serialization> serializationClass = (Class<? extends Serialization>) conf.getClassByName(serializationName); serializations.add( ReflectionUtils.newInstance(serializationClass, getConf())); } catch (ClassNotFoundException e) { LOG.warn("Serialization class not found: " + StringUtils.stringifyException(e)); } }
@SuppressWarnings("unchecked") private void add(Configuration conf, String serializationName) { try { Class<? extends Serialization> serializionClass = (Class<? extends Serialization>) conf.getClassByName(serializationName); serializations.add( ReflectionUtils.newInstance(serializionClass, getConf())); } catch (ClassNotFoundException e) { LOG.warn("Serilization class not found: " + StringUtils.stringifyException(e)); } }