org.jdom_1.1.1.v201101151400

16:49:40.908 INFO  jd.cli.Main - Decompiling org.jdom_1.1.1.v201101151400.jar
package org.jdom;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

public class Attribute
  implements Serializable, Cloneable
{
  private static final String CVS_ID = "@(#) $RCSfile: Attribute.java,v $ $Revision: 1.56 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
  public static final int UNDECLARED_TYPE = 0;
  public static final int CDATA_TYPE = 1;
  public static final int ID_TYPE = 2;
  public static final int IDREF_TYPE = 3;
  public static final int IDREFS_TYPE = 4;
  public static final int ENTITY_TYPE = 5;
  public static final int ENTITIES_TYPE = 6;
  public static final int NMTOKEN_TYPE = 7;
  public static final int NMTOKENS_TYPE = 8;
  public static final int NOTATION_TYPE = 9;
  public static final int ENUMERATED_TYPE = 10;
  protected String name;
  protected transient Namespace namespace;
  protected String value;
  protected int type = 0;
  protected Element parent;
  
  protected Attribute() {}
  
  public Attribute(String name, String value, Namespace namespace)
  {
    this(name, value, 0, namespace);
  }
  
  public Attribute(String name, String value, int type, Namespace namespace)
  {
    setName(name);
    setValue(value);
    setAttributeType(type);
    setNamespace(namespace);
  }
  
  public Attribute(String name, String value)
  {
    this(name, value, 0, Namespace.NO_NAMESPACE);
  }
  
  public Attribute(String name, String value, int type)
  {
    this(name, value, type, Namespace.NO_NAMESPACE);
  }
  
  public Element getParent()
  {
    return parent;
  }
  
  public Document getDocument()
  {
    Element parentElement = getParent();
    if (parentElement != null) {
      return parentElement.getDocument();
    }
    return null;
  }
  
  protected Attribute setParent(Element parent)
  {
    this.parent = parent;
    return this;
  }
  
  public Attribute detach()
  {
    Element parentElement = getParent();
    if (parentElement != null) {
      parentElement.removeAttribute(getName(), getNamespace());
    }
    return this;
  }
  
  public String getName()
  {
    return name;
  }
  
  public Attribute setName(String name)
  {
    String reason = Verifier.checkAttributeName(name);
    if (reason != null) {
      throw new IllegalNameException(name, "attribute", reason);
    }
    this.name = name;
    return this;
  }
  
  public String getQualifiedName()
  {
    String prefix = namespace.getPrefix();
    if ((prefix == null) || ("".equals(prefix))) {
      return getName();
    }
    return prefix + ':' + getName();
  }
  
  public String getNamespacePrefix()
  {
    return namespace.getPrefix();
  }
  
  public String getNamespaceURI()
  {
    return namespace.getURI();
  }
  
  public Namespace getNamespace()
  {
    return namespace;
  }
  
  public Attribute setNamespace(Namespace namespace)
  {
    if (namespace == null) {
      namespace = Namespace.NO_NAMESPACE;
    }
    if ((namespace != Namespace.NO_NAMESPACE) && ("".equals(namespace.getPrefix()))) {
      throw new IllegalNameException("", "attribute namespace", "An attribute namespace without a prefix can only be the NO_NAMESPACE namespace");
    }
    this.namespace = namespace;
    return this;
  }
  
  public String getValue()
  {
    return value;
  }
  
  public Attribute setValue(String value)
  {
    String reason = Verifier.checkCharacterData(value);
    if (reason != null) {
      throw new IllegalDataException(value, "attribute", reason);
    }
    this.value = value;
    return this;
  }
  
  public int getAttributeType()
  {
    return type;
  }
  
  public Attribute setAttributeType(int type)
  {
    if ((type < 0) || (type > 10)) {
      throw new IllegalDataException(String.valueOf(type), "attribute", "Illegal attribute type");
    }
    this.type = type;
    return this;
  }
  
  public String toString()
  {
    return "[Attribute: " + getQualifiedName() + "=\"" + value + "\"" + "]";
  }
  
  public final boolean equals(Object ob)
  {
    return ob == this;
  }
  
  public final int hashCode()
  {
    return super.hashCode();
  }
  
  public Object clone()
  {
    Attribute attribute = null;
    try
    {
      attribute = (Attribute)super.clone();
    }
    catch (CloneNotSupportedException ignore) {}
    parent = null;
    return attribute;
  }
  
  public int getIntValue()
    throws DataConversionException
  {
    try
    {
      return Integer.parseInt(value.trim());
    }
    catch (NumberFormatException e)
    {
      throw new DataConversionException(name, "int");
    }
  }
  
  public long getLongValue()
    throws DataConversionException
  {
    try
    {
      return Long.parseLong(value.trim());
    }
    catch (NumberFormatException e)
    {
      throw new DataConversionException(name, "long");
    }
  }
  
  public float getFloatValue()
    throws DataConversionException
  {
    try
    {
      return Float.valueOf(value.trim()).floatValue();
    }
    catch (NumberFormatException e)
    {
      throw new DataConversionException(name, "float");
    }
  }
  
  public double getDoubleValue()
    throws DataConversionException
  {
    try
    {
      return Double.valueOf(value.trim()).doubleValue();
    }
    catch (NumberFormatException e)
    {
      String v = value.trim();
      if ("INF".equals(v)) {
        return Double.POSITIVE_INFINITY;
      }
      if ("-INF".equals(v)) {
        return Double.NEGATIVE_INFINITY;
      }
      throw new DataConversionException(name, "double");
    }
  }
  
  public boolean getBooleanValue()
    throws DataConversionException
  {
    String valueTrim = value.trim();
    if ((valueTrim.equalsIgnoreCase("true")) || (valueTrim.equalsIgnoreCase("on")) || (valueTrim.equalsIgnoreCase("1")) || (valueTrim.equalsIgnoreCase("yes"))) {
      return true;
    }
    if ((valueTrim.equalsIgnoreCase("false")) || (valueTrim.equalsIgnoreCase("off")) || (valueTrim.equalsIgnoreCase("0")) || (valueTrim.equalsIgnoreCase("no"))) {
      return false;
    }
    throw new DataConversionException(name, "boolean");
  }
  
  private void writeObject(ObjectOutputStream out)
    throws IOException
  {
    out.defaultWriteObject();
    
    out.writeObject(namespace.getPrefix());
    out.writeObject(namespace.getURI());
  }
  
  private void readObject(ObjectInputStream in)
    throws IOException, ClassNotFoundException
  {
    in.defaultReadObject();
    
    namespace = Namespace.getNamespace((String)in.readObject(), (String)in.readObject());
  }
}

