private EMaterialType parseMaterial(final String materialString) { EMaterialType material; if ("*".equals(materialString)) { material = null; } else { material = EMaterialType.valueOf(materialString); } return material; }
private static EMaterialType getMaterial(Attributes attributes) { String string = attributes.getValue(MATERIAL); if (string == null) { return null; } else { try { return EMaterialType.valueOf(string); } catch (IllegalArgumentException e) { return null; } } }
private EMaterialType[] getMaterialTypeArray(Attributes attributes) { String foodOrderString = attributes.getValue(FOOD_ORDER); if (foodOrderString == null) { return null; } try { String[] foodOrderStrings = foodOrderString.split(","); EMaterialType[] foodOrder = new EMaterialType[foodOrderStrings.length]; for (int i = 0; i < foodOrderStrings.length; i++) { foodOrder[i] = EMaterialType.valueOf(foodOrderStrings[i]); } return foodOrder; } catch (IllegalArgumentException e) { throw new IllegalAccessError("Food order may only contain EMaterialTypes: " + foodOrderString); } }
private void readAndAddRelativeStack(Attributes attributes, ArrayList<RelativeStack> stacks) { try { int dx = Integer.parseInt(attributes.getValue(ATTR_DX)); int dy = Integer.parseInt(attributes.getValue(ATTR_DY)); EMaterialType type = EMaterialType.valueOf(attributes.getValue(ATTR_MATERIAl)); stacks.add(new RelativeStack(dx, dy, type)); } catch (NumberFormatException e) { System.err.println("Warning: illegal number " + "for stack attribute, in definiton for " + buildingName); } catch (IllegalArgumentException e) { System.err.println("Illegal material name in " + buildingName); } }
private void readConstructionStack(Attributes attributes) { try { int dx = Integer.parseInt(attributes.getValue(ATTR_DX)); int dy = Integer.parseInt(attributes.getValue(ATTR_DY)); EMaterialType type = EMaterialType.valueOf(attributes.getValue(ATTR_MATERIAl)); short requiredForBuild = Short.parseShort(attributes.getValue(ATTR_BUILDREQUIRED)); if (requiredForBuild <= 0) { throw new NumberFormatException("RequiredForBuild attribute needs to be an integer > 0"); } constructionStacks.add(new ConstructionStack(dx, dy, type, requiredForBuild)); } catch (NumberFormatException e) { System.err.println("Warning: illegal number " + "for stack attribute, in definiton for " + buildingName); } catch (IllegalArgumentException e) { System.err.println("Illegal material name in " + buildingName); } }
private static MapDataObject getObject(int type, String string) { switch (type) { case TYPE_TREE: return MapTreeObject.getInstance(); case TYPE_STONE: return StoneMapDataObject.getInstance(Integer.parseInt(string)); case TYPE_STACK: { String[] parts = string.split(","); return new StackMapDataObject(EMaterialType.valueOf(parts[0]), Integer.valueOf(parts[1])); } case TYPE_MOVABLE: { String[] parts = string.split(","); return new MovableObject(EMovableType.valueOf(parts[0]), Byte.valueOf(parts[1])); } case TYPE_BUILDING: { String[] parts = string.split(","); return new BuildingMapDataObject(EBuildingType.valueOf(parts[0]), Byte.valueOf(parts[1])); } default: return null; } }