001package Torello.JavaDoc.SyntaxHiLite;
002
003import Torello.Java.ParallelArrayException;
004import Torello.HTML.TagNode;
005
006import java.util.Arrays;
007
008public class AbstractHiLiter implements java.io.Serializable
009{
010    protected static final long serialVersionUID = 1;
011
012
013    // ********************************************************************************************
014    // ********************************************************************************************
015    // Instance Fields
016    // ********************************************************************************************
017    // ********************************************************************************************
018
019
020    protected final TagNode[] openers;
021    protected final TagNode[] closers;
022    protected final boolean[] utilize;
023
024    protected final int CONFIG_ARR_LEN;
025
026
027    // ********************************************************************************************
028    // ********************************************************************************************
029    // Constructor
030    // ********************************************************************************************
031    // ********************************************************************************************
032
033
034    protected AbstractHiLiter(
035            final TagNode[] openers,
036            final TagNode[] closers,
037            final boolean[] utilize
038        )
039    {
040        ParallelArrayException.check(openers, "openers", closers, "closers");
041        ParallelArrayException.check(closers, "closers", utilize, "utilize");
042
043        this.openers    = openers;
044        this.closers    = closers;
045        this.utilize    = utilize;
046
047        this.CONFIG_ARR_LEN = openers.length;
048    }
049
050
051    // ********************************************************************************************
052    // ********************************************************************************************
053    // Retrieval / Getter Methods
054    // ********************************************************************************************
055    // ********************************************************************************************
056
057    public TagNode getOpeningTag(byte whichOne)
058    {
059        checkWhichOne(whichOne);
060        return openers[whichOne];
061    }
062
063    public TagNode getClosingTag(byte whichOne)
064    {
065        checkWhichOne(whichOne);
066        return closers[whichOne];
067    }
068
069    public boolean getUtilized(byte whichOne)
070    {
071        checkWhichOne(whichOne);
072        return utilize[whichOne];
073    }
074
075    private void checkWhichOne(byte whichOne)
076    {
077        if ((whichOne < 1) || (whichOne >= this.CONFIG_ARR_LEN))
078
079            throw new IllegalArgumentException(
080                "You have passed an invalid value [" + whichOne + "], to parameter 'whichOne'.  " +
081                "This must be a valid byte, whose value is between 1 and " +
082                (this.CONFIG_ARR_LEN - 1)
083            );
084    }
085
086
087    // ********************************************************************************************
088    // ********************************************************************************************
089    // java.lang.Object
090    // ********************************************************************************************
091    // ********************************************************************************************
092
093
094    public boolean equals(Object other)
095    {
096        if (this == other) return true;
097        if (other == null) return false;
098
099        if (! (other instanceof AbstractHiLiter)) return false;
100
101        AbstractHiLiter o = (AbstractHiLiter) other;
102
103        return 
104                Arrays.equals(this.openers, o.openers)
105            &&  Arrays.equals(this.closers, o.closers)
106            &&  Arrays.equals(this.utilize, o.utilize);
107    }
108
109    public int hashCode()
110    { return Arrays.hashCode(this.openers); }
111}