1 6 package com.hp.hpl.jena.graph.query.regexptrees; 7 8 16 17 public abstract class Text extends RegexpTree 18 { 19 public static Text create( String s ) 20 { 21 return s.length() == 1 22 ? (Text) new TextChar( s.charAt( 0 ) ) 23 : new TextString( s ); 24 } 25 26 public static Text create( char ch ) 27 { return new TextChar( ch ); } 28 29 static class TextString extends Text 30 { 31 protected String literal; 32 33 TextString( String s ) 34 { literal = s; } 35 36 public String getString() 37 { return literal; } 38 39 public String toString() 40 { return "<text.s '" + literal + "'>"; } 41 42 public boolean equals( Object x ) 43 { return x instanceof TextString && literal.equals( ((TextString) x).literal ); } 44 45 public int hashCode() 46 { return literal.hashCode(); } 47 } 48 49 static class TextChar extends Text 50 { 51 protected char ch; 52 53 TextChar( char ch ) 54 { this.ch = ch; } 55 56 public String getString() 57 { return "" + ch; } 58 59 public String toString() 60 { return "<text.ch '" + ch + "'>"; } 61 62 public boolean equals( Object x ) 63 { return x instanceof TextChar && ch == ((TextChar) x).ch; } 64 65 public int hashCode() 66 { return ch; } 67 } 68 69 public abstract boolean equals( Object x ); 70 71 public abstract int hashCode(); 72 73 public abstract String getString(); 74 75 } 76 77 | Popular Tags |