public CollectionInfoColValue parseCollectionInfoColValue(byte[] val) { try { String tmp = new String(val); Iterable<String> split = Splitter.on(':').split(tmp); Iterator<String> iter = split.iterator(); String className = iter.next(); return new CollectionInfoColValue(className, Integer.parseInt(iter.next())); } catch (Throwable e) { throw new HectorObjectMapperException("exception while parsing collection info column value", e); } }
@Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + getOuterType().hashCode(); result = prime * result + ((collTypeName == null) ? 0 : collTypeName.hashCode()); result = prime * result + size; return result; }
@SuppressWarnings("rawtypes") public void instantiateCollection(Object obj, HColumn<String, byte[]> col, PropertyMappingDefinition md) { CollectionInfoColValue colValue = parseCollectionInfoColValue(col.getValue()); try { // type name is Class that needs instantiating. examine for special class // features, like ArrayList taking a size hint in constructor Collection<?> collObj; Class clazz = Class.forName(colValue.getCollTypeName()); if (ArrayList.class.isAssignableFrom(clazz)) { Constructor<ArrayList> cons = ArrayList.class.getConstructor(int.class); collObj = cons.newInstance(colValue.getSize()); } else { collObj = (Collection<?>) clazz.newInstance(); } // now save collection to object PropertyDescriptor pd = md.getPropDesc(); if (null == pd.getWriteMethod()) { throw new RuntimeException("property, " + pd.getName() + ", does not have a setter and therefore cannot be set"); } pd.getWriteMethod().invoke(obj, collObj); } catch (Throwable e) { throw new HectorObjectMapperException("exception while instantiating Collection type, " + colValue.getCollTypeName(), e); } }
@Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; CollectionInfoColValue other = (CollectionInfoColValue) obj; if (!getOuterType().equals(other.getOuterType())) return false; if (collTypeName == null) { if (other.collTypeName != null) return false; } else if (!collTypeName.equals(other.collTypeName)) return false; if (size != other.size) return false; return true; } }