001package Torello.JavaDoc.SyntaxHiLite; 002 003import Torello.CSS.ClassNameCSSException; 004 005import Torello.HTML.HTMLTags; 006import Torello.HTML.TagNode; 007import Torello.HTML.SD; 008import Torello.HTML.TC; 009 010import Torello.Java.Additional.Ret2; 011import Torello.JavaDoc.Annotations.LinkJavaSource; 012 013import java.util.Objects; 014import java.util.Arrays; 015 016public class AbstractConfig<T extends AbstractConfig<T>> 017 implements java.io.Serializable 018{ 019 protected static final long serialVersionUID = 1; 020 021 022 // ******************************************************************************************** 023 // ******************************************************************************************** 024 // Class-Config - Fields (These a) 025 // ******************************************************************************************** 026 // ******************************************************************************************** 027 028 029 protected final String[] classNames; 030 031 protected final boolean[] spansOrBolds, utilize; 032 033 protected boolean upperOrLower_TagName = true; 034 protected boolean upperOrLower_ClassAttrName = true; 035 protected SD quotes = null; 036 037 final int CONFIG_ARR_LEN; 038 039 final Class<T> captureTheClassDummy; 040 041 protected AbstractConfig( 042 final int CONFIG_ARR_LEN, 043 final boolean[] spansOrBolds, 044 final Class<T> captureTheClassDummy 045 ) 046 { 047 Objects.requireNonNull 048 (spansOrBolds, "The array passed to parameter 'spansOrBolds' is null"); 049 050 Objects.requireNonNull 051 (captureTheClassDummy, "The class passed to parameter 'captureTheClassDummy' is null"); 052 053 if (CONFIG_ARR_LEN < 1) throw new IllegalArgumentException( 054 '[' + CONFIG_ARR_LEN + "] was passed to CONFIG_ARR_LEN, but this value must be a " + 055 "positive integer that is greater than 0." 056 ); 057 058 if (spansOrBolds.length != CONFIG_ARR_LEN) throw new IllegalArgumentException( 059 "The length of the Array-Parameter 'spansOrBolds' is [" + spansOrBolds.length + "], " + 060 "but the value passed to parameter CONFIG_ARR_LENGTH was [" + CONFIG_ARR_LEN + "]. " + 061 "These values must be equals." 062 ); 063 064 this.CONFIG_ARR_LEN = CONFIG_ARR_LEN; 065 this.captureTheClassDummy = captureTheClassDummy; 066 067 this.classNames = new String[CONFIG_ARR_LEN]; 068 this.spansOrBolds = new boolean[CONFIG_ARR_LEN]; 069 this.utilize = new boolean[CONFIG_ARR_LEN]; 070 071 for (int i=1; i < CONFIG_ARR_LEN; i++) this.classNames[i] = "HL-" + i; 072 for (int i=0; i < CONFIG_ARR_LEN; i++) this.spansOrBolds[i] = spansOrBolds[i]; 073 for (int i=0; i < CONFIG_ARR_LEN; i++) this.utilize[i] = true; 074 } 075 076 protected AbstractConfig(AbstractConfig<T> c) 077 { 078 final int L = this.CONFIG_ARR_LEN = c.CONFIG_ARR_LEN; 079 080 this.captureTheClassDummy = c.captureTheClassDummy; 081 082 this.classNames = new String[c.CONFIG_ARR_LEN]; 083 this.spansOrBolds = new boolean[c.CONFIG_ARR_LEN]; 084 this.utilize = new boolean[c.CONFIG_ARR_LEN]; 085 086 System.arraycopy(c.classNames, 0, this.classNames, 0, L); 087 System.arraycopy(c.spansOrBolds, 0, this.spansOrBolds, 0, L); 088 System.arraycopy(c.utilize, 0, this.utilize, 0, L); 089 090 this.upperOrLower_TagName = c.upperOrLower_TagName; 091 this.upperOrLower_ClassAttrName = c.upperOrLower_ClassAttrName; 092 this.quotes = c.quotes; 093 } 094 095 096 // ******************************************************************************************** 097 // ******************************************************************************************** 098 // Class-Config - "Setters" and "Getters" (This is SYNCHRONIZED, That's Why) 099 // ******************************************************************************************** 100 // ******************************************************************************************** 101 102 103 public synchronized AbstractConfig<T> setClassNameCSS(byte whichOne, String className) 104 { 105 checkWhichOne(whichOne); 106 ClassNameCSSException.check(className); 107 this.classNames[whichOne] = className; 108 return this; 109 } 110 111 public synchronized String getClassName(byte whichOne) 112 { checkWhichOne(whichOne); return this.classNames[whichOne]; } 113 114 public synchronized AbstractConfig<T> setSpanOrBold(byte whichOne, boolean spanOrBold) 115 { 116 checkWhichOne(whichOne); 117 this.spansOrBolds[whichOne] = spanOrBold; 118 return this; 119 } 120 121 public synchronized boolean getSpansOrBolds(byte whichOne) 122 { checkWhichOne(whichOne); return this.spansOrBolds[whichOne]; } 123 124 public synchronized AbstractConfig<T> setUtilizeOrForget(byte whichOne, boolean useOrForget) 125 { 126 checkWhichOne(whichOne); 127 this.utilize[whichOne] = useOrForget; 128 return this; 129 } 130 131 public synchronized boolean getUtilized(byte whichOne) 132 { checkWhichOne(whichOne); return this.utilize[whichOne]; } 133 134 private void checkWhichOne(byte whichOne) 135 { 136 if ((whichOne < 1) || (whichOne >= this.CONFIG_ARR_LEN)) 137 138 throw new IllegalArgumentException( 139 "You have passed an invalid value [" + whichOne + "], to parameter 'whichOne'. " + 140 "This must be a valid byte, whose value is between 1 and " + 141 (this.CONFIG_ARR_LEN - 1) 142 ); 143 } 144 145 146 // ******************************************************************************************** 147 // ******************************************************************************************** 148 // STUFF 149 // ******************************************************************************************** 150 // ******************************************************************************************** 151 152 153 @LinkJavaSource(handle="ACGenerateHelper") 154 protected Ret2<TagNode[], TagNode[]> generateHiLiterHelper() 155 { return ACGenerateHelper.generate(this); } 156 157 @LinkJavaSource(handle="ACEqualsToString") 158 public boolean equals(Object other) 159 { return ACEqualsToString.equals(this, other); } 160 161 @LinkJavaSource(handle="ACEqualsToString") 162 public int hashCode() 163 { return ACEqualsToString.hashCode(this); } 164}