You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2022/09/30 12:26:34 UTC

[commons-compress] branch master updated: Use generics

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-compress.git


The following commit(s) were added to refs/heads/master by this push:
     new d013218d Use generics
     new ae113d98 Merge branch 'master' of https://gitbox.apache.org/repos/asf/commons-compress.git
d013218d is described below

commit d013218da2ada7f4917f01431e5eb742624f381a
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Fri Sep 30 08:26:03 2022 -0400

    Use generics
---
 .../harmony/pack200/AttributeDefinitionBands.java  |  35 ++--
 .../commons/compress/harmony/pack200/BandSet.java  |  37 ++---
 .../commons/compress/harmony/pack200/BcBands.java  |   6 +-
 .../compress/harmony/pack200/ClassBands.java       |  14 +-
 .../harmony/pack200/NewAttributeBands.java         | 181 +++++++++------------
 .../pack200/tests/NewAttributeBandsTest.java       |  40 ++---
 6 files changed, 147 insertions(+), 166 deletions(-)

diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/AttributeDefinitionBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/AttributeDefinitionBands.java
index a36b52c4..574ff779 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/AttributeDefinitionBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/AttributeDefinitionBands.java
@@ -35,12 +35,12 @@ public class AttributeDefinitionBands extends BandSet {
     public static final int CONTEXT_FIELD = 1;
     public static final int CONTEXT_METHOD = 2;
 
-    private final List classAttributeLayouts = new ArrayList();
-    private final List methodAttributeLayouts = new ArrayList();
-    private final List fieldAttributeLayouts = new ArrayList();
-    private final List codeAttributeLayouts = new ArrayList();
+    private final List<AttributeDefinition> classAttributeLayouts = new ArrayList<>();
+    private final List<AttributeDefinition> methodAttributeLayouts = new ArrayList<>();
+    private final List<AttributeDefinition> fieldAttributeLayouts = new ArrayList<>();
+    private final List<AttributeDefinition> codeAttributeLayouts = new ArrayList<>();
 
-    private final List attributeDefinitions = new ArrayList();
+    private final List<AttributeDefinition> attributeDefinitions = new ArrayList<>();
 
     private final CpBands cpBands;
     private final Segment segment;
@@ -49,10 +49,10 @@ public class AttributeDefinitionBands extends BandSet {
         super(effort, segment.getSegmentHeader());
         this.cpBands = segment.getCpBands();
         this.segment = segment;
-        final Map classLayouts = new HashMap();
-        final Map methodLayouts = new HashMap();
-        final Map fieldLayouts = new HashMap();
-        final Map codeLayouts = new HashMap();
+        final Map<String, String> classLayouts = new HashMap<>();
+        final Map<String, String> methodLayouts = new HashMap<>();
+        final Map<String, String> fieldLayouts = new HashMap<>();
+        final Map<String, String> codeLayouts = new HashMap<>();
 
         for (Attribute attributePrototype : attributePrototypes) {
             final NewAttribute newAttribute = (NewAttribute) attributePrototype;
@@ -123,7 +123,7 @@ public class AttributeDefinitionBands extends BandSet {
         final int[] attributeDefinitionName = new int[attributeDefinitions.size()];
         final int[] attributeDefinitionLayout = new int[attributeDefinitions.size()];
         for (int i = 0; i < attributeDefinitionLayout.length; i++) {
-            final AttributeDefinition def = (AttributeDefinition) attributeDefinitions.get(i);
+            final AttributeDefinition def = attributeDefinitions.get(i);
             attributeDefinitionHeader[i] = def.contextType | (def.index + 1 << 2);
             attributeDefinitionName[i] = def.name.getIndex();
             attributeDefinitionLayout[i] = def.layout.getIndex();
@@ -175,11 +175,10 @@ public class AttributeDefinitionBands extends BandSet {
         return temp;
     }
 
-    private void addAttributeDefinitions(final Map layouts, final int[] availableIndices, final int contextType) {
+    private void addAttributeDefinitions(final Map<String, String> layouts, final int[] availableIndices, final int contextType) {
         final int i = 0;
-        for (Object element : layouts.keySet()) {
-            final String name = (String) element;
-            final String layout = (String) layouts.get(name);
+        for (String name : layouts.keySet()) {
+            final String layout = layouts.get(name);
             final int index = availableIndices[i];
             final AttributeDefinition definition = new AttributeDefinition(index, contextType, cpBands.getCPUtf8(name),
                 cpBands.getCPUtf8(layout));
@@ -200,19 +199,19 @@ public class AttributeDefinitionBands extends BandSet {
         }
     }
 
-    public List getClassAttributeLayouts() {
+    public List<AttributeDefinition> getClassAttributeLayouts() {
         return classAttributeLayouts;
     }
 
-    public List getMethodAttributeLayouts() {
+    public List<AttributeDefinition> getMethodAttributeLayouts() {
         return methodAttributeLayouts;
     }
 
-    public List getFieldAttributeLayouts() {
+    public List<AttributeDefinition> getFieldAttributeLayouts() {
         return fieldAttributeLayouts;
     }
 
-    public List getCodeAttributeLayouts() {
+    public List<AttributeDefinition> getCodeAttributeLayouts() {
         return codeAttributeLayouts;
     }
 
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java b/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
index 6a03e469..cf3758b3 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/BandSet.java
@@ -211,7 +211,7 @@ public abstract class BandSet {
             }
         }
 
-        final List codecFamiliesToTry = new ArrayList();
+        final List<BHSDCodec[]> codecFamiliesToTry = new ArrayList<>();
 
         // See if the deltas are mainly small increments
         if (bandData.mainlyPositiveDeltas() && bandData.mainlySmallDeltas()) {
@@ -261,8 +261,7 @@ public abstract class BandSet {
             System.out.print("");
         }
 
-        for (Object element : codecFamiliesToTry) {
-            final BHSDCodec[] family = (BHSDCodec[]) element;
+        for (BHSDCodec[] family : codecFamiliesToTry) {
             tryCodecs(name, band, defaultCodec, bandData, results, encoded, family);
             if (timeToStop(results)) {
                 break;
@@ -353,7 +352,7 @@ public abstract class BandSet {
         results.numCodecsTried += 3; // quite a bit more effort to try this codec
         final Map<Integer, Integer> distinctValues = bandData.distinctValues;
 
-        final List favoured = new ArrayList();
+        final List<Integer> favoured = new ArrayList<>();
         distinctValues.forEach((k, v) -> {
             if (v.intValue() > 2 || distinctValues.size() < 256) { // TODO: tweak
                 favoured.add(k);
@@ -362,19 +361,19 @@ public abstract class BandSet {
 
         // Sort the favoured list with the most commonly occurring first
         if (distinctValues.size() > 255) {
-            favoured.sort((arg0, arg1) -> ((Integer) distinctValues.get(arg1)).compareTo((Integer) distinctValues.get(arg0)));
+            favoured.sort((arg0, arg1) -> distinctValues.get(arg1).compareTo(distinctValues.get(arg0)));
         }
 
         final IntList unfavoured = new IntList();
-        final Map favouredToIndex = new HashMap();
+        final Map<Integer, Integer> favouredToIndex = new HashMap<>();
         for (int i = 0; i < favoured.size(); i++) {
-            final Integer value = (Integer) favoured.get(i);
+            final Integer value = favoured.get(i);
             favouredToIndex.put(value, Integer.valueOf(i));
         }
 
         final int[] tokens = new int[band.length];
         for (int i = 0; i < band.length; i++) {
-            final Integer favouredIndex = (Integer) favouredToIndex.get(Integer.valueOf(band[i]));
+            final Integer favouredIndex = favouredToIndex.get(Integer.valueOf(band[i]));
             if (favouredIndex == null) {
                 tokens[i] = 0;
                 unfavoured.add(band[i]);
@@ -554,10 +553,10 @@ public abstract class BandSet {
      * @param integerList conversion source.
      * @return conversion result.
      */
-    protected int[] integerListToArray(final List integerList) {
+    protected int[] integerListToArray(final List<Integer> integerList) {
         final int[] array = new int[integerList.size()];
         for (int i = 0; i < array.length; i++) {
-            array[i] = ((Integer) integerList.get(i)).intValue();
+            array[i] = integerList.get(i).intValue();
         }
         return array;
     }
@@ -568,10 +567,10 @@ public abstract class BandSet {
      * @param longList conversion source.
      * @return conversion result.
      */
-    protected long[] longListToArray(final List longList) {
+    protected long[] longListToArray(final List<Long> longList) {
         final long[] array = new long[longList.size()];
         for (int i = 0; i < array.length; i++) {
-            array[i] = ((Long) longList.get(i)).longValue();
+            array[i] = longList.get(i).longValue();
         }
         return array;
     }
@@ -582,10 +581,10 @@ public abstract class BandSet {
      * @param list conversion source.
      * @return conversion result.
      */
-    protected int[] cpEntryListToArray(final List list) {
+    protected int[] cpEntryListToArray(final List<ConstantPoolEntry> list) {
         final int[] array = new int[list.size()];
         for (int i = 0; i < array.length; i++) {
-            array[i] = ((ConstantPoolEntry) list.get(i)).getIndex();
+            array[i] = list.get(i).getIndex();
             if (array[i] < 0) {
                 throw new RuntimeException("Index should be > 0");
             }
@@ -599,10 +598,10 @@ public abstract class BandSet {
      * @param theList conversion source.
      * @return conversion result.
      */
-    protected int[] cpEntryOrNullListToArray(final List theList) {
+    protected int[] cpEntryOrNullListToArray(final List<ConstantPoolEntry> theList) {
         final int[] array = new int[theList.size()];
         for (int j = 0; j < array.length; j++) {
-            final ConstantPoolEntry cpEntry = (ConstantPoolEntry) theList.get(j);
+            final ConstantPoolEntry cpEntry = theList.get(j);
             array[j] = cpEntry == null ? 0 : cpEntry.getIndex() + 1;
             if (cpEntry != null && cpEntry.getIndex() < 0) {
                 throw new RuntimeException("Index should be > 0");
@@ -653,7 +652,7 @@ public abstract class BandSet {
         private double averageAbsoluteDelta = 0;
         private double averageAbsoluteValue = 0;
 
-        private Map distinctValues;
+        private Map<Integer, Integer> distinctValues;
 
         /**
          * Create a new instance of BandData. The band is then analysed.
@@ -692,10 +691,10 @@ public abstract class BandSet {
                 averageAbsoluteValue += (double) Math.abs(band[i]) / (double) band.length;
                 if (effort > 3) { // do calculations needed to consider population codec
                     if (distinctValues == null) {
-                        distinctValues = new HashMap();
+                        distinctValues = new HashMap<>();
                     }
                     final Integer value = Integer.valueOf(band[i]);
-                    Integer count = (Integer) distinctValues.get(value);
+                    Integer count = distinctValues.get(value);
                     if (count == null) {
                         count = one;
                     } else {
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
index bd734be9..573931ca 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/BcBands.java
@@ -45,6 +45,8 @@ public class BcBands extends BandSet {
     private final IntList bcByte = new IntList();
     private final IntList bcShort = new IntList();
     private final IntList bcLocal = new IntList();
+    
+    // Integers and/or Labels?
     private final List bcLabel = new ArrayList();
     private final List bcIntref = new ArrayList();
     private final List bcFloatRef = new ArrayList();
@@ -75,7 +77,7 @@ public class BcBands extends BandSet {
     private static final int endMarker = 255;
 
     private final IntList bciRenumbering = new IntList();
-    private final Map labelsToOffsets = new HashMap();
+    private final Map<Label, Integer> labelsToOffsets = new HashMap<>();
     private int byteCodeOffset;
     private int renumberedOffset;
     private final IntList bcLabelRelativeOffsets = new IntList();
@@ -228,7 +230,7 @@ public class BcBands extends BandSet {
                 }
                 if (label instanceof Label) {
                     bcLabel.remove(i);
-                    final Integer offset = (Integer) labelsToOffsets.get(label);
+                    final Integer offset = labelsToOffsets.get(label);
                     final int relativeOffset = bcLabelRelativeOffsets.get(i);
                     bcLabel.add(i,
                         Integer.valueOf(bciRenumbering.get(offset.intValue()) - bciRenumbering.get(relativeOffset)));
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
index 0cb7699a..e384ee75 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/ClassBands.java
@@ -1128,7 +1128,7 @@ public class ClassBands extends BandSet {
         codeLocalVariableTableSlot.add(indx);
     }
 
-    public void doBciRenumbering(final IntList bciRenumbering, final Map labelsToOffsets) {
+    public void doBciRenumbering(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
         renumberBci(codeLineNumberTableBciP, bciRenumbering, labelsToOffsets);
         renumberBci(codeLocalVariableTableBciP, bciRenumbering, labelsToOffsets);
         renumberOffsetBci(codeLocalVariableTableBciP, codeLocalVariableTableSpanO, bciRenumbering, labelsToOffsets);
@@ -1158,7 +1158,7 @@ public class ClassBands extends BandSet {
         }
     }
 
-    private void renumberBci(final List list, final IntList bciRenumbering, final Map labelsToOffsets) {
+    private void renumberBci(final List list, final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
         for (int i = list.size() - 1; i >= 0; i--) {
             final Object label = list.get(i);
             if (label instanceof Integer) {
@@ -1166,14 +1166,14 @@ public class ClassBands extends BandSet {
             }
             if (label instanceof Label) {
                 list.remove(i);
-                final Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
+                final Integer bytecodeIndex = labelsToOffsets.get(label);
                 list.add(i, Integer.valueOf(bciRenumbering.get(bytecodeIndex.intValue())));
             }
         }
     }
 
     private void renumberOffsetBci(final List relative, final List list, final IntList bciRenumbering,
-        final Map labelsToOffsets) {
+        final Map<Label, Integer> labelsToOffsets) {
         for (int i = list.size() - 1; i >= 0; i--) {
             final Object label = list.get(i);
             if (label instanceof Integer) {
@@ -1181,7 +1181,7 @@ public class ClassBands extends BandSet {
             }
             if (label instanceof Label) {
                 list.remove(i);
-                final Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
+                final Integer bytecodeIndex = labelsToOffsets.get(label);
                 final Integer renumberedOffset = Integer
                     .valueOf(bciRenumbering.get(bytecodeIndex.intValue()) - ((Integer) relative.get(i)).intValue());
                 list.add(i, renumberedOffset);
@@ -1190,7 +1190,7 @@ public class ClassBands extends BandSet {
     }
 
     private void renumberDoubleOffsetBci(final List relative, final List firstOffset, final List list,
-        final IntList bciRenumbering, final Map labelsToOffsets) {
+        final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
         // TODO: There's probably a nicer way of doing this...
         for (int i = list.size() - 1; i >= 0; i--) {
             final Object label = list.get(i);
@@ -1199,7 +1199,7 @@ public class ClassBands extends BandSet {
             }
             if (label instanceof Label) {
                 list.remove(i);
-                final Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
+                final Integer bytecodeIndex = labelsToOffsets.get(label);
                 final Integer renumberedOffset = Integer.valueOf(bciRenumbering.get(bytecodeIndex.intValue())
                     - ((Integer) relative.get(i)).intValue() - ((Integer) firstOffset.get(i)).intValue());
                 list.add(i, renumberedOffset);
diff --git a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
index 9228eab9..591ac530 100644
--- a/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
+++ b/src/main/java/org/apache/commons/compress/harmony/pack200/NewAttributeBands.java
@@ -35,7 +35,7 @@ import org.objectweb.asm.Label;
  */
 public class NewAttributeBands extends BandSet {
 
-    protected List attributeLayoutElements;
+    protected List<AttributeLayoutElement> attributeLayoutElements;
     private int[] backwardsCallCounts;
     private final CpBands cpBands;
     private final AttributeDefinition def;
@@ -55,17 +55,15 @@ public class NewAttributeBands extends BandSet {
     public void addAttribute(final NewAttribute attribute) {
         usedAtLeastOnce = true;
         final InputStream stream = new ByteArrayInputStream(attribute.getBytes());
-        for (Object attributeLayoutElement : attributeLayoutElements) {
-            final AttributeLayoutElement layoutElement = (AttributeLayoutElement) attributeLayoutElement;
-            layoutElement.addAttributeToBand(attribute, stream);
+        for (AttributeLayoutElement attributeLayoutElement : attributeLayoutElements) {
+            attributeLayoutElement.addAttributeToBand(attribute, stream);
         }
     }
 
     @Override
     public void pack(final OutputStream out) throws IOException, Pack200Exception {
-        for (Object attributeLayoutElement : attributeLayoutElements) {
-            final AttributeLayoutElement layoutElement = (AttributeLayoutElement) attributeLayoutElement;
-            layoutElement.pack(out);
+        for (AttributeLayoutElement attributeLayoutElement : attributeLayoutElements) {
+            attributeLayoutElement.pack(out);
         }
     }
 
@@ -88,7 +86,7 @@ public class NewAttributeBands extends BandSet {
     private void parseLayout() throws IOException {
         final String layout = def.layout.getUnderlyingString();
         if (attributeLayoutElements == null) {
-            attributeLayoutElements = new ArrayList();
+            attributeLayoutElements = new ArrayList<>();
             final StringReader stream = new StringReader(layout);
             AttributeLayoutElement e;
             while ((e = readNextAttributeElement(stream)) != null) {
@@ -105,22 +103,21 @@ public class NewAttributeBands extends BandSet {
      */
     private void resolveCalls() {
         for (int i = 0; i < attributeLayoutElements.size(); i++) {
-            final AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElements.get(i);
+            final AttributeLayoutElement element = attributeLayoutElements.get(i);
             if (element instanceof Callable) {
                 final Callable callable = (Callable) element;
-                final List body = callable.body; // Look for calls in the body
-                for (Object element2 : body) {
-                    final LayoutElement layoutElement = (LayoutElement) element2;
+                final List<LayoutElement> body = callable.body; // Look for calls in the body
+                for (LayoutElement element2 : body) {
+                    final LayoutElement layoutElement = element2;
                     // Set the callable for each call
                     resolveCallsForElement(i, callable, layoutElement);
                 }
             }
         }
         int backwardsCallableIndex = 0;
-        for (Object attributeLayoutElement : attributeLayoutElements) {
-            final AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElement;
-            if (element instanceof Callable) {
-                final Callable callable = (Callable) element;
+        for (AttributeLayoutElement attributeLayoutElement : attributeLayoutElements) {
+            if (attributeLayoutElement instanceof Callable) {
+                final Callable callable = (Callable) attributeLayoutElement;
                 if (callable.isBackwardsCallable) {
                     callable.setBackwardsCallableIndex(backwardsCallableIndex);
                     backwardsCallableIndex++;
@@ -139,7 +136,7 @@ public class NewAttributeBands extends BandSet {
                 call.setCallable(currentCallable);
             } else if (index > 0) { // Forwards call
                 for (int k = i + 1; k < attributeLayoutElements.size(); k++) {
-                    final AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements.get(k);
+                    final AttributeLayoutElement el = attributeLayoutElements.get(k);
                     if (el instanceof Callable) {
                         index--;
                         if (index == 0) {
@@ -150,7 +147,7 @@ public class NewAttributeBands extends BandSet {
                 }
             } else { // Backwards call
                 for (int k = i - 1; k >= 0; k--) {
-                    final AttributeLayoutElement el = (AttributeLayoutElement) attributeLayoutElements.get(k);
+                    final AttributeLayoutElement el = attributeLayoutElements.get(k);
                     if (el instanceof Callable) {
                         index++;
                         if (index == 0) {
@@ -161,10 +158,9 @@ public class NewAttributeBands extends BandSet {
                 }
             }
         } else if (layoutElement instanceof Replication) {
-            final List children = ((Replication) layoutElement).layoutElements;
-            for (Object child : children) {
-                final LayoutElement object = (LayoutElement) child;
-                resolveCallsForElement(i, currentCallable, object);
+            final List<LayoutElement> children = ((Replication) layoutElement).layoutElements;
+            for (LayoutElement child : children) {
+                resolveCallsForElement(i, currentCallable, child);
             }
         }
     }
@@ -176,8 +172,7 @@ public class NewAttributeBands extends BandSet {
             return null;
         }
         if (nextChar == '[') {
-            final List body = readBody(getStreamUpToMatchingBracket(stream));
-            return new Callable(body);
+            return new Callable(readBody(getStreamUpToMatchingBracket(stream)));
         }
         stream.reset();
         return readNextLayoutElement(stream);
@@ -229,7 +224,7 @@ public class NewAttributeBands extends BandSet {
             if (int_type.equals("S")) {
                 int_type += (char) stream.read();
             }
-            final List unionCases = new ArrayList();
+            final List<UnionCase> unionCases = new ArrayList<>();
             UnionCase c;
             while ((c = readNextUnionCase(stream)) != null) {
                 unionCases.add(c);
@@ -237,7 +232,7 @@ public class NewAttributeBands extends BandSet {
             stream.read(); // '('
             stream.read(); // ')'
             stream.read(); // '['
-            List body = null;
+            List<LayoutElement> body = null;
             stream.mark(1);
             final char next = (char) stream.read();
             if (next != ']') {
@@ -282,7 +277,7 @@ public class NewAttributeBands extends BandSet {
         }
         stream.reset();
         stream.read(); // '('
-        final List tags = new ArrayList();
+        final List<Integer> tags = new ArrayList<>();
         Integer nextTag;
         do {
             nextTag = readNumber(stream);
@@ -311,7 +306,7 @@ public class NewAttributeBands extends BandSet {
 
         void pack(OutputStream out) throws IOException, Pack200Exception;
 
-        void renumberBci(IntList bciRenumbering, Map labelsToOffsets);
+        void renumberBci(IntList bciRenumbering, Map<Label, Integer> labelsToOffsets);
 
     }
 
@@ -421,7 +416,7 @@ public class NewAttributeBands extends BandSet {
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
             if (tag.startsWith("O") || tag.startsWith("PO")) {
                 renumberOffsetBci(previousIntegral.band, bciRenumbering, labelsToOffsets);
             } else if (tag.startsWith("P")) {
@@ -432,14 +427,14 @@ public class NewAttributeBands extends BandSet {
                     }
                     if (label instanceof Label) {
                         band.remove(i);
-                        final Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
+                        final Integer bytecodeIndex = labelsToOffsets.get(label);
                         band.add(i, Integer.valueOf(bciRenumbering.get(bytecodeIndex.intValue())));
                     }
                 }
             }
         }
 
-        private void renumberOffsetBci(final List relative, final IntList bciRenumbering, final Map labelsToOffsets) {
+        private void renumberOffsetBci(final List relative, final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
             for (int i = band.size() - 1; i >= 0; i--) {
                 final Object label = band.get(i);
                 if (label instanceof Integer) {
@@ -447,7 +442,7 @@ public class NewAttributeBands extends BandSet {
                 }
                 if (label instanceof Label) {
                     band.remove(i);
-                    final Integer bytecodeIndex = (Integer) labelsToOffsets.get(label);
+                    final Integer bytecodeIndex = labelsToOffsets.get(label);
                     final Integer renumberedOffset = Integer
                         .valueOf(bciRenumbering.get(bytecodeIndex.intValue()) - ((Integer) relative.get(i)).intValue());
                     band.add(i, renumberedOffset);
@@ -464,13 +459,13 @@ public class NewAttributeBands extends BandSet {
 
         private final Integral countElement;
 
-        private final List layoutElements = new ArrayList();
+        private final List<LayoutElement> layoutElements = new ArrayList<>();
 
         public Integral getCountElement() {
             return countElement;
         }
 
-        public List getLayoutElements() {
+        public List<LayoutElement> getLayoutElements() {
             return layoutElements;
         }
 
@@ -488,8 +483,7 @@ public class NewAttributeBands extends BandSet {
             countElement.addAttributeToBand(attribute, stream);
             final int count = countElement.latestValue();
             for (int i = 0; i < count; i++) {
-                for (Object layoutElement2 : layoutElements) {
-                    final AttributeLayoutElement layoutElement = (AttributeLayoutElement) layoutElement2;
+                for (AttributeLayoutElement layoutElement : layoutElements) {
                     layoutElement.addAttributeToBand(attribute, stream);
                 }
             }
@@ -498,16 +492,14 @@ public class NewAttributeBands extends BandSet {
         @Override
         public void pack(final OutputStream out) throws IOException, Pack200Exception {
             countElement.pack(out);
-            for (Object layoutElement2 : layoutElements) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) layoutElement2;
+            for (AttributeLayoutElement layoutElement : layoutElements) {
                 layoutElement.pack(out);
             }
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
-            for (Object layoutElement2 : layoutElements) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) layoutElement2;
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
+            for (AttributeLayoutElement layoutElement : layoutElements) {
                 layoutElement.renumberBci(bciRenumbering, labelsToOffsets);
             }
         }
@@ -519,10 +511,10 @@ public class NewAttributeBands extends BandSet {
     public class Union extends LayoutElement {
 
         private final Integral unionTag;
-        private final List unionCases;
-        private final List defaultCaseBody;
+        private final List<UnionCase> unionCases;
+        private final List<LayoutElement> defaultCaseBody;
 
-        public Union(final String tag, final List unionCases, final List body) {
+        public Union(final String tag, final List<UnionCase> unionCases, final List<LayoutElement> body) {
             this.unionTag = new Integral(tag);
             this.unionCases = unionCases;
             this.defaultCaseBody = body;
@@ -533,17 +525,15 @@ public class NewAttributeBands extends BandSet {
             unionTag.addAttributeToBand(attribute, stream);
             final long tag = unionTag.latestValue();
             boolean defaultCase = true;
-            for (Object element2 : unionCases) {
-                final UnionCase element = (UnionCase) element2;
-                if (element.hasTag(tag)) {
+            for (UnionCase unionCase : unionCases) {
+                if (unionCase.hasTag(tag)) {
                     defaultCase = false;
-                    element.addAttributeToBand(attribute, stream);
+                    unionCase.addAttributeToBand(attribute, stream);
                 }
             }
             if (defaultCase) {
-                for (Object element2 : defaultCaseBody) {
-                    final LayoutElement element = (LayoutElement) element2;
-                    element.addAttributeToBand(attribute, stream);
+                for (LayoutElement element2 : defaultCaseBody) {
+                    element2.addAttributeToBand(attribute, stream);
                 }
             }
         }
@@ -551,25 +541,21 @@ public class NewAttributeBands extends BandSet {
         @Override
         public void pack(final OutputStream out) throws IOException, Pack200Exception {
             unionTag.pack(out);
-            for (Object element : unionCases) {
-                final UnionCase unionCase = (UnionCase) element;
+            for (UnionCase unionCase : unionCases) {
                 unionCase.pack(out);
             }
-            for (Object element : defaultCaseBody) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) element;
-                layoutElement.pack(out);
+            for (LayoutElement element : defaultCaseBody) {
+                element.pack(out);
             }
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
-            for (Object element : unionCases) {
-                final UnionCase unionCase = (UnionCase) element;
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
+            for (UnionCase unionCase : unionCases) {
                 unionCase.renumberBci(bciRenumbering, labelsToOffsets);
             }
-            for (Object element : defaultCaseBody) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) element;
-                layoutElement.renumberBci(bciRenumbering, labelsToOffsets);
+            for (LayoutElement element : defaultCaseBody) {
+                element.renumberBci(bciRenumbering, labelsToOffsets);
             }
         }
 
@@ -577,11 +563,11 @@ public class NewAttributeBands extends BandSet {
             return unionTag;
         }
 
-        public List getUnionCases() {
+        public List<UnionCase> getUnionCases() {
             return unionCases;
         }
 
-        public List getDefaultCaseBody() {
+        public List<LayoutElement> getDefaultCaseBody() {
             return defaultCaseBody;
         }
     }
@@ -616,7 +602,7 @@ public class NewAttributeBands extends BandSet {
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
             // do nothing here as renumberBci will be called on the callable at another time
         }
 
@@ -636,7 +622,7 @@ public class NewAttributeBands extends BandSet {
 
         private final String tag;
 
-        private List band;
+        private List<ConstantPoolEntry> band;
 
         private boolean nullsAllowed = false;
 
@@ -678,7 +664,7 @@ public class NewAttributeBands extends BandSet {
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
             // nothing to do here
         }
 
@@ -686,13 +672,13 @@ public class NewAttributeBands extends BandSet {
 
     public class Callable implements AttributeLayoutElement {
 
-        private final List body;
+        private final List<LayoutElement> body;
 
         private boolean isBackwardsCallable;
 
         private int backwardsCallableIndex;
 
-        public Callable(final List body) {
+        public Callable(final List<LayoutElement> body) {
             this.body = body;
         }
 
@@ -717,29 +703,26 @@ public class NewAttributeBands extends BandSet {
 
         @Override
         public void addAttributeToBand(final NewAttribute attribute, final InputStream stream) {
-            for (Object element : body) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) element;
-                layoutElement.addAttributeToBand(attribute, stream);
+            for (AttributeLayoutElement element : body) {
+                element.addAttributeToBand(attribute, stream);
             }
         }
 
         @Override
-        public void pack(final OutputStream out) throws IOException, Pack200Exception {
-            for (Object element : body) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) element;
-                layoutElement.pack(out);
+        public void pack(final OutputStream outputStream) throws IOException, Pack200Exception {
+            for (AttributeLayoutElement element : body) {
+                element.pack(outputStream);
             }
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
-            for (Object element : body) {
-                final AttributeLayoutElement layoutElement = (AttributeLayoutElement) element;
-                layoutElement.renumberBci(bciRenumbering, labelsToOffsets);
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
+            for (AttributeLayoutElement element : body) {
+                element.renumberBci(bciRenumbering, labelsToOffsets);
             }
         }
 
-        public List getBody() {
+        public List<LayoutElement> getBody() {
             return body;
         }
     }
@@ -749,11 +732,11 @@ public class NewAttributeBands extends BandSet {
      */
     public class UnionCase extends LayoutElement {
 
-        private final List body;
+        private final List<LayoutElement> body;
 
-        private final List tags;
+        private final List<Integer> tags;
 
-        public UnionCase(final List tags) {
+        public UnionCase(final List<Integer> tags) {
             this.tags = tags;
             this.body = Collections.EMPTY_LIST;
         }
@@ -762,36 +745,33 @@ public class NewAttributeBands extends BandSet {
             return tags.contains(Integer.valueOf((int) l));
         }
 
-        public UnionCase(final List tags, final List body) {
+        public UnionCase(final List<Integer> tags, final List<LayoutElement> body) {
             this.tags = tags;
             this.body = body;
         }
 
         @Override
         public void addAttributeToBand(final NewAttribute attribute, final InputStream stream) {
-            for (Object element2 : body) {
-                final LayoutElement element = (LayoutElement) element2;
+            for (LayoutElement element : body) {
                 element.addAttributeToBand(attribute, stream);
             }
         }
 
         @Override
         public void pack(final OutputStream out) throws IOException, Pack200Exception {
-            for (Object element2 : body) {
-                final LayoutElement element = (LayoutElement) element2;
+            for (LayoutElement element : body) {
                 element.pack(out);
             }
         }
 
         @Override
-        public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
-            for (Object element2 : body) {
-                final LayoutElement element = (LayoutElement) element2;
+        public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
+            for (LayoutElement element : body) {
                 element.renumberBci(bciRenumbering, labelsToOffsets);
             }
         }
 
-        public List getBody() {
+        public List<LayoutElement> getBody() {
             return body;
         }
     }
@@ -924,14 +904,14 @@ public class NewAttributeBands extends BandSet {
     /**
      * Read a 'body' section of the layout from the given stream
      *
-     * @param stream
+     * @param reader
      * @return List of LayoutElements
      * @throws IOException If an I/O error occurs.
      */
-    private List readBody(final StringReader stream) throws IOException {
-        final List layoutElements = new ArrayList();
+    private List<LayoutElement> readBody(final StringReader reader) throws IOException {
+        final List<LayoutElement> layoutElements = new ArrayList<>();
         LayoutElement e;
-        while ((e = readNextLayoutElement(stream)) != null) {
+        while ((e = readNextLayoutElement(reader)) != null) {
             layoutElements.add(e);
         }
         return layoutElements;
@@ -943,10 +923,9 @@ public class NewAttributeBands extends BandSet {
      * @param bciRenumbering TODO
      * @param labelsToOffsets TODO
      */
-    public void renumberBci(final IntList bciRenumbering, final Map labelsToOffsets) {
-        for (Object attributeLayoutElement : attributeLayoutElements) {
-            final AttributeLayoutElement element = (AttributeLayoutElement) attributeLayoutElement;
-            element.renumberBci(bciRenumbering, labelsToOffsets);
+    public void renumberBci(final IntList bciRenumbering, final Map<Label, Integer> labelsToOffsets) {
+        for (AttributeLayoutElement attributeLayoutElement : attributeLayoutElements) {
+            attributeLayoutElement.renumberBci(bciRenumbering, labelsToOffsets);
         }
     }
 
diff --git a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java
index 51dad76d..90d5ada8 100644
--- a/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java
+++ b/src/test/java/org/apache/commons/compress/harmony/pack200/tests/NewAttributeBandsTest.java
@@ -21,8 +21,6 @@ import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.util.List;
 
-import junit.framework.TestCase;
-
 import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands;
 import org.apache.commons.compress.harmony.pack200.AttributeDefinitionBands.AttributeDefinition;
 import org.apache.commons.compress.harmony.pack200.CPUTF8;
@@ -30,9 +28,11 @@ import org.apache.commons.compress.harmony.pack200.Codec;
 import org.apache.commons.compress.harmony.pack200.CpBands;
 import org.apache.commons.compress.harmony.pack200.NewAttribute;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands;
+import org.apache.commons.compress.harmony.pack200.NewAttributeBands.AttributeLayoutElement;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Call;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Callable;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Integral;
+import org.apache.commons.compress.harmony.pack200.NewAttributeBands.LayoutElement;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Reference;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Replication;
 import org.apache.commons.compress.harmony.pack200.NewAttributeBands.Union;
@@ -40,6 +40,8 @@ import org.apache.commons.compress.harmony.pack200.NewAttributeBands.UnionCase;
 import org.apache.commons.compress.harmony.pack200.Pack200Exception;
 import org.apache.commons.compress.harmony.pack200.SegmentHeader;
 
+import junit.framework.TestCase;
+
 /**
  * Tests for pack200 support for non-predefined attributes
  */
@@ -51,7 +53,7 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(0, layoutElements.size());
     }
 
@@ -85,7 +87,7 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(1, layoutElements.size());
         Integral element = (Integral) layoutElements.get(0);
         assertEquals(layoutStr, element.getTag());
@@ -97,12 +99,12 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(1, layoutElements.size());
         Replication element = (Replication) layoutElements.get(0);
         Integral countElement = element.getCountElement();
         assertEquals("H", countElement.getTag());
-        List replicatedElements = element.getLayoutElements();
+        List<LayoutElement> replicatedElements = element.getLayoutElements();
         assertEquals(5, replicatedElements.size());
         Integral firstElement = (Integral) replicatedElements.get(0);
         assertEquals("PH", firstElement.getTag());
@@ -143,7 +145,7 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(1, layoutElements.size());
         Reference element = (Reference) layoutElements.get(0);
         assertEquals(layoutStr, element.getTag());
@@ -155,26 +157,26 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(1, layoutElements.size());
         Union element = (Union) layoutElements.get(0);
         Integral tag = element.getUnionTag();
         assertEquals("B", tag.getTag());
-        List unionCases = element.getUnionCases();
+        List<UnionCase> unionCases = element.getUnionCases();
         assertEquals(2, unionCases.size());
-        UnionCase firstCase = (UnionCase) unionCases.get(0);
+        UnionCase firstCase = unionCases.get(0);
         assertTrue(firstCase.hasTag(55));
         assertFalse(firstCase.hasTag(23));
-        List body = firstCase.getBody();
+        List<LayoutElement> body = firstCase.getBody();
         assertEquals(1, body.size());
         Integral bodyElement = (Integral) body.get(0);
         assertEquals("FH", bodyElement.getTag());
-        UnionCase secondCase = (UnionCase) unionCases.get(1);
+        UnionCase secondCase = unionCases.get(1);
         assertTrue(secondCase.hasTag(23));
         assertFalse(secondCase.hasTag(55));
         body = secondCase.getBody();
         assertEquals(0, body.size());
-        List defaultBody = element.getDefaultCaseBody();
+        List<LayoutElement> defaultBody = element.getDefaultCaseBody();
         assertEquals(1, defaultBody.size());
         Reference ref = (Reference) defaultBody.get(0);
         assertEquals("RSH", ref.getTag());
@@ -187,15 +189,15 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(3, layoutElements.size());
         Callable firstCallable = (Callable) layoutElements.get(0);
         Callable secondCallable = (Callable) layoutElements.get(1);
         Callable thirdCallable = (Callable) layoutElements.get(2);
-        List firstBody = firstCallable.getBody();
+        List<LayoutElement> firstBody = firstCallable.getBody();
         assertEquals(1, firstBody.size());
         Replication rep = (Replication) firstBody.get(0);
-        List repBody = rep.getLayoutElements();
+        List<LayoutElement> repBody = rep.getLayoutElements();
         assertEquals(1, repBody.size());
         Call call = (Call) repBody.get(0);
         assertEquals(1, call.getCallableIndex());
@@ -211,12 +213,12 @@ public class NewAttributeBandsTest extends TestCase {
         MockNewAttributeBands newAttributeBands = new MockNewAttributeBands(1,
                 null, null, new AttributeDefinition(35,
                         AttributeDefinitionBands.CONTEXT_CLASS, name, layout));
-        List layoutElements = newAttributeBands.getLayoutElements();
+        List<AttributeLayoutElement> layoutElements = newAttributeBands.getLayoutElements();
         assertEquals(3, layoutElements.size());
         Callable firstCallable = (Callable) layoutElements.get(0);
         Callable secondCallable = (Callable) layoutElements.get(1);
         Callable thirdCallable = (Callable) layoutElements.get(2);
-        List thirdBody = thirdCallable.getBody();
+        List<LayoutElement> thirdBody = thirdCallable.getBody();
         assertEquals(1, thirdBody.size());
         Call call = (Call) thirdBody.get(0);
         assertEquals(secondCallable, call.getCallable());
@@ -322,7 +324,7 @@ public class NewAttributeBandsTest extends TestCase {
             super(effort, cpBands, header, def);
         }
 
-        public List getLayoutElements() {
+        public List<AttributeLayoutElement> getLayoutElements() {
             return attributeLayoutElements;
         }
     }