Skip to content

Commit 2e8b5f3

Browse files
committed
- add min and max #21
- fix several warnings on tests - remove "public" from method declarations in interfaces
1 parent 83993a2 commit 2e8b5f3

File tree

11 files changed

+202
-90
lines changed

11 files changed

+202
-90
lines changed

android-linq.iml

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3-
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7" inherit-compiler-output="false">
3+
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
44
<output url="file://$MODULE_DIR$/target/classes" />
55
<output-test url="file://$MODULE_DIR$/target/test-classes" />
66
<content url="file://$MODULE_DIR$">
77
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8-
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
98
<sourceFolder url="file://$MODULE_DIR$/src/test/groovy" isTestSource="true" />
109
<excludeFolder url="file://$MODULE_DIR$/target" />
1110
</content>
12-
<orderEntry type="jdk" jdkName="1.7" jdkType="JavaSDK" />
11+
<orderEntry type="inheritedJdk" />
1312
<orderEntry type="sourceFolder" forTests="false" />
1413
<orderEntry type="module-library">
1514
<library>
1615
<CLASSES>
17-
<root url="jar://$APPLICATION_HOME_DIR$/lib/groovy-all-2.2.1.jar!/" />
18-
</CLASSES>
19-
<JAVADOC />
20-
<SOURCES />
21-
</library>
22-
</orderEntry>
23-
<orderEntry type="module-library">
24-
<library name="JUnit4">
25-
<CLASSES>
26-
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.11.jar!/" />
27-
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
28-
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-library-1.3.jar!/" />
16+
<root url="jar://$APPLICATION_HOME_DIR$/lib/groovy-all-2.4.6.jar!/" />
2917
</CLASSES>
3018
<JAVADOC />
3119
<SOURCES />
3220
</library>
3321
</orderEntry>
22+
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
23+
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
3424
</component>
3525
</module>

pom.xml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,17 @@
88
<groupId>br.com.zbra</groupId>
99
<artifactId>android-linq</artifactId>
1010
<version>1.0.1</version>
11-
<packaging>jar</packaging>
11+
<packaging>jar</packaging>
12+
13+
<dependencies>
14+
<dependency>
15+
<groupId>junit</groupId>
16+
<artifactId>junit</artifactId>
17+
<version>RELEASE</version>
18+
<scope>test</scope>
19+
</dependency>
20+
</dependencies>
21+
1222

1323
<properties>
1424
<maven.compiler.source>1.7</maven.compiler.source>

src/main/java/br/com/zbra/androidlinq/AbstractStream.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ public Integer aggregate(Integer v, T t) {
140140

141141
@Override
142142
public Long sum(final SelectorLong<T> selector) {
143-
return aggregate(0l, new Aggregator<T, Long>() {
143+
return aggregate(0L, new Aggregator<T, Long>() {
144144
@Override
145145
public Long aggregate(Long v, T t) {
146146
return v + selector.select(t);
@@ -178,6 +178,26 @@ public BigDecimal aggregate(BigDecimal v, T t) {
178178
});
179179
}
180180

181+
@Override
182+
public <TResult extends Comparable<TResult>> T min(Selector<T, TResult> selector) {
183+
return orderBy(selector).first();
184+
}
185+
186+
@Override
187+
public <TResult> T min(Selector<T, TResult> selector, Comparator<TResult> comparator) {
188+
return orderBy(selector, comparator).first();
189+
}
190+
191+
@Override
192+
public <TResult extends Comparable<TResult>> T max(Selector<T, TResult> selector) {
193+
return orderBy(selector).last();
194+
}
195+
196+
@Override
197+
public <TResult> T max(Selector<T, TResult> selector, Comparator<TResult> comparator) {
198+
return orderBy(selector, comparator).last();
199+
}
200+
181201
@Override
182202
public boolean any() {
183203
return iterator().hasNext();

src/main/java/br/com/zbra/androidlinq/OrderedStream.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public interface OrderedStream<T> extends Stream<T> {
1313
* @param <TKey> The type of the key returned by keySelector.
1414
* @return An Stream of type T whose elements are sorted according to a key.
1515
*/
16-
public <TKey> OrderedStream<T> thenBy(Selector<T, TKey> keySelector, Comparator<TKey> comparator);
16+
<TKey> OrderedStream<T> thenBy(Selector<T, TKey> keySelector, Comparator<TKey> comparator);
1717

1818
/**
1919
* Performs a subsequent ordering of the elements in a sequence in ascending order according to a key.
@@ -22,7 +22,7 @@ public interface OrderedStream<T> extends Stream<T> {
2222
* @param <TKey> The type of the key returned by keySelector.
2323
* @return An Stream of type T whose elements are sorted according to a key.
2424
*/
25-
public <TKey extends Comparable<TKey>> OrderedStream<T> thenBy(Selector<T, TKey> keySelector);
25+
<TKey extends Comparable<TKey>> OrderedStream<T> thenBy(Selector<T, TKey> keySelector);
2626

2727
/**
2828
* Performs a subsequent ordering of the elements in a sequence in descending order by using a specified comparer.
@@ -32,7 +32,7 @@ public interface OrderedStream<T> extends Stream<T> {
3232
* @param <TKey> The type of the key returned by keySelector.
3333
* @return An Stream of type T whose elements are sorted according to a key.
3434
*/
35-
public <TKey> OrderedStream<T> thenByDescending(Selector<T, TKey> keySelector, Comparator<TKey> comparator);
35+
<TKey> OrderedStream<T> thenByDescending(Selector<T, TKey> keySelector, Comparator<TKey> comparator);
3636

3737
/**
3838
* Performs a subsequent ordering of the elements in a sequence in descending order, according to a key.
@@ -41,6 +41,6 @@ public interface OrderedStream<T> extends Stream<T> {
4141
* @param <TKey> The type of the key returned by keySelector.
4242
* @return An Stream of type T whose elements are sorted according to a key.
4343
*/
44-
public <TKey extends Comparable<TKey>> OrderedStream<T> thenByDescending(Selector<T, TKey> keySelector);
44+
<TKey extends Comparable<TKey>> OrderedStream<T> thenByDescending(Selector<T, TKey> keySelector);
4545

4646
}

0 commit comments

Comments
 (0)