jaggregate
Class Strings

java.lang.Object
  extended by jaggregate.Strings

public class Strings
extends Object

Utility class that offers common operations on strings.

Version:
$Id: Strings.java,v 1.7 2008/10/03 19:01:23 pholser Exp $
Author:
Paul Holser

Field Summary
static UnaryFunctor<String,Integer> LENGTH
          A function which gives the length of its argument.
 
Method Summary
static UnaryFunction<String,Character> charAt(int index)
          Answers a function which will give the character value of a string target at the given index.
static UnaryPredicate<String> endsWith(String suffix)
          Answers a predicate which will answer true if its argument ends with the given suffix.
static UnaryPredicate<String> equalsIgnoreCase(String comparand)
          Answers a predicate which will answer true if its argument is equivalent to the given comparand, disregarding case.
static UnaryPredicate<String> hasSameContentsAs(CharSequence comparand)
          Answers a predicate which will answer true if its argument has the same string contents as the given comparand.
static UnaryPredicate<String> hasSubstring(CharSequence substring)
          Answers a predicate which will answer true if the given substring occurs anywhere within its argument.
static UnaryFunction<String,Integer> indexOf(int ch)
          Answers a function which will give the first index of a given character value in a given string.
static UnaryFunction<String,Integer> indexOf(String substring)
          Answers a function which will give the first index of a given substring in a given string.
static UnaryPredicate<String> isPrefixOf(String target)
          Answers a predicate which will answer true if its argument is a prefix of the given target.
static UnaryPredicate<CharSequence> isSubstringOf(String target)
          Answers a predicate which will answer true if the given string has the predicate's argument as a substring.
static UnaryPredicate<String> isSuffixOf(String target)
          Answers a predicate which will answer true if its argument is a suffix of the given string.
static UnaryFunction<String,Integer> lastIndexOf(int ch)
          Answers a function which will give the last index of a given character value in a given string.
static UnaryFunction<String,Integer> lastIndexOf(String substring)
          Answers a function which will give the last index of a given substring in a given string.
static UnaryPredicate<CharSequence> matchesPattern(String pattern)
          Answers a predicate which will answer true if any part of its argument matches the given regular expression pattern.
static UnaryPredicate<String> patternMatches(CharSequence target)
          Answers a predicate which will answer true if its regular expression pattern argument matches the given target.
static UnaryPredicate<String> startsWith(String prefix)
          Answers a predicate which will answer true if its argument starts with the given prefix.
static UnaryFunction<String,String> substring(int index)
          Answers a function which will give the substring of a given string beginning at the given index.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LENGTH

public static final UnaryFunctor<String,Integer> LENGTH
A function which gives the length of its argument.

See Also:
String.length()
Method Detail

hasSubstring

public static UnaryPredicate<String> hasSubstring(CharSequence substring)
Answers a predicate which will answer true if the given substring occurs anywhere within its argument.

Parameters:
substring - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with substring
Throws:
NullPointerException - if substring is null
See Also:
String.contains(CharSequence)

isSubstringOf

public static UnaryPredicate<CharSequence> isSubstringOf(String target)
Answers a predicate which will answer true if the given string has the predicate's argument as a substring.

Parameters:
target - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with target
Throws:
NullPointerException - if target is null
See Also:
String.contains(CharSequence)

hasSameContentsAs

public static UnaryPredicate<String> hasSameContentsAs(CharSequence comparand)
Answers a predicate which will answer true if its argument has the same string contents as the given comparand.

Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand
Throws:
NullPointerException - if comparand is null
See Also:
String.contentEquals(CharSequence)

endsWith

public static UnaryPredicate<String> endsWith(String suffix)
Answers a predicate which will answer true if its argument ends with the given suffix.

Parameters:
suffix - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with suffix
Throws:
NullPointerException - if suffix is null
See Also:
String.endsWith(String)

isSuffixOf

public static UnaryPredicate<String> isSuffixOf(String target)
Answers a predicate which will answer true if its argument is a suffix of the given string.

Parameters:
target - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with target
Throws:
NullPointerException - if target is null
See Also:
String.endsWith(String)

startsWith

public static UnaryPredicate<String> startsWith(String prefix)
Answers a predicate which will answer true if its argument starts with the given prefix.

Parameters:
prefix - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with prefix
Throws:
NullPointerException - if prefix is null

isPrefixOf

public static UnaryPredicate<String> isPrefixOf(String target)
Answers a predicate which will answer true if its argument is a prefix of the given target.

Parameters:
target - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with target
Throws:
NullPointerException - if target is null

equalsIgnoreCase

public static UnaryPredicate<String> equalsIgnoreCase(String comparand)
Answers a predicate which will answer true if its argument is equivalent to the given comparand, disregarding case.

Parameters:
comparand - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with comparand
Throws:
NullPointerException - if comparand is null
See Also:
String.equalsIgnoreCase(String)

matchesPattern

public static UnaryPredicate<CharSequence> matchesPattern(String pattern)
Answers a predicate which will answer true if any part of its argument matches the given regular expression pattern.

Parameters:
pattern - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with pattern
Throws:
NullPointerException - if pattern is null
See Also:
Matcher.find()

patternMatches

public static UnaryPredicate<String> patternMatches(CharSequence target)
Answers a predicate which will answer true if its regular expression pattern argument matches the given target.

Parameters:
target - the comparand to use with the returned predicate
Returns:
a predicate that can be used to compare arguments with target
Throws:
NullPointerException - if target is null
See Also:
Matcher.find()

charAt

public static UnaryFunction<String,Character> charAt(int index)
Answers a function which will give the character value of a string target at the given index.

Parameters:
index - index into a target string
Returns:
a function that will interrogate strings for the character at index
See Also:
String.charAt(int)

indexOf

public static UnaryFunction<String,Integer> indexOf(int ch)
Answers a function which will give the first index of a given character value in a given string.

Parameters:
ch - desired character in the target string
Returns:
a function that will interrogate strings for the first index of ch
See Also:
String.indexOf(int)

indexOf

public static UnaryFunction<String,Integer> indexOf(String substring)
Answers a function which will give the first index of a given substring in a given string.

Parameters:
substring - desired substring in the target string
Returns:
a function that will interrogate strings for the first index of substring
See Also:
String.indexOf(String)

lastIndexOf

public static UnaryFunction<String,Integer> lastIndexOf(int ch)
Answers a function which will give the last index of a given character value in a given string.

Parameters:
ch - desired character in the target string
Returns:
a function that will interrogate strings for the last index of ch
See Also:
String.lastIndexOf(int)

lastIndexOf

public static UnaryFunction<String,Integer> lastIndexOf(String substring)
Answers a function which will give the last index of a given substring in a given string.

Parameters:
substring - desired substring in the target string
Returns:
a function that will interrogate strings for the last index of substring
See Also:
String.lastIndexOf(String)

substring

public static UnaryFunction<String,String> substring(int index)
Answers a function which will give the substring of a given string beginning at the given index.

Parameters:
index - index at which to start the substring
Returns:
a function that will interrogate strings for substrings
See Also:
String.substring(int)


© Copyright 2004-2008 Paul R. Holser, Jr. All rights reserved. Licensed under the Academic Free License version 3.0. pholser@alumni.rice.edu