ignite-3682: fixes of notes; refactoring
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/a3f845b0 Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/a3f845b0 Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/a3f845b0 Branch: refs/heads/master Commit: a3f845b048fd9cadc8d1c722060447e5cc98ef23 Parents: 9165b0d Author: daradurvs <[email protected]> Authored: Thu Mar 30 23:36:25 2017 +0300 Committer: agura <[email protected]> Committed: Mon Apr 10 19:39:06 2017 +0300 ---------------------------------------------------------------------- .../ignite/internal/util/lang/GridFunc.java | 288 ++++++++++--------- .../lang/gridfunc/AlwaysFalsePredicate.java | 46 +++ .../util/lang/gridfunc/AlwaysTruePredicate.java | 46 +++ .../util/lang/gridfunc/AlwaysTrueReducer.java | 56 ++++ .../lang/gridfunc/ArrayListFactoryCallable.java | 41 +++ .../gridfunc/AtomicBooleanFactoryCallable.java | 40 +++ .../gridfunc/AtomicIntegerFactoryCallable.java | 40 +++ .../gridfunc/AtomicLongFactoryCallable.java | 40 +++ .../AtomicReferenceFactoryCallable.java | 40 +++ .../lang/gridfunc/CacheEntryGetKeyClosure.java | 40 +++ .../gridfunc/CacheEntryGetValueClosure.java | 42 +++ .../gridfunc/CacheEntryHasPeekPredicate.java | 41 +++ .../lang/gridfunc/ClusterNodeGetId8Closure.java | 41 +++ .../lang/gridfunc/ClusterNodeGetIdClosure.java | 41 +++ .../ConcurrentDequeFactoryCallable.java | 40 +++ .../ConcurrentHashSetFactoryCallable.java | 40 +++ .../gridfunc/ConcurrentMapFactoryCallable.java | 41 +++ .../lang/gridfunc/ContainsNodeIdsPredicate.java | 52 ++++ .../util/lang/gridfunc/ContainsPredicate.java | 55 ++++ .../gridfunc/EntryByKeyEvaluationPredicate.java | 53 ++++ .../EntryByValueEvaluationPredicate.java | 53 ++++ .../gridfunc/EqualsClusterNodeIdPredicate.java | 51 ++++ .../util/lang/gridfunc/EqualsUuidPredicate.java | 50 ++++ .../lang/gridfunc/FlatCollectionWrapper.java | 66 +++++ .../util/lang/gridfunc/FlatIterator.java | 102 +++++++ .../gridfunc/GridAbsClosureNoOperation.java | 39 --- .../util/lang/gridfunc/GridAbsClosurePrint.java | 49 ---- .../gridfunc/GridAbsClosureRunnableWrapper.java | 51 ---- .../lang/gridfunc/GridAbsClosureWrapper.java | 57 ---- ...IteratorAdapterClosurePredicatesWrapper.java | 138 --------- .../gridfunc/GridIteratorAdapterWrapper.java | 100 ------- ...GridIteratorOverInnerCollectionsAdapter.java | 100 ------- ...dSerializableCollectionPredicateWrapper.java | 78 ----- .../GridSerializableCollectionWrapper.java | 66 ----- ...ializableListReadOnlyWithTransformation.java | 78 ----- ...alizableMapPredicatesTransformerWrapper.java | 168 ----------- .../GridSerializableMapPredicatesWrapper.java | 121 -------- ...zableMapReadOnlyClosurePredicateWrapper.java | 165 ----------- ...SerializableMapReadOnlyPredicateWrapper.java | 153 ---------- ...zableReadOnlyCollectionPredicateWrapper.java | 79 ----- ...idSerializableReadOnlyCollectionWrapper.java | 95 ------ ...rializableReadOnlyTwoCollectionsWrapper.java | 100 ------- .../util/lang/gridfunc/HasEqualIdPredicate.java | 51 ++++ .../lang/gridfunc/HasNotEqualIdPredicate.java | 51 ++++ .../util/lang/gridfunc/IdentityClosure.java | 39 +++ .../IgniteCallableArrayListFactory.java | 41 --- .../IgniteCallableAtomicBooleanFactory.java | 40 --- .../IgniteCallableAtomicIntegerFactory.java | 40 --- .../IgniteCallableAtomicLongFactory.java | 40 --- .../IgniteCallableAtomicReferenceFactory.java | 40 --- .../IgniteCallableConcurrentHashMapFactory.java | 41 --- .../IgniteCallableConcurrentHashSetFactory.java | 40 --- .../gridfunc/IgniteCallableDequeFactory.java | 40 --- .../gridfunc/IgniteCallableHashMapFactory.java | 41 --- .../gridfunc/IgniteCallableHashSetFactory.java | 41 --- .../IgniteCallableLinkedListFactory.java | 40 --- .../lang/gridfunc/IgniteClosureCacheGet.java | 42 --- .../lang/gridfunc/IgniteClosureCacheGetKey.java | 40 --- .../gridfunc/IgniteClosureClusterNodeGetId.java | 41 --- .../IgniteClosureClusterNodeGetId8.java | 41 --- .../lang/gridfunc/IgniteClosureIdentity.java | 39 --- .../lang/gridfunc/IgniteClosureToString.java | 42 --- .../IgniteClosureUUIDToId8Transformer.java | 41 --- .../lang/gridfunc/IgniteOutClosureWrapper.java | 58 ---- .../gridfunc/IgnitePredicateAlwaysFalse.java | 46 --- .../gridfunc/IgnitePredicateAlwaysTrue.java | 46 --- .../gridfunc/IgnitePredicateCacheHasPeek.java | 41 --- .../gridfunc/IgnitePredicateContainNodeId.java | 52 ---- .../gridfunc/IgnitePredicateContainWrapper.java | 55 ---- .../IgnitePredicateEqualsClusterNodeId.java | 51 ---- .../gridfunc/IgnitePredicateEqualsUUID.java | 50 ---- .../IgnitePredicateEvaluateEntryByKey.java | 53 ---- .../IgnitePredicateEvaluateEntryByValue.java | 53 ---- .../gridfunc/IgnitePredicateHasEqualId.java | 51 ---- .../gridfunc/IgnitePredicateHasNotEqualId.java | 51 ---- .../IgnitePredicateIgniteFutureIsNotDone.java | 40 --- .../lang/gridfunc/IgnitePredicateIsAll.java | 52 ---- .../IgnitePredicateIsAssignableFrom.java | 51 ---- .../lang/gridfunc/IgnitePredicateIsNotAll.java | 52 ---- .../lang/gridfunc/IgnitePredicateIsNull.java | 44 --- .../IgnitePredicateNotContainWrapper.java | 54 ---- .../lang/gridfunc/IgnitePredicateNotEqual.java | 53 ---- .../lang/gridfunc/IgnitePredicateNotNull.java | 44 --- .../lang/gridfunc/IgniteReducerAlwaysTrue.java | 56 ---- .../util/lang/gridfunc/IgniteReducerIntSum.java | 51 ---- .../lang/gridfunc/IgniteReducerLongSum.java | 51 ---- .../gridfunc/IgniteReducerStringConcat.java | 79 ----- .../util/lang/gridfunc/IntSumReducer.java | 51 ++++ .../util/lang/gridfunc/IsAllPredicate.java | 52 ++++ .../gridfunc/IsAssignableFromPredicate.java | 51 ++++ .../util/lang/gridfunc/IsNotAllPredicate.java | 52 ++++ .../util/lang/gridfunc/IsNotDonePredicate.java | 40 +++ .../util/lang/gridfunc/IsNotNullPredicate.java | 44 +++ .../util/lang/gridfunc/IsNullPredicate.java | 44 +++ .../gridfunc/LinkedListFactoryCallable.java | 40 +++ .../util/lang/gridfunc/LongSumReducer.java | 51 ++++ .../util/lang/gridfunc/MapFactoryCallable.java | 41 +++ .../util/lang/gridfunc/NoOpClosure.java | 39 +++ .../lang/gridfunc/NotContainsPredicate.java | 54 ++++ .../util/lang/gridfunc/NotEqualPredicate.java | 53 ++++ .../lang/gridfunc/PredicateCollectionView.java | 78 +++++ .../util/lang/gridfunc/PredicateMapView.java | 121 ++++++++ .../util/lang/gridfunc/PredicateSetView.java | 153 ++++++++++ .../lang/gridfunc/ReadOnlyCollectionView.java | 95 ++++++ .../lang/gridfunc/ReadOnlyCollectionView2X.java | 100 +++++++ .../util/lang/gridfunc/SetFactoryCallable.java | 41 +++ .../util/lang/gridfunc/StringConcatReducer.java | 79 +++++ .../util/lang/gridfunc/ToStringClosure.java | 42 +++ .../lang/gridfunc/TransformCollectionView.java | 79 +++++ .../gridfunc/TransformFilteringIterator.java | 138 +++++++++ .../util/lang/gridfunc/TransformMapView.java | 168 +++++++++++ .../util/lang/gridfunc/TransformMapView2.java | 165 +++++++++++ .../util/lang/gridfunc/UuidToId8Closure.java | 41 +++ .../h2/GridIndexingSpiAbstractSelfTest.java | 2 - 114 files changed, 3368 insertions(+), 3733 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java index d246ee3..71ff014 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridFunc.java @@ -45,58 +45,60 @@ import org.apache.ignite.internal.util.GridConcurrentHashSet; import org.apache.ignite.internal.util.GridEmptyIterator; import org.apache.ignite.internal.util.GridLeanMap; import org.apache.ignite.internal.util.GridLeanSet; -import org.apache.ignite.internal.util.lang.gridfunc.GridAbsClosureNoOperation; -import org.apache.ignite.internal.util.lang.gridfunc.GridAbsClosurePrint; -import org.apache.ignite.internal.util.lang.gridfunc.GridAbsClosureRunnableWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridAbsClosureWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridIteratorAdapterClosurePredicatesWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridIteratorOverInnerCollectionsAdapter; -import org.apache.ignite.internal.util.lang.gridfunc.GridIteratorAdapterWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableCollectionPredicateWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableReadOnlyCollectionPredicateWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableCollectionWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableMapPredicatesTransformerWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableMapPredicatesWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableMapReadOnlyClosurePredicateWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableMapReadOnlyPredicateWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableReadOnlyCollectionWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.GridSerializableReadOnlyTwoCollectionsWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableArrayListFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableAtomicIntegerFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableConcurrentHashMapFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableConcurrentHashSetFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableDequeFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableHashMapFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableHashSetFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteCallableLinkedListFactory; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureCacheGet; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureCacheGetKey; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureClusterNodeGetId; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureClusterNodeGetId8; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureIdentity; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureToString; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteClosureUUIDToId8Transformer; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateIsAll; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateAlwaysFalse; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateAlwaysTrue; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateCacheHasPeek; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateContainNodeId; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateContainWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateEqualsClusterNodeId; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateEqualsUUID; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateHasEqualId; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateHasNotEqualId; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateIgniteFutureIsNotDone; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateIsNotAll; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateIsNull; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateNotContainWrapper; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateNotEqual; -import org.apache.ignite.internal.util.lang.gridfunc.IgnitePredicateNotNull; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteReducerAlwaysTrue; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteReducerIntSum; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteReducerLongSum; -import org.apache.ignite.internal.util.lang.gridfunc.IgniteReducerStringConcat; +import org.apache.ignite.internal.util.lang.gridfunc.AlwaysFalsePredicate; +import org.apache.ignite.internal.util.lang.gridfunc.AlwaysTruePredicate; +import org.apache.ignite.internal.util.lang.gridfunc.AlwaysTrueReducer; +import org.apache.ignite.internal.util.lang.gridfunc.ArrayListFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.AtomicBooleanFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.AtomicIntegerFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.AtomicLongFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.AtomicReferenceFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.CacheEntryGetValueClosure; +import org.apache.ignite.internal.util.lang.gridfunc.CacheEntryGetKeyClosure; +import org.apache.ignite.internal.util.lang.gridfunc.CacheEntryHasPeekPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.ClusterNodeGetId8Closure; +import org.apache.ignite.internal.util.lang.gridfunc.ClusterNodeGetIdClosure; +import org.apache.ignite.internal.util.lang.gridfunc.ConcurrentDequeFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.ConcurrentHashSetFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.ConcurrentMapFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.ContainsNodeIdsPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.ContainsPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.EntryByKeyEvaluationPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.EntryByValueEvaluationPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.EqualsClusterNodeIdPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.EqualsUuidPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.FlatCollectionWrapper; +import org.apache.ignite.internal.util.lang.gridfunc.FlatIterator; +import org.apache.ignite.internal.util.lang.gridfunc.HasEqualIdPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.HasNotEqualIdPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IdentityClosure; +import org.apache.ignite.internal.util.lang.gridfunc.IntSumReducer; +import org.apache.ignite.internal.util.lang.gridfunc.IsAllPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IsAssignableFromPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IsNotAllPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IsNotDonePredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IsNotNullPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.IsNullPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.LinkedListFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.LongSumReducer; +import org.apache.ignite.internal.util.lang.gridfunc.MapFactoryCallable; import org.apache.ignite.internal.util.lang.gridfunc.MultipleIterator; +import org.apache.ignite.internal.util.lang.gridfunc.NoOpClosure; +import org.apache.ignite.internal.util.lang.gridfunc.NotContainsPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.NotEqualPredicate; +import org.apache.ignite.internal.util.lang.gridfunc.PredicateCollectionView; +import org.apache.ignite.internal.util.lang.gridfunc.PredicateMapView; +import org.apache.ignite.internal.util.lang.gridfunc.PredicateSetView; +import org.apache.ignite.internal.util.lang.gridfunc.ReadOnlyCollectionView; +import org.apache.ignite.internal.util.lang.gridfunc.ReadOnlyCollectionView2X; +import org.apache.ignite.internal.util.lang.gridfunc.SetFactoryCallable; +import org.apache.ignite.internal.util.lang.gridfunc.StringConcatReducer; +import org.apache.ignite.internal.util.lang.gridfunc.ToStringClosure; +import org.apache.ignite.internal.util.lang.gridfunc.TransformCollectionView; +import org.apache.ignite.internal.util.lang.gridfunc.TransformFilteringIterator; +import org.apache.ignite.internal.util.lang.gridfunc.TransformMapView; +import org.apache.ignite.internal.util.lang.gridfunc.TransformMapView2; +import org.apache.ignite.internal.util.lang.gridfunc.UuidToId8Closure; import org.apache.ignite.internal.util.typedef.F; import org.apache.ignite.internal.util.typedef.internal.A; import org.apache.ignite.internal.util.typedef.internal.U; @@ -132,64 +134,64 @@ import org.jsr166.ThreadLocalRandom8; @SuppressWarnings("unchecked") public class GridFunc { /** */ - private static final GridAbsClosure NOOP = new GridAbsClosureNoOperation(); + private static final GridAbsClosure NOOP = new NoOpClosure(); /** */ - private static final IgniteClosure IDENTITY = new IgniteClosureIdentity(); + private static final IgniteClosure IDENTITY = new IdentityClosure(); /** */ - private static final IgnitePredicate<Object> ALWAYS_TRUE = new IgnitePredicateAlwaysTrue<>(); + private static final IgnitePredicate<Object> ALWAYS_TRUE = new AlwaysTruePredicate<>(); /** */ - private static final IgnitePredicate<Object> ALWAYS_FALSE = new IgnitePredicateAlwaysFalse<>(); + private static final IgnitePredicate<Object> ALWAYS_FALSE = new AlwaysFalsePredicate<>(); /** */ - private static final IgniteCallable<?> DEQUE_FACTORY = new IgniteCallableDequeFactory(); + private static final IgniteCallable<?> DEQUE_FACTORY = new ConcurrentDequeFactoryCallable(); /** */ - private static final IgnitePredicate<Object> IS_NOT_NULL = new IgnitePredicateNotNull(); + private static final IgnitePredicate<Object> IS_NOT_NULL = new IsNotNullPredicate(); /** */ - private static final IgniteCallable<?> LIST_FACTORY = new IgniteCallableArrayListFactory(); + private static final IgniteCallable<?> LIST_FACTORY = new ArrayListFactoryCallable(); /** */ - private static final IgniteCallable<?> LINKED_LIST_FACTORY = new IgniteCallableLinkedListFactory(); + private static final IgniteCallable<?> LINKED_LIST_FACTORY = new LinkedListFactoryCallable(); /** */ - private static final IgniteCallable<?> SET_FACTORY = new IgniteCallableHashSetFactory(); + private static final IgniteCallable<?> SET_FACTORY = new SetFactoryCallable(); /** */ - private static final IgniteCallable<AtomicInteger> ATOMIC_INT_FACTORY = new IgniteCallableAtomicIntegerFactory(); + private static final IgniteCallable<AtomicInteger> ATOMIC_INT_FACTORY = new AtomicIntegerFactoryCallable(); /** */ - private static final IgniteCallable<?> MAP_FACTORY = new IgniteCallableHashMapFactory(); + private static final IgniteCallable<?> MAP_FACTORY = new MapFactoryCallable(); /** */ - private static final IgniteCallable<?> CONCURRENT_MAP_FACTORY = new IgniteCallableConcurrentHashMapFactory(); + private static final IgniteCallable<?> CONCURRENT_MAP_FACTORY = new ConcurrentMapFactoryCallable(); /** */ - private static final IgniteCallable<?> CONCURRENT_SET_FACTORY = new IgniteCallableConcurrentHashSetFactory(); + private static final IgniteCallable<?> CONCURRENT_SET_FACTORY = new ConcurrentHashSetFactoryCallable(); /** */ - private static final IgniteClosure CACHE_ENTRY_KEY = new IgniteClosureCacheGetKey(); + private static final IgniteClosure CACHE_ENTRY_KEY = new CacheEntryGetKeyClosure(); /** */ - private static final IgniteClosure CACHE_ENTRY_VAL_GET = new IgniteClosureCacheGet(); + private static final IgniteClosure CACHE_ENTRY_VAL_GET = new CacheEntryGetValueClosure(); /** */ - private static final IgnitePredicate CACHE_ENTRY_HAS_PEEK_VAL = new IgnitePredicateCacheHasPeek(); + private static final IgnitePredicate CACHE_ENTRY_HAS_PEEK_VAL = new CacheEntryHasPeekPredicate(); /** */ - private static final IgniteClosure<ClusterNode, UUID> NODE2ID = new IgniteClosureClusterNodeGetId(); + private static final IgniteClosure<ClusterNode, UUID> NODE2ID = new ClusterNodeGetIdClosure(); /** */ - private static final IgniteClosure<ClusterNode, String> NODE2ID8 = new IgniteClosureClusterNodeGetId8(); + private static final IgniteClosure<ClusterNode, String> NODE2ID8 = new ClusterNodeGetId8Closure(); /** */ - private static final IgniteClosure<UUID, String> ID2ID8 = new IgniteClosureUUIDToId8Transformer(); + private static final IgniteClosure<UUID, String> ID2ID8 = new UuidToId8Closure(); /** */ - private static final IgnitePredicate<IgniteInternalFuture<?>> UNFINISHED_FUTURE = new IgnitePredicateIgniteFutureIsNotDone(); + private static final IgnitePredicate<IgniteInternalFuture<?>> UNFINISHED_FUTURE = new IsNotDonePredicate(); /** * Gets predicate that evaluates to {@code true} only for given local node ID. @@ -199,7 +201,7 @@ public class GridFunc { * @return Return {@code true} only for the node with given local node ID. */ public static <T extends ClusterNode> IgnitePredicate<T> localNode(final UUID locNodeId) { - return new IgnitePredicateHasEqualId<>(locNodeId); + return new HasEqualIdPredicate<>(locNodeId); } /** @@ -210,7 +212,7 @@ public class GridFunc { * @return Return {@code false} for the given local node ID. */ public static <T extends ClusterNode> IgnitePredicate<T> remoteNodes(final UUID locNodeId) { - return new IgnitePredicateHasNotEqualId<>(locNodeId); + return new HasNotEqualIdPredicate<>(locNodeId); } /** @@ -259,7 +261,7 @@ public class GridFunc { * @return Passed in element. */ public static <T> IgniteReducer<T, T> identityReducer(final T elem) { - return new IgniteReducerAlwaysTrue<>(elem); + return new AlwaysTrueReducer<>(elem); } /** @@ -271,7 +273,7 @@ public class GridFunc { */ @Deprecated public static IgniteReducer<Integer, Integer> sumIntReducer() { - return new IgniteReducerIntSum(); + return new IntSumReducer(); } /** @@ -283,7 +285,7 @@ public class GridFunc { */ @Deprecated public static IgniteReducer<Long, Long> sumLongReducer() { - return new IgniteReducerLongSum(); + return new LongSumReducer(); } /** @@ -318,7 +320,7 @@ public class GridFunc { */ @Deprecated public static IgniteReducer<String, String> concatReducer(@Nullable final String delim) { - return new IgniteReducerStringConcat(delim); + return new StringConcatReducer(delim); } /** @@ -352,14 +354,40 @@ public class GridFunc { } /** - * Creates absolute closure that does <tt>System.out.println(msg)</tt>. + * Convenient utility method that returns collection of node ID8s for a given + * collection of grid nodes. ID8 is a shorter string representation of node ID, + * mainly the first 8 characters. + * <p> + * Note that this method doesn't create a new collection but simply iterates + * over the input one. + * + * @param nodes Collection of grid nodes. + * @return Collection of node IDs for given collection of grid nodes. + */ + public static Collection<String> nodeId8s(@Nullable Collection<? extends ClusterNode> nodes) { + if (nodes == null || nodes.isEmpty()) + return Collections.emptyList(); + + return F.viewReadOnly(nodes, NODE2ID8); + } + + /** + * Convenient utility method that returns collection of node ID8s for a given + * collection of node IDs. ID8 is a shorter string representation of node ID, + * mainly the first 8 characters. + * <p> + * Note that this method doesn't create a new collection but simply iterates + * over the input one. * - * @param msg Message to print. - * @return Absolute closure that print message. + * @param ids Collection of nodeIds. + * @return Collection of node IDs for given collection of grid nodes. */ @Deprecated - public static GridAbsClosure println(final String msg) { - return new GridAbsClosurePrint(msg); + public static Collection<String> id8s(@Nullable Collection<UUID> ids) { + if (ids == null || ids.isEmpty()) + return Collections.emptyList(); + + return F.viewReadOnly(ids, ID2ID8); } /** @@ -449,7 +477,7 @@ public class GridFunc { if (isEmpty(c)) return Collections.singletonList(t); - return new GridSerializableReadOnlyCollectionWrapper<>(c, t); + return new ReadOnlyCollectionView<>(c, t); } } @@ -498,7 +526,7 @@ public class GridFunc { return c; } - return new GridSerializableReadOnlyTwoCollectionsWrapper<>(c1, c2); + return new ReadOnlyCollectionView2X<>(c1, c2); } } @@ -740,7 +768,7 @@ public class GridFunc { public static <T extends ClusterNode> IgnitePredicate<T> nodeForNodeId(final UUID nodeId) { A.notNull(nodeId, "nodeId"); - return new IgnitePredicateEqualsClusterNodeId<>(nodeId); + return new EqualsClusterNodeIdPredicate<>(nodeId); } /** @@ -756,7 +784,7 @@ public class GridFunc { if (isEmpty(nodeIds)) return alwaysFalse(); - return new IgnitePredicateContainNodeId<>(nodeIds); + return new ContainsNodeIdsPredicate<>(nodeIds); } /** @@ -770,7 +798,7 @@ public class GridFunc { public static IgnitePredicate<UUID> idForNodeId(final UUID nodeId) { A.notNull(nodeId, "nodeId"); - return new IgnitePredicateEqualsUUID(nodeId); + return new EqualsUuidPredicate(nodeId); } /** @@ -867,19 +895,6 @@ public class GridFunc { } /** - * Curries given closure. - * - * @param f Closure. - * @param e Parameter. - * @param <T> Input type. - * @return Curried closure. - */ - @Deprecated - public static <T> GridAbsClosure curry(final IgniteInClosure<? super T> f, final T e) { - return new GridAbsClosureWrapper<>(f, e); - } - - /** * Converts array to {@link List}. Note that resulting list cannot * be altered in size, as it it based on the passed in array - * only current elements can be changed. @@ -926,7 +941,7 @@ public class GridFunc { if (F.isEmpty(c)) return Collections.emptyList(); - return new GridSerializableCollectionWrapper<>(c); + return new FlatCollectionWrapper<>(c); } /** @@ -939,7 +954,7 @@ public class GridFunc { * @return Iterable over the elements of the inner collections. */ public static <T> GridIterator<T> flat(@Nullable final Iterable<? extends Iterable<T>> c) { - return isEmpty(c) ? GridFunc.<T>emptyIterator() : new GridIteratorOverInnerCollectionsAdapter<>(c); + return isEmpty(c) ? GridFunc.<T>emptyIterator() : new FlatIterator<T>(c); } /** @@ -951,18 +966,7 @@ public class GridFunc { * @return Iterator over the elements of given iterators. */ public static <T> Iterator<T> flatIterators(@Nullable final Iterable<Iterator<T>> c) { - return isEmpty(c) ? GridFunc.<T>emptyIterator() : new GridIteratorAdapterWrapper<>(c); - } - - /** - * Converts given runnable to an absolute closure. - * - * @param r Runnable to convert to closure. If {@code null} - no-op closure is returned. - * @return Closure that wraps given runnable. Note that wrapping closure always returns {@code null}. - */ - @Deprecated - public static GridAbsClosure as(@Nullable final Runnable r) { - return new GridAbsClosureRunnableWrapper(r); + return isEmpty(c) ? GridFunc.<T>emptyIterator() : new FlatIterator<T>(c); } /** @@ -1022,7 +1026,7 @@ public class GridFunc { if (isEmpty(c) || isAlwaysFalse(p)) return Collections.emptyList(); - return isEmpty(p) || isAlwaysTrue(p) ? c : new GridSerializableCollectionPredicateWrapper<>(c, p); + return isEmpty(p) || isAlwaysTrue(p) ? c : new PredicateCollectionView<>(c, p); } /** @@ -1048,7 +1052,31 @@ public class GridFunc { if (isEmpty(c) || isAlwaysFalse(p)) return Collections.emptyList(); - return new GridSerializableReadOnlyCollectionPredicateWrapper<T2, T1>(c, trans, p); + assert c != null; + + return new TransformCollectionView<T2, T1>(c, trans, p); + } + + /** + * Creates a view on given list with provided transformer and predicates. + * Resulting list will only "have" elements for which all provided predicates, if any, + * evaluate to {@code true}. Note that a new collection will be created and data will + * be copied. + * + * @param c Input list that serves as a base for the view. + * @param trans Transforming closure from T1 to T2. + * @param p Optional predicates. If predicates are not provided - all elements will be in the view. + * @return View on given list with provided predicate. + */ + @Deprecated + public static <T1, T2> List<T2> transformList(Collection<? extends T1> c, + IgniteClosure<? super T1, T2> trans, @Nullable IgnitePredicate<? super T1>... p) { + A.notNull(c, "c", trans, "trans"); + + if (isAlwaysFalse(p)) + return Collections.emptyList(); + + return new ArrayList<>(transform(retain(c, true, p), trans)); } /** @@ -1069,7 +1097,7 @@ public class GridFunc { if (isEmpty(m) || isAlwaysFalse(p)) return Collections.emptyMap(); - return isEmpty(p) || isAlwaysTrue(p) ? m : new GridSerializableMapPredicatesWrapper<K, V>(m, p); + return isEmpty(p) || isAlwaysTrue(p) ? m : new PredicateMapView<K, V>(m, p); } /** @@ -1096,7 +1124,7 @@ public class GridFunc { assert m != null; - return new GridSerializableMapPredicatesTransformerWrapper<K, V1, V>(m, trans, p); + return new TransformMapView<K, V1, V>(m, trans, p); } /** @@ -1122,7 +1150,7 @@ public class GridFunc { if (isEmpty(m) || isAlwaysFalse(p)) return Collections.emptyMap(); - return new GridSerializableMapReadOnlyClosurePredicateWrapper<K, V, V1>(m, trans, p); + return new TransformMapView2<K, V, V1>(m, trans, p); } /** @@ -1149,7 +1177,7 @@ public class GridFunc { if (isEmpty(c) || isAlwaysFalse(p)) return Collections.emptyMap(); - return new GridSerializableMapReadOnlyPredicateWrapper<K, V>(c, mapClo, p); + return new PredicateSetView<K, V>(c, mapClo, p); } /** @@ -1373,7 +1401,7 @@ public class GridFunc { if (isAlwaysFalse(p)) return F.emptyIterator(); - return new GridIteratorAdapterClosurePredicatesWrapper<>(c.iterator(), trans, readOnly, p); + return new TransformFilteringIterator<>(c.iterator(), trans, readOnly, p); } /** @@ -1394,7 +1422,7 @@ public class GridFunc { if (isAlwaysFalse(p)) return F.emptyIterator(); - return new GridIteratorAdapterClosurePredicatesWrapper<>(c, trans, readOnly, p); + return new TransformFilteringIterator<>(c, trans, readOnly, p); } /** @@ -1491,7 +1519,7 @@ public class GridFunc { */ @SafeVarargs public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) { - return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new IgnitePredicateIsNotAll<>(p); + return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new IsNotAllPredicate<>(p); } /** @@ -1505,7 +1533,7 @@ public class GridFunc { */ @Deprecated public static <T> IgnitePredicate<T> equalTo(@Nullable final T target) { - return new IgnitePredicateNotEqual<>(target); + return new NotEqualPredicate<>(target); } /** @@ -1518,7 +1546,7 @@ public class GridFunc { * to {@code target} or both are {@code null}. */ public static <T> IgnitePredicate<T> notEqualTo(@Nullable final T target) { - return new IgnitePredicateNotEqual<>(target); + return new NotEqualPredicate<>(target); } /** @@ -1667,7 +1695,7 @@ public class GridFunc { return (IgnitePredicate<T>)new GridNodePredicate(ids); } else - return new IgnitePredicateIsAll<>(ps); + return new IsAllPredicate<>(ps); } /** @@ -1689,7 +1717,7 @@ public class GridFunc { */ @Deprecated public static <T> IgniteClosure<T, String> string() { - return new IgniteClosureToString<>(); + return new ToStringClosure<>(); } /** @@ -1703,7 +1731,7 @@ public class GridFunc { * contained in given collection. */ public static <T> IgnitePredicate<T> notIn(@Nullable final Collection<? extends T> c) { - return isEmpty(c) ? GridFunc.<T>alwaysTrue() : new IgnitePredicateNotContainWrapper<>(c); + return isEmpty(c) ? GridFunc.<T>alwaysTrue() : new NotContainsPredicate<>(c); } /** @@ -2790,7 +2818,7 @@ public class GridFunc { * that is contained in the passed in collection. */ public static <T> IgnitePredicate<T> contains(@Nullable final Collection<T> c) { - return c == null || c.isEmpty() ? GridFunc.<T>alwaysFalse() : new IgnitePredicateContainWrapper(c); + return c == null || c.isEmpty() ? GridFunc.<T>alwaysFalse() : new ContainsPredicate(c); } /** @@ -2803,7 +2831,7 @@ public class GridFunc { * that is not contained in the passed in collection. */ public static <T> IgnitePredicate<T> notContains(@Nullable final Collection<T> c) { - return c == null || c.isEmpty() ? GridFunc.<T>alwaysTrue() : new IgnitePredicateNotContainWrapper(c); + return c == null || c.isEmpty() ? GridFunc.<T>alwaysTrue() : new NotContainsPredicate(c); } /** http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysFalsePredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysFalsePredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysFalsePredicate.java new file mode 100644 index 0000000..6e1dbb5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysFalsePredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Defines a predicate which accepts a parameter and always returns {@code false} + * + * @param <E> Type of predicate parameter. + */ +public class AlwaysFalsePredicate<E> implements IgnitePredicate<E> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Predicate body. + * + * @param e Predicate parameter. + * @return Always <code>false</code> + */ + @Override public boolean apply(E e) { + return true; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AlwaysFalsePredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTruePredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTruePredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTruePredicate.java new file mode 100644 index 0000000..e675820 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTruePredicate.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Defines a predicate which accepts a parameter and always returns {@code true} + * + * @param <E> Type of predicate parameter. + */ +public class AlwaysTruePredicate<E> implements IgnitePredicate<E> { + /** */ + private static final long serialVersionUID = 6101914246981105862L; + + /** + * Predicate body. + * + * @param e Predicate parameter. + * @return Always <code>true</code>. + */ + @Override public boolean apply(E e) { + return true; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AlwaysTruePredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTrueReducer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTrueReducer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTrueReducer.java new file mode 100644 index 0000000..70ab566 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AlwaysTrueReducer.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteReducer; + +/** + * Reducer which always returns {@code true} from {@link org.apache.ignite.lang.IgniteReducer#collect(Object)} + * + * @param <T> Reducer element type. + */ +public class AlwaysTrueReducer<T> implements IgniteReducer<T, T> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final T elem; + + /** + * @param elem Element to return from {@link org.apache.ignite.lang.IgniteReducer#reduce()} method. + */ + public AlwaysTrueReducer(T elem) { + this.elem = elem; + } + + /** {@inheritDoc} */ + @Override public boolean collect(T e) { + return true; + } + + /** {@inheritDoc} */ + @Override public T reduce() { + return elem; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AlwaysTrueReducer.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ArrayListFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ArrayListFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ArrayListFactoryCallable.java new file mode 100644 index 0000000..7612e49 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ArrayListFactoryCallable.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Array list factory. + */ +public class ArrayListFactoryCallable implements IgniteCallable<List> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ArrayList call() { + return new ArrayList(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ArrayListFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicBooleanFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicBooleanFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicBooleanFactoryCallable.java new file mode 100644 index 0000000..7084e70 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicBooleanFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic boolean factory. + */ +public class AtomicBooleanFactoryCallable implements IgniteCallable<AtomicBoolean> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicBoolean call() { + return new AtomicBoolean(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AtomicBooleanFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicIntegerFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicIntegerFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicIntegerFactoryCallable.java new file mode 100644 index 0000000..43c326c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicIntegerFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic integer factory. + */ +public class AtomicIntegerFactoryCallable implements IgniteCallable<AtomicInteger> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicInteger call() { + return new AtomicInteger(0); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AtomicIntegerFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicLongFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicLongFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicLongFactoryCallable.java new file mode 100644 index 0000000..c7074b2 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicLongFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicLong; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic long factory. + */ +public class AtomicLongFactoryCallable implements IgniteCallable<AtomicLong> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicLong call() { + return new AtomicLong(0); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AtomicLongFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicReferenceFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicReferenceFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicReferenceFactoryCallable.java new file mode 100644 index 0000000..6c20880 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/AtomicReferenceFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic reference factory. + */ +public class AtomicReferenceFactoryCallable implements IgniteCallable<AtomicReference> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicReference call() { + return new AtomicReference(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(AtomicReferenceFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetKeyClosure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetKeyClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetKeyClosure.java new file mode 100644 index 0000000..98d1c8a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetKeyClosure.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Map entry to key transformer closure. + */ +public class CacheEntryGetKeyClosure implements IgniteClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public Object apply(Object o) { + return ((Cache.Entry)o).getKey(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheEntryGetKeyClosure.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetValueClosure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetValueClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetValueClosure.java new file mode 100644 index 0000000..578813b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryGetValueClosure.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.jetbrains.annotations.Nullable; + +/** + * Cache entry to get-value transformer closure. + */ +public class CacheEntryGetValueClosure implements IgniteClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Nullable @Override public Object apply(Object o) { + return ((Cache.Entry)o).getValue(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheEntryGetValueClosure.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryHasPeekPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryHasPeekPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryHasPeekPredicate.java new file mode 100644 index 0000000..35042f0 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/CacheEntryHasPeekPredicate.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Cache entry has-peek-value predicate. + */ +public class CacheEntryHasPeekPredicate implements IgnitePredicate { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public boolean apply(Object o) { + return ((Cache.Entry)o).getValue() != null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(CacheEntryHasPeekPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetId8Closure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetId8Closure.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetId8Closure.java new file mode 100644 index 0000000..9568cdf --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetId8Closure.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Grid node to node ID8 transformer closure. + */ +public class ClusterNodeGetId8Closure implements IgniteClosure<ClusterNode, String> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public String apply(ClusterNode n) { + return U.id8(n.id()); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ClusterNodeGetId8Closure.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetIdClosure.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetIdClosure.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetIdClosure.java new file mode 100644 index 0000000..49ac70b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ClusterNodeGetIdClosure.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Grid node to node ID transformer closure. + */ +public class ClusterNodeGetIdClosure implements IgniteClosure<ClusterNode, UUID> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public UUID apply(ClusterNode n) { + return n.id(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ClusterNodeGetIdClosure.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentDequeFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentDequeFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentDequeFactoryCallable.java new file mode 100644 index 0000000..8af7fc8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentDequeFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; +import org.jsr166.ConcurrentLinkedDeque8; + +/** + * Deque factory. + */ +public class ConcurrentDequeFactoryCallable implements IgniteCallable<ConcurrentLinkedDeque8> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ConcurrentLinkedDeque8 call() { + return new ConcurrentLinkedDeque8(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ConcurrentDequeFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentHashSetFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentHashSetFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentHashSetFactoryCallable.java new file mode 100644 index 0000000..ce92eb1 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentHashSetFactoryCallable.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Concurrent hash set factory. + */ +public class ConcurrentHashSetFactoryCallable implements IgniteCallable<GridConcurrentHashSet> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public GridConcurrentHashSet call() { + return new GridConcurrentHashSet(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ConcurrentHashSetFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentMapFactoryCallable.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentMapFactoryCallable.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentMapFactoryCallable.java new file mode 100644 index 0000000..696944c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ConcurrentMapFactoryCallable.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.ConcurrentMap; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; +import org.jsr166.ConcurrentHashMap8; + +/** + * Concurrent hash map factory. + */ +public class ConcurrentMapFactoryCallable implements IgniteCallable<ConcurrentMap> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ConcurrentMap call() { + return new ConcurrentHashMap8(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ConcurrentMapFactoryCallable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsNodeIdsPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsNodeIdsPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsNodeIdsPredicate.java new file mode 100644 index 0000000..61f36dd --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsNodeIdsPredicate.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Grid node predicate evaluating on the given node IDs. + */ +public class ContainsNodeIdsPredicate<T extends ClusterNode> implements IgnitePredicate<T> { + /** */ + private static final long serialVersionUID = -5664060422647374863L; + + /** */ + private final Collection<UUID> nodeIds; + + /** + * @param nodeIds (Collection) + */ + public ContainsNodeIdsPredicate(Collection<UUID> nodeIds) { + this.nodeIds = nodeIds; + } + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode e) { + return nodeIds.contains(e.id()); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(ContainsNodeIdsPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsPredicate.java new file mode 100644 index 0000000..e3d613a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/ContainsPredicate.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Predicate which returns {@code true} if it receives an element that is contained in the passed in + * collection. + * + * @param <T> Type of the free variable for the predicate and type of the collection elements. + */ +public class ContainsPredicate<T> implements IgnitePredicate<T> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Collection<? extends T> c; + + /** + * @param c Collection to check for containment. + */ + public ContainsPredicate(Collection<? extends T> c) { + this.c = c; + } + + /** {@inheritDoc} */ + @Override public boolean apply(T t) { + assert c != null; + + return c.contains(t); + } + + /** {@inheritDoc} */ + public String toString() { + return S.toString(ContainsPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByKeyEvaluationPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByKeyEvaluationPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByKeyEvaluationPredicate.java new file mode 100644 index 0000000..c67ef3d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByKeyEvaluationPredicate.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Map; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Predicate evaluates to true for given value. + * Note that evaluation will be short-circuit when first predicate evaluated to false is found. + */ +public class EntryByKeyEvaluationPredicate<K, V> implements IgnitePredicate<Map.Entry<K, V>> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final IgnitePredicate<? super K>[] preds; + + /** + * @param preds Optional set of predicates to use for filtration. If none provided - original map (or its copy) will be + * returned. + */ + public EntryByKeyEvaluationPredicate(IgnitePredicate<? super K>... preds) { + this.preds = preds; + } + + /** {@inheritDoc} */ + @Override public boolean apply(Map.Entry<K, V> e) { + return GridFunc.isAll(e.getKey(), preds); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(EntryByKeyEvaluationPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByValueEvaluationPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByValueEvaluationPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByValueEvaluationPredicate.java new file mode 100644 index 0000000..77099da --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EntryByValueEvaluationPredicate.java @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Map; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Predicate evaluates to true for given value. + * Note that evaluation will be short-circuit when first predicate evaluated to false is found. + */ +public class EntryByValueEvaluationPredicate<K, V> implements IgnitePredicate<Map.Entry<K, V>> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final IgnitePredicate<? super V>[] preds; + + /** + * @param preds Optional set of predicates to use for filtration. If none provided - original map (or its copy) will be + * returned. + */ + public EntryByValueEvaluationPredicate(IgnitePredicate<? super V>... preds) { + this.preds = preds; + } + + /** {@inheritDoc} */ + @Override public boolean apply(Map.Entry<K, V> e) { + return GridFunc.isAll(e.getValue(), preds); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(EntryByValueEvaluationPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsClusterNodeIdPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsClusterNodeIdPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsClusterNodeIdPredicate.java new file mode 100644 index 0000000..22f83b8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsClusterNodeIdPredicate.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Creates grid node predicate evaluating on the given node ID. + */ +public class EqualsClusterNodeIdPredicate<T extends ClusterNode> implements IgnitePredicate<T> { + /** */ + private static final long serialVersionUID = -7082730222779476623L; + + /** */ + private final UUID nodeId; + + /** + * @param nodeId (Collection) + */ + public EqualsClusterNodeIdPredicate(UUID nodeId) { + this.nodeId = nodeId; + } + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode e) { + return e.id().equals(nodeId); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(EqualsClusterNodeIdPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsUuidPredicate.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsUuidPredicate.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsUuidPredicate.java new file mode 100644 index 0000000..4bb5c57 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/EqualsUuidPredicate.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.UUID; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * UUID equals predicate. + */ +public class EqualsUuidPredicate implements IgnitePredicate<UUID> { + /** */ + private static final long serialVersionUID = -5664060422647374863L; + + /** */ + private final UUID nodeId; + + /** + * @param nodeId Node ID for which returning predicate will evaluate to {@code true}. + */ + public EqualsUuidPredicate(UUID nodeId) { + this.nodeId = nodeId; + } + + /** {@inheritDoc} */ + @Override public boolean apply(UUID id) { + return id.equals(nodeId); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(EqualsUuidPredicate.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/a3f845b0/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/FlatCollectionWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/FlatCollectionWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/FlatCollectionWrapper.java new file mode 100644 index 0000000..80d3862 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/FlatCollectionWrapper.java @@ -0,0 +1,66 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.Iterator; +import org.apache.ignite.internal.util.GridSerializableCollection; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.NotNull; + +/** + * Wrapper which iterable over the elements of the inner collections. + * + * @param <T> Type of the inner collections. + */ +public class FlatCollectionWrapper<T> extends GridSerializableCollection<T> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Collection<? extends Collection<T>> cols; + + /** + * @param cols Input collection of collections. + */ + public FlatCollectionWrapper(Collection<? extends Collection<T>> cols) { + this.cols = cols; + } + + /** {@inheritDoc} */ + @NotNull @Override public Iterator<T> iterator() { + return GridFunc.flat((Iterable<? extends Iterable<T>>)cols); + } + + /** {@inheritDoc} */ + @Override public int size() { + return F.size(iterator()); + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return !iterator().hasNext(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(FlatCollectionWrapper.class, this); + } +}