/* Location:
 * Qualified Name:     org.jdom.Attribute
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

class AttributeList
  extends AbstractList
  implements List, Serializable
{
  private static final String CVS_ID = "@(#) $RCSfile: AttributeList.java,v $ $Revision: 1.24 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
  private static final int INITIAL_ARRAY_SIZE = 5;
  private Attribute[] elementData;
  private int size;
  private Element parent;
  
  private AttributeList() {}
  
  AttributeList(Element parent)
  {
    this.parent = parent;
  }
  
  final void uncheckedAddAttribute(Attribute a)
  {
    parent = parent;
    ensureCapacity(size + 1);
    elementData[(size++)] = a;
    modCount += 1;
  }
  
  public boolean add(Object obj)
  {
    if ((obj instanceof Attribute))
    {
      Attribute attribute = (Attribute)obj;
      int duplicate = indexOfDuplicate(attribute);
      if (duplicate < 0) {
        add(size(), attribute);
      } else {
        set(duplicate, attribute);
      }
    }
    else
    {
      if (obj == null) {
        throw new IllegalAddException("Cannot add null attribute");
      }
      throw new IllegalAddException("Class " + obj.getClass().getName() + " is not an attribute");
    }
    return true;
  }
  
  public void add(int index, Object obj)
  {
    if ((obj instanceof Attribute))
    {
      Attribute attribute = (Attribute)obj;
      int duplicate = indexOfDuplicate(attribute);
      if (duplicate >= 0) {
        throw new IllegalAddException("Cannot add duplicate attribute");
      }
      add(index, attribute);
    }
    else
    {
      if (obj == null) {
        throw new IllegalAddException("Cannot add null attribute");
      }
      throw new IllegalAddException("Class " + obj.getClass().getName() + " is not an attribute");
    }
    modCount += 1;
  }
  
  void add(int index, Attribute attribute)
  {
    if (attribute.getParent() != null) {
      throw new IllegalAddException("The attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\"");
    }
    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }
    if ((index < 0) || (index > size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    attribute.setParent(parent);
    
    ensureCapacity(size + 1);
    if (index == size)
    {
      elementData[(size++)] = attribute;
    }
    else
    {
      System.arraycopy(elementData, index, elementData, index + 1, size - index);
      elementData[index] = attribute;
      size += 1;
    }
    modCount += 1;
  }
  
  public boolean addAll(Collection collection)
  {
    return addAll(size(), collection);
  }
  
  public boolean addAll(int index, Collection collection)
  {
    if ((index < 0) || (index > size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    if ((collection == null) || (collection.size() == 0)) {
      return false;
    }
    ensureCapacity(size() + collection.size());
    
    int count = 0;
    try
    {
      Iterator i = collection.iterator();
      while (i.hasNext())
      {
        Object obj = i.next();
        add(index + count, obj);
        count++;
      }
    }
    catch (RuntimeException exception)
    {
      for (int i = 0; i < count; i++) {
        remove(index);
      }
      throw exception;
    }
    return true;
  }
  
  public void clear()
  {
    if (elementData != null)
    {
      for (int i = 0; i < size; i++)
      {
        Attribute attribute = elementData[i];
        attribute.setParent(null);
      }
      elementData = null;
      size = 0;
    }
    modCount += 1;
  }
  
  void clearAndSet(Collection collection)
  {
    Attribute[] old = elementData;
    int oldSize = size;
    
    elementData = null;
    size = 0;
    if ((collection != null) && (collection.size() != 0))
    {
      ensureCapacity(collection.size());
      try
      {
        addAll(0, collection);
      }
      catch (RuntimeException exception)
      {
        elementData = old;
        size = oldSize;
        throw exception;
      }
    }
    if (old != null) {
      for (int i = 0; i < oldSize; i++)
      {
        Attribute attribute = old[i];
        attribute.setParent(null);
      }
    }
    modCount += 1;
  }
  
  private void ensureCapacity(int minCapacity)
  {
    if (elementData == null)
    {
      elementData = new Attribute[Math.max(minCapacity, 5)];
    }
    else
    {
      int oldCapacity = elementData.length;
      if (minCapacity > oldCapacity)
      {
        Attribute[] oldData = elementData;
        int newCapacity = oldCapacity * 3 / 2 + 1;
        if (newCapacity < minCapacity) {
          newCapacity = minCapacity;
        }
        elementData = new Attribute[newCapacity];
        System.arraycopy(oldData, 0, elementData, 0, size);
      }
    }
  }
  
  public Object get(int index)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    return elementData[index];
  }
  
  Object get(String name, Namespace namespace)
  {
    int index = indexOf(name, namespace);
    if (index < 0) {
      return null;
    }
    return elementData[index];
  }
  
  int indexOf(String name, Namespace namespace)
  {
    String uri = namespace.getURI();
    if (elementData != null) {
      for (int i = 0; i < size; i++)
      {
        Attribute old = elementData[i];
        String oldURI = old.getNamespaceURI();
        String oldName = old.getName();
        if ((oldURI.equals(uri)) && (oldName.equals(name))) {
          return i;
        }
      }
    }
    return -1;
  }
  
  public Object remove(int index)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    Attribute old = elementData[index];
    old.setParent(null);
    int numMoved = size - index - 1;
    if (numMoved > 0) {
      System.arraycopy(elementData, index + 1, elementData, index, numMoved);
    }
    elementData[(--size)] = null;
    modCount += 1;
    return old;
  }
  
  boolean remove(String name, Namespace namespace)
  {
    int index = indexOf(name, namespace);
    if (index < 0) {
      return false;
    }
    remove(index);
    return true;
  }
  
  public Object set(int index, Object obj)
  {
    if ((obj instanceof Attribute))
    {
      Attribute attribute = (Attribute)obj;
      int duplicate = indexOfDuplicate(attribute);
      if ((duplicate >= 0) && (duplicate != index)) {
        throw new IllegalAddException("Cannot set duplicate attribute");
      }
      return set(index, attribute);
    }
    if (obj == null) {
      throw new IllegalAddException("Cannot add null attribute");
    }
    throw new IllegalAddException("Class " + obj.getClass().getName() + " is not an attribute");
  }
  
  Object set(int index, Attribute attribute)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    if (attribute.getParent() != null) {
      throw new IllegalAddException("The attribute already has an existing parent \"" + attribute.getParent().getQualifiedName() + "\"");
    }
    String reason = Verifier.checkNamespaceCollision(attribute, parent);
    if (reason != null) {
      throw new IllegalAddException(parent, attribute, reason);
    }
    Attribute old = elementData[index];
    old.setParent(null);
    
    elementData[index] = attribute;
    attribute.setParent(parent);
    return old;
  }
  
  private int indexOfDuplicate(Attribute attribute)
  {
    int duplicate = -1;
    String name = attribute.getName();
    Namespace namespace = attribute.getNamespace();
    duplicate = indexOf(name, namespace);
    return duplicate;
  }
  
  public int size()
  {
    return size;
  }
  
  public String toString()
  {
    return super.toString();
  }
}

/* Location:
 * Qualified Name:     org.jdom.AttributeList
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

public class CDATA
  extends Text
{
  private static final String CVS_ID = "@(#) $RCSfile: CDATA.java,v $ $Revision: 1.32 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
  
  protected CDATA() {}
  
  public CDATA(String string)
  {
    setText(string);
  }
  
  public Text setText(String str)
  {
    if ((str == null) || ("".equals(str)))
    {
      value = "";
      return this;
    }
    String reason = Verifier.checkCDATASection(str);
    if (reason != null) {
      throw new IllegalDataException(str, "CDATA section", reason);
    }
    value = str;
    
    return this;
  }
  
  public void append(String str)
  {
    if ((str == null) || ("".equals(str))) {
      return;
    }
    String tmpValue;
    String tmpValue;
    if (value == "") {
      tmpValue = str;
    } else {
      tmpValue = value + str;
    }
    String reason = Verifier.checkCDATASection(tmpValue);
    if (reason != null) {
      throw new IllegalDataException(str, "CDATA section", reason);
    }
    value = tmpValue;
  }
  
  public void append(Text text)
  {
    if (text == null) {
      return;
    }
    append(text.getText());
  }
  
  public String toString()
  {
    return 64 + "[CDATA: " + getText() + "]";
  }
}

/* Location:
 * Qualified Name:     org.jdom.CDATA
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import org.jdom.output.XMLOutputter;

public class Comment
  extends Content
{
  private static final String CVS_ID = "@(#) $RCSfile: Comment.java,v $ $Revision: 1.33 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
  protected String text;
  
  protected Comment() {}
  
  public Comment(String text)
  {
    setText(text);
  }
  
  public String getValue()
  {
    return text;
  }
  
  public String getText()
  {
    return text;
  }
  
  public Comment setText(String text)
  {
    String reason;
    if ((reason = Verifier.checkCommentData(text)) != null) {
      throw new IllegalDataException(text, "comment", reason);
    }
    this.text = text;
    return this;
  }
  
  public String toString()
  {
    return "[Comment: " + new XMLOutputter().outputString(this) + "]";
  }
}

/* Location:
 * Qualified Name:     org.jdom.Comment
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import java.io.Serializable;

public abstract class Content
  implements Cloneable, Serializable
{
  protected Parent parent = null;
  
  public Content detach()
  {
    if (parent != null) {
      parent.removeContent(this);
    }
    return this;
  }
  
  public Parent getParent()
  {
    return parent;
  }
  
  public Element getParentElement()
  {
    Parent parent = getParent();
    return (Element)((parent instanceof Element) ? parent : null);
  }
  
  protected Content setParent(Parent parent)
  {
    this.parent = parent;
    return this;
  }
  
  public Document getDocument()
  {
    if (parent == null) {
      return null;
    }
    return parent.getDocument();
  }
  
  public abstract String getValue();
  
  public Object clone()
  {
    try
    {
      Content c = (Content)super.clone();
      parent = null;
      return c;
    }
    catch (CloneNotSupportedException e) {}
    return null;
  }
  
  public final boolean equals(Object ob)
  {
    return ob == this;
  }
  
  public final int hashCode()
  {
    return super.hashCode();
  }
}

/* Location:
 * Qualified Name:     org.jdom.Content
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Iterator;
import java.util.ListIterator;
import org.jdom.filter.Filter;

class ContentList$FilterList
  extends AbstractList
  implements Serializable
{
  Filter filter;
  int count;
  int expected;
  private final ContentList this$0;
  
  ContentList$FilterList(ContentList paramContentList, Filter filter)
  {
    this$0 = paramContentList;count = 0;expected = -1;
    this.filter = filter;
  }
  
  public void add(int index, Object obj)
  {
    if (filter.matches(obj))
    {
      int adjusted = getAdjustedIndex(index);
      this$0.add(adjusted, obj);
      expected += 1;
      count += 1;
    }
    else
    {
      throw new IllegalAddException("Filter won't allow the " + obj.getClass().getName() + " '" + obj + "' to be added to the list");
    }
  }
  
  public Object get(int index)
  {
    int adjusted = getAdjustedIndex(index);
    return this$0.get(adjusted);
  }
  
  public Iterator iterator()
  {
    return new ContentList.FilterListIterator(this$0, filter, 0);
  }
  
  public ListIterator listIterator()
  {
    return new ContentList.FilterListIterator(this$0, filter, 0);
  }
  
  public ListIterator listIterator(int index)
  {
    return new ContentList.FilterListIterator(this$0, filter, index);
  }
  
  public Object remove(int index)
  {
    int adjusted = getAdjustedIndex(index);
    Object old = this$0.get(adjusted);
    if (filter.matches(old))
    {
      old = this$0.remove(adjusted);
      expected += 1;
      count -= 1;
    }
    else
    {
      throw new IllegalAddException("Filter won't allow the " + old.getClass().getName() + " '" + old + "' (index " + index + ") to be removed");
    }
    return old;
  }
  
  public Object set(int index, Object obj)
  {
    Object old = null;
    if (filter.matches(obj))
    {
      int adjusted = getAdjustedIndex(index);
      old = this$0.get(adjusted);
      if (!filter.matches(old)) {
        throw new IllegalAddException("Filter won't allow the " + old.getClass().getName() + " '" + old + "' (index " + index + ") to be removed");
      }
      old = this$0.set(adjusted, obj);
      expected += 2;
    }
    else
    {
      throw new IllegalAddException("Filter won't allow index " + index + " to be set to " + obj.getClass().getName());
    }
    return old;
  }
  
  public int size()
  {
    if (expected == ContentList.access$000(this$0)) {
      return count;
    }
    count = 0;
    for (int i = 0; i < this$0.size(); i++)
    {
      Object obj = ContentList.access$100(this$0)[i];
      if (filter.matches(obj)) {
        count += 1;
      }
    }
    expected = ContentList.access$000(this$0);
    return count;
  }
  
  private final int getAdjustedIndex(int index)
  {
    int adjusted = 0;
    for (int i = 0; i < ContentList.access$200(this$0); i++)
    {
      Object obj = ContentList.access$100(this$0)[i];
      if (filter.matches(obj))
      {
        if (index == adjusted) {
          return i;
        }
        adjusted++;
      }
    }
    if (index == adjusted) {
      return ContentList.access$200(this$0);
    }
    return ContentList.access$200(this$0) + 1;
  }
}

/* Location:
 * Qualified Name:     org.jdom.ContentList.FilterList
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import java.util.ConcurrentModificationException;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jdom.filter.Filter;

class ContentList$FilterListIterator
  implements ListIterator
{
  Filter filter;
  private boolean forward;
  private boolean canremove;
  private boolean canset;
  private int cursor;
  private int tmpcursor;
  private int index;
  private int expected;
  private int fsize;
  private final ContentList this$0;
  
  ContentList$FilterListIterator(ContentList arg1, Filter filter, int start)
  {
    this$0 = ???;forward = false;canremove = false;canset = false;cursor = -1;tmpcursor = -1;index = -1;expected = -1;fsize = 0;
    this.filter = filter;
    expected = ContentList.access$000(???);
    
    forward = false;
    if (start < 0) {
      throw new IndexOutOfBoundsException("Index: " + start);
    }
    fsize = 0;
    for (int i = 0; i < ???.size(); i++) {
      if (filter.matches(???.get(i)))
      {
        if (start == fsize)
        {
          cursor = i;
          
          index = fsize;
        }
        fsize += 1;
      }
    }
    if (start > fsize) {
      throw new IndexOutOfBoundsException("Index: " + start + " Size: " + fsize);
    }
    if (cursor == -1)
    {
      cursor = ???.size();
      index = fsize;
    }
  }
  
  public boolean hasNext()
  {
    return nextIndex() < fsize;
  }
  
  public Object next()
  {
    if (!hasNext()) {
      throw new NoSuchElementException("next() is beyond the end of the Iterator");
    }
    index = nextIndex();
    cursor = tmpcursor;
    forward = true;
    canremove = true;
    canset = true;
    return this$0.get(cursor);
  }
  
  public boolean hasPrevious()
  {
    return previousIndex() >= 0;
  }
  
  public Object previous()
  {
    if (!hasPrevious()) {
      throw new NoSuchElementException("previous() is before the start of the Iterator");
    }
    index = previousIndex();
    cursor = tmpcursor;
    forward = false;
    canremove = true;
    canset = true;
    return this$0.get(cursor);
  }
  
  public int nextIndex()
  {
    checkConcurrentModification();
    if (forward)
    {
      for (int i = cursor + 1; i < this$0.size(); i++) {
        if (filter.matches(this$0.get(i)))
        {
          tmpcursor = i;
          return index + 1;
        }
      }
      tmpcursor = this$0.size();
      return index + 1;
    }
    tmpcursor = cursor;
    return index;
  }
  
  public int previousIndex()
  {
    checkConcurrentModification();
    if (!forward)
    {
      for (int i = cursor - 1; i >= 0; i--) {
        if (filter.matches(this$0.get(i)))
        {
          tmpcursor = i;
          return index - 1;
        }
      }
      tmpcursor = -1;
      return index - 1;
    }
    tmpcursor = cursor;
    return index;
  }
  
  public void add(Object obj)
  {
    nextIndex();
    
    this$0.add(tmpcursor, obj);
    forward = true;
    expected = ContentList.access$000(this$0);
    canremove = (canset = 0);
    index = nextIndex();
    cursor = tmpcursor;
    fsize += 1;
  }
  
  public void remove()
  {
    if (!canremove) {
      throw new IllegalStateException("Can not remove an element unless either next() or previous() has been called since the last remove()");
    }
    nextIndex();
    this$0.remove(cursor);
    cursor = (tmpcursor - 1);
    expected = ContentList.access$000(this$0);
    
    forward = false;
    canremove = false;
    canset = false;
    fsize -= 1;
  }
  
  public void set(Object obj)
  {
    if (!canset) {
      throw new IllegalStateException("Can not set an element unless either next() or previous() has been called since the last remove() or set()");
    }
    checkConcurrentModification();
    if (!filter.matches(obj)) {
      throw new IllegalAddException("Filter won't allow index " + index + " to be set to " + obj.getClass().getName());
    }
    this$0.set(cursor, obj);
    expected = ContentList.access$000(this$0);
  }
  
  private void checkConcurrentModification()
  {
    if (expected != ContentList.access$000(this$0)) {
      throw new ConcurrentModificationException();
    }
  }
}

/* Location:
 * Qualified Name:     org.jdom.ContentList.FilterListIterator
 * Java Class Version: 1.2 (46.0)
 * JD-Core Version:    0.7.1
 */
