KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > hp > hpl > jena > graph > query > regexptrees > Text


1 /*
2   (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP, all rights reserved.
3   [See end of file]
4   $Id: Text.java,v 1.5 2005/02/21 11:52:30 andy_seaborne Exp $
5 */

6 package com.hp.hpl.jena.graph.query.regexptrees;
7
8 /**
9     Text - represents literal text for the match, to be taken as it stands. May
10     include material that was meta-quoted in the original patterm. There are
11     two sub-classes, one for strings and one for single characters; the factory
12     methods ensure that there are no single-character TextString instances.
13     
14     @author kers
15 */

16
17 public abstract class Text extends RegexpTree
18     {
19     public static Text create( String JavaDoc 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 JavaDoc literal;
32         
33         TextString( String JavaDoc s )
34             { literal = s; }
35         
36         public String JavaDoc getString()
37             { return literal; }
38         
39         public String JavaDoc toString()
40             { return "<text.s '" + literal + "'>"; }
41         
42         public boolean equals( Object JavaDoc 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 JavaDoc getString()
57             { return "" + ch; }
58         
59         public String JavaDoc toString()
60             { return "<text.ch '" + ch + "'>"; }
61         
62         public boolean equals( Object JavaDoc 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 JavaDoc x );
70     
71     public abstract int hashCode();
72     
73     public abstract String JavaDoc getString();
74     
75     }
76
77 /*
78     (c) Copyright 2004, 2005 Hewlett-Packard Development Company, LP
79     All rights reserved.
80     
81     Redistribution and use in source and binary forms, with or without
82     modification, are permitted provided that the following conditions
83     are met:
84     
85     1. Redistributions of source code must retain the above copyright
86        notice, this list of conditions and the following disclaimer.
87     
88     2. Redistributions in binary form must reproduce the above copyright
89        notice, this list of conditions and the following disclaimer in the
90        documentation and/or other materials provided with the distribution.
91     
92     3. The name of the author may not be used to endorse or promote products
93        derived from this software without specific prior written permission.
94     
95     THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
96     IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
97     OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
98     IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
99     INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
100     NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
101     DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
102     THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
103     (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
104     THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
105 */
Popular Tags