-
Notifications
You must be signed in to change notification settings - Fork 169
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
410 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cactoos.iterable; | ||
|
||
/** | ||
* An {@link Iterable} that is both synchronized and sticky. | ||
* | ||
* <p>Objects of this class are thread-safe.</p> | ||
* | ||
* @author Yegor Bugayenko (yegor256@gmail.com) | ||
* @version $Id$ | ||
* @param <X> Type of item | ||
* @since 0.24 | ||
*/ | ||
public final class SolidIterable<X> extends IterableEnvelope<X> { | ||
|
||
/** | ||
* Ctor. | ||
* @param src The underlying iterable | ||
*/ | ||
@SafeVarargs | ||
public SolidIterable(final X... src) { | ||
this(new IterableOf<>(src)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param iterable The iterable | ||
*/ | ||
public SolidIterable(final Iterable<X> iterable) { | ||
super(() -> new SyncIterable<>(new StickyIterable<>(iterable))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cactoos.list; | ||
|
||
import java.util.Collection; | ||
import java.util.Iterator; | ||
import org.cactoos.iterable.IterableOf; | ||
|
||
/** | ||
* A {@link java.util.List} that is both synchronized and sticky. | ||
* | ||
* <p>Objects of this class are thread-safe.</p> | ||
* | ||
* @author Yegor Bugayenko (yegor256@gmail.com) | ||
* @version $Id$ | ||
* @param <X> Type of item | ||
* @since 0.24 | ||
*/ | ||
public final class SolidList<X> extends ListEnvelope<X> { | ||
|
||
/** | ||
* Ctor. | ||
* @param items The array | ||
*/ | ||
@SafeVarargs | ||
public SolidList(final X... items) { | ||
this(new IterableOf<>(items)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param items The array | ||
*/ | ||
public SolidList(final Iterable<X> items) { | ||
this(new ListOf<>(items)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param items The array | ||
* @since 0.21 | ||
*/ | ||
public SolidList(final Iterator<X> items) { | ||
this(new ListOf<>(items)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param list The iterable | ||
*/ | ||
public SolidList(final Collection<X> list) { | ||
super(() -> new SyncList<>(new StickyList<>(list))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cactoos.map; | ||
|
||
import java.util.Iterator; | ||
import java.util.Map; | ||
import org.cactoos.Func; | ||
import org.cactoos.iterable.IterableOf; | ||
import org.cactoos.iterable.Mapped; | ||
|
||
/** | ||
* A {@link Map} that is both synchronized and sticky. | ||
* | ||
* <p>Objects of this class are thread-safe.</p> | ||
* | ||
* @author Yegor Bugayenko (yegor256@gmail.com) | ||
* @version $Id$ | ||
* @param <X> Type of key | ||
* @param <Y> Type of value | ||
* @since 0.24 | ||
*/ | ||
public final class SolidMap<X, Y> extends MapEnvelope<X, Y> { | ||
|
||
/** | ||
* Ctor. | ||
* @param list List of entries | ||
*/ | ||
@SafeVarargs | ||
public SolidMap(final Map.Entry<X, Y>... list) { | ||
this(new IterableOf<>(list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param map The map to extend | ||
* @param list List of entries | ||
*/ | ||
@SafeVarargs | ||
public SolidMap(final Map<X, Y> map, final Map.Entry<X, Y>... list) { | ||
this(map, new IterableOf<>(list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param map The map to extend | ||
* @param list List of items | ||
* @param key Func to create key | ||
* @param value Func to create value | ||
* @param <Z> Type of items in the list | ||
* @checkstyle ParameterNumberCheck (5 lines) | ||
*/ | ||
public <Z> SolidMap(final Map<X, Y> map, | ||
final Iterable<Z> list, final Func<Z, X> key, | ||
final Func<Z, Y> value) { | ||
this( | ||
map, list, | ||
item -> new MapEntry<>(key.apply(item), value.apply(item)) | ||
); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param list List of items | ||
* @param key Func to create key | ||
* @param value Func to create value | ||
* @param <Z> Type of items in the list | ||
*/ | ||
public <Z> SolidMap(final Iterable<Z> list, final Func<Z, X> key, | ||
final Func<Z, Y> value) { | ||
this(list, item -> new MapEntry<>(key.apply(item), value.apply(item))); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param list List of items | ||
* @param entry Func to create entry | ||
* @param <Z> Type of items in the list | ||
*/ | ||
public <Z> SolidMap(final Iterable<Z> list, | ||
final Func<Z, Map.Entry<X, Y>> entry) { | ||
this(new Mapped<>(entry, list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param map The map to extend | ||
* @param list List of items | ||
* @param entry Func to create entry | ||
* @param <Z> Type of items in the list | ||
*/ | ||
public <Z> SolidMap(final Map<X, Y> map, final Iterable<Z> list, | ||
final Func<Z, Map.Entry<X, Y>> entry) { | ||
this(map, new Mapped<>(entry, list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param list Entries for the entries | ||
*/ | ||
public SolidMap(final Iterable<Map.Entry<X, Y>> list) { | ||
this(new MapOf<>(list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param list Entries for the entries | ||
*/ | ||
public SolidMap(final Iterator<Map.Entry<X, Y>> list) { | ||
this(() -> list); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param map Pre-existing map we want to extend | ||
* @param list Entries for the entries | ||
*/ | ||
public SolidMap(final Map<X, Y> map, | ||
final Iterable<Map.Entry<X, Y>> list) { | ||
this(new MapOf<>(map, list)); | ||
} | ||
|
||
/** | ||
* Ctor. | ||
* @param map The map | ||
*/ | ||
public SolidMap(final Map<X, Y> map) { | ||
super(() -> new SyncMap<>(new StickyMap<>(map))); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/** | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2017 Yegor Bugayenko | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included | ||
* in all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
* SOFTWARE. | ||
*/ | ||
package org.cactoos.list; | ||
|
||
import org.hamcrest.MatcherAssert; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Test case for {@link SolidList}. | ||
* @author Yegor Bugayenko (yegor256@gmail.com) | ||
* @author Mehmet Yildirim (memoyil@gmail.com) | ||
* @version $Id$ | ||
* @since 0.24 | ||
* @checkstyle JavadocMethodCheck (500 lines) | ||
*/ | ||
public final class SolidListTest { | ||
|
||
@Test | ||
public void behavesAsCollection() throws Exception { | ||
MatcherAssert.assertThat( | ||
"Can't behave as a list", | ||
new SolidList<>(1, 0, -1, -1, 2), | ||
new BehavesAsList<>(0) | ||
); | ||
} | ||
|
||
} |
Oops, something went wrong.