├── .travis.yml
├── LICENSE
├── README.md
├── pom.xml
└── src
├── test
└── java
│ └── net
│ └── codestory
│ └── FluentTest.java
└── main
└── java
└── net
└── codestory
└── Fluent.java
/.travis.yml:
--------------------------------------------------------------------------------
1 | # Use docker-based build environment
2 | sudo: false
3 |
4 | language: java
5 | jdk:
6 | - oraclejdk8
7 |
8 | cache:
9 | directories:
10 | - '$HOME/.m2/repository'
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Copyright (C) 2013 all@code-story.net
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License");
4 | you may not use this file except in compliance with the License.
5 | You may obtain a copy of the License at
6 |
7 | http://www.apache.org/licenses/LICENSE-2.0
8 |
9 | Unless required by applicable law or agreed to in writing, software
10 | distributed under the License is distributed on an "AS IS" BASIS,
11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 | See the License for the specific language governing permissions and
13 | limitations under the License
14 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Fluent
2 |
3 | Java 8 Streams and Iterables on Steroids.
4 |
5 | # Build status
6 |
7 | [](https://travis-ci.org/CodeStory/fluent)
8 |
9 | # Environment
10 |
11 | - `java-1.8`
12 |
13 | ## Maven
14 |
15 | Release versions are deployed on Maven Central:
16 |
17 | ```xml
18 |
19 | net.code-story
20 | fluent
21 | 1.4
22 |
23 | ```
24 |
25 | # Build
26 |
27 | ```bash
28 | mvn clean verify
29 | ```
30 |
31 | # Deploy on Maven Central
32 |
33 | Build the release:
34 |
35 | ```bash
36 | mvn release:clean release:prepare release:perform
37 | ```
38 |
--------------------------------------------------------------------------------
/pom.xml:
--------------------------------------------------------------------------------
1 |
2 |
3 | 4.0.0
4 |
5 | net.code-story
6 | fluent
7 | 1.5-SNAPSHOT
8 | jar
9 |
10 | CodeStory - Fluent Stream/Iterable
11 | Streams and Iterables on Steroids
12 | https://github.com/CodeStory/fluent
13 |
14 |
15 | org.sonatype.oss
16 | oss-parent
17 | 9
18 |
19 |
20 |
21 |
22 | scm:git:git@github.com:CodeStory/fluent.git
23 | scm:git:git@github.com:CodeStory/fluent.git
24 | scm:git:git@github.com:CodeStory/fluent.git
25 | HEAD
26 |
27 |
28 |
29 |
30 | Apache 2
31 | http://www.apache.org/licenses/LICENSE-2.0.txt
32 | repo
33 | A business-friendly OSS license
34 |
35 |
36 |
37 |
38 | 3.0.4
39 |
40 |
41 |
42 | UTF-8
43 | 1.8
44 | 1.8
45 |
46 |
47 |
48 |
49 | release
50 |
51 |
52 |
53 | maven-gpg-plugin
54 | 1.5
55 |
56 |
57 | sign-artifacts
58 | verify
59 |
60 | sign
61 |
62 |
63 |
64 |
65 |
66 |
67 |
68 |
69 |
70 |
71 |
72 |
73 |
74 | maven-clean-plugin
75 | 2.5
76 |
77 |
78 | maven-compiler-plugin
79 | 3.1
80 |
81 |
82 | maven-deploy-plugin
83 | 2.8.1
84 |
85 |
86 | maven-install-plugin
87 | 2.5.1
88 |
89 |
90 | maven-jar-plugin
91 | 2.5
92 |
93 |
94 | maven-resources-plugin
95 | 2.6
96 |
97 |
98 | maven-site-plugin
99 | 3.4
100 |
101 |
102 | maven-source-plugin
103 | 2.3
104 |
105 |
106 | maven-release-plugin
107 | 2.5
108 |
109 |
110 | maven-surefire-plugin
111 | 2.17
112 |
113 |
114 |
115 |
116 |
117 | org.sonatype.plugins
118 | nexus-staging-maven-plugin
119 | 1.6.2
120 | true
121 |
122 | ossrh
123 | https://oss.sonatype.org/
124 | true
125 |
126 |
127 |
128 | maven-release-plugin
129 |
130 | release
131 |
132 |
133 |
134 | maven-source-plugin
135 |
136 |
137 | attach-sources
138 |
139 | jar
140 |
141 |
142 |
143 |
144 |
145 | false
146 | com.mycila.maven-license-plugin
147 | maven-license-plugin
148 | 1.9.0
149 |
150 | ${project.basedir}/LICENSE
151 | true
152 | true
153 | true
154 |
155 | **/*.java
156 |
157 |
158 | JAVADOC_STYLE
159 |
160 |
161 |
162 |
163 | enforce-license-headers
164 | validate
165 |
166 | check
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 | junit
178 | junit
179 | 4.12-beta-2
180 | test
181 |
182 |
183 | org.assertj
184 | assertj-core
185 | 1.7.0
186 | test
187 |
188 |
189 |
190 |
--------------------------------------------------------------------------------
/src/test/java/net/codestory/FluentTest.java:
--------------------------------------------------------------------------------
1 | /**
2 | * Copyright (C) 2013 all@code-story.net
3 | *
4 | * Licensed under the Apache License, Version 2.0 (the "License");
5 | * you may not use this file except in compliance with the License.
6 | * You may obtain a copy of the License at
7 | *
8 | * http://www.apache.org/licenses/LICENSE-2.0
9 | *
10 | * Unless required by applicable law or agreed to in writing, software
11 | * distributed under the License is distributed on an "AS IS" BASIS,
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 | * See the License for the specific language governing permissions and
14 | * limitations under the License
15 | */
16 | package net.codestory;
17 |
18 | import org.junit.Test;
19 |
20 | import java.util.*;
21 | import java.util.stream.*;
22 |
23 | import static org.assertj.core.api.Assertions.assertThat;
24 |
25 | public class FluentTest {
26 | @Test
27 | public void create_empty() {
28 | Iterable empty = Fluent.of();
29 |
30 | assertThat(empty).isEmpty();
31 | }
32 |
33 | @Test
34 | public void create_for_array() {
35 | Iterable values = Fluent.of("FIRST", "SECOND");
36 |
37 | assertThat(values).containsExactly("FIRST", "SECOND");
38 | }
39 |
40 | @Test
41 | public void create_for_iterable() {
42 | Iterable values = Fluent.of(Arrays.asList("FIRST", "SECOND"));
43 |
44 | assertThat(values).containsExactly("FIRST", "SECOND");
45 | }
46 |
47 | @Test
48 | public void create_for_self() {
49 | Fluent fluent = Fluent.of(Arrays.asList("FIRST", "SECOND"));
50 | Iterable values = Fluent.of(fluent);
51 |
52 | assertThat((Object) values).isSameAs(fluent);
53 | }
54 |
55 | @Test
56 | public void create_for_iterator() {
57 | Fluent fluent = Fluent.of(Arrays.asList("FIRST", "SECOND").iterator());
58 |
59 | assertThat(fluent.toList()).containsExactly("FIRST", "SECOND");
60 | assertThat(fluent.toList()).isEmpty();
61 | }
62 |
63 | @Test
64 | public void create_for_stream() {
65 | Fluent fluent = Fluent.of(Stream.of("FIRST", "SECOND"));
66 |
67 | assertThat(fluent.toList()).containsExactly("FIRST", "SECOND");
68 | }
69 |
70 | @Test
71 | public void create_for_int_array() {
72 | int[] ints = {1, 2, 3, 4, 5};
73 |
74 | Iterable values = Fluent.of(ints);
75 |
76 | assertThat(values).containsExactly(1, 2, 3, 4, 5);
77 | }
78 |
79 | @Test
80 | public void create_for_long_array() {
81 | long[] longs = {1L, 2L, 3L, 4L, 5L};
82 |
83 | Iterable values = Fluent.of(longs);
84 |
85 | assertThat(values).containsExactly(1L, 2L, 3L, 4L, 5L);
86 | }
87 |
88 | @Test
89 | public void create_for_double_array() {
90 | double[] doubles = {1, 2, 3, 4, 5};
91 |
92 | Iterable values = Fluent.of(doubles);
93 |
94 | assertThat(values).containsExactly(1D, 2D, 3D, 4D, 5D);
95 | }
96 |
97 | @Test
98 | public void transform_values() {
99 | Iterable values = Fluent.of("a", "b").map(String::toUpperCase);
100 |
101 | assertThat(values).containsExactly("A", "B");
102 | }
103 |
104 | @Test
105 | public void filter_values() {
106 | Iterable values = Fluent.of(1, 2, 3, 4, 5).filter(v -> v > 3);
107 |
108 | assertThat(values).containsExactly(4, 5);
109 | }
110 |
111 | @Test
112 | public void exclude_values() {
113 | Iterable values = Fluent.of(1, 2, 3, 4, 5).exclude(v -> v > 3);
114 |
115 | assertThat(values).containsExactly(1, 2, 3);
116 | }
117 |
118 | @Test
119 | public void count_values() {
120 | long count = Fluent.of(1, 2, 3, 4, 5).size();
121 |
122 | assertThat(count).isEqualTo(5L);
123 | }
124 |
125 | @Test
126 | public void count_with_predicate() {
127 | long count = Fluent.of(1, 2, 3, 4, 5).count(v -> v > 3);
128 |
129 | assertThat(count).isEqualTo(2L);
130 | }
131 |
132 | @Test
133 | public void first_value() {
134 | Optional first = Fluent.of(1, 2, 3, 4, 5).first();
135 |
136 | assertThat(first.get()).isEqualTo(1);
137 | }
138 |
139 | @Test
140 | public void no_first_value() {
141 | Optional