001: /*
002: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP, all rights reserved.
003: [See end of file]
004: $Id: Text.java,v 1.8 2008/01/02 12:06:04 andy_seaborne Exp $
005: */
006: package com.hp.hpl.jena.graph.query.regexptrees;
007:
008: /**
009: Text - represents literal text for the match, to be taken as it stands. May
010: include material that was meta-quoted in the original patterm. There are
011: two sub-classes, one for strings and one for single characters; the factory
012: methods ensure that there are no single-character TextString instances.
013:
014: @author kers
015: */
016:
017: public abstract class Text extends RegexpTree {
018: public static Text create(String s) {
019: return s.length() == 1 ? (Text) new TextChar(s.charAt(0))
020: : new TextString(s);
021: }
022:
023: public static Text create(char ch) {
024: return new TextChar(ch);
025: }
026:
027: static class TextString extends Text {
028: protected String literal;
029:
030: TextString(String s) {
031: literal = s;
032: }
033:
034: public String getString() {
035: return literal;
036: }
037:
038: public String toString() {
039: return "<text.s '" + literal + "'>";
040: }
041:
042: public boolean equals(Object x) {
043: return x instanceof TextString
044: && literal.equals(((TextString) x).literal);
045: }
046:
047: public int hashCode() {
048: return literal.hashCode();
049: }
050: }
051:
052: static class TextChar extends Text {
053: protected char ch;
054:
055: TextChar(char ch) {
056: this .ch = ch;
057: }
058:
059: public String getString() {
060: return "" + ch;
061: }
062:
063: public String toString() {
064: return "<text.ch '" + ch + "'>";
065: }
066:
067: public boolean equals(Object x) {
068: return x instanceof TextChar && ch == ((TextChar) x).ch;
069: }
070:
071: public int hashCode() {
072: return ch;
073: }
074: }
075:
076: public abstract boolean equals(Object x);
077:
078: public abstract int hashCode();
079:
080: public abstract String getString();
081:
082: }
083:
084: /*
085: (c) Copyright 2004, 2005, 2006, 2007, 2008 Hewlett-Packard Development Company, LP
086: All rights reserved.
087:
088: Redistribution and use in source and binary forms, with or without
089: modification, are permitted provided that the following conditions
090: are met:
091:
092: 1. Redistributions of source code must retain the above copyright
093: notice, this list of conditions and the following disclaimer.
094:
095: 2. Redistributions in binary form must reproduce the above copyright
096: notice, this list of conditions and the following disclaimer in the
097: documentation and/or other materials provided with the distribution.
098:
099: 3. The name of the author may not be used to endorse or promote products
100: derived from this software without specific prior written permission.
101:
102: THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
103: IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
104: OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
105: IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
106: INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
107: NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
108: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
109: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
110: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
111: THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
112: */
|