de.fuberlin.wiwiss.d2rq.map
Class Pattern

java.lang.Object
  extended byde.fuberlin.wiwiss.d2rq.map.Pattern
All Implemented Interfaces:
java.lang.Cloneable, Prefixable, ValueSource

public class Pattern
extends java.lang.Object
implements ValueSource, Prefixable

A pattern that combines one or more database columns into a String. Often used as an UriPattern for generating URIs from a column's primary key.

(Note: The implementation makes some assumptions about the Column class to keep the code simple and fast. This means Pattern may not work with some hypothetical subclasses of Column.)

History:
08-03-2004: Initial version of this class.

Version:
V0.2
Author:
Richard Cyganiak

Nested Class Summary
 class Pattern.PartsIterator
           
 
Field Summary
private  java.util.List columns
           
private  java.util.Set columnsAsSet
           
private  java.lang.String firstLiteralPart
           
private  java.util.List literalParts
           
private  java.lang.String pattern
           
 
Constructor Summary
Pattern(java.lang.String pattern)
          Constructs a new Pattern instance from a pattern syntax string
 
Method Summary
 java.lang.Object clone()
          Make a shallow copy of this.
 boolean couldFit(java.lang.String value)
          Checks if a given value fits this source without querying the database.
 java.util.Set getColumns()
          Returns a set of all columns containing data necessary for this ValueSource.
 java.util.Map getColumnValues(java.lang.String value)
          Extracts column values according to the pattern from a value string.
 java.lang.String getValue(java.lang.String[] row, java.util.Map columnNameNumberMap)
          Constructs a String from the pattern using the given database row.
 java.lang.String joinPattern(java.lang.String joinOp)
           
 void matchPatternIntoNodeConstraint(Pattern other, NodeConstraint c)
           
private  void parsePattern()
           
 java.util.Iterator partsIterator()
           
 void prefixTables(TablePrefixer prefixer)
          Changes the fields in a newly created clone that are to be modified when making aliasses.
 java.lang.String reconstructPattern()
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

pattern

private java.lang.String pattern

firstLiteralPart

private java.lang.String firstLiteralPart

columns

private java.util.List columns

literalParts

private java.util.List literalParts

columnsAsSet

private java.util.Set columnsAsSet
Constructor Detail

Pattern

public Pattern(java.lang.String pattern)
Constructs a new Pattern instance from a pattern syntax string

Parameters:
pattern - a pattern syntax string
Throws:
D2RQException - on malformed pattern
Method Detail

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
Description copied from interface: Prefixable
Make a shallow copy of this. General advice: Do not overwrite clone(). prefixTables() works best with shallow copy which Object implements. Issues: I have not found a (preferred) static equivalent of clone(). Since Objects clone() method is protected, we cannot just declare Cloneable, if we want to call clone() from outside of that class hierarchy. Instead it must be public and implemented in each Prefixable class by a call to super.clone().

Specified by:
clone in interface Prefixable
Throws:
java.lang.CloneNotSupportedException

prefixTables

public void prefixTables(TablePrefixer prefixer)
Description copied from interface: Prefixable
Changes the fields in a newly created clone that are to be modified when making aliasses.

Specified by:
prefixTables in interface Prefixable
Parameters:
prefixer - does the actual prefixing of simple and complex types.

matchPatternIntoNodeConstraint

public void matchPatternIntoNodeConstraint(Pattern other,
                                           NodeConstraint c)

couldFit

public boolean couldFit(java.lang.String value)
Description copied from interface: ValueSource
Checks if a given value fits this source without querying the database.

Specified by:
couldFit in interface ValueSource

getColumns

public java.util.Set getColumns()
Description copied from interface: ValueSource
Returns a set of all columns containing data necessary for this ValueSource.

Specified by:
getColumns in interface ValueSource
Returns:
a set of {Column}s

getColumnValues

public java.util.Map getColumnValues(java.lang.String value)
Extracts column values according to the pattern from a value string. The keys are Columns, the values are strings.

Specified by:
getColumnValues in interface ValueSource
Parameters:
value - value to be checked.
Returns:
a map with Column keys and string values
See Also:
ValueSource.getColumnValues(java.lang.String)

getValue

public java.lang.String getValue(java.lang.String[] row,
                                 java.util.Map columnNameNumberMap)
Constructs a String from the pattern using the given database row.

Specified by:
getValue in interface ValueSource
Parameters:
row - a database row
columnNameNumberMap - a map from qualified column names to indices into the row array
Returns:
the pattern's value for the given row

reconstructPattern

public java.lang.String reconstructPattern()

joinPattern

public java.lang.String joinPattern(java.lang.String joinOp)

toString

public java.lang.String toString()

parsePattern

private void parsePattern()

partsIterator

public java.util.Iterator partsIterator()