예제 #1
0
 private void incrementArraySize() {
   if (attributeVisitors == null) {
     attributeVisitors = new AttributeVisitor[1];
   } else {
     AttributeVisitor[] newAttributeVisitors = new AttributeVisitor[attributeVisitors.length + 1];
     System.arraycopy(attributeVisitors, 0, newAttributeVisitors, 0, attributeVisitors.length);
     attributeVisitors = newAttributeVisitors;
   }
 }
 private void ensureArraySize() {
   if (instructionVisitors == null) {
     instructionVisitors = new InstructionVisitor[ARRAY_SIZE_INCREMENT];
   } else if (instructionVisitors.length == instructionVisitorCount) {
     InstructionVisitor[] newInstructionVisitors =
         new InstructionVisitor[instructionVisitorCount + ARRAY_SIZE_INCREMENT];
     System.arraycopy(instructionVisitors, 0, newInstructionVisitors, 0, instructionVisitorCount);
     instructionVisitors = newInstructionVisitors;
   }
 }
예제 #3
0
  /**
   * Deletes the attributes with the given name from the given array of attributes, returning the
   * new number of attributes.
   */
  private int deleteAttribute(int attributesCount, Attribute[] attributes, String attributeName) {
    // Find the attribute.
    int index = findAttributeIndex(attributesCount, attributes, attributeName);
    if (index < 0) {
      return attributesCount;
    }

    // Shift the other attributes in the array.
    System.arraycopy(attributes, index + 1, attributes, index, attributesCount - index - 1);

    // Clear the last entry in the array.
    attributes[--attributesCount] = null;

    return attributesCount;
  }
예제 #4
0
  /**
   * Appends the given attribute to the given array of attributes, creating a new array if
   * necessary.
   */
  private Attribute[] addAttribute(
      int attributesCount, Attribute[] attributes, Attribute attribute) {
    // Is the array too small to contain the additional attribute?
    if (attributes.length <= attributesCount) {
      // Create a new array and copy the attributes into it.
      Attribute[] newAttributes = new Attribute[attributesCount + 1];
      System.arraycopy(attributes, 0, newAttributes, 0, attributesCount);
      attributes = newAttributes;
    }

    // Append the attribute.
    attributes[attributesCount] = attribute;

    return attributes;
  }