org.gcn.plinguacore.util
Class GeneString

java.lang.Object
  extended by org.gcn.plinguacore.util.GeneString

public class GeneString
extends java.lang.Object

Class to handle strings in P-systems. The name, GeneString, is due to the analogy between this strings of symbols and the DNA string (main use of this kind of object in modeling)

Author:
Research Group on Natural Computing (http://www.gcn.us.es)

Constructor Summary
GeneString(java.lang.String s)
           
 
Method Summary
 int count(MultiSet<java.lang.String> content)
           
 int getNumberOfGroups()
           
static java.lang.String getString(java.lang.String s)
           
static boolean isGeneString(java.lang.String s)
           
 boolean matches(java.lang.String s)
           
 java.lang.String replace(java.lang.String replacement, java.lang.String s)
          Replaces the string s according to this gene string with the string replacement.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

GeneString

public GeneString(java.lang.String s)
Parameters:
s - A gene string, that is, a string of the form: "", where s_i can be a string or the symbol ?. The symbol ?, which represents any possible string can not appear at the beginning or at the end of the gene string. In this case, ? will be ignored
Method Detail

isGeneString

public static boolean isGeneString(java.lang.String s)
Parameters:
s - The string to test
Returns:
true if the given string is a gene string, that is, if it begins with "<" and ends with ">"

getString

public static java.lang.String getString(java.lang.String s)
Parameters:
s - A string of the form: ""
Returns:
the string within the separators: w1w2...

matches

public boolean matches(java.lang.String s)
Parameters:
s -
Returns:
true if, and only if, the entire region sequence defined by s matches this matcher's pattern

count

public int count(MultiSet<java.lang.String> content)
Parameters:
content - MultiSet with symbols and strings
Returns:
The number of substring in the multiset that this gene string matches

replace

public java.lang.String replace(java.lang.String replacement,
                                java.lang.String s)
Replaces the string s according to this gene string with the string replacement.

Parameters:
replacement - The replacement string
s - The string to be replaced
Returns:
The result of replacing s with replacement according to the pattern defined by this gene string. For example, if this Gene String is "", the given string to be replaced is "aa.ccc.bb.ccc", which obviously matches the gene string's pattern, and the replacement string is "dd.?.dd", the result would be "dd.ccc.dd.ccc" That is, the substring "aa" is replaced with "dd". After that, an arbitrary string ? comes and is maintained until we find the substring "bb", which is replaced with "dd". The rest of the string to be replaced is not modified.

getNumberOfGroups

public int getNumberOfGroups()
Returns:
the number of ? that this gene string contains

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object