1 8 9 package net.sourceforge.chaperon.model.extended; 10 11 import net.sourceforge.chaperon.common.Decoder; 12 import net.sourceforge.chaperon.model.Violations; 13 14 20 public class SingleCharacter extends Pattern 21 { 22 private char character; 23 24 27 public SingleCharacter() {} 28 29 34 public SingleCharacter(char character) 35 { 36 setCharacter(character); 37 } 38 39 44 public void setCharacter(char character) 45 { 46 this.character = character; 47 } 48 49 54 public void setCharacterAsString(String character) 55 { 56 if (character.startsWith("#")) 57 this.character = (char)Integer.parseInt(character.substring(1)); 58 else 59 this.character = character.charAt(0); 60 } 61 62 67 public char getCharacter() 68 { 69 return character; 70 } 71 72 public String getCharacterAsString() 73 { 74 return String.valueOf(character); 75 } 76 77 public boolean isNullable() 78 { 79 return false; 80 } 81 82 public PatternSet getFirstSet() 83 { 84 PatternSet set = new PatternSet(); 85 set.addPattern(this); 86 return set; 87 } 88 89 public PatternSet getLastSet() 90 { 91 PatternSet set = new PatternSet(); 92 set.addPattern(this); 93 return set; 94 } 95 96 public char[] getLimits() 97 { 98 return new char[]{getCharacter()}; 99 } 100 101 public boolean contains(char minimum, char maximum) 102 { 103 return (getCharacter()==minimum) && (getCharacter()==maximum); 104 } 105 106 public boolean contains(char c) 107 { 108 return c==character; 109 } 110 111 public String getSymbol() 112 { 113 return null; 114 } 115 116 121 public String toString() 122 { 123 return Decoder.toChar(character)+"["+index+"]"; 124 } 125 126 133 public Object clone() 134 { 135 SingleCharacter clone = new SingleCharacter(); 136 clone.setCharacter(getCharacter()); 137 return clone; 138 } 139 140 145 public Violations validate() 146 { 147 Violations violations = new Violations(); 148 149 152 return violations; 153 } 154 } 155 | Popular Tags |