001 package fj.function;
002
003 import fj.F;
004 import fj.F2;
005 import static fj.Function.curry;
006
007 /**
008 * Curried string functions.
009 *
010 * @version %build.number%<br>
011 * <ul>
012 * <li>$LastChangedRevision$</li>
013 * <li>$LastChangedDate$</li>
014 * </ul>
015 */
016 public class Strings {
017 private Strings() {
018 throw new UnsupportedOperationException();
019 }
020
021 /**
022 * A curried version of {@link String#isEmpty()}.
023 */
024 public static final F<String, Boolean> isEmpty = new F<String, Boolean>() {
025 public Boolean f(final String s) {
026 return s.length() == 0;
027 }
028 };
029
030 /**
031 * A curried version of {@link String#length()}.
032 */
033 public static final F<String, Integer> length = new F<String, Integer>() {
034 public Integer f(final String s) {
035 return s.length();
036 }
037 };
038
039 /**
040 * A curried version of {@link String#contains(CharSequence)}.
041 * The function returns true if the second argument contains the first.
042 */
043 public static final F<String, F<String, Boolean>> contains = curry(new F2<String, String, Boolean>() {
044 public Boolean f(final String s1, final String s2) {
045 return s2.contains(s1);
046 }
047 });
048
049 /**
050 * A curried version of {@link String#matches(String)}.
051 * The function returns true if the second argument matches the first.
052 */
053 public static final F<String, F<String, Boolean>> matches = curry(new F2<String, String, Boolean>() {
054 public Boolean f(final String s1, final String s2) {
055 return s2.matches(s1);
056 }
057 });
058
059 }