Class Text
- java.lang.Object
-
- net.ssehub.easy.instantiation.core.model.artifactModel.representation.AbstractArtifactRepresentation
-
- net.ssehub.easy.instantiation.core.model.artifactModel.representation.Text
-
- All Implemented Interfaces:
IArtifactChangedListener,IArtifactRepresentation,IStringValueProvider,IVilType
public class Text extends AbstractArtifactRepresentation implements IArtifactChangedListener, IStringValueProvider
The textual representation of an artifact (if there is any). Please note that this class is not an artifact by itself rather then a specific representation of an artifact.- Author:
- Holger Eichelberger
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface net.ssehub.easy.instantiation.core.model.vilTypes.IStringValueProvider
IStringValueProvider.StringComparator
-
-
Field Summary
Fields Modifier and Type Field Description static TextCONSTANT_EMPTYprivate java.io.Filefileprivate java.lang.Stringtext
-
Constructor Summary
Constructors Constructor Description Text(boolean modifiable)Creates a new empty textual representation.Text(java.io.File file, boolean modifiable)Creates a new textual representation fromfile.Text(java.lang.String text, boolean modifiable)Creates a new textual representation fromtext.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Textappend(java.lang.String text)Appends the given text.Textappend(Text text)Appends the textual representation of another artifact.voidartifactChanged(java.lang.Object cause)Is called when the artifact was changed, e.g., to trigger a reanalysis of substructures.private booleancontainsRegex(java.lang.String regex)Returns whether this textual representation contains a match for the givenregex.private intgetRegexMatchLength(java.lang.String regex)Calculates the length of the first string in the text that matches the given regular expression.java.lang.StringgetStringValue(IStringValueProvider.StringComparator comparator)Returns the string value of this object.java.lang.StringgetText()Returns the actual text.intindexOf(java.lang.String search)Returns the index of the first occurrence of the givenstring.intindexOf(java.lang.String search, int fromIndex)Returns the index of the first occurrence of the given string, starting the search at the specified index.intindexOf(Text search)Returns the index of the first occurrence of the given textual representation of another artifact.intindexOf(Text search, int fromIndex)Returns the index of the first occurrence of the given textual representation of another artifact, starting the search at the specified index.private intindexOfRegex(java.lang.String regex)Returns the index of the first match of the given regular expression.private intindexOfRegex(java.lang.String regex, int fromIndex)Returns the index of the first match of the given regular expression, starting the search at the specified index.Textinsert(int index, java.lang.String insertion)Inserts the givenstringat the givenindex.Textinsert(int index, Text insertion)Inserts the textual representation of another artifact at the givenindex.booleanisEmpty()Returns whether this artifact representation is empty.booleanmatches(java.lang.String regex)Returns whether this textual representation matches the givenregex.Textprepend(java.lang.String text)Prepends the given text.Textprepend(Text text)Prepends the textual representation of another artifact.Textremove(java.lang.String part)Removes the the first occurrence of the given string in this.Textremove(Text part)Removes the the first occurrence of the given textual representation of another artifact in this.TextremoveAll(java.lang.String part)Removes all occurrences of the given string in this.TextremoveAll(Text part)Removes all occurrences of the given textual representation of another artifact in this.private voidremoveRegex(java.lang.String regex)Removes the first string in this that matches the given regular expression.Textreplace(java.lang.String search, java.lang.String replacement)Replaces all occurrences ofsearchbyreplacement.voidsetText(java.lang.String text)Changes the entire text of this artifact.Textsubstitute(java.lang.String regex, java.lang.String replacement)Substitutes all parts matching the regular expressionregexbyreplacement.voidupdateContents()Updates the contents.voidwrite(java.io.Writer out)Writes the data to the given output stream.-
Methods inherited from class net.ssehub.easy.instantiation.core.model.artifactModel.representation.AbstractArtifactRepresentation
getListeners, isModifiable, setTriggerEnabled, triggerArtifactChanged
-
-
-
-
Field Detail
-
CONSTANT_EMPTY
public static final Text CONSTANT_EMPTY
-
text
private java.lang.String text
-
file
private java.io.File file
-
-
Constructor Detail
-
Text
public Text(boolean modifiable)
Creates a new empty textual representation.- Parameters:
modifiable- whether this representation shall be modifiable
-
Text
public Text(java.io.File file, boolean modifiable) throws VilExceptionCreates a new textual representation fromfile.- Parameters:
file- the file to be considered as inputmodifiable- whether this representation shall be modifiable- Throws:
VilException- in case that reading fails for some reason
-
Text
public Text(java.lang.String text, boolean modifiable) throws VilExceptionCreates a new textual representation fromtext.- Parameters:
text- the text to be considered as inputmodifiable- whether this representation shall be modifiable- Throws:
VilException- in case that reading fails for some reason
-
-
Method Detail
-
updateContents
public void updateContents() throws VilExceptionDescription copied from interface:IArtifactRepresentationUpdates the contents.- Specified by:
updateContentsin interfaceIArtifactRepresentation- Throws:
VilException- in case that reading fails for some reason
-
isEmpty
public boolean isEmpty()
Description copied from interface:IArtifactRepresentationReturns whether this artifact representation is empty.- Specified by:
isEmptyin interfaceIArtifactRepresentation- Returns:
trueif it is empty,falseelse
-
substitute
public Text substitute(java.lang.String regex, java.lang.String replacement) throws VilException
Substitutes all parts matching the regular expressionregexbyreplacement.- Parameters:
regex- the regular expression to search forreplacement- the replacement- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
matches
public boolean matches(java.lang.String regex) throws VilExceptionReturns whether this textual representation matches the givenregex.- Parameters:
regex- the regular expression to be matched- Returns:
trueifregexmatches this textual representation,falseelse- Throws:
VilException- if the pattern is invalid
-
replace
public Text replace(java.lang.String search, java.lang.String replacement) throws VilException
Replaces all occurrences ofsearchbyreplacement.- Parameters:
search- the string to search forreplacement- the replacement string- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
append
public Text append(java.lang.String text) throws VilException
Appends the given text.- Parameters:
text- the text to be appended- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
prepend
public Text prepend(java.lang.String text) throws VilException
Prepends the given text.- Parameters:
text- the text to be prepended- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
append
public Text append(Text text) throws VilException
Appends the textual representation of another artifact.- Parameters:
text- the text to be appended- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
prepend
public Text prepend(Text text) throws VilException
Prepends the textual representation of another artifact.- Parameters:
text- the text to be prepended- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
insert
public Text insert(int index, Text insertion) throws VilException
Inserts the textual representation of another artifact at the givenindex.- Parameters:
index- the index in thisinsertion- the text to be inserted- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
insert
public Text insert(int index, java.lang.String insertion) throws VilException
Inserts the givenstringat the givenindex.- Parameters:
index- the index in thisinsertion- the string to be inserted- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
indexOf
public int indexOf(Text search)
Returns the index of the first occurrence of the given textual representation of another artifact.- Parameters:
search- the textual representation of another artifact- Returns:
- the index of
searchin this, or -1 if the text does not occur
-
indexOf
public int indexOf(java.lang.String search)
Returns the index of the first occurrence of the givenstring.- Parameters:
search- the string to be searched for- Returns:
- the index of
searchin this, or -1 if the string does not occur
-
indexOfRegex
private int indexOfRegex(java.lang.String regex)
Returns the index of the first match of the given regular expression.- Parameters:
regex- the regular expression to search for- Returns:
- the index of
regexin this, or -1 if no match was found
-
indexOf
public int indexOf(Text search, int fromIndex)
Returns the index of the first occurrence of the given textual representation of another artifact, starting the search at the specified index.- Parameters:
search- the textual representation of another artifactfromIndex- the index to start the search from- Returns:
- the index of
searchin this, or -1 if the text does not occur
-
indexOf
public int indexOf(java.lang.String search, int fromIndex)Returns the index of the first occurrence of the given string, starting the search at the specified index.- Parameters:
search- the string to be searched forfromIndex- the index to start the search from- Returns:
- the index of
searchin this, or -1 if the string does not occur
-
indexOfRegex
private int indexOfRegex(java.lang.String regex, int fromIndex)Returns the index of the first match of the given regular expression, starting the search at the specified index.- Parameters:
regex- the regular expression to search forfromIndex- the index to start the search from- Returns:
- the index of
regexin this, or -1 if no match was found
-
remove
public Text remove(Text part) throws VilException
Removes the the first occurrence of the given textual representation of another artifact in this.- Parameters:
part- the textual representation of another artifact to be removed- Returns:
- this (for concatenated operations)
- Throws:
VilException- ArtifactException in case that listener updates fail
-
remove
public Text remove(java.lang.String part) throws VilException
Removes the the first occurrence of the given string in this.- Parameters:
part- the string to be removed- Returns:
- this (for concatenated operations)
- Throws:
VilException- ArtifactException in case that listener updates fail
-
removeRegex
private void removeRegex(java.lang.String regex)
Removes the first string in this that matches the given regular expression.- Parameters:
regex- the regular expression with which a match shall be found
-
getRegexMatchLength
private int getRegexMatchLength(java.lang.String regex)
Calculates the length of the first string in the text that matches the given regular expression.- Parameters:
regex- the regular expression with which a match shall be found- Returns:
- the length of the match in the text, or -1 if no match was found.
-
removeAll
public Text removeAll(Text part) throws VilException
Removes all occurrences of the given textual representation of another artifact in this.- Parameters:
part- the textual representation of another artifact to be removed- Returns:
- this (for concatenated operations)
- Throws:
VilException- ArtifactException in case that listener updates fail
-
removeAll
public Text removeAll(java.lang.String part) throws VilException
Removes all occurrences of the given string in this.- Parameters:
part- the string to be removed- Returns:
- this (for concatenated operations)
- Throws:
VilException- in case that listener updates fail
-
containsRegex
private boolean containsRegex(java.lang.String regex)
Returns whether this textual representation contains a match for the givenregex.- Parameters:
regex- the regular expression to be matched- Returns:
trueif this textual representation contains a match forregex,falseelse
-
getText
public java.lang.String getText()
Returns the actual text.- Returns:
- the actual text
-
artifactChanged
public void artifactChanged(java.lang.Object cause) throws VilExceptionDescription copied from interface:IArtifactChangedListenerIs called when the artifact was changed, e.g., to trigger a reanalysis of substructures.- Specified by:
artifactChangedin interfaceIArtifactChangedListener- Parameters:
cause- the cause for the change, e.g., an artifact representation- Throws:
VilException- in case that the required operations fail for some reason
-
setText
public void setText(java.lang.String text)
Changes the entire text of this artifact.- Parameters:
text- the text to be changed
-
write
public void write(java.io.Writer out) throws java.io.IOExceptionWrites the data to the given output stream.- Parameters:
out- the target output stream- Throws:
java.io.IOException- in case of I/O problems
-
getStringValue
public java.lang.String getStringValue(IStringValueProvider.StringComparator comparator)
Description copied from interface:IStringValueProviderReturns the string value of this object.- Specified by:
getStringValuein interfaceIStringValueProvider- Parameters:
comparator- if the sequence of elements, e.g., in case of collections, shall be ordered according to the comparator, null if the original sequence shall be returned- Returns:
- the string value
-
-