From 3e60761326819e174c442ebe0adc2c929b24fab9 Mon Sep 17 00:00:00 2001 From: zml2008 Date: Sat, 3 Mar 2012 16:47:12 -0800 Subject: [PATCH] Reduce excess casting --- .../com/sk89q/worldedit/CuboidClipboard.java | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/sk89q/worldedit/CuboidClipboard.java b/src/main/java/com/sk89q/worldedit/CuboidClipboard.java index 7a839039e..04707a2b7 100644 --- a/src/main/java/com/sk89q/worldedit/CuboidClipboard.java +++ b/src/main/java/com/sk89q/worldedit/CuboidClipboard.java @@ -435,40 +435,40 @@ public class CuboidClipboard { } // Get information - short width = (Short) getChildTag(schematic, "Width", ShortTag.class).getValue(); - short length = (Short) getChildTag(schematic, "Length", ShortTag.class).getValue(); - short height = (Short) getChildTag(schematic, "Height", ShortTag.class).getValue(); + short width = getChildTag(schematic, "Width", ShortTag.class).getValue(); + short length = getChildTag(schematic, "Length", ShortTag.class).getValue(); + short height = getChildTag(schematic, "Height", ShortTag.class).getValue(); try { - int originX = (Integer) getChildTag(schematic, "WEOriginX", IntTag.class).getValue(); - int originY = (Integer) getChildTag(schematic, "WEOriginY", IntTag.class).getValue(); - int originZ = (Integer) getChildTag(schematic, "WEOriginZ", IntTag.class).getValue(); + int originX = getChildTag(schematic, "WEOriginX", IntTag.class).getValue(); + int originY = getChildTag(schematic, "WEOriginY", IntTag.class).getValue(); + int originZ = getChildTag(schematic, "WEOriginZ", IntTag.class).getValue(); origin = new Vector(originX, originY, originZ); } catch (DataException e) { // No origin data } try { - int offsetX = (Integer) getChildTag(schematic, "WEOffsetX", IntTag.class).getValue(); - int offsetY = (Integer) getChildTag(schematic, "WEOffsetY", IntTag.class).getValue(); - int offsetZ = (Integer) getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue(); + int offsetX = getChildTag(schematic, "WEOffsetX", IntTag.class).getValue(); + int offsetY = getChildTag(schematic, "WEOffsetY", IntTag.class).getValue(); + int offsetZ = getChildTag(schematic, "WEOffsetZ", IntTag.class).getValue(); offset = new Vector(offsetX, offsetY, offsetZ); } catch (DataException e) { // No offset data } // Check type of Schematic - String materials = (String) getChildTag(schematic, "Materials", StringTag.class).getValue(); + String materials = getChildTag(schematic, "Materials", StringTag.class).getValue(); if (!materials.equals("Alpha")) { throw new DataException("Schematic file is not an Alpha schematic"); } // Get blocks - byte[] blocks = (byte[]) getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); - byte[] blockData = (byte[]) getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); + byte[] blocks = getChildTag(schematic, "Blocks", ByteArrayTag.class).getValue(); + byte[] blockData = getChildTag(schematic, "Data", ByteArrayTag.class).getValue(); // Need to pull out tile entities - List tileEntities = (List) ((ListTag) getChildTag(schematic, "TileEntities", ListTag.class)) + List tileEntities = (List)getChildTag(schematic, "TileEntities", ListTag.class) .getValue(); Map> tileEntitiesMap = new HashMap>(); @@ -572,8 +572,8 @@ public class CuboidClipboard { * @return child tag * @throws DataException */ - private static Tag getChildTag(Map items, String key, - Class expected) throws DataException { + private static T getChildTag(Map items, String key, + Class expected) throws DataException { if (!items.containsKey(key)) { throw new DataException("Schematic file is missing a \"" + key + "\" tag"); @@ -583,7 +583,7 @@ public class CuboidClipboard { throw new DataException( key + " tag is not of tag type " + expected.getName()); } - return tag; + return expected.cast(tag); } /**