Skip to content

Commit

Permalink
#176: renames and more ctors
Browse files Browse the repository at this point in the history
  • Loading branch information
yegor256 committed Jun 19, 2017
1 parent 5fcdcb6 commit f9b77f4
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* @param <T> Type of item
* @since 0.1
*/
public final class ConcatenatedIterable<T> implements Iterable<T> {
public final class ConcatIterable<T> implements Iterable<T> {

/**
* Iterables.
Expand All @@ -49,22 +49,22 @@ public final class ConcatenatedIterable<T> implements Iterable<T> {
*/
@SafeVarargs
@SuppressWarnings("varargs")
public ConcatenatedIterable(final Iterable<T>... items) {
public ConcatIterable(final Iterable<T>... items) {
this(new IterableAsList<>(items));
}

/**
* Ctor.
* @param items Items to concatenate
*/
public ConcatenatedIterable(final Iterable<Iterable<T>> items) {
public ConcatIterable(final Iterable<Iterable<T>> items) {
this.list = items;
}

@Override
public Iterator<T> iterator() {
return new ConcatenatedIterator<>(
new TransformedIterable<>(
return new ConcatIterator<>(
new MappedIterable<>(
this.list,
new StickyFunc<>(Iterable::iterator)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
* @param <T> Type of item
* @since 0.1
*/
public final class ConcatenatedIterator<T> implements Iterator<T> {
public final class ConcatIterator<T> implements Iterator<T> {

/**
* Iterables.
Expand All @@ -48,15 +48,15 @@ public final class ConcatenatedIterator<T> implements Iterator<T> {
*/
@SafeVarargs
@SuppressWarnings("varargs")
public ConcatenatedIterator(final Iterator<T>... items) {
public ConcatIterator(final Iterator<T>... items) {
this(new IterableAsList<>(items));
}

/**
* Ctor.
* @param items Items to concatenate
*/
public ConcatenatedIterator(final Iterable<Iterator<T>> items) {
public ConcatIterator(final Iterable<Iterator<T>> items) {
this.list = items;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/cactoos/list/IterableAsBooleans.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public IterableAsBooleans(final Iterable<X> src,

@Override
public Iterator<Boolean> iterator() {
return new TransformedIterator<>(
return new MappedIterator<>(
this.iterable.iterator(),
this.func
);
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/org/cactoos/list/MapAsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package org.cactoos.list;

import java.util.AbstractMap;
import java.util.Map;
import java.util.Properties;
import org.cactoos.Scalar;
Expand All @@ -45,6 +46,23 @@ public final class MapAsProperties implements Scalar<Properties> {
*/
private final UncheckedScalar<Properties> result;

/**
* Ctor.
* @param entries The map with properties
*/
public MapAsProperties(final Map.Entry<?, ?>... entries) {
this(
new IterableAsMap<>(
new MappedIterable<Map.Entry<?, ?>, Map.Entry<String, String>>(
new ArrayAsIterable<>(entries),
input -> new AbstractMap.SimpleEntry<>(
input.getKey().toString(), input.getValue().toString()
)
)
)
);
}

/**
* Ctor.
* @param map The map with properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.cactoos.Func;

/**
* Transformed iterable.
* Mapped iterable.
*
* <p>There is no thread-safety guarantee.
*
Expand All @@ -37,7 +37,7 @@
* @param <Y> Type of target item
* @since 0.1
*/
public final class TransformedIterable<X, Y> implements Iterable<Y> {
public final class MappedIterable<X, Y> implements Iterable<Y> {

/**
* Iterable.
Expand All @@ -54,14 +54,14 @@ public final class TransformedIterable<X, Y> implements Iterable<Y> {
* @param src Source iterable
* @param fnc Func
*/
public TransformedIterable(final Iterable<X> src, final Func<X, Y> fnc) {
public MappedIterable(final Iterable<X> src, final Func<X, Y> fnc) {
this.iterable = src;
this.func = fnc;
}

@Override
public Iterator<Y> iterator() {
return new TransformedIterator<>(
return new MappedIterator<>(
this.iterable.iterator(), this.func
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.cactoos.func.UncheckedFunc;

/**
* Transformed iterator.
* Mapped iterator.
*
* <p>There is no thread-safety guarantee.
*
Expand All @@ -38,7 +38,7 @@
* @param <Y> Type of target item
* @since 0.1
*/
public final class TransformedIterator<X, Y> implements Iterator<Y> {
public final class MappedIterator<X, Y> implements Iterator<Y> {

/**
* Iterator.
Expand All @@ -55,7 +55,7 @@ public final class TransformedIterator<X, Y> implements Iterator<Y> {
* @param src Source iterable
* @param fnc Func
*/
public TransformedIterator(final Iterator<X> src, final Func<X, Y> fnc) {
public MappedIterator(final Iterator<X> src, final Func<X, Y> fnc) {
this.iterator = src;
this.func = fnc;
}
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/list/AllOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public void iteratesList() {
MatcherAssert.assertThat(
"Can't iterate a list with a procedure",
new AllOf(
new TransformedIterable<>(
new MappedIterable<>(
new ArrayAsIterable<>("hello", "world"),
list::add
)
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/org/cactoos/list/AnyOfTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public void iteratesList() {
MatcherAssert.assertThat(
"Can't iterate a list",
new AnyOf(
new TransformedIterable<>(
new MappedIterable<>(
new ArrayAsIterable<>("a", "file", "is", "corrupt"),
txt -> txt.length() > 2
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,21 +28,21 @@
import org.junit.Test;

/**
* Test case for {@link ConcatenatedIterable}.
* Test case for {@link ConcatIterable}.
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.1
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class ConcatenatedIterableTest {
public final class ConcatIterableTest {

@Test
@SuppressWarnings("unchecked")
public void transformsList() {
MatcherAssert.assertThat(
"Can't concatenate iterables together",
new LengthOfIterable(
new ConcatenatedIterable<>(
new ConcatIterable<>(
new ArrayAsIterable<>("hello", "world", "друг"),
new ArrayAsIterable<>("how", "are", "you"),
new ArrayAsIterable<>("what's", "up")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,19 @@
import org.junit.Test;

/**
* Test case for {@link TransformedIterable}.
* Test case for {@link MappedIterable}.
* @author Yegor Bugayenko (yegor256@gmail.com)
* @version $Id$
* @since 0.1
* @checkstyle JavadocMethodCheck (500 lines)
*/
public final class TransformedIterableTest {
public final class MappedIterableTest {

@Test
public void transformsList() throws IOException {
MatcherAssert.assertThat(
"Can't transform an iterable",
new TransformedIterable<String, Text>(
new MappedIterable<String, Text>(
new ArrayAsIterable<>(
"hello", "world", "друг"
),
Expand All @@ -59,7 +59,7 @@ public void transformsList() throws IOException {
public void transformsEmptyList() {
MatcherAssert.assertThat(
"Can't transform an empty iterable",
new TransformedIterable<String, Text>(
new MappedIterable<String, Text>(
Collections.emptyList(),
input -> new UpperText(new StringAsText(input))
),
Expand Down

0 comments on commit f9b77f4

Please sign in to comment.