Example #1
0
 @SuppressWarnings("unchecked")
 public <T extends ItemSpecification> T getSpecification(Class<T> type) {
   for (ItemSpecification itemSpecification : getSpecifications()) {
     if (itemSpecification.getClass() == type) return (T) itemSpecification;
   }
   return null;
 }
Example #2
0
  public List<String> getSpecificationNames() {
    List<String> specInfo = new ArrayList<String>(getSpecifications().size());

    for (ItemSpecification itemSpec : getSpecifications()) {
      specInfo.add(
          itemSpec.getName()
              + (itemSpec.getSpecificationLabel() != null
                  ? "(" + itemSpec.getSpecificationLabel() + ")"
                  : "")
              + ": "
              + itemSpec.getInfo());
    }

    return specInfo;
  }
Example #3
0
  /*
   * (non-Javadoc)
   *
   * @see java.lang.Object#clone()
   */
  @Override
  public Item clone() {
    Item item;
    try {
      item = (Item) super.clone();

      item.itemSpecs = new ArrayList<ItemSpecification>(getSpecifications().size());

      for (ItemSpecification specification : getSpecifications()) {
        item.itemSpecs.add(specification.clone());
      }

      item.weaponSpecsHelper = null;
      item.shieldSpecsHelper = null;
      item.distanceWeaponSpecsHelper = null;
      item.armorSpecsHelper = null;
      item.miscSpecsHelper = null;
    } catch (CloneNotSupportedException e) {
      return null;
    }

    return item;
  }
Example #4
0
  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);
    }
  }
Example #5
0
 public boolean hasSpecification(Class<? extends ItemSpecification> type) {
   for (ItemSpecification itemSpecification : getSpecifications()) {
     if (itemSpecification.getClass() == type) return true;
   }
   return false;
 }