org.silverpeas.util
Class StringDataExtractor

java.lang.Object
  extended by org.silverpeas.util.StringDataExtractor

public class StringDataExtractor
extends Object

Author:
Yohann Chastagnier

Nested Class Summary
static interface StringDataExtractor.ExtractorDirective
          This interface permits to implement several way to extract data from a string.
static class StringDataExtractor.RegexpPatternDirective
          Class that permits to specify the directives in order to extract data.
 
Method Summary
 List<String> extract()
          Extracts data from a strict by applying the specified extract pattern directives.
 String extractUnique()
          Calls first extract() and then return the only contained value from the result, null if no value extracted.
static StringDataExtractor from(String source)
          Gets an instance of StringDataExtractor
 StringDataExtractor withDirective(StringDataExtractor.ExtractorDirective directive)
          Indicates a directive of data extraction.
 StringDataExtractor withDirectives(List<? extends StringDataExtractor.ExtractorDirective> directives)
          Indicates a directive of data extraction.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

from

public static StringDataExtractor from(String source)
Gets an instance of StringDataExtractor

Parameters:
source - the string from which data must be extracted.
Returns:
an instance of StringDataExtractor

withDirective

public StringDataExtractor withDirective(StringDataExtractor.ExtractorDirective directive)
Indicates a directive of data extraction.

Parameters:
directive - the directive that will handle the data extraction.
Returns:
the current instance of StringDataExtractor.

withDirectives

public StringDataExtractor withDirectives(List<? extends StringDataExtractor.ExtractorDirective> directives)
Indicates a directive of data extraction.

Parameters:
directives - the directives that will handle the data extraction.
Returns:
the current instance of StringDataExtractor.

extract

public List<String> extract()
Extracts data from a strict by applying the specified extract pattern directives.

Returns:
the list of data.

extractUnique

public String extractUnique()
                     throws IllegalStateException
Calls first extract() and then return the only contained value from the result, null if no value extracted.

Returns:
the unique value aimed by the extraction.
Throws:
IllegalStateException - if it exists several values behind the extraction directive.


Copyright © 2016 Silverpeas. All Rights Reserved.