Skip to content

Commit 67a16a7

Browse files
committed
Added extra javadoc and deprecated warnings
1 parent 94a79d0 commit 67a16a7

11 files changed

Lines changed: 80 additions & 14 deletions

File tree

core/src/main/java/fj/data/Array.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -805,6 +805,9 @@ public static <A> Array<A> iterableArray(final Iterable<A> i) {
805805
return iterableList(i).toArray();
806806
}
807807

808+
/**
809+
* Creates an Array from the iterator.
810+
*/
808811
public static <A> Array<A> iteratorArray(final Iterator<A> i) {
809812
return iterableArray(() -> i);
810813
}

core/src/main/java/fj/data/DList.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ private DList(final F<List<A>,Trampoline<List<A>>> appendFn) {
2323
/**
2424
* Creates a DList from the function
2525
*
26-
* For alternatives functions to create a DList see:
26+
* For alternatives functions to create a DList:
2727
* @see #iterableDList
2828
* @see #iteratorDList
2929
* @see #arrayDList

core/src/main/java/fj/data/HashSet.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,16 @@ public static <A> HashSet<A> empty() {
9797
return empty(anyEqual(), anyHash());
9898
}
9999

100+
/**
101+
* Create a HashSet from the Iterable.
102+
*/
100103
public static <A> HashSet<A> iterableHashSet(final Iterable<A> it) {
101104
return iterableHashSet(anyEqual(), anyHash(), it);
102105
}
103106

107+
/**
108+
* Create a HashSet from the Iterable.
109+
*/
104110
public static <A> HashSet<A> iterableHashSet(final Equal<A> e, final Hash<A> h, final Iterable<A> it) {
105111
final HashSet<A> hs = empty(e, h);
106112
for (A a: it) {
@@ -109,29 +115,47 @@ public static <A> HashSet<A> iterableHashSet(final Equal<A> e, final Hash<A> h,
109115
return hs;
110116
}
111117

118+
/**
119+
* Create a HashSet from the Iterator.
120+
*/
112121
public static <A> HashSet<A> iteratorHashSet(final Iterator<A> it) {
113122
return iterableHashSet(() -> it);
114123
}
115124

125+
/**
126+
* Create a HashSet from the Iterator.
127+
*/
116128
public static <A> HashSet<A> iteratorHashSet(final Equal<A> e, final Hash<A> h, final Iterator<A> it) {
117129
return iterableHashSet(e, h, () -> it);
118130
}
119131

132+
/**
133+
* Create a HashSet from the array.
134+
*/
120135
@SafeVarargs
121136
public static <A> HashSet<A> arrayHashSet(final A...as) {
122137
return iterableHashSet(Array.array(as));
123138
}
124139

140+
/**
141+
* Create a HashSet from the array.
142+
*/
125143
@SafeVarargs
126144
public static <A> HashSet<A> arrayHashSet(final Equal<A> e, final Hash<A> h, final A...as) {
127145
return iterableHashSet(e, h, Array.array(as));
128146
}
129147

148+
/**
149+
* Create a HashSet from the array.
150+
*/
130151
@SafeVarargs
131152
public static <A> HashSet<A> hashSet(final A...as) {
132153
return arrayHashSet(as);
133154
}
134155

156+
/**
157+
* Create a HashSet from the array.
158+
*/
135159
@SafeVarargs
136160
public static <A> HashSet<A> hashSet(final Equal<A> e, final Hash<A> h, final A...as) {
137161
return arrayHashSet(e, h, as);

core/src/main/java/fj/data/List.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1541,10 +1541,14 @@ private void tail(final List<A> tail) {
15411541
return arrayList(as);
15421542
}
15431543

1544+
/**
1545+
* Constructs a list from the given elements.
1546+
*/
15441547
@SafeVarargs
15451548
public static <A> List<A> arrayList(final A... as) {
15461549
return Array.array(as).toList();
15471550
}
1551+
15481552
/**
15491553
* Constructs a list from the given Iterable.
15501554
* @deprecated As of release 4.5, use {@link #iterableList(Iterable)}

core/src/main/java/fj/data/Seq.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,14 +84,18 @@ public static <A> Seq<A> single(final A a) {
8484
*/
8585
@Deprecated
8686
public static <A>Seq<A> seq(final List<A> list) {
87-
return listSeq(list);
87+
return iterableSeq(list);
8888
}
8989

9090
/**
9191
* Constructs a sequence from the given list.
92+
*
93+
* @deprecated As of release 4.5, use {@link #iterableSeq}
94+
*
9295
* @param list The list to create the sequence from.
9396
* @return A sequence with the elements of the list.
9497
*/
98+
@Deprecated
9599
public static <A>Seq<A> listSeq(final List<A> list) {
96100
return iterableSeq(list);
97101
}
@@ -118,6 +122,9 @@ public static <A>Seq<A> iteratorSeq(final Iterator<A> i) {
118122
return iterableSeq(() -> i);
119123
}
120124

125+
/**
126+
* Constructs a sequence from the array.
127+
*/
121128
@SafeVarargs
122129
public static <A>Seq<A> arraySeq(A... as) {
123130
return iterableSeq(Array.array(as));

core/src/main/java/fj/data/Set.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,7 @@ public static <A> Set<A> arraySet(final Ord<A> o, final A...as) {
593593
/**
594594
* Constructs a set from the list.
595595
*
596-
* @deprecated As of release 4.5, use {@link #fromList}
596+
* @deprecated As of release 4.5, use {@link #iterableSet}
597597
*
598598
* @param o An order for the elements of the new set.
599599
* @param list The elements to add to a set.
@@ -606,7 +606,10 @@ public static <A> Set<A> set(final Ord<A> o, List<A> list) {
606606

607607
/**
608608
* Constructs a set from the list.
609+
*
610+
* @deprecated As of release 4.5, use {@link #iterableSet}
609611
*/
612+
@Deprecated
610613
public static <A> Set<A> fromList(final Ord<A> o, List<A> list) {
611614
return iterableSet(o, list);
612615
}

core/src/main/java/fj/data/TreeMap.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,24 @@ public String toString() {
7373
/**
7474
* Constructs a tree map from the given elements.
7575
*
76+
* @deprecated As of release 4.5, use {@link #iterableTreeMap(Ord, Iterable)}
77+
*
7678
* @param keyOrd An order for the keys of the tree map.
7779
* @param list The elements to construct the tree map with.
7880
* @return a TreeMap with the given elements.
7981
*/
82+
@Deprecated
8083
public static <K, V> TreeMap<K, V> treeMap(final Ord<K> keyOrd, final List<P2<K, V>> list) {
8184
return iterableTreeMap(keyOrd, list);
8285
}
8386

87+
/**
88+
* Constructs a tree map from the given elements.
89+
*
90+
* @param keyOrd An order for the keys of the tree map.
91+
* @param it The elements to construct the tree map with.
92+
* @return A TreeMap with the given elements.
93+
*/
8494
public static <K, V> TreeMap<K, V> iterableTreeMap(final Ord<K> keyOrd, final Iterable<P2<K, V>> it) {
8595
TreeMap<K, V> tm = empty(keyOrd);
8696
for (final P2<K, V> p2 : it) {
@@ -89,10 +99,24 @@ public static <K, V> TreeMap<K, V> iterableTreeMap(final Ord<K> keyOrd, final It
8999
return tm;
90100
}
91101

102+
/**
103+
* Constructs a tree map from the given elements.
104+
*
105+
* @param keyOrd An order for the keys of the tree map.
106+
* @param it The elements to construct the tree map with.
107+
* @return A TreeMap with the given elements.
108+
*/
92109
public static <K, V> TreeMap<K, V> iteratorTreeMap(final Ord<K> keyOrd, final Iterator<P2<K, V>> it) {
93110
return iterableTreeMap(keyOrd, () -> it);
94111
}
95112

113+
/**
114+
* Constructs a tree map from the given elements.
115+
*
116+
* @param keyOrd An order for the keys of the tree map.
117+
* @param ps The elements to construct the tree map with.
118+
* @return A TreeMap with the given elements.
119+
*/
96120
@SafeVarargs
97121
public static <K, V> TreeMap<K, V> arrayTreeMap(final Ord<K> keyOrd, final P2<K, V>...ps) {
98122
return iterableTreeMap(keyOrd, Array.array(ps));

core/src/test/java/fj/data/TreeMapTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import static fj.P.p;
1414
import static fj.data.Option.none;
1515
import static fj.data.Option.some;
16+
import static fj.data.TreeMap.iterableTreeMap;
1617
import static org.hamcrest.CoreMatchers.equalTo;
1718
import static org.junit.Assert.assertEquals;
1819
import static org.junit.Assert.assertThat;
@@ -29,7 +30,7 @@ public void split() {
2930
int pivot = 4;
3031
int max = 5;
3132
List<Integer> l = List.range(1, max + 1);
32-
TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
33+
TreeMap<Integer, String> m2 = iterableTreeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
3334
P3<Set<String>, Option<String>, Set<String>> p = m2.split(Ord.stringOrd, pivot);
3435

3536
// print debug info
@@ -51,7 +52,7 @@ public void split() {
5152
}
5253

5354
private static Set<String> toSetString(List<Integer> list) {
54-
return Set.fromList(Ord.stringOrd, list.map(i -> i.toString()));
55+
return Set.iterableSet(Ord.stringOrd, list.map(i -> i.toString()));
5556
}
5657

5758
@Test
@@ -60,14 +61,14 @@ public void splitLookup() {
6061
int pivot = 4;
6162
int max = 5;
6263
List<Integer> l = List.range(1, max + 1);
63-
TreeMap<Integer, String> m2 = TreeMap.treeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
64+
TreeMap<Integer, String> m2 = iterableTreeMap(Ord.intOrd, l.zip(l.map(i -> i.toString())));
6465
P3<TreeMap<Integer, String>, Option<String>, TreeMap<Integer, String>> p3 = m2.splitLookup(pivot);
6566

6667
// create expected output
6768
List<Integer> leftList = List.range(1, pivot);
68-
TreeMap<Integer, String> leftMap = TreeMap.treeMap(Ord.intOrd, leftList.zip(leftList.map(i -> i.toString())));
69+
TreeMap<Integer, String> leftMap = iterableTreeMap(Ord.intOrd, leftList.zip(leftList.map(i -> i.toString())));
6970
List<Integer> rightList = List.range(pivot + 1, max + 1);
70-
TreeMap<Integer, String> rightMap = TreeMap.treeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString())));
71+
TreeMap<Integer, String> rightMap = iterableTreeMap(Ord.intOrd, rightList.zip(rightList.map(i -> i.toString())));
7172

7273
// debug info
7374
if (true) {
@@ -86,7 +87,7 @@ public void splitLookup() {
8687
public void toMutableMap() {
8788
int max = 5;
8889
List<List<Integer>> l = List.range(1, max + 1).map(n -> List.single(n));
89-
TreeMap<List<Integer>, String> m2 = TreeMap.treeMap(Ord.listOrd(Ord.intOrd), l.zip(l.map(i -> i.toString())));
90+
TreeMap<List<Integer>, String> m2 = iterableTreeMap(Ord.listOrd(Ord.intOrd), l.zip(l.map(i -> i.toString())));
9091
Map<List<Integer>, String> mm = m2.toMutableMap();
9192
assertEquals(m2.keys(), List.iterableList(mm.keySet()));
9293
}

performance/src/main/java/fj/data/DListPerformance.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public List<Integer> unbox(List<Integer> a) {
3434
private static final BenchmarkMethods<Seq<Integer>> seqMethods = new BenchmarkMethods<Seq<Integer>>() {
3535
@Override
3636
public Seq<Integer> range(int from, int to) {
37-
return Seq.listSeq(List.range(from, to));
37+
return Seq.iterableSeq(List.range(from, to));
3838
}
3939
@Override
4040
public Seq<Integer> append(Seq<Integer> a, Seq<Integer> b) {

props-core/src/test/java/fj/data/properties/SeqProperties.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public Property foldRight() {
118118

119119
public Property length() {
120120
return property(arbList(arbInteger), list ->
121-
prop(Seq.listSeq(list).length() == list.length())
121+
prop(Seq.iterableSeq(list).length() == list.length())
122122
);
123123
}
124124

0 commit comments

Comments
 (0)