package org.jdom;

import java.io.Serializable;
import java.util.AbstractList;
import java.util.Collection;
import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.NoSuchElementException;
import org.jdom.filter.Filter;

final class ContentList
  extends AbstractList
  implements Serializable
{
  private static final String CVS_ID = "@(#) $RCSfile: ContentList.java,v $ $Revision: 1.42 $ $Date: 2007/11/10 05:28:58 $ $Name: jdom_1_1_1 $";
  private static final long serialVersionUID = 1L;
  private static final int INITIAL_ARRAY_SIZE = 5;
  private Content[] elementData;
  private int size;
  private Parent parent;
  
  ContentList(Parent parent)
  {
    this.parent = parent;
  }
  
  final void uncheckedAddContent(Content c)
  {
    parent = parent;
    ensureCapacity(size + 1);
    elementData[(size++)] = c;
    modCount += 1;
  }
  
  public void add(int index, Object obj)
  {
    if (obj == null) {
      throw new IllegalAddException("Cannot add null object");
    }
    if ((obj instanceof String)) {
      obj = new Text(obj.toString());
    }
    if ((obj instanceof Content)) {
      add(index, (Content)obj);
    } else {
      throw new IllegalAddException("Class " + obj.getClass().getName() + " is of unrecognized type and cannot be added");
    }
  }
  
  private void documentCanContain(int index, Content child)
    throws IllegalAddException
  {
    if ((child instanceof Element))
    {
      if (indexOfFirstElement() >= 0) {
        throw new IllegalAddException("Cannot add a second root element, only one is allowed");
      }
      if (indexOfDocType() > index) {
        throw new IllegalAddException("A root element cannot be added before the DocType");
      }
    }
    if ((child instanceof DocType))
    {
      if (indexOfDocType() >= 0) {
        throw new IllegalAddException("Cannot add a second doctype, only one is allowed");
      }
      int firstElt = indexOfFirstElement();
      if ((firstElt != -1) && (firstElt < index)) {
        throw new IllegalAddException("A DocType cannot be added after the root element");
      }
    }
    if ((child instanceof CDATA)) {
      throw new IllegalAddException("A CDATA is not allowed at the document root");
    }
    if ((child instanceof Text)) {
      throw new IllegalAddException("A Text is not allowed at the document root");
    }
    if ((child instanceof EntityRef)) {
      throw new IllegalAddException("An EntityRef is not allowed at the document root");
    }
  }
  
  private static void elementCanContain(int index, Content child)
    throws IllegalAddException
  {
    if ((child instanceof DocType)) {
      throw new IllegalAddException("A DocType is not allowed except at the document level");
    }
  }
  
  void add(int index, Content child)
  {
    if (child == null) {
      throw new IllegalAddException("Cannot add null object");
    }
    if ((parent instanceof Document)) {
      documentCanContain(index, child);
    } else {
      elementCanContain(index, child);
    }
    if (child.getParent() != null)
    {
      Parent p = child.getParent();
      if ((p instanceof Document)) {
        throw new IllegalAddException((Element)child, "The Content already has an existing parent document");
      }
      throw new IllegalAddException("The Content already has an existing parent \"" + ((Element)p).getQualifiedName() + "\"");
    }
    if (child == parent) {
      throw new IllegalAddException("The Element cannot be added to itself");
    }
    if (((parent instanceof Element)) && ((child instanceof Element)) && (((Element)child).isAncestor((Element)parent))) {
      throw new IllegalAddException("The Element cannot be added as a descendent of itself");
    }
    if ((index < 0) || (index > size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    child.setParent(parent);
    
    ensureCapacity(size + 1);
    if (index == size)
    {
      elementData[(size++)] = child;
    }
    else
    {
      System.arraycopy(elementData, index, elementData, index + 1, size - index);
      elementData[index] = child;
      size += 1;
    }
    modCount += 1;
  }
  
  public boolean addAll(Collection collection)
  {
    return addAll(size(), collection);
  }
  
  public boolean addAll(int index, Collection collection)
  {
    if ((index < 0) || (index > size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    if ((collection == null) || (collection.size() == 0)) {
      return false;
    }
    ensureCapacity(size() + collection.size());
    
    int count = 0;
    try
    {
      Iterator i = collection.iterator();
      while (i.hasNext())
      {
        Object obj = i.next();
        add(index + count, obj);
        count++;
      }
    }
    catch (RuntimeException exception)
    {
      for (int i = 0; i < count; i++) {
        remove(index);
      }
      throw exception;
    }
    return true;
  }
  
  public void clear()
  {
    if (elementData != null)
    {
      for (int i = 0; i < size; i++)
      {
        Content obj = elementData[i];
        removeParent(obj);
      }
      elementData = null;
      size = 0;
    }
    modCount += 1;
  }
  
  void clearAndSet(Collection collection)
  {
    Content[] old = elementData;
    int oldSize = size;
    
    elementData = null;
    size = 0;
    if ((collection != null) && (collection.size() != 0))
    {
      ensureCapacity(collection.size());
      try
      {
        addAll(0, collection);
      }
      catch (RuntimeException exception)
      {
        elementData = old;
        size = oldSize;
        throw exception;
      }
    }
    if (old != null) {
      for (int i = 0; i < oldSize; i++) {
        removeParent(old[i]);
      }
    }
    modCount += 1;
  }
  
  void ensureCapacity(int minCapacity)
  {
    if (elementData == null)
    {
      elementData = new Content[Math.max(minCapacity, 5)];
    }
    else
    {
      int oldCapacity = elementData.length;
      if (minCapacity > oldCapacity)
      {
        Object[] oldData = elementData;
        int newCapacity = oldCapacity * 3 / 2 + 1;
        if (newCapacity < minCapacity) {
          newCapacity = minCapacity;
        }
        elementData = new Content[newCapacity];
        System.arraycopy(oldData, 0, elementData, 0, size);
      }
    }
  }
  
  public Object get(int index)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    return elementData[index];
  }
  
  List getView(Filter filter)
  {
    return new FilterList(filter);
  }
  
  int indexOfFirstElement()
  {
    if (elementData != null) {
      for (int i = 0; i < size; i++) {
        if ((elementData[i] instanceof Element)) {
          return i;
        }
      }
    }
    return -1;
  }
  
  int indexOfDocType()
  {
    if (elementData != null) {
      for (int i = 0; i < size; i++) {
        if ((elementData[i] instanceof DocType)) {
          return i;
        }
      }
    }
    return -1;
  }
  
  public Object remove(int index)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    Content old = elementData[index];
    removeParent(old);
    int numMoved = size - index - 1;
    if (numMoved > 0) {
      System.arraycopy(elementData, index + 1, elementData, index, numMoved);
    }
    elementData[(--size)] = null;
    modCount += 1;
    return old;
  }
  
  private static void removeParent(Content c)
  {
    c.setParent(null);
  }
  
  public Object set(int index, Object obj)
  {
    if ((index < 0) || (index >= size)) {
      throw new IndexOutOfBoundsException("Index: " + index + " Size: " + size());
    }
    if (((obj instanceof Element)) && ((parent instanceof Document)))
    {
      int root = indexOfFirstElement();
      if ((root >= 0) && (root != index)) {
        throw new IllegalAddException("Cannot add a second root element, only one is allowed");
      }
    }
    if (((obj instanceof DocType)) && ((parent instanceof Document)))
    {
      int docTypeIndex = indexOfDocType();
      if ((docTypeIndex >= 0) && (docTypeIndex != index)) {
        throw new IllegalAddException("Cannot add a second doctype, only one is allowed");
      }
    }
    Object old = remove(index);
    try
    {
      add(index, obj);
    }
    catch (RuntimeException exception)
    {
      add(index, old);
      throw exception;
    }
    return old;
  }
  
  public int size()
  {
    return size;
  }
  
  public String toString()
  {
    return super.toString();
  }
  
  private int getModCount()
  {
    return modCount;
  }
  
  class FilterList
    extends AbstractList
    implements Serializable
  {
    Filter filter;
    int count = 0;
    int expected = -1;
    
    FilterList(Filter filter)
    {
      this.filter = filter;
    }
    
    public void add(int index, Object obj)
    {
      if (filter.matches(obj))
      {
        int adjusted = getAdjustedIndex(index);
        ContentList.this.add(adjusted, obj);
        expected += 1;
        count += 1;
      }
      else
      {
        throw new IllegalAddException("Filter won't allow the " + obj.getClass().getName() + " '" + obj + "' to be added to the list");
      }
    }
    
    public Object get(int index)
    {
      int adjusted = getAdjustedIndex(index);
      return ContentList.this.get(adjusted);
    }
    
    public Iterator iterator()
    {
      return new ContentList.FilterListIterator(ContentList.this, filter, 0);
    }
    
    public ListIterator listIterator()
    {
      return new ContentList.FilterListIterator(ContentList.this, filter, 0);
    }
    
    public ListIterator listIterator(int index)
    {
      return new ContentList.FilterListIterator(ContentList.this, filter, index);
    }
    
    public Object remove(int index)
    {
      int adjusted = getAdjustedIndex(index);
      Object old = ContentList.this.get(adjusted);
      if (filter.matches(old))
      {
        old = ContentList.this.remove(adjusted);
        expected += 1;
        count -= 1;
      }
      else
      {
        throw new IllegalAddException("Filter won't allow the " + old.getClass().getName() + " '" + old + "' (index " + index + ") to be removed");
      }
      return old;
    }
    
    public Object set(int index, Object obj)
    {
      Object old = null;
      if (filter.matches(obj))
      {
        int adjusted = getAdjustedIndex(index);
        old = ContentList.this.get(adjusted);
        if (!filter.matches(old)) {
          throw new IllegalAddException("Filter won't allow the " + old.getClass().getName() + " '" + old + "' (index " + index + ") to be removed");
        }
        old = ContentList.this.set(adjusted, obj);
        expected += 2;
      }
      else
      {
        throw new IllegalAddException("Filter won't allow index " + index + " to be set to " + obj.getClass().getName());
      }
      return old;
    }
    
    public int size()
    {
      if (expected == ContentList.this.getModCount()) {
        return count;
      }
      count = 0;
      for (int i = 0; i < ContentList.this.size(); i++)
      {
        Object obj = elementData[i];
        if (filter.matches(obj)) {
          count += 1;
        }
      }
      expected = ContentList.this.getModCount();
      return count;
    }
    
    private final int getAdjustedIndex(int index)
    {
      int adjusted = 0;
      for (int i = 0; i < size; i++)
      {
        Object obj = elementData[i];
        if (filter.matches(obj))
        {
          if (index == adjusted) {
            return i;
          }
          adjusted++;
        }
      }
      if (index == adjusted) {
        return size;
      }
      return size + 1;
    }
  }
  
  class FilterListIterator
    implements ListIterator
  {
    Filter filter;
    private boolean forward = false;
    private boolean canremove = false;
    private boolean canset = false;
    private int cursor = -1;
    private int tmpcursor = -1;
    private int index = -1;
    private int expected = -1;
    private int fsize = 0;
    
    FilterListIterator(Filter filter, int start)
    {
      this.filter = filter;
      expected = ContentList.this.getModCount();
      
      forward = false;
      if (start < 0) {
        throw new IndexOutOfBoundsException("Index: " + start);
      }
      fsize = 0;
      for (int i = 0; i < size(); i++) {
        if (filter.matches(get(i)))
        {
          if (start == fsize)
          {
            cursor = i;
            
            index = fsize;
          }
          fsize += 1;
        }
      }
      if (start > fsize) {
        throw new IndexOutOfBoundsException("Index: " + start + " Size: " + fsize);
      }
      if (cursor == -1)
      {
        cursor = size();
        index = fsize;
      }
    }
    
    public boolean hasNext()
    {
      return nextIndex() < fsize;
    }
    
    public Object next()
    {
      if (!hasNext()) {
        throw new NoSuchElementException("next() is beyond the end of the Iterator");
      }
      index = nextIndex();
      cursor = tmpcursor;
      forward = true;
      canremove = true;
      canset = true;
      return get(cursor);
    }
    
    public boolean hasPrevious()
    {
      return previousIndex() >= 0;
    }
    
    public Object previous()
    {
      if (!hasPrevious()) {
        throw new NoSuchElementException("previous() is before the start of the Iterator");
      }
      index = previousIndex();
      cursor = tmpcursor;
      forward = false;
      canremove = true;
      canset = true;
      return get(cursor);
    }
    
    public int nextIndex()
    {
      checkConcurrentModification();
      if (forward)
      {
        for (int i = cursor + 1; i < size(); i++) {
          if (filter.matches(get(i)))
          {
            tmpcursor = i;
            return
1 2 3 4 5 6 7 8

Further reading...

For more information on Java 1.5 Tiger, you may find Java 1.5 Tiger, A developer's Notebook by D. Flanagan and B. McLaughlin from O'Reilly of interest.

New!JAR listings


Copyright 2006-2017. Infinite Loop Ltd