@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof Rating) { Rating r = (Rating) obj; return new EqualsBuilder().append(user, r.user) .append(item, r.item) .append(value, r.value) .append(getTimestamp(), r.getTimestamp()) .isEquals(); } else { return super.equals(obj); } }
private static BeanAttributeGetter generateGetter(DynamicClassLoader dlc, Class<? extends AbstractBeanEntity> type, Method getter) { ClassNode node = new ClassNode(); node.name = String.format("%s$$AttrGet$%s", Type.getInternalName(type), getter.getName()); node.access = ACC_PUBLIC; node.version = V1_8; node.superName = Type.getInternalName(BeanAttributeGetter.class); node.methods.add(generateGetterConstructor()); node.methods.add(generateGetterMethod(type, getter)); if (Type.getReturnType(getter).equals(Type.LONG_TYPE)) { node.methods.add(generateLongGetterMethod(type, getter)); } else if (Type.getReturnType(getter).equals(Type.DOUBLE_TYPE)) { node.methods.add(generateDoubleGetterMethod(type, getter)); } Class<? extends BeanAttributeGetter> cls = dlc.defineClass(node).asSubclass(BeanAttributeGetter.class); try { return cls.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Cannot instantiate " + cls, e); } }
protected static BeanEntityLayout makeLayout(Class<? extends AbstractBeanEntity> type) { BeanEntityLayout res = cache.get(type); if (res != null) { return res; } DynamicClassLoader dlc = new DynamicClassLoader(type.getClassLoader()); Map<String, BeanAttributeGetter> attrs = new HashMap<>(); List<TypedName<?>> names = new ArrayList<>(); for (Method m: type.getMethods()) { EntityAttribute annot = m.getAnnotation(EntityAttribute.class); if (annot != null) { BeanAttributeGetter gfunc = generateGetter(dlc, type, m); attrs.put(annot.value(), gfunc); names.add(TypedName.create(annot.value(), TypeToken.of(m.getGenericReturnType()))); } } AttributeSet aset = AttributeSet.create(names); ImmutableList.Builder<BeanAttributeGetter> mhlb = ImmutableList.builder(); for (String name: aset.nameSet()) { mhlb.add(attrs.get(name)); } res = new BeanEntityLayout(aset, mhlb.build()); cache.put(type, res); return res; }
private static BeanAttributeGetter generateGetter(DynamicClassLoader dlc, Class<? extends AbstractBeanEntity> type, Method getter) { ClassNode node = new ClassNode(); node.name = String.format("%s$$AttrGet$%s", Type.getInternalName(type), getter.getName()); node.access = ACC_PUBLIC; node.version = V1_8; node.superName = Type.getInternalName(BeanAttributeGetter.class); node.methods.add(generateGetterConstructor()); node.methods.add(generateGetterMethod(type, getter)); if (Type.getReturnType(getter).equals(Type.LONG_TYPE)) { node.methods.add(generateLongGetterMethod(type, getter)); } else if (Type.getReturnType(getter).equals(Type.DOUBLE_TYPE)) { node.methods.add(generateDoubleGetterMethod(type, getter)); } Class<? extends BeanAttributeGetter> cls = dlc.defineClass(node).asSubclass(BeanAttributeGetter.class); try { return cls.newInstance(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException("Cannot instantiate " + cls, e); } }
@Override public boolean equals(Object obj) { if (obj == this) { return true; } else if (obj instanceof Rating) { Rating r = (Rating) obj; return new EqualsBuilder().append(user, r.user) .append(item, r.item) .append(value, r.value) .append(getTimestamp(), r.getTimestamp()) .isEquals(); } else { return super.equals(obj); } }
protected static BeanEntityLayout makeLayout(Class<? extends AbstractBeanEntity> type) { BeanEntityLayout res = cache.get(type); if (res != null) { return res; } DynamicClassLoader dlc = new DynamicClassLoader(type.getClassLoader()); Map<String, BeanAttributeGetter> attrs = new HashMap<>(); List<TypedName<?>> names = new ArrayList<>(); for (Method m: type.getMethods()) { EntityAttribute annot = m.getAnnotation(EntityAttribute.class); if (annot != null) { BeanAttributeGetter gfunc = generateGetter(dlc, type, m); attrs.put(annot.value(), gfunc); names.add(TypedName.create(annot.value(), TypeToken.of(m.getGenericReturnType()))); } } AttributeSet aset = AttributeSet.create(names); ImmutableList.Builder<BeanAttributeGetter> mhlb = ImmutableList.builder(); for (String name: aset.nameSet()) { mhlb.add(attrs.get(name)); } res = new BeanEntityLayout(aset, mhlb.build()); cache.put(type, res); return res; }