Skip to content

Commit f1df42c

Browse files
committed
Rename Finction1 with Function in examples.
1 parent 2728be7 commit f1df42c

File tree

7 files changed

+23
-19
lines changed

7 files changed

+23
-19
lines changed

examples/src/main/java/com/github/underscore/examples/Chaining.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* The MIT License (MIT)
33
*
4-
* Copyright 2015 Valentyn Kolesnikov
4+
* Copyright 2015-2018 Valentyn Kolesnikov
55
*
66
* Permission is hereby granted, free of charge, to any person obtaining a copy
77
* of this software and associated documentation files (the "Software"), to deal
@@ -35,7 +35,7 @@ public static <E> E first(final Iterable<E> iterable) {
3535
return iterable.iterator().next();
3636
}
3737

38-
public static <T, E> List<T> map(final List<E> list, final Function1<? super E, T> func) {
38+
public static <T, E> List<T> map(final List<E> list, final Function<? super E, T> func) {
3939
final List<T> transformed = new ArrayList<T>(list.size());
4040
for (E element : list) {
4141
transformed.add(func.apply(element));
@@ -44,7 +44,7 @@ public static <T, E> List<T> map(final List<E> list, final Function1<? super E,
4444
}
4545

4646
public static <E, T extends Comparable<? super T>> List<E> sortBy(final List<E> iterable,
47-
final Function1<E, T> func) {
47+
final Function<E, T> func) {
4848
final List<E> sortedList = new ArrayList<E>(iterable);
4949
Collections.sort(sortedList, new Comparator<E>() {
5050
@Override
@@ -85,11 +85,11 @@ public Chain<T> first() {
8585
return new Chain<T>(Chaining.first(list));
8686
}
8787

88-
public <F> Chain<F> map(final Function1<? super T, F> func) {
88+
public <F> Chain<F> map(final Function<? super T, F> func) {
8989
return new Chain<F>(Chaining.map(list, func));
9090
}
9191

92-
public <F extends Comparable<? super F>> Chain<T> sortBy(final Function1<T, F> func) {
92+
public <F extends Comparable<? super F>> Chain<T> sortBy(final Function<T, F> func) {
9393
return new Chain<T>(Chaining.sortBy(list, func));
9494
}
9595

examples/src/main/java/com/github/underscore/examples/Function1.java renamed to examples/src/main/java/com/github/underscore/examples/Function.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.github.underscore.examples;
22

3-
public interface Function1<F, T> {
3+
public interface Function<F, T> {
44
T apply(F arg);
55

66
@Override

examples/src/main/java/com/github/underscore/examples/Intersection.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
public class Intersection {
3434
public static <E> Optional<E> find(final Iterable<E> iterable, final Predicate<E> pred) {
3535
for (E element : iterable) {
36-
if (pred.apply(element)) {
36+
if (pred.test(element)) {
3737
return Optional.of(element);
3838
}
3939
}
@@ -47,7 +47,7 @@ public static <E> boolean some(final Iterable<E> iterable, final Predicate<E> pr
4747
public static <E> boolean contains(final Iterable<E> iterable, final E elem) {
4848
return some(iterable, new Predicate<E>() {
4949
@Override
50-
public Boolean apply(E e) {
50+
public boolean test(E e) {
5151
return elem == null ? e == null : elem.equals(e);
5252
}
5353
});
@@ -56,7 +56,7 @@ public Boolean apply(E e) {
5656
public static <E> List<E> filter(final List<E> list, final Predicate<E> pred) {
5757
final List<E> filtered = new ArrayList<E>();
5858
for (E element : list) {
59-
if (pred.apply(element)) {
59+
if (pred.test(element)) {
6060
filtered.add(element);
6161
}
6262
}
@@ -66,7 +66,7 @@ public static <E> List<E> filter(final List<E> list, final Predicate<E> pred) {
6666
public static <E> List<E> intersection(final List<E> list1, final List<E> list2) {
6767
return filter(list1, new Predicate<E>() {
6868
@Override
69-
public Boolean apply(E elem) {
69+
public boolean test(E elem) {
7070
return contains(list2, elem);
7171
}
7272
});
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
package com.github.underscore.examples;
22

3-
public interface Predicate<T> extends Function1<T, Boolean> {
3+
public interface Predicate<T> {
4+
boolean test(T arg);
5+
6+
@Override
7+
boolean equals(Object object);
48
}

examples/src/main/java/com/github/underscore/examples/SnakeCase.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,9 +88,9 @@ public static List<String> words(final String string) {
8888
return result;
8989
}
9090

91-
private static Function1<String, String> createCompounder(
91+
private static Function<String, String> createCompounder(
9292
final Function3<String, String, Integer, String> callback) {
93-
return new Function1<String, String>() {
93+
return new Function<String, String>() {
9494
public String apply(final String string) {
9595
int index = -1;
9696
List<String> array = words(deburr(string));

examples/src/main/java/com/github/underscore/examples/Xor.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public static <E> List<E> uniq(final List<E> list) {
3737

3838
public static <E> Optional<E> find(final Iterable<E> iterable, final Predicate<E> pred) {
3939
for (E element : iterable) {
40-
if (pred.apply(element)) {
40+
if (pred.test(element)) {
4141
return Optional.of(element);
4242
}
4343
}
@@ -51,7 +51,7 @@ public static <E> boolean some(final Iterable<E> iterable, final Predicate<E> pr
5151
public static <E> boolean contains(final Iterable<E> iterable, final E elem) {
5252
return some(iterable, new Predicate<E>() {
5353
@Override
54-
public Boolean apply(E e) {
54+
public boolean test(E e) {
5555
return elem == null ? e == null : elem.equals(e);
5656
}
5757
});
@@ -60,7 +60,7 @@ public Boolean apply(E e) {
6060
public static <E> List<E> filter(final List<E> list, final Predicate<E> pred) {
6161
final List<E> filtered = new ArrayList<E>();
6262
for (E element : list) {
63-
if (pred.apply(element)) {
63+
if (pred.test(element)) {
6464
filtered.add(element);
6565
}
6666
}
@@ -70,7 +70,7 @@ public static <E> List<E> filter(final List<E> list, final Predicate<E> pred) {
7070
public static <E> List<E> difference(final List<E> list1, final List<E> list2) {
7171
return filter(list1, new Predicate<E>() {
7272
@Override
73-
public Boolean apply(E elem) {
73+
public boolean test(E elem) {
7474
return !contains(list2, elem);
7575
}
7676
});

examples/src/test/java/com/github/underscore/examples/ChainingTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,13 @@ public void chain() {
5858
} };
5959
final String youngest = Chaining.chain(stooges)
6060
.sortBy(
61-
new Function1<Map<String, Object>, Integer>() {
61+
new Function<Map<String, Object>, Integer>() {
6262
public Integer apply(Map<String, Object> item) {
6363
return (Integer) item.get("age");
6464
}
6565
})
6666
.map(
67-
new Function1<Map<String, Object>, String>() {
67+
new Function<Map<String, Object>, String>() {
6868
public String apply(Map<String, Object> item) {
6969
return item.get("name") + " is " + item.get("age");
7070
}

0 commit comments

Comments
 (0)