@SuppressWarnings("unchecked") public <T extends ItemSpecification> T getSpecification(Class<T> type) { for (ItemSpecification itemSpecification : getSpecifications()) { if (itemSpecification.getClass() == type) return (T) itemSpecification; } return null; }
public void addSpecification(ItemSpecification itemSpecification) { int version = 0; for (ItemSpecification specification : itemSpecs) { if (specification.getClass().equals(itemSpecification.getClass())) { version++; } } itemSpecification.setVersion(version); itemSpecification.setItem(this); itemSpecs.add(itemSpecification); if (itemSpecification.getType() != null) { if (TextUtils.isEmpty(itemTypes)) itemTypes = ITEM_TYPES_SEP; itemTypes = itemTypes.concat(itemSpecification.getType().name() + ITEM_TYPES_SEP); } }
public boolean hasSpecification(Class<? extends ItemSpecification> type) { for (ItemSpecification itemSpecification : getSpecifications()) { if (itemSpecification.getClass() == type) return true; } return false; }