Skip to content

Commit 7d366ef

Browse files
committed
Merge pull request #8 from magro/master
Add isNotNullOrEmpty to Strings.
2 parents 298c05f + 3dceccb commit 7d366ef

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

core/src/main/java/fj/Ord.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,4 +637,25 @@ public Ordering f(final A a2) {
637637
}
638638
});
639639
}
640+
641+
/**
642+
* An order instance that uses {@link Object#hashCode()} for computing the order.
643+
*
644+
* @return An order instance that is based on {@link Object#hashCode()}.
645+
*/
646+
public static <A> Ord<A> hashOrd() {
647+
return Ord.<A> ord(new F<A, F<A, Ordering>>() {
648+
@Override
649+
public F<A, Ordering> f(final A a) {
650+
return new F<A, Ordering>() {
651+
@Override
652+
public Ordering f(final A a2) {
653+
final int x = a.hashCode() - a2.hashCode();
654+
return x < 0 ? Ordering.LT : x == 0 ? Ordering.EQ : Ordering.GT;
655+
}
656+
};
657+
}
658+
});
659+
}
660+
640661
}

core/src/main/java/fj/function/Strings.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,16 @@ private Strings() {
1414
throw new UnsupportedOperationException();
1515
}
1616

17+
/**
18+
* This function checks if a given String is neither <code>null</code> nor empty.
19+
*/
20+
public static final F<String, Boolean> isNotNullOrEmpty = new F<String, Boolean>() {
21+
@Override
22+
public Boolean f(final String a) {
23+
return a != null && a.length() > 0;
24+
}
25+
};
26+
1727
/**
1828
* A curried version of {@link String#isEmpty()}.
1929
*/

0 commit comments

Comments
 (0)