FileDocCategorySizeDatePackage
POIFSDocumentPath.javaAPI DocApache Poi 3.0.18368Mon Jan 01 12:39:34 GMT 2007org.apache.poi.poifs.filesystem

POIFSDocumentPath

public class POIFSDocumentPath extends Object
Class POIFSDocumentPath
author
Marc Johnson (mjohnson at apache dot org)
version
%I%, %G%

Fields Summary
private String[]
components
private int
hashcode
Constructors Summary
public POIFSDocumentPath(String[] components)
constructor for the path of a document that is not in the root of the POIFSFileSystem

param
components the Strings making up the path to a document. The Strings must be ordered as they appear in the directory hierarchy of the the document -- the first string must be the name of a directory in the root of the POIFSFileSystem, and every Nth (for N > 1) string thereafter must be the name of a directory in the directory identified by the (N-1)th string.

If the components parameter is null or has zero length, the POIFSDocumentPath is appropriate for a document that is in the root of a POIFSFileSystem

exception
IllegalArgumentException if any of the elements in the components parameter are null or have zero length


                                                                                                                                                                                                                                                                                                                                                                                                                                                                            

        
         
    
        if (components == null)
        {
            this.components = new String[ 0 ];
        }
        else
        {
            this.components = new String[ components.length ];
            for (int j = 0; j < components.length; j++)
            {
                if ((components[ j ] == null)
                        || (components[ j ].length() == 0))
                {
                    throw new IllegalArgumentException(
                        "components cannot contain null or empty strings");
                }
                this.components[ j ] = components[ j ];
            }
        }
    
public POIFSDocumentPath()
simple constructor for the path of a document that is in the root of the POIFSFileSystem. The constructor that takes an array of Strings can also be used to create such a POIFSDocumentPath by passing it a null or empty String array

        this.components = new String[ 0 ];
    
public POIFSDocumentPath(POIFSDocumentPath path, String[] components)
constructor that adds additional subdirectories to an existing path

param
path the existing path
param
components the additional subdirectory names to be added
exception
IllegalArgumentException if any of the Strings in components is null or zero length

        if (components == null)
        {
            this.components = new String[ path.components.length ];
        }
        else
        {
            this.components =
                new String[ path.components.length + components.length ];
        }
        for (int j = 0; j < path.components.length; j++)
        {
            this.components[ j ] = path.components[ j ];
        }
        if (components != null)
        {
            for (int j = 0; j < components.length; j++)
            {
                if ((components[ j ] == null)
                        || (components[ j ].length() == 0))
                {
                    throw new IllegalArgumentException(
                        "components cannot contain null or empty strings");
                }
                this.components[ j + path.components.length ] =
                    components[ j ];
            }
        }
    
Methods Summary
public booleanequals(java.lang.Object o)
equality. Two POIFSDocumentPath instances are equal if they have the same number of component Strings, and if each component String is equal to its coresponding component String

param
o the object we're checking equality for
return
true if the object is equal to this object

        boolean rval = false;

        if ((o != null) && (o.getClass() == this.getClass()))
        {
            if (this == o)
            {
                rval = true;
            }
            else
            {
                POIFSDocumentPath path = ( POIFSDocumentPath ) o;

                if (path.components.length == this.components.length)
                {
                    rval = true;
                    for (int j = 0; j < this.components.length; j++)
                    {
                        if (!path.components[ j ]
                                .equals(this.components[ j ]))
                        {
                            rval = false;
                            break;
                        }
                    }
                }
            }
        }
        return rval;
    
public java.lang.StringgetComponent(int n)
get the specified component

param
n which component (0 ... length() - 1)
return
the nth component;
exception
ArrayIndexOutOfBoundsException if n < 0 or n >= length()

        return components[ n ];
    
public org.apache.poi.poifs.filesystem.POIFSDocumentPathgetParent()

Returns the path's parent or null if this path is the root path.

since
2002-01-24
return
path of parent, or null if this path is the root path

        final int length = components.length - 1;

        if (length < 0)
        {
            return null;
        }
        POIFSDocumentPath parent = new POIFSDocumentPath(null);

        parent.components = new String[ length ];
        System.arraycopy(components, 0, parent.components, 0, length);
        return parent;
    
public inthashCode()
calculate and return the hashcode

return
hashcode

        if (hashcode == 0)
        {
            for (int j = 0; j < components.length; j++)
            {
                hashcode += components[ j ].hashCode();
            }
        }
        return hashcode;
    
public intlength()

return
the number of components

        return components.length;
    
public java.lang.StringtoString()

Returns a string representation of the path. Components are separated by the platform-specific file separator.

return
string representation
since
2002-01-24

        final StringBuffer b = new StringBuffer();
        final int          l = length();

        b.append(File.separatorChar);
        for (int i = 0; i < l; i++)
        {
            b.append(getComponent(i));
            if (i < l - 1)
            {
                b.append(File.separatorChar);
            }
        }
        return b.toString();