// Decompiled by Jad v1.5.8e. Copyright 2001 Pavel Kouznetsov.
// Jad home page: http://www.geocities.com/kpdus/jad.html
// Decompiler options: packimports(3) deadcode 
// Source File Name:   JavaName.java

package com.symantec.itools.lang;

import java.io.File;
import java.io.Serializable;

// Referenced classes of package com.symantec.itools.lang:
//            NotJavaNameException

public class JavaName
    implements Serializable
{

    public JavaName(String s)
        throws NotJavaNameException
    {
        this(s, true);
    }

    public JavaName(String s, boolean flag)
        throws NotJavaNameException
    {
        validateName(s, flag);
    }

    public String getPackage()
    {
        return packageName;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String s)
    {
        name = s;
    }

    public void setPackage(String s)
    {
        packageName = s;
    }

    public void setExtension(String s)
    {
        extension = s;
    }

    public String getExtension()
    {
        return extension;
    }

    protected void validateName(String s, boolean flag)
        throws NotJavaNameException
    {
        int i = s.lastIndexOf('/');
        if(i == 0)
            throw new NotJavaNameException(s);
        if(i == -1)
            packageName = "/";
        else
        if(i > 0)
            packageName = getNamePart(s, 0, i);
        int k = s.lastIndexOf('.');
        int j;
        if(k < 0)
            j = s.length();
        else
            j = k;
        if(flag)
            name = getNamePart(s, i + 1, j);
        else
            name = s.substring(i + 1, j);
        if(k >= 0)
            extension = s.substring(k + 1);
    }

    protected String getNamePart(String s, int i, int j)
    {
        return s.substring(i, j).replace(File.separatorChar, '/');
    }

    public String getFullName()
    {
        if(packageName.equals("/"))
            if(extension == null)
                return name;
            else
                return name + '.' + extension;
        if(extension == null)
            return packageName + '/' + name;
        else
            return packageName + '/' + name + '.' + extension;
    }

    public int hashCode()
    {
        return getFullName().hashCode();
    }

    public boolean equals(Object obj)
    {
        String s;
        if(obj instanceof JavaName)
            s = ((JavaName)obj).getFullName();
        else
        if(obj instanceof String)
            s = (String)obj;
        else
            return false;
        return s.equals(getFullName());
    }

    protected String packageName;
    protected String name;
    protected String extension;
}
