Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#160 let's get rid of List.add() #183

Closed
wants to merge 51 commits into from
Closed
Changes from 1 commit
Commits
Show all changes
51 commits
Select commit Hold shift + click to select a range
df558e0
Concat implementation commit
super132 Apr 16, 2015
2c0ea83
Committing unit test cases
super132 Apr 16, 2015
86739ff
Suppressing warnings for EMPTY_LIST usage
Apr 16, 2015
89db00c
Fixing code styling issues
super132 Apr 16, 2015
5956ed4
Another fixes to styling and refactoring
Apr 16, 2015
442eda3
Further styling fixes
super132 Apr 16, 2015
71641d8
Another fixes to styling.
Apr 16, 2015
f04c129
Minor style fixes.
super132 Apr 16, 2015
bc62609
Minor code styles fixes in unit test
super132 Apr 16, 2015
575fb86
Another minor code style fixes to unit test
super132 Apr 16, 2015
5eef73b
More minor updates to code stlyes
super132 Apr 16, 2015
202b6c7
Correct author name and since version.
super132 Apr 16, 2015
b666115
Code changes to address code review comments
super132 Apr 18, 2015
adf8469
Merge branch 'master' of https://github.com/yegor256/takes.git
super132 Apr 18, 2015
8ec1dd2
Fixing code style issues
super132 Apr 18, 2015
ad0dc65
Minor fixes to code style
super132 Apr 18, 2015
b416e3a
Code static analysis fix
super132 Apr 18, 2015
3d1abbc
Minor fix.
super132 Apr 18, 2015
97e42d2
Addressing code review comments
super132 Apr 19, 2015
cf1b7c1
Code styling changes as per advised in comments
super132 Apr 19, 2015
4bca084
Using Collection.emptyList() to avoid unchecked casting.
super132 Apr 20, 2015
a2b21e6
Select class is created for separating filtering and concatenation logic
Apr 20, 2015
a2a9dcf
Fixing code static analysis issues.
Apr 20, 2015
a06b488
Refactor according to code review comments
Apr 20, 2015
321ab09
Fixing compilation error in CI.
super132 Apr 20, 2015
a1e2dd7
Fixing static code analysis issues.
super132 Apr 20, 2015
a2d9672
Code refactor for PMD issues
super132 Apr 20, 2015
6a93539
minor Code style fixes
super132 Apr 20, 2015
36fcee6
Code static analysis fix.
super132 Apr 20, 2015
520fbe5
Code refactoring for addressing code review comments
super132 Apr 21, 2015
cc2de62
Merge branch 'master' of https://github.com/super132/takes.git
super132 Apr 21, 2015
6b016ef
Fixing code styling issues
super132 Apr 21, 2015
02f8612
Minor stlying fix
super132 Apr 21, 2015
a823694
Other minor code style fixes
super132 Apr 21, 2015
3f1d3ff
Further code refinements.
super132 Apr 21, 2015
c371d8a
Minor code refactoring.
super132 Apr 21, 2015
3537d5e
Revert "Minor code refactoring."
Apr 21, 2015
99eaf3d
Minor javadoc update
super132 Apr 21, 2015
d02c65a
Extracting out negation condition from LowerStartsWith
super132 Apr 22, 2015
546168d
Fixing code style issues
super132 Apr 22, 2015
299627a
Minor update to javadoc
super132 Apr 22, 2015
91d760b
Minor spacing update
super132 Apr 22, 2015
69ff934
Refactored SelectIterator to use Guava AbstractIterator
super132 Apr 22, 2015
45b2079
Updating POM to enable use of Guava
super132 Apr 22, 2015
1385aee
Fixing POM.xml
super132 Apr 22, 2015
76012c2
Fixing minor space problem.
super132 Apr 22, 2015
9750dc8
Adding super() call in constructor
super132 Apr 22, 2015
a3693bb
Refactoring LowerStartsWith condition into two to fulfill design needs
super132 Apr 22, 2015
6e25d5b
Fixing minor spacing issues
super132 Apr 22, 2015
1af3583
Removing Guava dependency
super132 Apr 23, 2015
08737a0
Refactoring case insensitive comparison to inline condition.
super132 Apr 25, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Conflicts:
	src/main/java/org/takes/rs/RsWithHeaders.java
  • Loading branch information
super132 committed Apr 18, 2015
commit adf846986362515ebcba632d8da39cbb0e633907
37 changes: 27 additions & 10 deletions src/main/java/org/takes/misc/Transformer.java
Original file line number Diff line number Diff line change
@@ -28,18 +28,18 @@
import java.util.List;

/**
* Transform elements in an iterable into others.
* Transform elements in an iterable (in type T) into others (in type K).
*
* @author Jason Wong ([email protected])
* @version $Id$
* @since 0.13.8
*/
public class Transformer<T> implements Iterable<T> {
public class Transformer<T, K> implements Iterable<K> {

/**
* Internal storage.
*/
private final transient List<T> storage = new LinkedList<T>();
private final transient List<K> storage = new LinkedList<K>();

/**
* Transform elements in the supplied iterable by the action supplied.
@@ -48,26 +48,26 @@ public class Transformer<T> implements Iterable<T> {
* @param action The actual transformation implementation
*/
public Transformer(final Iterable<T> list,
final Transformer.Action<T> action) {
final Transformer.Action<T, K> action) {
final Iterator<T> itr = list.iterator();
while (itr.hasNext()) {
this.storage.add(action.transform(itr.next()));
}
}

@Override
public final Iterator<T> iterator() {
public final Iterator<K> iterator() {
return this.storage.iterator();
}

public interface Action<T> {
public interface Action<T, K> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@super132 I think here we should do as with Condition, so please move Action to a separate class and place the implementers as inner classes there.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@krzyk , I missed this one. I will move it out as a separate class.

/**
* The transform action of the element.
* The transform action of the element of type T to K.
*
* @param element Element of the iterable
* @return Transformed element
*/
T transform(T element);
K transform(T element);
}

/**
@@ -79,12 +79,29 @@ public interface Action<T> {
*
*/
public static final class Trim implements
Transformer.Action<String> {
Transformer.Action<String, String> {

@Override
public String transform(final String element) {
return element.trim();
}
}

/**
* Convert CharSequence into String
*
* @author Jason Wong ([email protected])
* @version $Id$
* @since 0.13.8
*
*/
public static final class ToString implements
Transformer.Action<CharSequence, String> {

}
@Override
public String transform(CharSequence element) {
return element.toString();
}

}
}
15 changes: 11 additions & 4 deletions src/main/java/org/takes/rs/RsWithHeaders.java
Original file line number Diff line number Diff line change
@@ -26,10 +26,13 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

import lombok.EqualsAndHashCode;

import org.takes.Response;
import org.takes.misc.Concat;
import org.takes.misc.Transformer;
import org.takes.misc.Transformer.Trim;

/**
* Response decorator, with an additional headers.
@@ -62,13 +65,17 @@ public RsWithHeaders(final Response res,
super(
new Response() {
@Override
@SuppressWarnings("unchecked")
public Iterable<String> head() throws IOException {
return new Concat<String>(
res.head(),
new Transformer<String>(
headers,
new Transformer.Trim()
)
new Transformer<String, String>(
new Transformer<CharSequence, String>(
(Iterable<CharSequence>)headers,
new Transformer.ToString()
)
, new Transformer.Trim()
)
);
}
@Override
4 changes: 2 additions & 2 deletions src/test/java/org/takes/misc/IterableTransformTest.java
Original file line number Diff line number Diff line change
@@ -48,9 +48,9 @@ public void iterableTransform() {
alist.add("b1");
alist.add("c1");
MatcherAssert.assertThat(
new Transformer<String>(
new Transformer<String, String>(
alist,
new Transformer.Action<String>() {
new Transformer.Action<String, String>() {
@Override
public String transform(final String element) {
return element.concat("t");
You are viewing a condensed version of this merge commit. You can view the full changes here.