You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ignite.apache.org by vo...@apache.org on 2016/01/02 22:31:58 UTC
[1/4] ignite git commit: IGNITE-2330: Simplified GridFunc.
Repository: ignite
Updated Branches:
refs/heads/ignite-2265 5c1cd29c5 -> d88b2991d
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple3.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple3.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple3.java
index b999e2a..e5d247a 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple3.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple3.java
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.Nullable;
* This class doesn't provide any synchronization for multi-threaded access
* and it is responsibility of the user of this class to provide outside
* synchronization, if needed.
- * @see GridFunc#t3()
* @see GridFunc#t(Object, Object, Object)
*/
public class GridTuple3<V1, V2, V3> implements Iterable<Object>, Externalizable, Cloneable {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple4.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple4.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple4.java
index c95a859..d1e69b5 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple4.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple4.java
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.Nullable;
* This class doesn't provide any synchronization for multi-threaded access
* and it is responsibility of the user of this class to provide outside
* synchronization, if needed.
- * @see GridFunc#t4()
* @see GridFunc#t(Object, Object, Object, Object)
*/
public class GridTuple4<V1, V2, V3, V4> implements Iterable<Object>, Externalizable, Cloneable {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple5.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple5.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple5.java
index 9790f48..7d25996 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple5.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple5.java
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.Nullable;
* This class doesn't provide any synchronization for multi-threaded access
* and it is responsibility of the user of this class to provide outside
* synchronization, if needed.
- * @see GridFunc#t5()
* @see GridFunc#t(Object, Object, Object, Object, Object)
*/
public class GridTuple5<V1, V2, V3, V4, V5> implements Iterable<Object>, Externalizable, Cloneable {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple6.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple6.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple6.java
index 044944b..c904587 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple6.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTuple6.java
@@ -34,7 +34,6 @@ import org.jetbrains.annotations.Nullable;
* This class doesn't provide any synchronization for multi-threaded access
* and it is responsibility of the user of this class to provide outside
* synchronization, if needed.
- * @see GridFunc#t5()
* @see GridFunc#t(Object, Object, Object, Object, Object)
*/
public class GridTuple6<V1, V2, V3, V4, V5, V6> implements Iterable<Object>, Externalizable,
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTupleV.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTupleV.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTupleV.java
index 225366a..58e18aa 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTupleV.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/GridTupleV.java
@@ -35,7 +35,6 @@ import org.apache.ignite.internal.util.typedef.internal.U;
* This class doesn't provide any synchronization for multi-threaded access
* and it is responsibility of the user of this class to provide outside
* synchronization, if needed.
- * @see GridFunc#tv(Object...)
*/
public class GridTupleV implements Iterable<Object>, Externalizable, Cloneable {
/** */
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
index 5c6bb9a..44ca067 100644
--- a/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
+++ b/modules/core/src/main/java/org/apache/ignite/lang/IgniteUuid.java
@@ -186,7 +186,7 @@ public final class IgniteUuid implements Comparable<IgniteUuid>, Iterable<Ignite
/** {@inheritDoc} */
@Override public GridIterator<IgniteUuid> iterator() {
- return F.iterator(Collections.singleton(this), F.<IgniteUuid>identity(), true);
+ return F.identityIteratorReadOnly(Collections.singleton(this));
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java b/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
index c7c635e..56a627a 100644
--- a/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
+++ b/modules/core/src/main/java/org/apache/ignite/spi/eventstorage/memory/MemoryEventStorageSpi.java
@@ -216,6 +216,7 @@ public class MemoryEventStorageSpi extends IgniteSpiAdapter implements EventStor
}
/** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
@Override public <T extends Event> Collection<T> localEvents(IgnitePredicate<T> p) {
A.notNull(p, "p");
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLuceneQueryIndexTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLuceneQueryIndexTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLuceneQueryIndexTest.java
index 59a3eca..1e868b7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLuceneQueryIndexTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/GridCacheLuceneQueryIndexTest.java
@@ -21,6 +21,7 @@ import java.io.Serializable;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.Callable;
+import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
@@ -335,7 +336,8 @@ public class GridCacheLuceneQueryIndexTest extends GridCommonAbstractTest {
map = new HashMap<>();
}
- map.put(new ObjectKey(String.valueOf(i)), F.rand(vals));
+ map.put(new ObjectKey(String.valueOf(i)),
+ vals[ThreadLocalRandom.current().nextInt(vals.length)]);
}
if (!map.isEmpty()) {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java
index cb24e54..52737e7 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/processors/cache/distributed/GridCacheEventAbstractTest.java
@@ -757,7 +757,7 @@ public abstract class GridCacheEventAbstractTest extends GridCacheAbstractSelfTe
if (TEST_INFO)
X.println("Cache event: " + evt.shortDisplay());
- AtomicInteger cntr = F.addIfAbsent(cntrs, evt.type(), F.newAtomicInt());
+ AtomicInteger cntr = F.addIfAbsent(cntrs, evt.type(), new AtomicInteger());
assert cntr != null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryCrashDetectionSelfTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryCrashDetectionSelfTest.java b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryCrashDetectionSelfTest.java
index 1aae999..3482fd6 100644
--- a/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryCrashDetectionSelfTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/internal/util/ipc/shmem/IpcSharedMemoryCrashDetectionSelfTest.java
@@ -517,12 +517,16 @@ public class IpcSharedMemoryCrashDetectionSelfTest extends GridCommonAbstractTes
* @param shmemIds Shared memory IDs string.
*/
public void shmemIds(String shmemIds) {
- this.shmemIds = (shmemIds == null) ? null :
- F.transform(shmemIds.split(","), new C1<String, Integer>() {
- @Override public Integer apply(String s) {
- return Long.valueOf(s).intValue();
- }
- });
+ if (shmemIds == null)
+ this.shmemIds = null;
+ else {
+ String[] tokens = shmemIds.split(",");
+
+ this.shmemIds = new ArrayList<>(tokens.length);
+
+ for (String token : tokens)
+ this.shmemIds.add(Long.valueOf(token).intValue());
+ }
}
}
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
index 37e7afe..353367e 100644
--- a/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
+++ b/modules/core/src/test/java/org/apache/ignite/lang/GridBasicPerformanceTest.java
@@ -748,8 +748,14 @@ public class GridBasicPerformanceTest {
for (int i = 0; i < MAX; i++) {
if (sort)
Arrays.binarySearch(arr, ThreadLocalRandom8.current().nextInt(lim));
- else
- F.contains(arr, ThreadLocalRandom8.current().nextInt(lim));
+ else {
+ int val = ThreadLocalRandom8.current().nextInt(lim);
+
+ for (long arrItem : arr) {
+ if (arrItem == val)
+ break;
+ }
+ }
}
long time = System.currentTimeMillis() - start;
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/lang/GridFuncPerformanceTest.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/lang/GridFuncPerformanceTest.java b/modules/core/src/test/java/org/apache/ignite/lang/GridFuncPerformanceTest.java
deleted file mode 100644
index 5afd75f..0000000
--- a/modules/core/src/test/java/org/apache/ignite/lang/GridFuncPerformanceTest.java
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * 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.lang;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import org.apache.ignite.internal.util.lang.GridIterator;
-import org.apache.ignite.internal.util.typedef.F;
-import org.apache.ignite.testframework.junits.common.GridCommonAbstractTest;
-import org.apache.ignite.testframework.junits.common.GridCommonTest;
-
-/**
- * GridFunc performance test.
- */
-@GridCommonTest(group = "Lang")
-public class GridFuncPerformanceTest extends GridCommonAbstractTest {
- /**
- * Creates test.
- */
- public GridFuncPerformanceTest() {
- super(/*start grid*/false);
- }
-
- /**
- *
- */
- public void testTransformingIteratorPerformance() {
- // Warmup.
- testBody();
- testBody();
- testBody();
-
- long r1 = testBody();
- long r2 = testBody();
- long r3 = testBody();
-
- double r = (r1 + r2 + r3) / 3.f;
-
- System.out.println("Average result is: " + Math.round(r) + "msec.");
- }
-
- /**
- *
- * @return Duration of the test.
- */
- @SuppressWarnings({"UnusedDeclaration"})
- private long testBody() {
- int MAX = 20000000;
-
- Collection<Integer> l = new ArrayList<>(MAX);
-
- for (int i = 0; i < MAX / 10; i++)
- l.add(i);
-
- IgniteClosure<Integer, Integer> c = new IgniteClosure<Integer, Integer>() {
- @Override public Integer apply(Integer e) {
- return e;
- }
- };
-
- IgnitePredicate<Integer> p1 = new IgnitePredicate<Integer>() {
- @Override public boolean apply(Integer e) {
- return e % 2 == 0;
- }
- };
- IgnitePredicate<Integer> p2 = new IgnitePredicate<Integer>() {
- @Override public boolean apply(Integer e) {
- return e % 2 != 0;
- }
- };
-
- GridIterator<Integer> iter = F.iterator(l, c, true, p1, p2);
-
- long n = 0;
-
- long start = System.currentTimeMillis();
-
- for (Integer i : iter)
- n += i;
-
- long duration = System.currentTimeMillis() - start;
-
- System.out.println("Duration: " + duration + "msec.");
-
- return duration;
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java b/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java
index 5d517a4..10b140e 100644
--- a/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java
+++ b/modules/core/src/test/java/org/apache/ignite/loadtest/GridLoadTestStatistics.java
@@ -107,7 +107,7 @@ public class GridLoadTestStatistics {
AtomicInteger cnt;
synchronized (nodeCnts) {
- cnt = F.addIfAbsent(nodeCnts, id, F.newAtomicInt());
+ cnt = F.addIfAbsent(nodeCnts, id, new AtomicInteger());
}
assert cnt != null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
----------------------------------------------------------------------
diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
index 28adeee..9582df0 100644
--- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
+++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2TreeIndex.java
@@ -24,10 +24,10 @@ import java.util.Iterator;
import java.util.NavigableMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
-import org.apache.ignite.internal.util.GridEmptyIterator;
import org.apache.ignite.internal.util.offheap.unsafe.GridOffHeapSnapTreeMap;
import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeGuard;
import org.apache.ignite.internal.util.snaptree.SnapTreeMap;
+import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.SB;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.spi.indexing.IndexingQueryFilter;
@@ -319,7 +319,7 @@ public class GridH2TreeIndex extends GridH2IndexBase implements Comparator<GridS
comparable(last, 1));
if (range == null)
- return new GridEmptyIterator<>();
+ return F.emptyIterator();
return filter(range.values().iterator());
}
[3/4] ignite git commit: IGNITE-2330: Simplified GridFunc.
Posted by vo...@apache.org.
IGNITE-2330: Simplified GridFunc.
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/80579253
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/80579253
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/80579253
Branch: refs/heads/ignite-2265
Commit: 80579253febd6389dbb3a84706671cc8083df1f2
Parents: dffcb83
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Sun Jan 3 01:15:24 2016 +0400
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Sun Jan 3 01:15:24 2016 +0400
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 27 +-
.../internal/cluster/ClusterGroupAdapter.java | 10 +-
.../discovery/GridDiscoveryManager.java | 19 +-
.../loadbalancer/GridLoadBalancerManager.java | 8 +-
.../processors/cache/GridCacheAdapter.java | 14 +-
.../processors/cache/GridCacheContext.java | 3 +-
.../cache/GridCacheEvictionManager.java | 5 +-
.../processors/cache/GridCacheIoManager.java | 5 +-
.../processors/cache/GridCacheIterator.java | 4 +-
.../processors/cache/GridCacheKeySet.java | 2 +-
.../GridCachePartitionExchangeManager.java | 12 +-
.../processors/cache/GridCacheProcessor.java | 9 +-
.../processors/cache/GridCacheSwapManager.java | 7 +-
.../processors/cache/GridCacheUtils.java | 92 +
.../cache/GridCacheValueCollection.java | 5 +-
.../processors/cache/IgniteCacheProxy.java | 4 +-
.../dht/GridClientPartitionTopology.java | 3 +-
.../dht/GridDhtPartitionTopologyImpl.java | 3 +-
.../dht/GridDhtTransactionalCacheAdapter.java | 3 +-
.../distributed/dht/GridDhtTxLocalAdapter.java | 3 +-
.../distributed/dht/GridDhtTxPrepareFuture.java | 5 +-
.../dht/atomic/GridDhtAtomicCache.java | 21 +-
.../dht/preloader/GridDhtForceKeysFuture.java | 8 +-
.../distributed/near/GridNearCacheAdapter.java | 11 +-
.../local/atomic/GridLocalAtomicCache.java | 17 +-
.../GridCacheAtomicStampedImpl.java | 5 +-
.../internal/processors/igfs/IgfsProcessor.java | 8 +-
.../dotnet/PlatformDotNetCacheStore.java | 4 +-
.../top/GridTopologyCommandHandler.java | 3 +-
.../org/apache/ignite/internal/util/F0.java | 325 +---
.../internal/util/GridExecutionStatistics.java | 4 +-
.../ignite/internal/util/IgniteUtils.java | 4 +-
.../ignite/internal/util/lang/GridFunc.java | 1776 ++++--------------
.../ignite/internal/util/lang/GridTuple3.java | 1 -
.../ignite/internal/util/lang/GridTuple4.java | 1 -
.../ignite/internal/util/lang/GridTuple5.java | 1 -
.../ignite/internal/util/lang/GridTuple6.java | 1 -
.../ignite/internal/util/lang/GridTupleV.java | 1 -
.../java/org/apache/ignite/lang/IgniteUuid.java | 2 +-
.../memory/MemoryEventStorageSpi.java | 1 +
.../cache/GridCacheLuceneQueryIndexTest.java | 4 +-
.../distributed/GridCacheEventAbstractTest.java | 2 +-
.../IpcSharedMemoryCrashDetectionSelfTest.java | 16 +-
.../ignite/lang/GridBasicPerformanceTest.java | 10 +-
.../ignite/lang/GridFuncPerformanceTest.java | 102 -
.../ignite/loadtest/GridLoadTestStatistics.java | 2 +-
.../query/h2/opt/GridH2TreeIndex.java | 4 +-
47 files changed, 583 insertions(+), 1994 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
index 14b5816..7fc0313 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/IgniteKernal.java
@@ -589,8 +589,16 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
@Override public List<String> getLifecycleBeansFormatted() {
LifecycleBean[] beans = cfg.getLifecycleBeans();
- return F.isEmpty(beans) ? Collections.<String>emptyList() :
- (List<String>)F.transform(beans, F.<LifecycleBean>string());
+ if (F.isEmpty(beans))
+ return Collections.emptyList();
+ else {
+ List<String> res = new ArrayList<>(beans.length);
+
+ for (LifecycleBean bean : beans)
+ res.add(String.valueOf(bean));
+
+ return res;
+ }
}
/**
@@ -2269,16 +2277,19 @@ public class IgniteKernal implements IgniteEx, IgniteMXBean, Externalizable {
Collection<Object> objs = new ArrayList<>();
if (!F.isEmpty(cfg.getLifecycleBeans()))
- F.copy(objs, cfg.getLifecycleBeans());
+ Collections.addAll(objs, cfg.getLifecycleBeans());
if (!F.isEmpty(cfg.getSegmentationResolvers()))
- F.copy(objs, cfg.getSegmentationResolvers());
+ Collections.addAll(objs, cfg.getSegmentationResolvers());
- if (cfg.getConnectorConfiguration() != null)
- F.copy(objs, cfg.getConnectorConfiguration().getMessageInterceptor(),
- cfg.getConnectorConfiguration().getSslContextFactory());
+ if (cfg.getConnectorConfiguration() != null) {
+ objs.add(cfg.getConnectorConfiguration().getMessageInterceptor());
+ objs.add(cfg.getConnectorConfiguration().getSslContextFactory());
+ }
- F.copy(objs, cfg.getMarshaller(), cfg.getGridLogger(), cfg.getMBeanServer());
+ objs.add(cfg.getMarshaller());
+ objs.add(cfg.getGridLogger());
+ objs.add(cfg.getMBeanServer());
return objs;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
index 75168a1..a153b83 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/cluster/ClusterGroupAdapter.java
@@ -51,6 +51,7 @@ import org.apache.ignite.internal.IgniteServicesImpl;
import org.apache.ignite.internal.IgnitionEx;
import org.apache.ignite.internal.executor.GridExecutorService;
import org.apache.ignite.internal.managers.discovery.GridDiscoveryManager;
+import org.apache.ignite.internal.util.lang.GridNodePredicate;
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;
@@ -367,8 +368,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
guard();
try {
- if (p != null)
- ctx.resource().injectGeneric(p);
+ ctx.resource().injectGeneric(p);
return new ClusterGroupAdapter(ctx, subjId, this.p != null ? F.and(p, this.p) : p);
}
@@ -703,6 +703,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
}
/** {@inheritDoc} */
+ @SuppressWarnings("unchecked")
@Override public void readExternal(ObjectInput in) throws IOException, ClassNotFoundException {
gridName = U.readString(in);
subjId = U.readUuid(in);
@@ -919,7 +920,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
ClusterNode node = isOldest ? U.oldest(super.nodes(), null) : U.youngest(super.nodes(), null);
- IgnitePredicate<ClusterNode> p = F.nodeForNodes(node);
+ IgnitePredicate<ClusterNode> p = new GridNodePredicate(node);
state = new AgeClusterGroupState(node, p, lastTopVer);
}
@@ -961,8 +962,7 @@ public class ClusterGroupAdapter implements ClusterGroupEx, Externalizable {
guard();
try {
- if (p != null)
- ctx.resource().injectGeneric(p);
+ ctx.resource().injectGeneric(p);
return new ClusterGroupAdapter(ctx, this.subjId, new GroupPredicate(this, p));
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
index 72a2bef..844fd0f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/discovery/GridDiscoveryManager.java
@@ -30,7 +30,6 @@ import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
@@ -79,7 +78,6 @@ import org.apache.ignite.internal.processors.cache.GridCacheAdapter;
import org.apache.ignite.internal.processors.jobmetrics.GridJobMetrics;
import org.apache.ignite.internal.processors.security.SecurityContext;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridBoundedConcurrentOrderedMap;
import org.apache.ignite.internal.util.GridSpinBusyLock;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -1317,13 +1315,26 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi> {
}
/**
+ * Gets collection of node for given node IDs.
+ *
+ * @param ids Ids to include.
+ * @return Collection with all alive nodes for given IDs.
+ */
+ public Collection<ClusterNode> nodes(@Nullable Collection<UUID> ids) {
+ return F.isEmpty(ids) ? Collections.<ClusterNode>emptyList() :
+ F.view(
+ F.viewReadOnly(ids, U.id2Node(ctx)),
+ F.notNull());
+ }
+
+ /**
* Gets collection of node for given node IDs and predicates.
*
* @param ids Ids to include.
* @param p Filter for IDs.
* @return Collection with all alive nodes for given IDs.
*/
- public Collection<ClusterNode> nodes(@Nullable Collection<UUID> ids, IgnitePredicate<UUID>... p) {
+ public Collection<ClusterNode> nodes(@Nullable Collection<UUID> ids, IgnitePredicate<UUID> p) {
return F.isEmpty(ids) ? Collections.<ClusterNode>emptyList() :
F.view(
F.viewReadOnly(ids, U.id2Node(ctx), p),
@@ -2565,7 +2576,7 @@ public class GridDiscoveryManager extends GridManagerAdapter<DiscoverySpi> {
nearEnabledCaches = Collections.unmodifiableSet(nearEnabledSet);
daemonNodes = Collections.unmodifiableList(new ArrayList<>(
- F.view(F.concat(false, loc, rmts), F0.not(daemonFilter))));
+ F.view(F.concat(false, loc, rmts), F.not(daemonFilter))));
Map<UUID, ClusterNode> nodeMap = new HashMap<>(allNodes().size() + daemonNodes.size(), 1.0f);
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java b/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java
index 631168b..efe09b0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/managers/loadbalancer/GridLoadBalancerManager.java
@@ -18,6 +18,7 @@
package org.apache.ignite.internal.managers.loadbalancer;
import java.util.Collection;
+import java.util.LinkedList;
import java.util.List;
import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.IgniteException;
@@ -92,7 +93,12 @@ public class GridLoadBalancerManager extends GridManagerAdapter<LoadBalancingSpi
if (F.isEmpty(exclNodes))
return GridLoadBalancerManager.this.getBalancedNode(ses, top, job);
- List<ClusterNode> nodes = F.loseList(top, true, exclNodes);
+ List<ClusterNode> nodes = new LinkedList<>();
+
+ for (ClusterNode topNode : top) {
+ if (!exclNodes.contains(topNode))
+ nodes.add(topNode);
+ }
if (nodes.isEmpty())
return null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
index 5d4c386..a4cf737 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheAdapter.java
@@ -106,7 +106,6 @@ import org.apache.ignite.internal.util.future.GridFutureAdapter;
import org.apache.ignite.internal.util.lang.GridClosureException;
import org.apache.ignite.internal.util.lang.GridTriple;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
-import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.internal.util.typedef.C2;
import org.apache.ignite.internal.util.typedef.CI1;
import org.apache.ignite.internal.util.typedef.CI2;
@@ -2150,12 +2149,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
return syncOp(new SyncOp<Map<K, EntryProcessorResult<T>>>(keys.size() == 1) {
@Nullable @Override public Map<K, EntryProcessorResult<T>> op(IgniteTxLocalAdapter tx)
throws IgniteCheckedException {
- Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = F.viewAsMap(keys,
- new C1<K, EntryProcessor<K, V, Object>>() {
- @Override public EntryProcessor apply(K k) {
- return entryProcessor;
- }
- });
+ Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = CU.invokeMap(keys, entryProcessor);
IgniteInternalFuture<GridCacheReturn> fut = tx.invokeAsync(ctx, invokeMap, args);
@@ -2222,11 +2216,7 @@ public abstract class GridCacheAdapter<K, V> implements IgniteInternalCache<K, V
IgniteInternalFuture<?> fut = asyncOp(new AsyncInOp(keys) {
@Override public IgniteInternalFuture<GridCacheReturn> inOp(IgniteTxLocalAdapter tx) {
- Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor<K, V, Object>>() {
- @Override public EntryProcessor apply(K k) {
- return entryProcessor;
- }
- });
+ Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = CU.invokeMap(keys, entryProcessor);
return tx.invokeAsync(ctx, invokeMap, args);
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
index c10ebf3..ef49567 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheContext.java
@@ -85,7 +85,6 @@ import org.apache.ignite.internal.processors.closure.GridClosureProcessor;
import org.apache.ignite.internal.processors.offheap.GridOffHeapProcessor;
import org.apache.ignite.internal.processors.plugin.CachePluginManager;
import org.apache.ignite.internal.processors.timeout.GridTimeoutProcessor;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.lang.GridFunc;
import org.apache.ignite.internal.util.offheap.unsafe.GridUnsafeMemory;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
@@ -1512,7 +1511,7 @@ public class GridCacheContext<K, V> implements Externalizable {
Collection<ClusterNode> nearNodes = null;
if (!F.isEmpty(readers)) {
- nearNodes = discovery().nodes(readers, F0.notEqualTo(nearNodeId));
+ nearNodes = discovery().nodes(readers, F.notEqualTo(nearNodeId));
if (log.isDebugEnabled())
log.debug("Mapping entry to near nodes [nodes=" + U.nodeIds(nearNodes) + ", entry=" + entry + ']');
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
index 845e204..f542f4b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheEvictionManager.java
@@ -63,7 +63,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
import org.apache.ignite.internal.processors.timeout.GridTimeoutObjectAdapter;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridBusyLock;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
import org.apache.ignite.internal.util.GridUnsafe;
@@ -1310,7 +1309,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
try {
GridCacheVersion ver = e.version();
- return info.version().equals(ver) && F.isAll(info.filter());
+ return info.version().equals(ver) && F.isAll(e, info.filter());
}
catch (GridCacheEntryRemovedException ignored) {
return false;
@@ -1341,7 +1340,7 @@ public class GridCacheEvictionManager extends GridCacheManagerAdapter {
Collection<ClusterNode> backups;
if (evictSync)
- backups = F.view(cctx.dht().topology().nodes(entry.partition(), topVer), F0.notEqualTo(cctx.localNode()));
+ backups = F.view(cctx.dht().topology().nodes(entry.partition(), topVer), F.notEqualTo(cctx.localNode()));
else
backups = Collections.emptySet();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
index 0aa8b1b..4c9cdf2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIoManager.java
@@ -57,7 +57,6 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPr
import org.apache.ignite.internal.processors.cache.distributed.near.GridNearTxPrepareResponse;
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryRequest;
import org.apache.ignite.internal.processors.cache.query.GridCacheQueryResponse;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.GridSpinReadWriteLock;
import org.apache.ignite.internal.util.typedef.CI1;
@@ -731,7 +730,7 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
}
if (added) {
- if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
+ if (!F.exist(F.nodeIds(nodes), F.not(F.contains(leftIds)))) {
if (log.isDebugEnabled())
log.debug("Message will not be sent because all nodes left topology [msg=" + msg +
", nodes=" + U.toShortString(nodes) + ']');
@@ -767,7 +766,7 @@ public class GridCacheIoManager extends GridCacheSharedManagerAdapter {
U.sleep(retryDelay);
}
- if (!F.exist(F.nodeIds(nodes), F0.not(F.contains(leftIds)))) {
+ if (!F.exist(F.nodeIds(nodes), F.not(F.contains(leftIds)))) {
if (log.isDebugEnabled())
log.debug("Message will not be sent because all nodes left topology [msg=" + msg + ", nodes=" +
U.toShortString(nodes) + ']');
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIterator.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIterator.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIterator.java
index 19da4a8..e4a471c 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIterator.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheIterator.java
@@ -19,6 +19,8 @@ package org.apache.ignite.internal.processors.cache;
import java.util.Iterator;
import javax.cache.Cache;
+
+import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridSerializableIterator;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.lang.IgniteClosure;
@@ -57,7 +59,7 @@ public class GridCacheIterator<K, V, T> implements GridSerializableIterator<T> {
) {
this.cctx = cctx;
- it = F.iterator0(c, false, filter);
+ it = F.identityIterator(c, F0.and(filter));
this.trans = trans;
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
index 6d18b7d..af0c704 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheKeySet.java
@@ -66,7 +66,7 @@ public class GridCacheKeySet<K, V> extends GridSerializableSet<K> {
/** {@inheritDoc} */
@Override public Iterator<K> iterator() {
- return new GridCacheIterator<>(ctx, map.values(), F.<K, V>cacheEntry2Key(), filter);
+ return new GridCacheIterator<>(ctx, map.values(), CU.<K, V>cacheEntry2Key(), filter);
}
/** {@inheritDoc} */
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
index a0f7f93..4732597 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCachePartitionExchangeManager.java
@@ -80,6 +80,7 @@ import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.internal.util.worker.GridWorker;
import org.apache.ignite.lang.IgniteBiInClosure;
+import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteProductVersion;
import org.apache.ignite.lang.IgniteUuid;
import org.apache.ignite.thread.IgniteThread;
@@ -1270,9 +1271,16 @@ public class GridCachePartitionExchangeManager<K, V> extends GridCacheSharedMana
}
// After workers line up and before preloading starts we initialize all futures.
- if (log.isDebugEnabled())
+ if (log.isDebugEnabled()) {
+ IgnitePredicate p = new IgnitePredicate<IgniteInternalFuture<?>>() {
+ @Override public boolean apply(IgniteInternalFuture<?> f) {
+ return !f.isDone();
+ }
+ };
+
log.debug("Before waiting for exchange futures [futs" +
- F.view(exchFuts.values(), F.unfinishedFutures()) + ", worker=" + this + ']');
+ F.view(exchFuts.values(), p) + ", worker=" + this + ']');
+ }
// Take next exchange future.
exchFut = poll(futQ, timeout, this);
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
index ff02e70..f6fc9d4 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheProcessor.java
@@ -96,7 +96,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionManager;
import org.apache.ignite.internal.processors.plugin.CachePluginManager;
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -1160,8 +1159,12 @@ public class GridCacheProcessor extends GridProcessorAdapter {
log.debug("Executed onKernalStart() callback for DHT cache: " + dht.name());
}
- for (GridCacheManager mgr : F.view(ctx.managers(), F0.notContains(dhtExcludes(ctx))))
- mgr.onKernalStart();
+ Collection<GridCacheManager> excluded = dhtExcludes(ctx);
+
+ for (GridCacheManager mgr : ctx.managers()) {
+ if (!excluded.contains(mgr))
+ mgr.onKernalStart();
+ }
cache.onKernalStart();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
index 37b5e15..4490f63 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheSwapManager.java
@@ -42,7 +42,6 @@ import org.apache.ignite.internal.processors.offheap.GridOffHeapProcessor;
import org.apache.ignite.internal.util.GridCloseableIteratorAdapter;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
import org.apache.ignite.internal.util.GridEmptyCloseableIterator;
-import org.apache.ignite.internal.util.GridEmptyIterator;
import org.apache.ignite.internal.util.GridWeakIterator;
import org.apache.ignite.internal.util.lang.GridCloseableIterator;
import org.apache.ignite.internal.util.lang.GridTuple;
@@ -1581,7 +1580,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
*/
public <K, V> Iterator<Map.Entry<K, V>> lazySwapIterator() throws IgniteCheckedException {
if (!swapEnabled)
- return new GridEmptyIterator<>();
+ return F.emptyIterator();
return lazyIterator(cctx.gridSwap().rawIterator(spaceName));
}
@@ -1672,7 +1671,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
private <K, V> Iterator<Map.Entry<K, V>> lazyIterator(
final GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> it) {
if (it == null)
- return new GridEmptyIterator<>();
+ return F.emptyIterator();
checkIteratorQueue();
@@ -1743,7 +1742,7 @@ public class GridCacheSwapManager extends GridCacheManagerAdapter {
private Iterator<KeyCacheObject> keyIterator(
final GridCloseableIterator<? extends Map.Entry<byte[], byte[]>> it) {
if (it == null)
- return new GridEmptyIterator<>();
+ return F.emptyIterator();
checkIteratorQueue();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
index 51f6dcd..b7baf7e 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheUtils.java
@@ -43,6 +43,8 @@ import javax.cache.configuration.Factory;
import javax.cache.expiry.Duration;
import javax.cache.expiry.ExpiryPolicy;
import javax.cache.integration.CacheWriterException;
+import javax.cache.processor.EntryProcessor;
+
import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.IgniteCheckedException;
@@ -284,6 +286,41 @@ public class GridCacheUtils {
}
};
+ /** */
+ private static final IgniteClosure CACHE_ENTRY_KEY = new IgniteClosure() {
+ @Override public Object apply(Object o) {
+ return ((Cache.Entry)o).getKey();
+ }
+
+ @Override public String toString() {
+ return "Map entry to key transformer closure.";
+ }
+ };
+
+ /** */
+ private static final IgniteClosure CACHE_ENTRY_VAL_GET = new IgniteClosure() {
+ @SuppressWarnings({"unchecked"})
+ @Nullable @Override public Object apply(Object o) {
+ return ((Cache.Entry)o).getValue();
+ }
+
+ @Override public String toString() {
+ return "Cache entry to get-value transformer closure.";
+ }
+ };
+
+ /** */
+ private static final IgnitePredicate CACHE_ENTRY_HAS_PEEK_VAL = new IgnitePredicate() {
+ @SuppressWarnings({"unchecked"})
+ @Override public boolean apply(Object o) {
+ return ((Cache.Entry)o).getValue() != null;
+ }
+
+ @Override public String toString() {
+ return "Cache entry has-peek-value predicate.";
+ }
+ };
+
/**
* Ensure singleton.
*/
@@ -1863,4 +1900,59 @@ public class GridCacheUtils {
return res;
}
+
+ /**
+ * Create invoke map for the given key set. All provided values will be set to the passed entry processor.
+ *
+ * @param keys Keys.
+ * @param entryProc Entry processor.
+ * @return Invoke map.
+ */
+ @SuppressWarnings("unchecked")
+ public static <K, V, T> Map<? extends K, EntryProcessor<K, V, Object>> invokeMap(
+ final Set<? extends K> keys, final EntryProcessor<K, V, T> entryProc) {
+ return F.viewAsMap(keys,
+ new C1<K, EntryProcessor<K, V, Object>>() {
+ @Override public EntryProcessor apply(K k) {
+ return entryProc;
+ }
+ });
+ }
+
+ /**
+ * Gets closure that returns key for cache entry. The closure internally
+ * delegates to {@link javax.cache.Cache.Entry#getKey()} method.
+ *
+ * @param <K> Key type.
+ * @return Closure that returns key for an entry.
+ */
+ @SuppressWarnings({"unchecked"})
+ public static <K, V> IgniteClosure<Cache.Entry<K, V>, K> cacheEntry2Key() {
+ return (IgniteClosure<Cache.Entry<K, V>, K>)CACHE_ENTRY_KEY;
+ }
+
+ /**
+ * Gets closure that returns value for an entry. The closure internally
+ * delegates to {@link javax.cache.Cache.Entry#get(Object)} method.
+ *
+ * @param <K> Key type.
+ * @param <V> Value type.
+ * @return Closure that returns value for an entry.
+ */
+ @SuppressWarnings({"unchecked"})
+ public static <K, V> IgniteClosure<Cache.Entry<K, V>, V> cacheEntry2Get() {
+ return (IgniteClosure<Cache.Entry<K, V>, V>)CACHE_ENTRY_VAL_GET;
+ }
+
+ /**
+ * Gets predicate which returns {@code true} if entry has peek value.
+ *
+ * @param <K> Cache key type.
+ * @param <V> Cache value type.
+ * @return Predicate which returns {@code true} if entry has peek value.
+ */
+ @SuppressWarnings({"unchecked"})
+ public static <K, V> IgnitePredicate<Cache.Entry<K, V>> cacheHasPeekValue() {
+ return (IgnitePredicate<Cache.Entry<K, V>>)CACHE_ENTRY_HAS_PEEK_VAL;
+ }
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueCollection.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueCollection.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueCollection.java
index 2d1686e..68b54b3 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueCollection.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/GridCacheValueCollection.java
@@ -27,6 +27,7 @@ import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridSerializableCollection;
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.CU;
import org.apache.ignite.lang.IgnitePredicate;
import org.jetbrains.annotations.Nullable;
@@ -72,8 +73,8 @@ public class GridCacheValueCollection<K, V> extends GridSerializableCollection<V
return new GridCacheIterator<K, V, V>(
ctx,
map.values(),
- F.<K, V>cacheEntry2Get(),
- ctx.vararg(F0.and(filter, F.<K, V>cacheHasPeekValue()))
+ CU.<K, V>cacheEntry2Get(),
+ ctx.vararg(F0.and(filter, CU.<K, V>cacheHasPeekValue()))
) {
{
advance();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
index 27a7587..a6e0ea8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/IgniteCacheProxy.java
@@ -69,7 +69,6 @@ import org.apache.ignite.internal.processors.cache.query.CacheQuery;
import org.apache.ignite.internal.processors.cache.query.CacheQueryFuture;
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
import org.apache.ignite.internal.util.GridCloseableIteratorAdapter;
-import org.apache.ignite.internal.util.GridEmptyIterator;
import org.apache.ignite.internal.util.future.IgniteFutureImpl;
import org.apache.ignite.internal.util.lang.GridClosureException;
import org.apache.ignite.internal.util.lang.IgniteOutClosureX;
@@ -77,6 +76,7 @@ import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.tostring.GridToStringInclude;
import org.apache.ignite.internal.util.typedef.CI1;
import org.apache.ignite.internal.util.typedef.CX1;
+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.CU;
import org.apache.ignite.internal.util.typedef.internal.S;
@@ -579,7 +579,7 @@ public class IgniteCacheProxy<K, V> extends AsyncSupportAdapter<IgniteCache<K, V
return new QueryCursor<Cache.Entry<K, V>>() {
@Override public Iterator<Cache.Entry<K, V>> iterator() {
- return cur != null ? cur.iterator() : new GridEmptyIterator<Cache.Entry<K, V>>();
+ return cur != null ? cur.iterator() : F.<Cache.Entry<K, V>>emptyIterator();
}
@Override public List<Cache.Entry<K, V>> getAll() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
index 8aef5ad..9c18ad0 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridClientPartitionTopology.java
@@ -37,7 +37,6 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.Gri
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap2;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridAtomicLong;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.F;
@@ -698,7 +697,7 @@ public class GridClientPartitionTopology implements GridDhtPartitionTopology {
// Remove obsolete mappings.
if (cur != null) {
- for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) {
+ for (Integer p : F.view(cur.keySet(), F.notIn(parts.keySet()))) {
Set<UUID> ids = part2node.get(p);
if (ids != null)
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
index a0709c5..cdf0fc2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtPartitionTopologyImpl.java
@@ -41,7 +41,6 @@ import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.Gri
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionFullMap;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionMap2;
import org.apache.ignite.internal.processors.cache.distributed.dht.preloader.GridDhtPartitionsExchangeFuture;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridAtomicLong;
import org.apache.ignite.internal.util.tostring.GridToStringExclude;
import org.apache.ignite.internal.util.typedef.F;
@@ -1055,7 +1054,7 @@ class GridDhtPartitionTopologyImpl implements GridDhtPartitionTopology {
// Remove obsolete mappings.
if (cur != null) {
- for (Integer p : F.view(cur.keySet(), F0.notIn(parts.keySet()))) {
+ for (Integer p : F.view(cur.keySet(), F.notIn(parts.keySet()))) {
Set<UUID> ids = part2node.get(p);
if (ids != null)
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
index ae24ed1..2b40436 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTransactionalCacheAdapter.java
@@ -60,7 +60,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteTxKey;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.transactions.IgniteTxRollbackCheckedException;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
import org.apache.ignite.internal.util.lang.GridClosureException;
@@ -1382,7 +1381,7 @@ public abstract class GridDhtTransactionalCacheAdapter<K, V> extends GridDhtCach
Collection<ClusterNode> nearNodes = null;
if (!F.isEmpty(readers)) {
- nearNodes = ctx.discovery().nodes(readers, F0.not(F.idForNodeId(nodeId)));
+ nearNodes = ctx.discovery().nodes(readers, F.not(F.idForNodeId(nodeId)));
if (log.isDebugEnabled())
log.debug("Mapping entry to near nodes [nodes=" + U.toShortString(nearNodes) + ", entry=" + cached +
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
index 534a560..1fe3ae2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxLocalAdapter.java
@@ -42,7 +42,6 @@ import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxEntry;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalAdapter;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanMap;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
@@ -641,7 +640,7 @@ public abstract class GridDhtTxLocalAdapter extends IgniteTxLocalAdapter {
// Otherwise, during rollback we will not know whether locks need
// to be rolled back.
// Loose all skipped and previously locked (we cannot reenter locks here).
- final Collection<KeyCacheObject> passedKeys = skipped != null ? F.view(keys, F0.notIn(skipped)) : keys;
+ final Collection<KeyCacheObject> passedKeys = skipped != null ? F.view(keys, F.notIn(skipped)) : keys;
if (log.isDebugEnabled())
log.debug("Lock keys: " + passedKeys);
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
index 40399b4..47dafc8 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
@@ -60,7 +60,6 @@ import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.processors.dr.GridDrType;
import org.apache.ignite.internal.transactions.IgniteTxHeuristicCheckedException;
import org.apache.ignite.internal.transactions.IgniteTxOptimisticCheckedException;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -1287,14 +1286,14 @@ public final class GridDhtTxPrepareFuture extends GridCompoundFuture<IgniteInter
if (!F.isEmpty(readers)) {
Collection<ClusterNode> nearNodes =
- cctx.discovery().nodes(readers, F0.not(F.idForNodeId(tx.nearNodeId())));
+ cctx.discovery().nodes(readers, F.not(F.idForNodeId(tx.nearNodeId())));
if (log.isDebugEnabled())
log.debug("Mapping entry to near nodes [nodes=" + U.toShortString(nearNodes) +
", entry=" + entry + ']');
// Exclude DHT nodes.
- map(entry, F.view(nearNodes, F0.notIn(dhtNodes)), nearMap);
+ map(entry, F.view(nearNodes, F.notIn(dhtNodes)), nearMap);
}
else if (log.isDebugEnabled())
log.debug("Entry has no near readers: " + entry);
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
index 393413e..e0b108b 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/atomic/GridDhtAtomicCache.java
@@ -77,12 +77,10 @@ import org.apache.ignite.internal.processors.cache.distributed.near.GridNearSing
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrExpirationInfo;
import org.apache.ignite.internal.processors.cache.dr.GridCacheDrInfo;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
-import org.apache.ignite.internal.processors.cache.transactions.IgniteTxManager;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionConflictContext;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersionEx;
import org.apache.ignite.internal.processors.timeout.GridTimeoutObject;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -412,9 +410,9 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public IgniteInternalFuture<V> getAndPutAsync0(K key, V val, @Nullable CacheEntryPredicate... filter) {
- A.notNull(key, "key");
+ A.notNull(key, "key", val, "val");
- return updateAllAsync0(F0.asMap(key, val),
+ return updateAllAsync0(F.asMap(key, val),
null,
null,
null,
@@ -428,9 +426,9 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public IgniteInternalFuture<Boolean> putAsync0(K key, V val, @Nullable CacheEntryPredicate... filter) {
- A.notNull(key, "key");
+ A.notNull(key, "key", val, "val");
- return updateAllAsync0(F0.asMap(key, val),
+ return updateAllAsync0(F.asMap(key, val),
null,
null,
null,
@@ -445,7 +443,7 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
@Override public V tryPutIfAbsent(K key, V val) throws IgniteCheckedException {
A.notNull(key, "key", val, "val");
- return (V)updateAllAsync0(F0.asMap(key, val),
+ return (V)updateAllAsync0(F.asMap(key, val),
null,
null,
null,
@@ -795,18 +793,13 @@ public class GridDhtAtomicCache<K, V> extends GridDhtCacheAdapter<K, V> {
/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override public <T> IgniteInternalFuture<Map<K, EntryProcessorResult<T>>> invokeAllAsync(Set<? extends K> keys,
- final EntryProcessor<K, V, T> entryProcessor,
- Object... args) {
+ EntryProcessor<K, V, T> entryProcessor, Object... args) {
A.notNull(keys, "keys", entryProcessor, "entryProcessor");
if (keyCheck)
validateCacheKeys(keys);
- Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() {
- @Override public EntryProcessor apply(K k) {
- return entryProcessor;
- }
- });
+ Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = CU.invokeMap(keys, entryProcessor);
CacheOperationContext opCtx = ctx.operationContextPerCall();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
index 7970a44..6b03131 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/preloader/GridDhtForceKeysFuture.java
@@ -43,7 +43,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtFuture;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtLocalPartition;
import org.apache.ignite.internal.processors.cache.distributed.dht.GridDhtPartitionTopology;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.future.GridCompoundFuture;
import org.apache.ignite.internal.util.future.GridFutureAdapter;
@@ -521,8 +520,11 @@ public final class GridDhtForceKeysFuture<K, V> extends GridCompoundFuture<Objec
if (!cctx.rebalanceEnabled()) {
Collection<KeyCacheObject> retryKeys = F.view(
keys,
- F0.notIn(missedKeys),
- F0.notIn(F.viewReadOnly(res.forcedInfos(), CU.<KeyCacheObject, V>info2Key())));
+ F.and(
+ F.notIn(missedKeys),
+ F.notIn(F.viewReadOnly(res.forcedInfos(), CU.<KeyCacheObject, V>info2Key()))
+ )
+ );
if (!retryKeys.isEmpty())
map(retryKeys, F.concat(false, node, exc));
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
index 5bf18d9..5c48dc7 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/near/GridNearCacheAdapter.java
@@ -64,6 +64,7 @@ import org.apache.ignite.internal.util.typedef.C1;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.P1;
import org.apache.ignite.internal.util.typedef.internal.A;
+import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.lang.IgniteBiPredicate;
import org.jetbrains.annotations.NotNull;
@@ -416,7 +417,7 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
/** {@inheritDoc} */
@Override public Collection<V> values(CacheEntryPredicate... filter) {
- return new GridCacheValueCollection<>(ctx, entrySet(filter), ctx.vararg(F.<K, V>cacheHasPeekValue()));
+ return new GridCacheValueCollection<>(ctx, entrySet(filter), ctx.vararg(CU.<K, V>cacheHasPeekValue()));
}
/** {@inheritDoc} */
@@ -558,12 +559,12 @@ public abstract class GridNearCacheAdapter<K, V> extends GridDistributedCacheAda
/** {@inheritDoc} */
@NotNull @Override public Iterator<Cache.Entry<K, V>> iterator() {
return new EntryIterator(nearSet.iterator(),
- F.iterator0(dhtSet, false, new P1<Cache.Entry<K, V>>() {
- @Override public boolean apply(Cache.Entry<K, V> e) {
+ F.identityIterator(dhtSet, new P1<Cache.Entry<K, V>>() {
+ @Override
+ public boolean apply(Cache.Entry<K, V> e) {
try {
return GridNearCacheAdapter.super.localPeek(e.getKey(), NEAR_PEEK_MODE, null) == null;
- }
- catch (IgniteCheckedException ex) {
+ } catch (IgniteCheckedException ex) {
throw new IgniteException(ex);
}
}
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
index 6130ead..3b60f96 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/local/atomic/GridLocalAtomicCache.java
@@ -60,7 +60,6 @@ import org.apache.ignite.internal.processors.cache.KeyCacheObject;
import org.apache.ignite.internal.processors.cache.local.GridLocalCacheEntry;
import org.apache.ignite.internal.processors.cache.transactions.IgniteTxLocalEx;
import org.apache.ignite.internal.processors.cache.version.GridCacheVersion;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridUnsafe;
import org.apache.ignite.internal.util.future.GridEmbeddedFuture;
import org.apache.ignite.internal.util.future.GridFinishedFuture;
@@ -189,7 +188,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Override public IgniteInternalFuture<V> getAndPutAsync0(K key, V val, @Nullable CacheEntryPredicate... filter) {
A.notNull(key, "key", val, "val");
- return updateAllAsync0(F0.asMap(key, val),
+ return updateAllAsync0(F.asMap(key, val),
null,
null,
true,
@@ -202,7 +201,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
@Override public IgniteInternalFuture<Boolean> putAsync0(K key, V val, @Nullable CacheEntryPredicate... filter) {
A.notNull(key, "key", val, "val");
- return updateAllAsync0(F0.asMap(key, val),
+ return updateAllAsync0(F.asMap(key, val),
null,
null,
false,
@@ -659,11 +658,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (keyCheck)
validateCacheKeys(keys);
- Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() {
- @Override public EntryProcessor apply(K k) {
- return entryProcessor;
- }
- });
+ Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = CU.invokeMap(keys, entryProcessor);
CacheOperationContext opCtx = ctx.operationContextPerCall();
@@ -729,11 +724,7 @@ public class GridLocalAtomicCache<K, V> extends GridCacheAdapter<K, V> {
if (keyCheck)
validateCacheKeys(keys);
- Map<? extends K, EntryProcessor> invokeMap = F.viewAsMap(keys, new C1<K, EntryProcessor>() {
- @Override public EntryProcessor apply(K k) {
- return entryProcessor;
- }
- });
+ Map<? extends K, EntryProcessor<K, V, Object>> invokeMap = CU.invokeMap(keys, entryProcessor);
return updateAllAsync0(null,
invokeMap,
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
index f7a82a9..84c4269 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/datastructures/GridCacheAtomicStampedImpl.java
@@ -30,7 +30,6 @@ import org.apache.ignite.internal.GridKernalContext;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.IgniteInternalCache;
import org.apache.ignite.internal.processors.cache.transactions.IgniteInternalTx;
-import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.tostring.GridToStringBuilder;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.internal.CU;
@@ -179,8 +178,8 @@ public final class GridCacheAtomicStampedImpl<T, S> implements GridCacheAtomicSt
checkRemoved();
try {
- return CU.outTx(internalCompareAndSet(F0.equalTo(expVal), wrapperClosure(newVal),
- F0.equalTo(expStamp), wrapperClosure(newStamp)), ctx);
+ return CU.outTx(internalCompareAndSet(F.equalTo(expVal), wrapperClosure(newVal),
+ F.equalTo(expStamp), wrapperClosure(newStamp)), ctx);
}
catch (IgniteCheckedException e) {
throw U.convertException(e);
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java
index 5b8cf86..b313084 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/igfs/IgfsProcessor.java
@@ -45,7 +45,6 @@ import org.apache.ignite.internal.IgniteNodeAttributes;
import org.apache.ignite.internal.processors.query.GridQueryProcessor;
import org.apache.ignite.internal.util.ipc.IpcServerEndpoint;
import org.apache.ignite.internal.util.typedef.C1;
-import org.apache.ignite.internal.util.typedef.CI1;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.X;
import org.apache.ignite.internal.util.typedef.internal.U;
@@ -128,11 +127,8 @@ public class IgfsProcessor extends IgfsProcessorAdapter {
final Map<String, CacheConfiguration> cacheCfgs = new HashMap<>();
- F.forEach(gridCfg.getCacheConfiguration(), new CI1<CacheConfiguration>() {
- @Override public void apply(CacheConfiguration c) {
- cacheCfgs.put(c.getName(), c);
- }
- });
+ for (CacheConfiguration c : gridCfg.getCacheConfiguration())
+ cacheCfgs.put(c.getName(), c);
Collection<IgfsAttributes> attrVals = new ArrayList<>();
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
index 7e65c22..9f0fd3f 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/platform/dotnet/PlatformDotNetCacheStore.java
@@ -235,13 +235,13 @@ public class PlatformDotNetCacheStore<K, V> implements CacheStore<K, V>, Platfor
@Override public Set<Entry<K, V>> entrySet() {
return new AbstractSet<Entry<K, V>>() {
@Override public Iterator<Entry<K, V>> iterator() {
- return F.iterator(entries, new C1<Cache.Entry<? extends K, ? extends V>, Entry<K, V>>() {
+ return F.iteratorReadOnly(entries, new C1<Cache.Entry<? extends K, ? extends V>, Entry<K, V>>() {
private static final long serialVersionUID = 0L;
@Override public Entry<K, V> apply(Cache.Entry<? extends K, ? extends V> entry) {
return new GridMapEntry<>(entry.getKey(), entry.getValue());
}
- }, true);
+ });
}
@Override public int size() {
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
index 297785e..5e12199 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/rest/handlers/top/GridTopologyCommandHandler.java
@@ -135,8 +135,7 @@ public class GridTopologyCommandHandler extends GridRestCommandHandlerAdapter {
}
else
node = F.find(ctx.discovery().allNodes(), null, new P1<ClusterNode>() {
- @Override
- public boolean apply(ClusterNode n) {
+ @Override public boolean apply(ClusterNode n) {
return containsIp(n.addresses(), ip);
}
});
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java b/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
index 7e9e448..b819226 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/F0.java
@@ -17,8 +17,6 @@
package org.apache.ignite.internal.util;
-import java.util.Collection;
-import java.util.Map;
import java.util.Set;
import java.util.UUID;
import org.apache.ignite.IgniteCheckedException;
@@ -27,11 +25,9 @@ import org.apache.ignite.internal.processors.cache.CacheEntryPredicateAdapter;
import org.apache.ignite.internal.processors.cache.CacheEntrySerializablePredicate;
import org.apache.ignite.internal.processors.cache.GridCacheContext;
import org.apache.ignite.internal.processors.cache.GridCacheEntryEx;
-import org.apache.ignite.internal.util.lang.GridFunc;
import org.apache.ignite.internal.util.lang.GridNodePredicate;
import org.apache.ignite.internal.util.typedef.F;
import org.apache.ignite.internal.util.typedef.P1;
-import org.apache.ignite.internal.util.typedef.internal.A;
import org.apache.ignite.internal.util.typedef.internal.CU;
import org.apache.ignite.lang.IgnitePredicate;
import org.jetbrains.annotations.Nullable;
@@ -42,79 +38,6 @@ import org.jetbrains.annotations.Nullable;
*/
public class F0 {
/**
- * Negates given predicates.
- * <p>
- * Gets predicate (not peer-deployable) that evaluates to {@code true} if any of given predicates
- * evaluates to {@code false}. If all predicates evaluate to {@code true} the
- * result predicate will evaluate to {@code false}.
- *
- * @param p Predicate to negate.
- * @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Negated predicate (not peer-deployable).
- */
- public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) {
- return F.isAlwaysFalse(p) ? F.<T>alwaysTrue() : F.isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
- @Override public boolean apply(T t) {
- return !F.isAll(t, p);
- }
- };
- }
-
- /**
- * Gets predicate (not peer-deployable) that evaluates to {@code true} if its free variable is not equal
- * to {@code target} or both are {@code null}.
- *
- * @param target Object to compare free variable to.
- * @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate (not peer-deployable) that evaluates to {@code true} if its free variable is not equal
- * to {@code target} or both are {@code null}.
- */
- public static <T> IgnitePredicate<T> notEqualTo(@Nullable final T target) {
- return new P1<T>() {
- @Override public boolean apply(T t) {
- return !F.eq(t, target);
- }
- };
- }
-
- /**
- * Gets predicate (not peer-deployable) that returns {@code true} if its free variable
- * is not contained in given collection.
- *
- * @param c Collection to check for containment.
- * @param <T> Type of the free variable for the predicate and type of the
- * collection elements.
- * @return Predicate (not peer-deployable) that returns {@code true} if its free variable is not
- * contained in given collection.
- */
- public static <T> IgnitePredicate<T> notIn(@Nullable final Collection<? extends T> c) {
- return F.isEmpty(c) ? GridFunc.<T>alwaysTrue() : new P1<T>() {
- @Override public boolean apply(T t) {
- assert c != null;
-
- return !c.contains(t);
- }
- };
- }
-
- /**
- * Gets predicate (not perr-deployable) that evaluates to {@code true} if its free variable is equal
- * to {@code target} or both are {@code null}.
- *
- * @param target Object to compare free variable to.
- * @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate that evaluates to {@code true} if its free variable is equal to
- * {@code target} or both are {@code null}.
- */
- public static <T> IgnitePredicate<T> equalTo(@Nullable final T target) {
- return new P1<T>() {
- @Override public boolean apply(T t) {
- return F.eq(t, target);
- }
- };
- }
-
- /**
* @param p1 Filter1.
* @param p2 Filter2.
* @return And filter.
@@ -133,16 +56,12 @@ public class F0 {
if (e1 && e2)
return CU.alwaysTrue0();
- if (e1 && !e2) {
- assert p2 != null;
-
+ if (e1) {
if (p2.length == 1)
return p2[0];
}
- if (!e1 && e2) {
- assert p1 != null;
-
+ if (e2) {
if (p1.length == 1)
return p1[0];
}
@@ -150,16 +69,12 @@ public class F0 {
return new CacheEntrySerializablePredicate(new CacheEntryPredicateAdapter() {
@Override public boolean apply(GridCacheEntryEx e) {
if (!e1) {
- assert p1 != null;
-
for (CacheEntryPredicate p : p1)
if (p != null && !p.apply(e))
return false;
}
if (!e2) {
- assert p2 != null;
-
for (CacheEntryPredicate p : p2)
if (p != null && !p.apply(e))
return false;
@@ -186,15 +101,11 @@ public class F0 {
@Override public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException {
if (!e1) {
- assert p1 != null;
-
for (CacheEntryPredicate p : p1)
p.prepareMarshal(ctx);
}
if (!e2) {
- assert p2 != null;
-
for (CacheEntryPredicate p : p2)
p.prepareMarshal(ctx);
}
@@ -203,63 +114,6 @@ public class F0 {
}
/**
- * @param p Filter1.
- * @param ps Filter2.
- * @return And filter.
- */
- public static CacheEntryPredicate and0(
- @Nullable final CacheEntryPredicate p,
- @Nullable final CacheEntryPredicate... ps) {
- if (p == null && F.isEmptyOrNulls(ps))
- return CU.alwaysTrue0();
-
- if (F.isAlwaysFalse(p) && F.isAlwaysFalse(ps))
- return CU.alwaysFalse0();
-
- if (F.isAlwaysTrue(p) && F.isAlwaysTrue(ps))
- return CU.alwaysTrue0();
-
- return new CacheEntrySerializablePredicate(new CacheEntryPredicateAdapter() {
- @Override public boolean apply(GridCacheEntryEx e) {
- assert ps != null;
-
- if (p != null && !p.apply(e))
- return false;
-
- for (CacheEntryPredicate p : ps) {
- if (p != null && !p.apply(e))
- return false;
- }
-
- return true;
- }
-
- @Override public void entryLocked(boolean locked) {
- assert ps != null;
-
- if (p != null)
- p.entryLocked(locked);
-
- for (CacheEntryPredicate p : ps) {
- if (p != null)
- p.entryLocked(locked);
- }
- }
-
- @Override public void prepareMarshal(GridCacheContext ctx) throws IgniteCheckedException {
- assert ps != null;
-
- if (p != null)
- p.prepareMarshal(ctx);
-
- for (CacheEntryPredicate p : ps)
- if (p != null)
- p.prepareMarshal(ctx);
- }
- });
- }
-
- /**
* Get a predicate (non peer-deployable) that evaluates to {@code true} if each of its component predicates
* evaluates to {@code true}. The components are evaluated in order they are supplied.
* Evaluation will be stopped as soon as first predicate evaluates to {@code false}.
@@ -287,16 +141,12 @@ public class F0 {
if (e1 && e2)
return F.alwaysTrue();
- if (e1 && !e2) {
- assert p2 != null;
-
+ if (e1) {
if (p2.length == 1)
return (IgnitePredicate<T>)p2[0];
}
- if (!e1 && e2) {
- assert p1 != null;
-
+ if (e2) {
if (p1.length == 1)
return (IgnitePredicate<T>)p1[0];
}
@@ -305,15 +155,11 @@ public class F0 {
Set<UUID> ids = new GridLeanSet<>();
if (!e1) {
- assert p1 != null;
-
for (IgnitePredicate<? super T> p : p1)
ids.addAll(((GridNodePredicate)p).nodeIds());
}
if (!e2) {
- assert p2 != null;
-
for (IgnitePredicate<? super T> p : p2)
ids.addAll(((GridNodePredicate)p).nodeIds());
}
@@ -325,16 +171,12 @@ public class F0 {
return new P1<T>() {
@Override public boolean apply(T t) {
if (!e1) {
- assert p1 != null;
-
for (IgnitePredicate<? super T> p : p1)
if (p != null && !p.apply(t))
return false;
}
if (!e2) {
- assert p2 != null;
-
for (IgnitePredicate<? super T> p : p2)
if (p != null && !p.apply(t))
return false;
@@ -347,148 +189,6 @@ public class F0 {
}
/**
- * Get a predicate (not peer-deployable) that evaluates to {@code true} if each of its component predicates
- * evaluates to {@code true}. The components are evaluated in order they are supplied.
- * Evaluation will be stopped as soon as first predicate evaluates to {@code false}.
- * Passed in predicates are NOT copied. If no predicates are passed in the returned
- * predicate will always evaluate to {@code false}.
- *
- * @param ps Passed in predicate. If none provided - always-{@code false} predicate is
- * returned.
- * @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate that evaluates to {@code true} if each of its component predicates
- * evaluates to {@code true}.
- */
- @SuppressWarnings("unchecked")
- public static <T> IgnitePredicate<T> and(
- @Nullable final IgnitePredicate<? super T> p,
- @Nullable final IgnitePredicate<? super T>... ps
- ) {
- if (p == null && F.isEmptyOrNulls(ps))
- return F.alwaysTrue();
-
- if (F.isAlwaysFalse(p) && F.isAlwaysFalse(ps))
- return F.alwaysFalse();
-
- if (F.isAlwaysTrue(p) && F.isAlwaysTrue(ps))
- return F.alwaysTrue();
-
- if (isAllNodePredicates(p) && isAllNodePredicates(ps)) {
- assert ps != null;
-
- Set<UUID> ids = new GridLeanSet<>();
-
- for (IgnitePredicate<? super T> p0 : ps) {
- Collection<UUID> list = ((GridNodePredicate)p0).nodeIds();
-
- if (ids.isEmpty())
- ids.addAll(list);
- else
- ids.retainAll(list);
- }
-
- Collection<UUID> list = ((GridNodePredicate)p).nodeIds();
-
- if (ids.isEmpty())
- ids.addAll(list);
- else
- ids.retainAll(list);
-
- // T must be <T extends GridNode>.
- return (IgnitePredicate<T>)new GridNodePredicate(ids);
- }
- else {
- return new P1<T>() {
- @Override public boolean apply(T t) {
- assert ps != null;
-
- if (p != null && !p.apply(t))
- return false;
-
- for (IgnitePredicate<? super T> p : ps)
- if (p != null && !p.apply(t))
- return false;
-
- return true;
- }
- };
- }
- }
-
- /**
- * Gets predicate (not peer-deployable) that returns {@code true} if its free variable is contained
- * in given collection.
- *
- * @param c Collection to check for containment.
- * @param <T> Type of the free variable for the predicate and type of the
- * collection elements.
- * @return Predicate (not peer-deployable) that returns {@code true} if its free variable is
- * contained in given collection.
- */
- public static <T> IgnitePredicate<T> in(@Nullable final Collection<? extends T> c) {
- return F.isEmpty(c) ? GridFunc.<T>alwaysFalse() : new P1<T>() {
- @Override public boolean apply(T t) {
- assert c != null;
-
- return c.contains(t);
- }
- };
- }
-
- /**
- * Provides predicate (not peer-deployable) which returns {@code true} if it receives an element
- * that is contained in the passed in collection.
- *
- * @param c Collection used for predicate filter.
- * @param <T> Element type.
- * @return Predicate which returns {@code true} if it receives an element
- * 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 P1<T>() {
- @Override public boolean apply(T t) {
- return c.contains(t);
- }
- };
- }
-
- /**
- * Provides predicate (not peer-deployable) which returns {@code true} if it receives an element
- * that is not contained in the passed in collection.
- *
- * @param c Collection used for predicate filter.
- * @param <T> Element type.
- * @return Predicate which returns {@code true} if it receives an element
- * 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 P1<T>() {
- @Override public boolean apply(T t) {
- return !c.contains(t);
- }
- };
- }
-
- /**
- * Tests if all passed in predicates are instances of {@link GridNodePredicate} class.
- *
- * @param ps Collection of predicates to test.
- * @return {@code True} if all passed in predicates are instances of {@link GridNodePredicate} class.
- */
- public static boolean isAllNodePredicates(@Nullable Iterable<? extends IgnitePredicate<?>> ps) {
- if (F.isEmpty(ps))
- return false;
-
- assert ps != null;
-
- for (IgnitePredicate<?> p : ps)
- if (!(p instanceof GridNodePredicate))
- return false;
-
- return true;
- }
-
- /**
* Tests if all passed in predicates are instances of {@link GridNodePredicate} class.
*
* @param ps Collection of predicates to test.
@@ -498,27 +198,10 @@ public class F0 {
if (F.isEmpty(ps))
return false;
- assert ps != null;
-
for (IgnitePredicate<?> p : ps)
if (!(p instanceof GridNodePredicate))
return false;
return true;
}
-
- /**
- * Creates map with given values, adding a strict not-null check for value.
- *
- * @param key Key.
- * @param val Value.
- * @param <K> Key's type.
- * @param <V> Value's type.
- * @return Created map.
- */
- public static <K, V> Map<K, V> asMap(K key, V val) {
- A.notNull(val, "val");
-
- return F.asMap(key, val);
- }
}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/GridExecutionStatistics.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/GridExecutionStatistics.java b/modules/core/src/main/java/org/apache/ignite/internal/util/GridExecutionStatistics.java
index a23fe28..fc2e3a2 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/GridExecutionStatistics.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/GridExecutionStatistics.java
@@ -71,13 +71,13 @@ public class GridExecutionStatistics {
long time = startTime.get().get2();
- AtomicInteger cnt = F.addIfAbsent(cntMap, name, F.newAtomicInt());
+ AtomicInteger cnt = F.addIfAbsent(cntMap, name, new AtomicInteger());
assert cnt != null;
cnt.incrementAndGet();
- AtomicLong d = F.addIfAbsent(durationMap, name, F.newAtomicLong());
+ AtomicLong d = F.addIfAbsent(durationMap, name, new AtomicLong());
assert d != null;
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
----------------------------------------------------------------------
diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
index 480859d..a92ccab 100644
--- a/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
+++ b/modules/core/src/main/java/org/apache/ignite/internal/util/IgniteUtils.java
@@ -8508,7 +8508,7 @@ public abstract class IgniteUtils {
throw new IgniteCheckedException("Addresses can not be resolved [addr=" + addrs +
", hostNames=" + hostNames + ']');
- return F.viewListReadOnly(res, F.<InetAddress>identity());
+ return Collections.unmodifiableList(res);
}
/**
@@ -8555,7 +8555,7 @@ public abstract class IgniteUtils {
res.add(new InetSocketAddress(addr, port));
}
- return F.viewListReadOnly(res, F.<InetSocketAddress>identity());
+ return Collections.unmodifiableList(res);
}
/**
[4/4] ignite git commit: Merge branch 'master' into ignite-2265
Posted by vo...@apache.org.
Merge branch 'master' into ignite-2265
Project: http://git-wip-us.apache.org/repos/asf/ignite/repo
Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/d88b2991
Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/d88b2991
Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/d88b2991
Branch: refs/heads/ignite-2265
Commit: d88b2991d2f6297162f63699e17b12b15610339e
Parents: 5c1cd29 8057925
Author: vozerov-gridgain <vo...@gridgain.com>
Authored: Sun Jan 3 01:28:01 2016 +0400
Committer: vozerov-gridgain <vo...@gridgain.com>
Committed: Sun Jan 3 01:28:01 2016 +0400
----------------------------------------------------------------------
.../apache/ignite/internal/IgniteKernal.java | 27 +-
.../internal/cluster/ClusterGroupAdapter.java | 10 +-
.../discovery/GridDiscoveryManager.java | 19 +-
.../loadbalancer/GridLoadBalancerManager.java | 8 +-
.../processors/cache/GridCacheAdapter.java | 14 +-
.../processors/cache/GridCacheContext.java | 3 +-
.../cache/GridCacheEvictionManager.java | 5 +-
.../processors/cache/GridCacheIoManager.java | 5 +-
.../processors/cache/GridCacheIterator.java | 4 +-
.../processors/cache/GridCacheKeySet.java | 2 +-
.../GridCachePartitionExchangeManager.java | 12 +-
.../processors/cache/GridCacheProcessor.java | 9 +-
.../processors/cache/GridCacheSwapManager.java | 7 +-
.../processors/cache/GridCacheUtils.java | 92 +
.../cache/GridCacheValueCollection.java | 5 +-
.../processors/cache/IgniteCacheProxy.java | 4 +-
.../dht/GridClientPartitionTopology.java | 3 +-
.../dht/GridDhtPartitionTopologyImpl.java | 3 +-
.../dht/GridDhtTransactionalCacheAdapter.java | 3 +-
.../distributed/dht/GridDhtTxLocalAdapter.java | 3 +-
.../distributed/dht/GridDhtTxPrepareFuture.java | 5 +-
.../dht/atomic/GridDhtAtomicCache.java | 21 +-
.../dht/preloader/GridDhtForceKeysFuture.java | 8 +-
.../distributed/near/GridNearCacheAdapter.java | 11 +-
.../local/atomic/GridLocalAtomicCache.java | 17 +-
.../GridCacheAtomicStampedImpl.java | 5 +-
.../internal/processors/igfs/IgfsProcessor.java | 8 +-
.../dotnet/PlatformDotNetCacheStore.java | 4 +-
.../top/GridTopologyCommandHandler.java | 3 +-
.../org/apache/ignite/internal/util/F0.java | 325 +---
.../internal/util/GridExecutionStatistics.java | 4 +-
.../ignite/internal/util/IgniteUtils.java | 4 +-
.../ignite/internal/util/lang/GridFunc.java | 1776 ++++--------------
.../ignite/internal/util/lang/GridTuple3.java | 1 -
.../ignite/internal/util/lang/GridTuple4.java | 1 -
.../ignite/internal/util/lang/GridTuple5.java | 1 -
.../ignite/internal/util/lang/GridTuple6.java | 1 -
.../ignite/internal/util/lang/GridTupleV.java | 1 -
.../java/org/apache/ignite/lang/IgniteUuid.java | 2 +-
.../memory/MemoryEventStorageSpi.java | 1 +
.../cache/GridCacheLuceneQueryIndexTest.java | 4 +-
.../distributed/GridCacheEventAbstractTest.java | 2 +-
.../IpcSharedMemoryCrashDetectionSelfTest.java | 16 +-
.../ignite/lang/GridBasicPerformanceTest.java | 10 +-
.../ignite/lang/GridFuncPerformanceTest.java | 102 -
.../ignite/loadtest/GridLoadTestStatistics.java | 2 +-
.../query/h2/opt/GridH2TreeIndex.java | 4 +-
47 files changed, 583 insertions(+), 1994 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/ignite/blob/d88b2991/modules/core/src/main/java/org/apache/ignite/internal/processors/cache/distributed/dht/GridDhtTxPrepareFuture.java
----------------------------------------------------------------------
[2/4] ignite git commit: IGNITE-2330: Simplified GridFunc.
Posted by vo...@apache.org.
http://git-wip-us.apache.org/repos/asf/ignite/blob/80579253/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 0678657..015be5c 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
@@ -35,16 +35,10 @@ import java.util.Set;
import java.util.UUID;
import java.util.concurrent.Callable;
import java.util.concurrent.ConcurrentMap;
-import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;
-import java.util.concurrent.atomic.AtomicReference;
-import javax.cache.Cache;
-import org.apache.ignite.IgniteCheckedException;
import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.compute.ComputeJobResult;
-import org.apache.ignite.internal.IgniteFutureTimeoutCheckedException;
-import org.apache.ignite.internal.IgniteInternalFuture;
import org.apache.ignite.internal.util.F0;
import org.apache.ignite.internal.util.GridConcurrentHashSet;
import org.apache.ignite.internal.util.GridEmptyIterator;
@@ -52,7 +46,6 @@ import org.apache.ignite.internal.util.GridLeanMap;
import org.apache.ignite.internal.util.GridLeanSet;
import org.apache.ignite.internal.util.GridSerializableCollection;
import org.apache.ignite.internal.util.GridSerializableIterator;
-import org.apache.ignite.internal.util.GridSerializableList;
import org.apache.ignite.internal.util.GridSerializableMap;
import org.apache.ignite.internal.util.GridSerializableSet;
import org.apache.ignite.internal.util.typedef.C1;
@@ -68,7 +61,6 @@ import org.apache.ignite.lang.IgniteBiTuple;
import org.apache.ignite.lang.IgniteCallable;
import org.apache.ignite.lang.IgniteClosure;
import org.apache.ignite.lang.IgniteInClosure;
-import org.apache.ignite.lang.IgniteOutClosure;
import org.apache.ignite.lang.IgnitePredicate;
import org.apache.ignite.lang.IgniteReducer;
import org.jetbrains.annotations.NotNull;
@@ -152,13 +144,6 @@ public class GridFunc {
};
/** */
- public static final IgnitePredicate<Object> IS_NULL = new P1<Object>() {
- @Override public boolean apply(Object o) {
- return o == null;
- }
- };
-
- /** */
public static final IgnitePredicate<Object> IS_NOT_NULL = new P1<Object>() {
@Override public boolean apply(Object o) {
return o != null;
@@ -166,28 +151,6 @@ public class GridFunc {
};
/** */
- private static final IgniteCallable<?> LIST_FACTORY = new IgniteCallable<List>() {
- @Override public List call() {
- return new ArrayList();
- }
-
- @Override public String toString() {
- return "Array list factory.";
- }
- };
-
- /** */
- private static final IgniteCallable<?> LINKED_LIST_FACTORY = new IgniteCallable<LinkedList>() {
- @Override public LinkedList call() {
- return new LinkedList();
- }
-
- @Override public String toString() {
- return "Linked list factory.";
- }
- };
-
- /** */
private static final IgniteCallable<?> SET_FACTORY = new IgniteCallable<Set>() {
@Override public Set call() {
return new HashSet();
@@ -199,61 +162,6 @@ public class GridFunc {
};
/** */
- private static final IgniteCallable<AtomicInteger> ATOMIC_INT_FACTORY = new IgniteCallable<AtomicInteger>() {
- @Override public AtomicInteger call() {
- return new AtomicInteger(0);
- }
-
- @Override public String toString() {
- return "Atomic integer factory.";
- }
- };
-
- /** */
- private static final IgniteCallable<AtomicLong> ATOMIC_LONG_FACTORY = new IgniteCallable<AtomicLong>() {
- @Override public AtomicLong call() {
- return new AtomicLong(0);
- }
-
- @Override public String toString() {
- return "Atomic long factory.";
- }
- };
-
- /** */
- private static final IgniteCallable<AtomicBoolean> ATOMIC_BOOL_FACTORY = new IgniteCallable<AtomicBoolean>() {
- @Override public AtomicBoolean call() {
- return new AtomicBoolean();
- }
-
- @Override public String toString() {
- return "Atomic boolean factory.";
- }
- };
-
- /** */
- private static final IgniteCallable<?> ATOMIC_REF_FACTORY = new IgniteCallable<AtomicReference>() {
- @Override public AtomicReference call() {
- return new AtomicReference();
- }
-
- @Override public String toString() {
- return "Atomic reference factory.";
- }
- };
-
- /** */
- private static final IgniteCallable<?> MAP_FACTORY = new IgniteCallable<Map>() {
- @Override public Map call() {
- return new HashMap();
- }
-
- @Override public String toString() {
- return "Hash map factory.";
- }
- };
-
- /** */
private static final IgniteCallable<?> CONCURRENT_MAP_FACTORY = new IgniteCallable<ConcurrentMap>() {
@Override public ConcurrentMap call() {
return new ConcurrentHashMap8();
@@ -276,42 +184,6 @@ public class GridFunc {
};
/** */
- private static final IgniteClosure CACHE_ENTRY_KEY = new IgniteClosure() {
- @Override public Object apply(Object o) {
- return ((Cache.Entry)o).getKey();
- }
-
- @Override public String toString() {
- return "Map entry to key transformer closure.";
- }
- };
-
-
- /** */
- private static final IgniteClosure CACHE_ENTRY_VAL_GET = new IgniteClosure() {
- @SuppressWarnings({"unchecked"})
- @Nullable @Override public Object apply(Object o) {
- return ((Cache.Entry)o).getValue();
- }
-
- @Override public String toString() {
- return "Cache entry to get-value transformer closure.";
- }
- };
-
- /** */
- private static final IgnitePredicate CACHE_ENTRY_HAS_PEEK_VAL = new IgnitePredicate() {
- @SuppressWarnings({"unchecked"})
- @Override public boolean apply(Object o) {
- return ((Cache.Entry)o).getValue() != null;
- }
-
- @Override public String toString() {
- return "Cache entry has-peek-value predicate.";
- }
- };
-
- /** */
private static final IgniteClosure<ClusterNode, UUID> NODE2ID = new IgniteClosure<ClusterNode, UUID>() {
@Override public UUID apply(ClusterNode n) {
return n.id();
@@ -344,12 +216,8 @@ public class GridFunc {
}
};
- /** */
- private static final IgnitePredicate<IgniteInternalFuture<?>> UNFINISHED_FUTURE = new IgnitePredicate<IgniteInternalFuture<?>>() {
- @Override public boolean apply(IgniteInternalFuture<?> f) {
- return !f.isDone();
- }
- };
+ /** Empty iterator. */
+ private static final GridEmptyIterator EMPTY_ITER = new GridEmptyIterator();
/**
* Gets predicate that evaluates to {@code true} only for given local node ID.
@@ -382,23 +250,6 @@ public class GridFunc {
}
/**
- * Creates new collection by removing duplicates from the given collection.
- *
- * @param c Collection to remove duplicates from.
- * @param <T> Type of the collection.
- * @return De-duped collection.
- */
- public static <T> Collection<T> dedup(Collection<? extends T> c) {
- A.notNull(c, "c");
-
- Collection<T> set = new GridLeanSet<>();
-
- set.addAll(c);
-
- return set;
- }
-
- /**
* Calculates sum of all elements.
* <p>
* <img src="{@docRoot}/img/sum.png">
@@ -578,8 +429,6 @@ public class GridFunc {
if (isEmpty(res))
return Collections.emptyList();
- assert res != null;
-
Collection<T> c = new ArrayList<>(res.size());
for (ComputeJobResult r : res)
@@ -693,20 +542,6 @@ public class GridFunc {
}
/**
- * Gets random value from given array. This operation
- * does not iterate through array elements and returns immediately.
- *
- * @param c Input collection.
- * @param <T> Type of the collection.
- * @return Random value from the input collection.
- */
- public static <T> T rand(T... c) {
- A.notNull(c, "c");
-
- return c[ThreadLocalRandom8.current().nextInt(c.length)];
- }
-
- /**
* Concatenates an element to a collection. If {@code copy} flag is {@code true}, then
* a new collection will be created and the element and passed in collection will be
* copied into the new one. The returned collection will be modifiable. If {@code copy}
@@ -729,8 +564,6 @@ public class GridFunc {
return l;
}
- assert c != null;
-
Collection<T> ret = new ArrayList<>(c.size() + 1);
ret.add(t);
@@ -742,8 +575,6 @@ public class GridFunc {
if (isEmpty(c))
return Collections.singletonList(t);
- assert c != null;
-
return new GridSerializableCollection<T>() {
@NotNull
@Override public Iterator<T> iterator() {
@@ -800,8 +631,11 @@ public class GridFunc {
if (isEmpty(c1) && isEmpty(c2))
return new ArrayList<>(0);
- if (isEmpty(c1))
+ if (isEmpty(c1)) {
+ assert c2 != null;
+
return new ArrayList<>(c2);
+ }
if (isEmpty(c2))
return new ArrayList<>(c1);
@@ -874,7 +708,7 @@ public class GridFunc {
* @param obj One or more elements.
* @return Concatenated array.
*/
- public static <T> T[] concat(@Nullable T[] arr, T... obj) {
+ public static <T> T[] concat(@Nullable T[] arr, T[] obj) {
T[] newArr;
if (arr == null || arr.length == 0)
@@ -889,17 +723,15 @@ public class GridFunc {
}
/**
- * Concatenates multiple iterators as single one.
+ * Concatenate two iterators.
*
- * @param iters Iterators.
+ * @param iter1 Iterator 1.
+ * @param iter2 Iterator 2.
* @return Single iterator.
*/
@SuppressWarnings("unchecked")
- public static <T> Iterator<T> concat(Iterator<T> ... iters) {
- if (iters.length == 1)
- return iters[0];
-
- return concat(asList(iters).iterator());
+ public static <T> Iterator<T> concat(Iterator<T> iter1, Iterator<T> iter2) {
+ return concat(asList(iter1, iter2).iterator());
}
/**
@@ -980,11 +812,10 @@ public class GridFunc {
* @param <T> Type of collections.
* @return Collection of remaining elements
*/
- public static <T0, T extends T0> Collection<T> lose(Collection<T> c, boolean cp,
- @Nullable Collection<T0> filter) {
+ public static <T0, T extends T0> Collection<T> lose(Collection<T> c, boolean cp, @Nullable Collection<T0> filter) {
A.notNull(c, "c");
- return lose(c, cp, F0.in(filter));
+ return lose(c, cp, in(filter));
}
/**
@@ -994,11 +825,11 @@ public class GridFunc {
* @param c Input collection.
* @param cp If {@code true} method creates new collection without modifying the input one,
* otherwise does <tt>in-place</tt> modifications.
- * @param p Predicates to filter by. If no predicates provided - no elements are lost.
+ * @param p Predicate.
* @param <T> Type of collections.
* @return Collection of remaining elements.
*/
- public static <T> Collection<T> lose(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> Collection<T> lose(Collection<T> c, boolean cp, IgnitePredicate<? super T> p) {
A.notNull(c, "c");
Collection<T> res;
@@ -1006,19 +837,18 @@ public class GridFunc {
if (!cp) {
res = c;
- if (isEmpty(p))
- res.clear();
- else if (!isAlwaysFalse(p))
- for (Iterator<T> iter = res.iterator(); iter.hasNext();)
- if (isAll(iter.next(), p))
+ if (!isAlwaysFalse(p)) {
+ for (Iterator<T> iter = res.iterator(); iter.hasNext(); )
+ if (p.apply(iter.next()))
iter.remove();
+ }
}
else {
res = new LinkedList<>();
- if (!isEmpty(p) && !isAlwaysTrue(p))
+ if (!isAlwaysTrue(p))
for (T t : c)
- if (!isAll(t, p))
+ if (!p.apply(t))
res.add(t);
}
@@ -1026,162 +856,6 @@ public class GridFunc {
}
/**
- * Loses all entries in input map that are evaluated to {@code true} by all given predicates.
- *
- * @param m Map to filter.
- * @param cp If {@code true} method creates new map not modifying input, otherwise does
- * <tt>in-place</tt> modifications.
- * @param p Optional set of predicates to use for filtration. If none provided - original map
- * will (or its copy) be returned.
- * @param <K> Type of the free variable for the predicate and type of map's keys.
- * @param <V> Type of the free variable for the predicate and type of map's values.
- * @return Filtered map.
- */
- @SuppressWarnings({"unchecked"})
- public static <K, V> Map<K, V> lose(Map<K, V> m, boolean cp,
- @Nullable IgnitePredicate<? super Map.Entry<K, V>>... p) {
- A.notNull(m, "m");
-
- Map<K, V> res;
-
- if (!cp) {
- res = m;
-
- if (isEmpty(p))
- res.clear();
- else if (!isAlwaysFalse(p))
- for (Iterator<Map.Entry<K, V>> iter = m.entrySet().iterator(); iter.hasNext();)
- if (isAll(iter.next(), p))
- iter.remove();
- }
- else {
- res = U.newHashMap(m.size());
-
- if (!isEmpty(p) && !isAlwaysTrue(p))
- for (Map.Entry<K, V> e : m.entrySet())
- if (!F.isAll(e, p))
- res.put(e.getKey(), e.getValue());
- }
-
- return res;
- }
-
- /**
- * Loses all entries in input map which keys are evaluated to {@code true} by all
- * given predicates.
- *
- * @param m Map to filter.
- * @param cp If {@code true} method creates new map not modifying input, otherwise does
- * <tt>in-place</tt> modifications.
- * @param p Optional set of predicates to use for filtration. If none provided - original
- * map (or its copy) will be returned.
- * @param <K> Type of the free variable for the predicate and type of map's keys.
- * @param <V> Type of map's values.
- * @return Filtered map.
- */
- public static <K, V> Map<K, V> loseKeys(
- Map<K, V> m,
- boolean cp,
- @Nullable final IgnitePredicate<? super K>... p
- ) {
- return lose(m, cp, new P1<Map.Entry<K, V>>() {
- @Override public boolean apply(Map.Entry<K, V> e) {
- return isAll(e.getKey(), p);
- }
- });
- }
-
- /**
- * Loses all entries in input map which values are evaluated to {@code true} by all
- * given predicates.
- *
- * @param m Map to filter.
- * @param cp If {@code true} method creates new map not modifying input, otherwise does
- * <tt>in-place</tt> modifications.
- * @param p Optional set of predicates to use for filtration. If none provided - original
- * map (or its copy) will be returned.
- * @param <K> Type of the free variable for the predicate and type of map's keys.
- * @param <V> Type of map's values.
- * @return Filtered map.
- */
- public static <K, V> Map<K, V> loseValues(Map<K, V> m, boolean cp,
- @Nullable final IgnitePredicate<? super V>... p) {
- return lose(m, cp, new P1<Map.Entry<K, V>>() {
- @Override public boolean apply(Map.Entry<K, V> e) {
- return isAll(e.getValue(), p);
- }
- });
- }
-
- /**
- * Loses all elements in input list that are contained in {@code filter} collection.
- *
- * @param c Input list.
- * @param cp If {@code true} method creates new list not modifying input,
- * otherwise does <tt>in-place</tt> modifications.
- * @param filter Filter collection. If {@code filter} collection is empty or
- * {@code null} - no elements are lost.
- * @param <T> Type of list.
- * @return List of remaining elements
- */
- public static <T> List<T> loseList(List<T> c, boolean cp, @Nullable Collection<? super T> filter) {
- A.notNull(c, "c");
-
- List<T> res;
-
- if (!cp) {
- res = c;
-
- if (filter != null)
- res.removeAll(filter);
- }
- else {
- res = new LinkedList<>();
-
- for (T t : c) {
- if (filter == null || !filter.contains(t))
- res.add(t);
- }
- }
-
- return res;
- }
-
- /**
- * Loses all elements in input list for which any of the predicates evaluate to {@code true}.
- *
- * @param c Input list.
- * @param cp If {@code true} method creates new list not modifying input,
- * otherwise does <tt>in-place</tt> modifications.
- * @param p Looses all elements for which any of the predicates evaluate to {@code true}.
- * @param <T> Type of list.
- * @return List of remaining elements
- */
- public static <T> List<T> filterList(List<T> c, boolean cp, @Nullable IgnitePredicate<T>... p) {
- A.notNull(c, "c");
-
- List<T> res;
-
- if (!cp) {
- res = c;
-
- if (p != null)
- for (Iterator<T> it = c.iterator(); it.hasNext();)
- if (isAny(it.next(), p))
- it.remove();
- }
- else {
- res = new ArrayList<>(c.size());
-
- for (T t : c)
- if (!isAny(t, p))
- res.add(t);
- }
-
- return res;
- }
-
- /**
* Gets closure which converts node to node ID.
*
* @return Closure which converts node to node ID.
@@ -1253,19 +927,6 @@ public class GridFunc {
}
/**
- * Creates predicates that evaluates to {@code true} for each node in given collection.
- * Note that if collection is empty the result predicate will always evaluate to {@code false}.
- * Implementation simply creates {@link GridNodePredicate} instance.
- *
- * @param nodes Collection of nodes. If none provided - result predicate will always
- * return {@code false}.
- * @return Predicates that evaluates to {@code true} for each node in given collection.
- */
- public static IgnitePredicate<ClusterNode> nodeForNodes(ClusterNode... nodes) {
- return new GridNodePredicate(nodes);
- }
-
- /**
* Retains all elements in input collection that are contained in {@code filter}.
*
* @param c Input collection.
@@ -1280,7 +941,26 @@ public class GridFunc {
@Nullable Collection<? extends T0> filter) {
A.notNull(c, "c");
- return retain(c, cp, F0.in(filter));
+ return retain(c, cp, in(filter));
+ }
+
+ /**
+ * Retains all elements in input collection that are evaluated to {@code true}
+ * by the given predicate.
+ *
+ * @param c Input collection.
+ * @param cp If {@code true} method creates collection not modifying input, otherwise does
+ * <tt>in-place</tt> modifications.
+ * @param p Predicates to filter by. If no predicates provides - all elements
+ * will be retained.
+ * @param <T> Type of collections.
+ * @return Collection of retain elements.
+ */
+ public static <T> Collection<T> retain(Collection<T> c, boolean cp, IgnitePredicate<? super T> p) {
+ A.notNull(c, "c");
+ A.notNull(p, "p");
+
+ return lose(c, cp, not(p));
}
/**
@@ -1295,7 +975,7 @@ public class GridFunc {
* @param <T> Type of collections.
* @return Collection of retain elements.
*/
- public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> Collection<T> retain(Collection<T> c, boolean cp, @Nullable IgnitePredicate<? super T>[] p) {
A.notNull(c, "c");
return lose(c, cp, not(p));
@@ -1345,36 +1025,19 @@ public class GridFunc {
}
/**
- * Curries given closure.
+ * Create list containing two elements.
*
- * @param f Closure.
- * @param e Parameter.
- * @param <T> Input type.
- * @param <R> Output type.
- * @return Curried closure.
+ * @param t1 First element.
+ * @param t2 Second element.
+ * @return List.
*/
- public static <T, R> IgniteOutClosure<R> curry(final IgniteClosure<? super T, R> f, final T e) {
- return new IgniteOutClosure<R>() {
- @Override public R apply() {
- return f.apply(e);
- }
- };
- }
+ public static <T> List<T> asList(T t1, T t2) {
+ ArrayList<T> res = new ArrayList<>(2);
- /**
- * Curries given closure.
- *
- * @param f Closure.
- * @param e Parameter.
- * @param <T> Input type.
- * @return Curried closure.
- */
- public static <T> GridAbsClosure curry(final IgniteInClosure<? super T> f, final T e) {
- return new GridAbsClosure() {
- @Override public void apply() {
- f.apply(e);
- }
- };
+ res.add(t1);
+ res.add(t2);
+
+ return res;
}
/**
@@ -1390,6 +1053,7 @@ public class GridFunc {
* @param <T> Array type.
* @return {@link List} instance for array.
*/
+ @SuppressWarnings("unchecked")
public static <T> List<T> asList(@Nullable T... vals) {
return isEmpty(vals) ? Collections.<T>emptyList() : Arrays.asList(vals);
}
@@ -1400,8 +1064,9 @@ public class GridFunc {
* @param <T> Type of the iterator.
* @return Newly created empty iterator.
*/
+ @SuppressWarnings("unchecked")
public static <T> GridIterator<T> emptyIterator() {
- return new GridEmptyIterator<>();
+ return EMPTY_ITER;
}
/**
@@ -1574,6 +1239,29 @@ public class GridFunc {
}
/**
+ * Gets size of the given collection.
+ *
+ * @param c Collection.
+ * @return Size.
+ */
+ public static <T> int size(@Nullable Collection<? extends T> c) {
+ return c == null || c.isEmpty() ? 0 : c.size();
+ }
+
+ /**
+ * Gets size of the given collection with provided optional predicates.
+ *
+ * @param c Collection to size.
+ * @param p Optional predicates that filters out elements from count.
+ * @param <T> Type of the iterator.
+ * @return Number of elements in the collection for which all given predicates
+ * evaluates to {@code true}. If no predicates is provided - all elements are counted.
+ */
+ public static <T> int size(@Nullable Collection<? extends T> c, IgnitePredicate<? super T> p) {
+ return c == null || c.isEmpty() ? 0 : isAlwaysTrue(p) ? c.size() : size(c.iterator(), p);
+ }
+
+ /**
* Gets size of the given collection with provided optional predicates.
*
* @param c Collection to size.
@@ -1582,12 +1270,34 @@ public class GridFunc {
* @return Number of elements in the collection for which all given predicates
* evaluates to {@code true}. If no predicates is provided - all elements are counted.
*/
- public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> int size(@Nullable Collection<? extends T> c, @Nullable IgnitePredicate<? super T>[] p) {
return c == null || c.isEmpty() ? 0 : isEmpty(p) || isAlwaysTrue(p) ? c.size() : size(c.iterator(), p);
}
/**
- * Gets size of the given iterator with provided optional predicates. Iterator
+ * Gets size of the given iterator. Iterator will be traversed to get the count.
+ *
+ * @param it Iterator to size.
+ * @param <T> Type of the iterator.
+ * @return Number of elements in the iterator.
+ */
+ public static <T> int size(@Nullable Iterator<? extends T> it) {
+ if (it == null)
+ return 0;
+
+ int n = 0;
+
+ while (it.hasNext()) {
+ n++;
+
+ it.next();
+ }
+
+ return n;
+ }
+
+ /**
+ * Gets size of the given iterator with provided optional predicate. Iterator
* will be traversed to get the count.
*
* @param it Iterator to size.
@@ -1596,7 +1306,7 @@ public class GridFunc {
* @return Number of elements in the iterator for which all given predicates
* evaluates to {@code true}. If no predicates is provided - all elements are counted.
*/
- public static <T> int size(@Nullable Iterator<? extends T> it, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> int size(@Nullable Iterator<? extends T> it, IgnitePredicate<? super T> p) {
if (it == null)
return 0;
@@ -1604,7 +1314,7 @@ public class GridFunc {
if (!isAlwaysFalse(p)) {
while (it.hasNext()) {
- if (isAll(it.next(), p))
+ if (p.apply(it.next()))
n++;
}
}
@@ -1613,34 +1323,52 @@ public class GridFunc {
}
/**
- * Creates write-through light-weight view on given collection with provided predicates. Resulting
- * collection will only "have" elements for which all provided predicates, if any, evaluate
- * to {@code true}. Note that only wrapping collection will be created and no duplication of
- * data will occur. Also note that if array of given predicates is not empty then method
- * {@code size()} uses full iteration through the collection.
+ * Gets size of the given iterator with provided optional predicates. Iterator
+ * will be traversed to get the count.
*
- * @param c Input collection that serves as a base for the view.
- * @param p Optional predicates. If predicates are not provided - all elements will be in the view.
- * @param <T> Type of the collection.
- * @return Light-weight view on given collection with provided predicate.
- */
- @SafeVarargs
- public static <T> Collection<T> view(@Nullable final Collection<T> c,
- @Nullable final IgnitePredicate<? super T>... p) {
- if (isEmpty(c) || isAlwaysFalse(p))
- return Collections.emptyList();
+ * @param it Iterator to size.
+ * @param p Optional predicates that filters out elements from count.
+ * @param <T> Type of the iterator.
+ * @return Number of elements in the iterator for which all given predicates
+ * evaluates to {@code true}. If no predicates is provided - all elements are counted.
+ */
+ public static <T> int size(@Nullable Iterator<? extends T> it, @Nullable IgnitePredicate<? super T>[] p) {
+ if (it == null)
+ return 0;
+
+ int n = 0;
- assert c != null;
+ if (!isAlwaysFalse(p)) {
+ while (it.hasNext()) {
+ if (isAll(it.next(), p))
+ n++;
+ }
+ }
+
+ return n;
+ }
+
+ /**
+ * Creates write-through light-weight view on given collection.
+ *
+ * @param c Input collection that serves as a base for the view.
+ * @param p Optional predicates. If predicates are not provided - all elements will be in the view.
+ * @param <T> Type of the collection.
+ * @return Light-weight view on given collection with provided predicate.
+ */
+ public static <T> Collection<T> view(@Nullable final Collection<T> c, final IgnitePredicate<? super T> p) {
+ if (isEmpty(c) || isAlwaysFalse(p))
+ return Collections.emptyList();
- return isEmpty(p) || isAlwaysTrue(p) ? c : new GridSerializableCollection<T>() {
+ return isAlwaysTrue(p) ? c : new GridSerializableCollection<T>() {
// Pass through (will fail for readonly).
@Override public boolean add(T e) {
- return isAll(e, p) && c.add(e);
+ return p.apply(e) && c.add(e);
}
@NotNull
@Override public Iterator<T> iterator() {
- return F.iterator0(c, false, p);
+ return identityIterator(c, p);
}
@Override public int size() {
@@ -1648,117 +1376,82 @@ public class GridFunc {
}
@Override public boolean isEmpty() {
- return F.isEmpty(p) ? c.isEmpty() : !iterator().hasNext();
+ return !iterator().hasNext();
}
};
}
/**
- * Creates read-only light-weight view on given collection with transformation and provided
- * predicates. Resulting collection will only "have" {@code transformed} elements for which
- * all provided predicate, if any, evaluates to {@code true}. Note that only wrapping
- * collection will be created and no duplication of data will occur. Also note that if array
- * of given predicates is not empty then method {@code size()} uses full iteration through
- * the collection.
+ * Creates read-only light-weight view on given collection with transformation.
*
* @param c Input collection that serves as a base for the view.
* @param trans Transformation closure.
- * @param p Optional predicated. If predicates are not provided - all elements will be in the view.
* @param <T1> Type of the collection.
* @return Light-weight view on given collection with provided predicate.
*/
@SuppressWarnings("RedundantTypeArguments")
- @SafeVarargs
public static <T1, T2> Collection<T2> viewReadOnly(@Nullable final Collection<? extends T1> c,
- final IgniteClosure<? super T1, T2> trans, @Nullable final IgnitePredicate<? super T1>... p) {
+ final IgniteClosure<? super T1, T2> trans) {
A.notNull(trans, "trans");
- if (isEmpty(c) || isAlwaysFalse(p))
+ if (isEmpty(c))
return Collections.emptyList();
- assert c != null;
-
return new GridSerializableCollection<T2>() {
@NotNull
@Override public Iterator<T2> iterator() {
- return F.<T1, T2>iterator(c, trans, true, p);
+ return F.<T1, T2>iteratorReadOnly(c, trans);
}
@Override public int size() {
- return F.isEmpty(p) ? c.size() : F.size(iterator());
+ return c.size();
}
@Override public boolean isEmpty() {
- return F.isEmpty(p) ? c.isEmpty() : !iterator().hasNext();
+ return c.isEmpty();
}
};
}
/**
- * Creates read-only light-weight view on given list with provided transformation.
- * Resulting list will only "have" {@code transformed} elements. Note that only wrapping
- * list will be created and no duplication of data will occur.
+ * Creates read-only light-weight view on given collection with transformation and provided
+ * predicates. Resulting collection will only "have" {@code transformed} elements for which
+ * all provided predicate, if any, evaluates to {@code true}. Note that only wrapping
+ * collection will be created and no duplication of data will occur. Also note that if array
+ * of given predicates is not empty then method {@code size()} uses full iteration through
+ * the collection.
*
- * @param c Input list that serves as a base for the view.
+ * @param c Input collection that serves as a base for the view.
* @param trans Transformation closure.
- * @param <T1> Type of the list.
- * @return Light-weight view on given list with provided transformation.
+ * @param p Optional predicated. If predicates are not provided - all elements will be in the view.
+ * @param <T1> Type of the collection.
+ * @return Light-weight view on given collection with provided predicate.
*/
@SuppressWarnings("RedundantTypeArguments")
- public static <T1, T2> List<T2> viewListReadOnly(@Nullable final List<? extends T1> c,
- final IgniteClosure<? super T1, T2> trans) {
+ public static <T1, T2> Collection<T2> viewReadOnly(@Nullable final Collection<? extends T1> c,
+ final IgniteClosure<? super T1, T2> trans, @Nullable final IgnitePredicate<? super T1> p) {
A.notNull(trans, "trans");
- if (isEmpty(c))
+ if (isEmpty(c) || isAlwaysFalse(p))
return Collections.emptyList();
- assert c != null;
-
- return new GridSerializableList<T2>() {
- /** */
- private static final long serialVersionUID = 3126625219739967068L;
-
- @Override public T2 get(int idx) {
- return trans.apply(c.get(idx));
- }
-
+ return new GridSerializableCollection<T2>() {
@NotNull
@Override public Iterator<T2> iterator() {
- return F.<T1, T2>iterator(c, trans, true);
+ return F.<T1, T2>iterator(c, trans, true, p);
}
@Override public int size() {
- return c.size();
+ return F.size(iterator());
}
@Override public boolean isEmpty() {
- return c.isEmpty();
+ return !iterator().hasNext();
}
};
}
/**
- * 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.
- */
- 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));
- }
-
- /**
* Creates light-weight view on given map with provided predicates. Resulting map will
* only "have" keys for which all provided predicates, if any, evaluates to {@code true}.
* Note that only wrapping map will be created and no duplication of data will occur.
@@ -1766,26 +1459,24 @@ public class GridFunc {
* uses full iteration through the entry set.
*
* @param m Input map that serves as a base for the view.
- * @param p Optional predicates. If predicates are not provided - all will be in the view.
+ * @param p Predicate.
* @param <K> Type of the key.
* @param <V> Type of the value.
* @return Light-weight view on given map with provided predicate.
*/
public static <K0, K extends K0, V0, V extends V0> Map<K, V> view(@Nullable final Map<K, V> m,
- @Nullable final IgnitePredicate<? super K>... p) {
+ final IgnitePredicate<? super K> p) {
if (isEmpty(m) || isAlwaysFalse(p))
return Collections.emptyMap();
- assert m != null;
-
- return isEmpty(p) || isAlwaysTrue(p) ? m : new GridSerializableMap<K, V>() {
+ return isAlwaysTrue(p) ? m : new GridSerializableMap<K, V>() {
/** */
private static final long serialVersionUID = 5531745605372387948L;
/** Entry predicate. */
private IgnitePredicate<Entry<K, V>> ep = new P1<Map.Entry<K, V>>() {
@Override public boolean apply(Entry<K, V> e) {
- return isAll(e.getKey(), p);
+ return p.apply(e.getKey());
}
};
@@ -1794,7 +1485,7 @@ public class GridFunc {
return new GridSerializableSet<Map.Entry<K, V>>() {
@NotNull
@Override public Iterator<Entry<K, V>> iterator() {
- return iterator0(m.entrySet(), false, ep);
+ return identityIterator(m.entrySet(), ep);
}
@Override public int size() {
@@ -1803,12 +1494,12 @@ public class GridFunc {
@SuppressWarnings({"unchecked"})
@Override public boolean remove(Object o) {
- return F.isAll((Map.Entry<K, V>)o, ep) && m.entrySet().remove(o);
+ return ep.apply((Map.Entry<K, V>)o) && m.entrySet().remove(o);
}
@SuppressWarnings({"unchecked"})
@Override public boolean contains(Object o) {
- return F.isAll((Map.Entry<K, V>)o, ep) && m.entrySet().contains(o);
+ return ep.apply((Map.Entry<K, V>)o) && m.entrySet().contains(o);
}
@Override public boolean isEmpty() {
@@ -1823,13 +1514,13 @@ public class GridFunc {
@SuppressWarnings({"unchecked"})
@Nullable @Override public V get(Object key) {
- return isAll((K)key, p) ? m.get(key) : null;
+ return p.apply((K)key) ? m.get(key) : null;
}
@Nullable @Override public V put(K key, V val) {
V oldVal = get(key);
- if (isAll(key, p))
+ if (p.apply(key))
m.put(key, val);
return oldVal;
@@ -1837,7 +1528,7 @@ public class GridFunc {
@SuppressWarnings({"unchecked"})
@Override public boolean containsKey(Object key) {
- return isAll((K)key, p) && m.containsKey(key);
+ return p.apply((K)key) && m.containsKey(key);
}
};
}
@@ -1851,38 +1542,26 @@ public class GridFunc {
*
* @param m Input map that serves as a base for the view.
* @param trans Transformer for map value transformation.
- * @param p Optional predicates. If predicates are not provided - all will be in the view.
* @param <K> Type of the key.
* @param <V> Type of the input map value.
* @param <V1> Type of the output map value.
* @return Light-weight view on given map with provided predicate and transformer.
*/
public static <K0, K extends K0, V0, V extends V0, V1> Map<K, V1> viewReadOnly(@Nullable final Map<K, V> m,
- final IgniteClosure<V, V1> trans, @Nullable final IgnitePredicate<? super K>... p) {
+ final IgniteClosure<V, V1> trans) {
A.notNull(trans, "trans");
- if (isEmpty(m) || isAlwaysFalse(p))
+ if (isEmpty(m))
return Collections.emptyMap();
- assert m != null;
-
- final boolean hasPred = p != null && p.length > 0;
-
return new GridSerializableMap<K, V1>() {
- /** Entry predicate. */
- private IgnitePredicate<Entry<K, V>> ep = new P1<Map.Entry<K, V>>() {
- @Override public boolean apply(Entry<K, V> e) {
- return isAll(e.getKey(), p);
- }
- };
-
@NotNull
@Override public Set<Entry<K, V1>> entrySet() {
return new GridSerializableSet<Map.Entry<K, V1>>() {
@NotNull
@Override public Iterator<Entry<K, V1>> iterator() {
return new Iterator<Entry<K, V1>>() {
- private Iterator<Entry<K, V>> it = iterator0(m.entrySet(), true, ep);
+ private Iterator<Entry<K, V>> it = identityIteratorReadOnly(m.entrySet());
@Override public boolean hasNext() {
return it.hasNext();
@@ -1913,7 +1592,7 @@ public class GridFunc {
}
@Override public int size() {
- return hasPred ? F.size(m.keySet(), p) : m.size();
+ return m.size();
}
@SuppressWarnings({"unchecked"})
@@ -1923,27 +1602,25 @@ public class GridFunc {
@SuppressWarnings({"unchecked"})
@Override public boolean contains(Object o) {
- return F.isAll((Map.Entry<K, V>)o, ep) && m.entrySet().contains(o);
+ return m.entrySet().contains(o);
}
@Override public boolean isEmpty() {
- return hasPred ? !iterator().hasNext() : m.isEmpty();
+ return m.isEmpty();
}
};
}
@Override public boolean isEmpty() {
- return hasPred ? entrySet().isEmpty() : m.isEmpty();
+ return m.isEmpty();
}
@SuppressWarnings({"unchecked"})
@Nullable @Override public V1 get(Object key) {
- if (isAll((K)key, p)) {
- V v = m.get(key);
+ V v = m.get(key);
- if (v != null)
- return trans.apply(v);
- }
+ if (v != null)
+ return trans.apply(v);
return null;
}
@@ -1958,170 +1635,34 @@ public class GridFunc {
@SuppressWarnings({"unchecked"})
@Override public boolean containsKey(Object key) {
- return isAll((K)key, p) && m.containsKey(key);
+ return m.containsKey(key);
}
};
}
/**
- * Read-only view on map that supports transformation of values and key filtering. Resulting map will
- * only "have" keys for which all provided predicates, if any, evaluates to {@code true}.
- * Note that only wrapping map will be created and no duplication of data will occur.
- * Also note that if array of given predicates is not empty then method {@code size()}
- * uses full iteration through the entry set.
- *
- * @param m Input map that serves as a base for the view.
- * @param trans Transformer for map value transformation.
- * @param p Optional predicates. If predicates are not provided - all will be in the view.
- * @param <K> Type of the key.
- * @param <V> Type of the input map value.
- * @param <V1> Type of the output map value.
- * @return Light-weight view on given map with provided predicate and transformer.
- */
- public static <K0, K extends K0, V0, V extends V0, V1> Map<K, V1> viewReadOnly(@Nullable final Map<K, V> m,
- final IgniteBiClosure<K, V, V1> trans, @Nullable final IgnitePredicate<? super K>... p) {
- A.notNull(trans, "trans");
-
- if (isEmpty(m) || isAlwaysFalse(p))
- return Collections.emptyMap();
-
- assert m != null;
-
- return new GridSerializableMap<K, V1>() {
- /** Entry predicate. */
- private IgnitePredicate<Entry<K, V>> ep = new P1<Map.Entry<K, V>>() {
- @Override public boolean apply(Entry<K, V> e) {
- return isAll(e.getKey(), p);
- }
- };
-
- @NotNull
- @Override public Set<Entry<K, V1>> entrySet() {
- return new GridSerializableSet<Map.Entry<K, V1>>() {
- @NotNull
- @Override public Iterator<Entry<K, V1>> iterator() {
- return new Iterator<Entry<K, V1>>() {
- private Iterator<Entry<K, V>> it = iterator0(m.entrySet(), true, ep);
-
- @Override public boolean hasNext() {
- return it.hasNext();
- }
-
- @Override public Entry<K, V1> next() {
- final Entry<K, V> e = it.next();
-
- return new Entry<K, V1>() {
- @Override public K getKey() {
- return e.getKey();
- }
-
- @Override public V1 getValue() {
- return trans.apply(e.getKey(), e.getValue());
- }
-
- @Override public V1 setValue(V1 val) {
- throw new UnsupportedOperationException(
- "Put is not supported for readonly map view.");
- }
- };
- }
-
- @Override public void remove() {
- throw new UnsupportedOperationException("Remove is not support for readonly map view.");
- }
- };
- }
-
- @Override public int size() {
- return F.size(m.keySet(), p);
- }
-
- @SuppressWarnings({"unchecked"})
- @Override public boolean remove(Object o) {
- throw new UnsupportedOperationException("Remove is not support for readonly map view.");
- }
-
- @SuppressWarnings({"unchecked"})
- @Override public boolean contains(Object o) {
- return F.isAll((Map.Entry<K, V>)o, ep) && m.entrySet().contains(o);
- }
-
- @Override public boolean isEmpty() {
- return !iterator().hasNext();
- }
- };
- }
-
- @Override public boolean isEmpty() {
- return entrySet().isEmpty();
- }
-
- @SuppressWarnings({"unchecked"})
- @Nullable @Override public V1 get(Object key) {
- if (isAll((K)key, p)) {
- V v = m.get(key);
-
- if (v != null)
- return trans.apply((K)key, v);
- }
-
- return null;
- }
-
- @Nullable @Override public V1 put(K key, V1 val) {
- throw new UnsupportedOperationException("Put is not supported for readonly map view.");
- }
-
- @Override public V1 remove(Object key) {
- throw new UnsupportedOperationException("Remove is not supported for readonly map view.");
- }
-
- @SuppressWarnings({"unchecked"})
- @Override public boolean containsKey(Object key) {
- return isAll((K)key, p) && m.containsKey(key);
- }
- };
- }
-
- /**
- * Read-only map view of a collection. Resulting map is a lightweight view of an input collection,
- * with filtered elements of an input collection as keys, and closure execution results
- * as values. The map will only contain keys for which all provided predicates, if any, evaluate
- * to {@code true}. Note that only wrapping map will be created and no duplication of data will occur.
- * Also note that if array of given predicates is not empty then method {@code size()}
- * uses full iteration through the entry set.
+ * Read-only map view of a collection.
*
* @param c Input collection.
* @param mapClo Mapping closure, that maps key to value.
- * @param p Optional predicates to filter input collection. If predicates are not provided - all
- * elements will be in the view.
* @param <K> Key type.
* @param <V> Value type.
* @return Light-weight view on given map with provided predicates and mapping.
*/
@SuppressWarnings("TypeMayBeWeakened")
public static <K0, K extends K0, V0, V extends V0> Map<K, V> viewAsMap(@Nullable final Set<K> c,
- final IgniteClosure<? super K, V> mapClo, @Nullable final IgnitePredicate<? super K>... p) {
+ final IgniteClosure<? super K, V> mapClo) {
A.notNull(mapClo, "trans");
- if (isEmpty(c) || isAlwaysFalse(p))
+ if (isEmpty(c))
return Collections.emptyMap();
- assert c != null;
-
return new GridSerializableMap<K, V>() {
- /** Entry predicate. */
- private IgnitePredicate<K> ep = new P1<K>() {
- @Override public boolean apply(K e) {
- return isAll(e, p);
- }
- };
-
@NotNull @Override public Set<Entry<K, V>> entrySet() {
return new GridSerializableSet<Entry<K, V>>() {
@NotNull @Override public Iterator<Entry<K, V>> iterator() {
return new Iterator<Entry<K, V>>() {
- private Iterator<K> it = iterator0(c, true, ep);
+ private Iterator<K> it = identityIteratorReadOnly(c);
@Override public boolean hasNext() {
return it.hasNext();
@@ -2154,7 +1695,7 @@ public class GridFunc {
}
@Override public int size() {
- return F.size(c, p);
+ return c.size();
}
@Override public boolean remove(Object o) {
@@ -2162,15 +1703,16 @@ public class GridFunc {
}
@Override public boolean isEmpty() {
- return !iterator().hasNext();
+ return c.isEmpty();
}
};
}
@Override public boolean isEmpty() {
- return entrySet().isEmpty();
+ return c.isEmpty();
}
+ @SuppressWarnings("unchecked")
@Nullable @Override public V get(Object key) {
if (containsKey(key))
return mapClo.apply((K)key);
@@ -2186,8 +1728,9 @@ public class GridFunc {
throw new UnsupportedOperationException("Remove is not supported for readonly collection view.");
}
+ @SuppressWarnings("SuspiciousMethodCalls")
@Override public boolean containsKey(Object key) {
- return isAll((K)key, p) && c.contains(key);
+ return c.contains(key);
}
};
}
@@ -2290,40 +1833,6 @@ public class GridFunc {
}
/**
- * Utility map getter. This method analogous to {@link #addIfAbsent(Map, Object, Callable)}
- * method but this one doesn't put the default value into the map when key is not found.
- *
- * @param map Map to get value from.
- * @param key Map key (can be {@code null}).
- * @param c Optional factory closure for the default value to be returned in
- * when {@code key} is not found. If closure is not provided - {@code null} will be returned.
- * @param <K> Map key type.
- * @param <V> Map value type.
- * @return Value for the {@code key} or default value produced by {@code c} if key is not
- * found (or {@code null} if key is not found and closure is not provided).
- * @throws GridClosureException Thrown in case when callable throws exception.
- * @see #newLinkedList()
- * @see #newList()
- * @see #newSet()
- * @see #newMap()
- * @see #newAtomicLong()
- * @see #newAtomicInt()
- * @see #newAtomicRef()
- * @see #newAtomicBoolean()
- */
- @Nullable public static <K, V> V returnIfAbsent(Map<? extends K, ? extends V> map, @Nullable K key,
- @Nullable Callable<V> c) {
- A.notNull(map, "map");
-
- try {
- return !map.containsKey(key) ? c == null ? null : c.call() : map.get(key);
- }
- catch (Exception e) {
- throw wrap(e);
- }
- }
-
- /**
* Returns a factory closure that creates new {@link ConcurrentLinkedDeque8} instance.
* Note that this method does not create a new closure but returns a static one.
*
@@ -2337,82 +1846,6 @@ public class GridFunc {
}
/**
- * Returns a factory closure that creates new {@link List} instance. Note that this
- * method does not create a new closure but returns a static one.
- *
- * @param <T> Type parameters for the created {@link List}.
- * @return Factory closure that creates new {@link List} instance every
- * time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- @SuppressWarnings("unchecked")
- public static <T> IgniteCallable<List<T>> newList() {
- return (IgniteCallable<List<T>>)LIST_FACTORY;
- }
-
- /**
- * Returns a factory closure that creates new {@link AtomicInteger} instance
- * initialized to {@code zero}. Note that this method does not create a new
- * closure but returns a static one.
- *
- * @return Factory closure that creates new {@link AtomicInteger} instance
- * initialized to {@code zero} every time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- public static IgniteCallable<AtomicInteger> newAtomicInt() {
- return ATOMIC_INT_FACTORY;
- }
-
- /**
- * Returns a factory closure that creates new {@link AtomicLong} instance
- * initialized to {@code zero}. Note that this method does not create a new
- * closure but returns a static one.
- *
- * @return Factory closure that creates new {@link AtomicLong} instance
- * initialized to {@code zero} every time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- public static IgniteCallable<AtomicLong> newAtomicLong() {
- return ATOMIC_LONG_FACTORY;
- }
-
- /**
- * Returns a factory closure that creates new {@link AtomicReference} instance
- * initialized to {@code null}. Note that this method does not create a new closure
- * but returns a static one.
- *
- * @param <T> Type of the atomic reference.
- * @return Factory closure that creates new {@link AtomicReference} instance
- * initialized to {@code null} every time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- @SuppressWarnings("unchecked")
- public static <T> IgniteCallable<AtomicReference<T>> newAtomicRef() {
- return (IgniteCallable<AtomicReference<T>>)ATOMIC_REF_FACTORY;
- }
-
- /**
- * Returns a factory closure that creates new {@link AtomicBoolean} instance
- * initialized to {@code false}. Note that this method does not create a new
- * closure but returns a static one.
- *
- * @return Factory closure that creates new {@link AtomicBoolean} instance
- * initialized to {@code false} every time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- public static IgniteCallable<AtomicBoolean> newAtomicBoolean() {
- return ATOMIC_BOOL_FACTORY;
- }
-
- /**
- * Returns a factory closure that creates new {@link LinkedList} instance.
- * Note that this method does not create a new closure but returns a static one.
- *
- * @param <T> Type parameters for the created {@link LinkedList}.
- * @return Factory closure that creates new {@link LinkedList} instance every time its {@link
- * org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- @SuppressWarnings("unchecked")
- public static <T> IgniteCallable<LinkedList<T>> newLinkedList() {
- return (IgniteCallable<LinkedList<T>>)LINKED_LIST_FACTORY;
- }
-
- /**
* Returns a factory closure that creates new {@link Set} instance. Note that this
* method does not create a new closure but returns a static one.
*
@@ -2426,20 +1859,6 @@ public class GridFunc {
}
/**
- * Returns a factory closure that creates new {@link Map} instance. Note
- * that this method does not create a new closure but returns a static one.
- *
- * @param <K> Type of the key for the created {@link Map}.
- * @param <V> Type of the value for the created {@link Map}.
- * @return Factory closure that creates new {@link Map} instance every
- * time its {@link org.apache.ignite.lang.IgniteOutClosure#apply()} method is called.
- */
- @SuppressWarnings("unchecked")
- public static <K, V> IgniteCallable<Map<K, V>> newMap() {
- return (IgniteCallable<Map<K, V>>)MAP_FACTORY;
- }
-
- /**
* Returns a factory closure that creates new {@link ConcurrentMap} instance.
* Note that this method does not create a new closure but returns a static one.
*
@@ -2466,6 +1885,18 @@ public class GridFunc {
}
/**
+ * Creates and returns iterator from given collection.
+ *
+ * @param c Input collection.
+ * @param <T> Type of the collection elements.
+ * @return Iterator from given collection and optional filtering predicate.
+ */
+ @SuppressWarnings({"unchecked"})
+ public static <T> GridIterator<T> identityIteratorReadOnly(Iterable<? extends T> c) {
+ return iteratorReadOnly(c, IDENTITY);
+ }
+
+ /**
* Creates and returns iterator from given collection and optional filtering predicates.
* Returned iterator will only have elements for which all given predicates evaluates to
* {@code true} (if provided). Note that this method will not create new collection but
@@ -2473,16 +1904,29 @@ public class GridFunc {
* evaluate to {@code true} for.
*
* @param c Input collection.
- * @param readOnly If {@code true}, then resulting iterator will not allow modifications
- * to the underlying collection.
- * @param p Optional filtering predicates.
+ * @param p Optional filtering predicate.
* @param <T> Type of the collection elements.
* @return Iterator from given collection and optional filtering predicate.
*/
@SuppressWarnings({"unchecked"})
- public static <T> GridIterator<T> iterator0(Iterable<? extends T> c, boolean readOnly,
- IgnitePredicate<? super T>... p) {
- return F.iterator(c, IDENTITY, readOnly, p);
+ public static <T> GridIterator<T> identityIterator(Iterable<? extends T> c, IgnitePredicate<? super T> p) {
+ return iterator(c, IDENTITY, false, p);
+ }
+
+ /**
+ * Creates and returns transforming iterator from given collection.
+ *
+ * @param c Input collection.
+ * @param trans Transforming closure to convert from T1 to T2.
+ * @param <T1> Type of the collection elements.
+ * @param <T2> Type of returned elements.
+ * @return Iterator from given collection and optional filtering predicate.
+ */
+ public static <T1, T2> GridIterator<T2> iteratorReadOnly(final Iterable<? extends T1> c,
+ final IgniteClosure<? super T1, T2> trans) {
+ A.notNull(c, "c", trans, "trans");
+
+ return iterator(c.iterator(), trans, true);
}
/**
@@ -2496,15 +1940,14 @@ public class GridFunc {
* @param trans Transforming closure to convert from T1 to T2.
* @param readOnly If {@code true}, then resulting iterator will not allow modifications
* to the underlying collection.
- * @param p Optional filtering predicates.
+ * @param p Filtering predicate.
* @param <T1> Type of the collection elements.
* @param <T2> Type of returned elements.
* @return Iterator from given collection and optional filtering predicate.
*/
public static <T1, T2> GridIterator<T2> iterator(final Iterable<? extends T1> c,
- final IgniteClosure<? super T1, T2> trans, final boolean readOnly,
- @Nullable final IgnitePredicate<? super T1>... p) {
- A.notNull(c, "c", trans, "trans");
+ final IgniteClosure<? super T1, T2> trans, final boolean readOnly, final IgnitePredicate<? super T1> p) {
+ A.notNull(c, "c", trans, "trans", p, "p");
if (isAlwaysFalse(p))
return F.emptyIterator();
@@ -2523,53 +1966,36 @@ public class GridFunc {
private Iterator<? extends T1> iter = c.iterator();
@Override public boolean hasNextX() {
- if (isEmpty(p))
- return iter.hasNext();
+ if (!moved)
+ return more;
else {
- if (!moved)
- return more;
- else {
- more = false;
-
- while (iter.hasNext()) {
- elem = iter.next();
+ more = false;
- boolean isAll = true;
+ while (iter.hasNext()) {
+ elem = iter.next();
- for (IgnitePredicate<? super T1> r : p)
- if (r != null && !r.apply(elem)) {
- isAll = false;
+ if (p.apply(elem)) {
+ more = true;
+ moved = false;
- break;
- }
-
- if (isAll) {
- more = true;
- moved = false;
-
- return true;
- }
+ return true;
}
+ }
- elem = null; // Give to GC.
+ elem = null; // Give to GC.
- return false;
- }
+ return false;
}
}
@Nullable @Override public T2 nextX() {
- if (isEmpty(p))
- return trans.apply(iter.next());
- else {
- if (hasNext()) {
- moved = true;
+ if (hasNext()) {
+ moved = true;
- return trans.apply(elem);
- }
- else
- throw new NoSuchElementException();
+ return trans.apply(elem);
}
+ else
+ throw new NoSuchElementException();
}
@Override public void removeX() {
@@ -2586,80 +2012,22 @@ public class GridFunc {
* @param trans Transforming closure to convert from T1 to T2.
* @param readOnly If {@code true}, then resulting iterator will not allow modifications
* to the underlying collection.
- * @param p Optional filtering predicates.
* @return Iterator from given iterator and optional filtering predicate.
*/
- public static <T1, T2> Iterator<T2> iterator(final Iterator<? extends T1> c,
- final IgniteClosure<? super T1, T2> trans,
- final boolean readOnly,
- @Nullable final IgnitePredicate<? super T1>... p)
- {
+ public static <T1, T2> GridIterator<T2> iterator(final Iterator<? extends T1> c,
+ final IgniteClosure<? super T1, T2> trans, final boolean readOnly) {
A.notNull(c, "c", trans, "trans");
- if (isAlwaysFalse(p))
- return F.emptyIterator();
-
return new GridIteratorAdapter<T2>() {
/** */
- private T1 elem;
-
- /** */
- private boolean moved = true;
-
- /** */
- private boolean more;
-
- /** */
private Iterator<? extends T1> iter = c;
@Override public boolean hasNextX() {
- if (isEmpty(p))
- return iter.hasNext();
- else {
- if (!moved)
- return more;
- else {
- more = false;
-
- while (iter.hasNext()) {
- elem = iter.next();
-
- boolean isAll = true;
-
- for (IgnitePredicate<? super T1> r : p)
- if (r != null && !r.apply(elem)) {
- isAll = false;
-
- break;
- }
-
- if (isAll) {
- more = true;
- moved = false;
-
- return true;
- }
- }
-
- elem = null; // Give to GC.
-
- return false;
- }
- }
+ return iter.hasNext();
}
@Nullable @Override public T2 nextX() {
- if (isEmpty(p))
- return trans.apply(iter.next());
- else {
- if (hasNext()) {
- moved = true;
-
- return trans.apply(elem);
- }
- else
- throw new NoSuchElementException();
- }
+ return trans.apply(iter.next());
}
@Override public void removeX() {
@@ -2740,23 +2108,35 @@ public class GridFunc {
}
/**
- * Gets predicate that evaluates to {@code true} if its free variable is {@code null}.
+ * Gets predicate that evaluates to {@code true} if its free variable is not {@code null}.
*
* @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate that evaluates to {@code true} if its free variable is {@code null}.
+ * @return Predicate that evaluates to {@code true} if its free variable is not {@code null}.
*/
- public static <T> IgnitePredicate<T> isNull() {
- return (IgnitePredicate<T>) IS_NULL;
+ @SuppressWarnings("unchecked")
+ public static <T> IgnitePredicate<T> notNull() {
+ return (IgnitePredicate<T>)IS_NOT_NULL;
}
/**
- * Gets predicate that evaluates to {@code true} if its free variable is not {@code null}.
+ * Negates given predicate.
+ * <p>
+ * Gets predicate that evaluates to {@code true} if any of given predicates
+ * evaluates to {@code false}. If all predicates evaluate to {@code true} the
+ * result predicate will evaluate to {@code false}.
*
+ * @param p Predicate to negate.
* @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate that evaluates to {@code true} if its free variable is not {@code null}.
+ * @return Negated predicate.
*/
- public static <T> IgnitePredicate<T> notNull() {
- return (IgnitePredicate<T>) IS_NOT_NULL;
+ public static <T> IgnitePredicate<T> not(final IgnitePredicate<? super T> p) {
+ A.notNull(p, "p");
+
+ return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
+ @Override public boolean apply(T t) {
+ return !p.apply(t);
+ }
+ };
}
/**
@@ -2770,8 +2150,7 @@ public class GridFunc {
* @param <T> Type of the free variable, i.e. the element the predicate is called on.
* @return Negated predicate.
*/
- @SafeVarargs
- public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>... p) {
+ public static <T> IgnitePredicate<T> not(@Nullable final IgnitePredicate<? super T>[] p) {
return isAlwaysFalse(p) ? F.<T>alwaysTrue() : isAlwaysTrue(p) ? F.<T>alwaysFalse() : new P1<T>() {
@Override public boolean apply(T t) {
return !isAll(t, p);
@@ -2814,30 +2193,13 @@ public class GridFunc {
}
/**
- * Gets predicate that evaluates to {@code true} if its free variable is instance of the given class.
- *
- * @param cls Class to compare to.
- * @param <T> Type of the free variable, i.e. the element the predicate is called on.
- * @return Predicate that evaluates to {@code true} if its free variable is instance
- * of the given class.
- */
- public static <T> IgnitePredicate<T> instanceOf(final Class<?> cls) {
- A.notNull(cls, "cls");
-
- return new P1<T>() {
- @Override public boolean apply(T t) {
- return t != null && cls.isAssignableFrom(t.getClass());
- }
- };
- }
-
- /**
* Gets first element from given collection or returns {@code null} if the collection is empty.
*
* @param c A collection.
* @param <T> Type of the collection.
* @return Collections' first element or {@code null} in case if the collection is empty.
*/
+ @SuppressWarnings("unchecked")
public static <T> T first(@Nullable Iterable<? extends T> c) {
if (c == null)
return null;
@@ -2870,12 +2232,11 @@ public class GridFunc {
* @param <T> Type of the collection.
* @return Collections' first element or {@code null} in case if the collection is empty.
*/
+ @SuppressWarnings("unchecked")
@Nullable public static <T> T last(@Nullable Iterable<? extends T> c) {
if (c == null)
return null;
- assert c != null;
-
if (c instanceof RandomAccess && c instanceof List) {
List<T> l = (List<T>)c;
@@ -2960,8 +2321,6 @@ public class GridFunc {
return F.alwaysTrue();
if (F0.isAllNodePredicates(ps)) {
- assert ps != null;
-
Set<UUID> ids = new HashSet<>();
for (IgnitePredicate<? super T> p : ps) {
@@ -2981,8 +2340,6 @@ public class GridFunc {
else {
return new P1<T>() {
@Override public boolean apply(T t) {
- assert ps != null;
-
for (IgnitePredicate<? super T> p : ps)
if (p != null && !p.apply(t))
return false;
@@ -3019,6 +2376,24 @@ public class GridFunc {
}
/**
+ * Gets predicate (not peer-deployable) that returns {@code true} if its free variable is contained
+ * in given collection.
+ *
+ * @param c Collection to check for containment.
+ * @param <T> Type of the free variable for the predicate and type of the
+ * collection elements.
+ * @return Predicate (not peer-deployable) that returns {@code true} if its free variable is
+ * contained in given collection.
+ */
+ public static <T> IgnitePredicate<T> in(@Nullable final Collection<? extends T> c) {
+ return isEmpty(c) ? GridFunc.<T>alwaysFalse() : new P1<T>() {
+ @Override public boolean apply(T t) {
+ return c.contains(t);
+ }
+ };
+ }
+
+ /**
* Gets predicate that returns {@code true} if its free variable is not
* contained in given collection.
*
@@ -3031,8 +2406,6 @@ public class GridFunc {
public static <T> IgnitePredicate<T> notIn(@Nullable final Collection<? extends T> c) {
return isEmpty(c) ? GridFunc.<T>alwaysTrue() : new P1<T>() {
@Override public boolean apply(T t) {
- assert c != null;
-
return !c.contains(t);
}
};
@@ -3045,27 +2418,13 @@ public class GridFunc {
*/
@SuppressWarnings("unchecked")
public static <T, C extends Collection<T>> C addAll(C c, Iterable<? extends T> it) {
- if (it == null)
- return c;
-
- if (it instanceof Collection<?>) {
- c.addAll((Collection<? extends T>)it);
-
- return c;
- }
-
- return addAll(c, it.iterator());
- }
-
- /**
- * @param c Target collection.
- * @param it Iterator to fetch.
- * @return Modified target collection.
- */
- public static <T, C extends Collection<T>> C addAll(C c, Iterator<? extends T> it) {
if (it != null) {
- while (it.hasNext())
- c.add(it.next());
+ if (it instanceof Collection<?>)
+ c.addAll((Collection<? extends T>)it);
+ else {
+ for (T item : it)
+ c.add(item);
+ }
}
return c;
@@ -3142,14 +2501,7 @@ public class GridFunc {
* found (or {@code null} if key is not found and closure is not provided). Note that
* in case when key is not found the default value will be put into the map.
* @throws GridClosureException Thrown in case when callable throws exception.
- * @see #newLinkedList()
- * @see #newList()
* @see #newSet()
- * @see #newMap()
- * @see #newAtomicLong()
- * @see #newAtomicInt()
- * @see #newAtomicRef()
- * @see #newAtomicBoolean()
*/
@Nullable public static <K, V> V addIfAbsent(Map<? super K, V> map, @Nullable K key,
@Nullable Callable<? extends V> c) {
@@ -3227,79 +2579,34 @@ public class GridFunc {
*
* @param c Collection to call closure over.
* @param f Side-effect only closure to call over the collection.
- * @param p Optional set of predicates. Only if collection element evaluates
- * to {@code true} for given predicates the closure will be applied to it.
- * If no predicates provided - closure will be applied to all collection
- * elements.
* @param <X> Type of the free variable for the closure and type of the
* collection elements.
*/
- public static <X> void forEach(Iterable<? extends X> c, IgniteInClosure<? super X> f,
- @Nullable IgnitePredicate<? super X>... p) {
- A.notNull(c, "c", f, "f");
-
- for (X x : c)
- if (isAll(x, p))
- f.apply(x);
- }
-
- /**
- * Calls given {@code side-effect only} closure over the each element of the provided array.
- *
- * @param c Array to call closure over.
- * @param f Side-effect only closure to call over the array.
- * @param p Optional set of predicates. Only if collection element evaluates
- * to {@code true} for given predicates the closure will be applied to it.
- * If no predicates provided - closure will be applied to all collection
- * elements.
- * @param <X> Type of the free variable for the closure and type of the array
- * elements.
- */
- @SuppressWarnings("RedundantTypeArguments")
- public static <X> void forEach(X[] c, IgniteInClosure<? super X> f, @Nullable IgnitePredicate<? super X>... p) {
- A.notNull(c, "c", f, "f");
-
- F.<X>forEach(asList(c), f, p);
- }
-
- /**
- * Adds (copies) to given collection all elements in <tt>'from'</tt> array.
- *
- * @param to Collection to copy to.
- * @param from Array to copy from.
- * @param <T> Type of the free variable for the predicate and type of the collection elements.
- * @return Collection to copy to.
- */
- public static <T> Collection<T> copy(Collection<T> to, T... from) {
- A.notNull(to, "to", from, "from");
-
- copy(to, asList(from));
+ public static <X> void forEach(Iterable<? extends X> c, IgniteInClosure<? super X> f) {
+ A.notNull(c, "c", f, "f");
- return to;
+ for (X x : c)
+ f.apply(x);
}
/**
- * Adds (copies) to given collection using provided predicates. Element is copied if all
- * predicates evaluate to {@code true}.
+ * Calls given {@code side-effect only} closure over the each element of the provided
+ * collection.
*
- * @param to Collection to copy to.
- * @param from Collection to copy from.
- * @param p Optional set of predicates to use for filtration.
- * @param <T> Type of the free variable for the predicate and type of the collection elements.
- * @return Collection to copy to.
+ * @param c Collection to call closure over.
+ * @param f Side-effect only closure to call over the collection.
+ * @param p Optional predicate. Only if collection element evaluates
+ * to {@code true} for given predicate the closure will be applied to it.
+ * @param <X> Type of the free variable for the closure and type of the
+ * collection elements.
*/
- public static <T> Collection<T> copy(Collection<T> to, Iterable<? extends T> from,
- @Nullable IgnitePredicate<? super T>... p) {
- A.notNull(to, "to", from, "from");
-
- if (!isAlwaysFalse(p)) {
- for (T t : from) {
- if (isAll(t, p))
- to.add(t);
- }
- }
+ public static <X> void forEach(Iterable<? extends X> c, IgniteInClosure<? super X> f,
+ IgnitePredicate<? super X> p) {
+ A.notNull(c, "c", f, "f", p, "f");
- return to;
+ for (X x : c)
+ if (p.apply(x))
+ f.apply(x);
}
/**
@@ -3336,21 +2643,6 @@ public class GridFunc {
}
/**
- * Transforms an array to read only collection using provided closure.
- *
- * @param c Initial array to transform.
- * @param f Closure to use for transformation.
- * @param <X> Type of the free variable for the closure and type of the array elements.
- * @param <Y> Type of the closure's return value.
- * @return Transformed read only collection.
- */
- public static <X, Y> Collection<Y> transform(X[] c, IgniteClosure<? super X, Y> f) {
- A.notNull(c, "c", f, "f");
-
- return viewReadOnly(asList(c), f);
- }
-
- /**
* Tests if all provided predicates evaluate to {@code true} for given value. Note that
* evaluation will be short-circuit when first predicate evaluated to {@code false} is found.
*
@@ -3361,7 +2653,7 @@ public class GridFunc {
* @return Returns {@code true} if given set of predicates is {@code null}, is empty, or all predicates
* evaluate to {@code true} for given value, {@code false} otherwise.
*/
- public static <T> boolean isAll(@Nullable T t, @Nullable IgnitePredicate<? super T>... p) {
+ public static <T> boolean isAll(@Nullable T t, @Nullable IgnitePredicate<? super T>[] p) {
if (p != null)
for (IgnitePredicate<? super T> r : p)
if (r != null && !r.apply(t))
@@ -3371,27 +2663,6 @@ public class GridFunc {
}
/**
- * Tests if any of provided predicates evaluate to {@code true} for given value. Note
- * that evaluation will be short-circuit when first predicate evaluated to {@code true}
- * is found.
- *
- * @param t Value to test.
- * @param p Optional set of predicates to use for evaluation.
- * @param <T> Type of the value and free variable of the predicates.
- * @return Returns {@code true} if any of predicates evaluates to {@code true} for given
- * value, {@code false} otherwise. Returns {@code false} if given set of predicates
- * is {@code null} or empty.
- */
- public static <T> boolean isAny(@Nullable T t, @Nullable IgnitePredicate<? super T>... p) {
- if (p != null)
- for (IgnitePredicate<? super T> r : p)
- if (r != null && r.apply(t))
- return true;
-
- return false;
- }
-
- /**
* Creates an absolute (no-arg) closure that does nothing.
*
* @return Absolute (no-arg) closure that does nothing.
@@ -3411,14 +2682,12 @@ public class GridFunc {
* @return First element in given collection for which predicate evaluates to
* {@code true} - or {@code null} if such element cannot be found.
*/
- @SafeVarargs
- @Nullable public static <V> V find(Iterable<? extends V> c, @Nullable V dfltVal,
- @Nullable IgnitePredicate<? super V>... p) {
+ @Nullable public static <V> V find(Iterable<? extends V> c, @Nullable V dfltVal, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
- if (!isEmpty(p) && !isAlwaysFalse(p)) {
+ if (!isAlwaysFalse(p)) {
for (V v : c) {
- if (isAny(v, p))
+ if (p.apply(v))
return v;
}
}
@@ -3427,35 +2696,6 @@ public class GridFunc {
}
/**
- * Finds, transforms and returns first element in given collection for which any of
- * the provided predicates evaluates to {@code true}.
- *
- * @param c Input collection.
- * @param dfltVal Default value to return when no element is found.
- * @param f Transforming closure.
- * @param p Optional set of finder predicates.
- * @param <V> Type of the collection elements.
- * @return First element in given collection for which predicate evaluates to
- * {@code true} - or {@code null} if such element cannot be found.
- */
- public static <V, Y> Y find(Iterable<? extends V> c, @Nullable Y dfltVal, IgniteClosure<? super V, Y> f,
- @Nullable IgnitePredicate<? super V>... p) {
- A.notNull(c, "c", f, "f");
-
- if (isAlwaysTrue(p) && c.iterator().hasNext())
- return f.apply(c.iterator().next());
-
- if (!isEmpty(p) && !isAlwaysFalse(p)) {
- for (V v : c) {
- if (isAny(v, p))
- return f.apply(v);
- }
- }
-
- return dfltVal;
- }
-
- /**
* Checks if collection {@code c1} contains any elements from collection {@code c2}.
*
* @param c1 Collection to check for containment. If {@code null} - this method returns {@code false}.
@@ -3482,7 +2722,7 @@ public class GridFunc {
* @return {@code true} if collection {@code c1} contains at least one element from collection
* {@code c2}.
*/
- public static <T> boolean containsAny(@Nullable Collection<? extends T> c1, @Nullable T... c2) {
+ public static <T> boolean containsAny(@Nullable Collection<? extends T> c1, @Nullable T[] c2) {
if (c1 != null && !c1.isEmpty() && c2 != null && c2.length > 0)
for (T t : c2)
if (c1.contains(t))
@@ -3526,35 +2766,6 @@ public class GridFunc {
}
/**
- * Partitions input collection in two: first containing elements for which given
- * predicate evaluates to {@code true} - and second containing the elements for which
- * predicate evaluates to {@code false}.
- *
- * @param c Input collection.
- * @param p Partitioning predicate.
- * @param <V> Type of the collection elements.
- * @return Tuple of two collections: first containing elements for which given predicate
- * evaluates to {@code true} - and second containing the elements for which predicate
- * evaluates to {@code false}.
- */
- public static <V> IgniteBiTuple<Collection<V>, Collection<V>> partition(Iterable<? extends V> c,
- IgnitePredicate<? super V> p) {
- A.notNull(c, "c", p, "p");
-
- Collection<V> c1 = new LinkedList<>();
- Collection<V> c2 = new LinkedList<>();
-
- for (V v : c) {
- if (p.apply(v))
- c1.add(v);
- else
- c2.add(v);
- }
-
- return t(c1, c2);
- }
-
- /**
* Checks for existence of the element in input collection for which all provided predicates
* evaluate to {@code true}.
*
@@ -3564,18 +2775,16 @@ public class GridFunc {
* @return {@code true} if input collection contains element for which all the provided
* predicates evaluates to {@code true} - otherwise returns {@code false}.
*/
- public static <V> boolean exist(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p) {
+ public static <V> boolean exist(Iterable<? extends V> c, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
- else if (isEmpty(p))
- return true;
else
for (V v : c)
- if (isAll(v, p))
+ if (p.apply(v))
return true;
return false;
@@ -3592,16 +2801,16 @@ public class GridFunc {
* @return Returns {@code true} if all given predicates evaluate to {@code true} for
* all elements. Returns {@code false} otherwise.
*/
- public static <V> boolean forAll(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p) {
+ public static <V> boolean forAll(Iterable<? extends V> c, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
- else if (!isEmpty(p)) {
+ else {
for (V v : c) {
- if (!isAll(v, p))
+ if (!p.apply(v))
return false;
}
}
@@ -3621,17 +2830,18 @@ public class GridFunc {
* entries. Returns {@code false} otherwise.
*/
public static <K1, K extends K1, V1, V extends V1> boolean forAll(Map<K, V> m,
- @Nullable IgnitePredicate<? super Map.Entry<K, V>>... p) {
+ IgnitePredicate<? super Map.Entry<K, V>> p) {
A.notNull(m, "m");
if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
- else if (!isEmpty(p))
+ else {
for (Map.Entry<K, V> e : m.entrySet())
- if (!isAll(e, p))
+ if (!p.apply(e))
return false;
+ }
return true;
}
@@ -3648,20 +2858,16 @@ public class GridFunc {
* @return Returns {@code true} if all given predicates evaluate to {@code true} for
* at least one element. Returns {@code false} otherwise.
*/
- public static <V> boolean forAny(Iterable<? extends V> c, @Nullable IgnitePredicate<? super V>... p) {
+ public static <V> boolean forAny(Iterable<? extends V> c, IgnitePredicate<? super V> p) {
A.notNull(c, "c");
- if (!c.iterator().hasNext())
- return false;
- else if (isEmpty(p))
- return true;
- else if (isAlwaysFalse(p))
+ if (isAlwaysFalse(p))
return false;
else if (isAlwaysTrue(p))
return true;
else {
for (V v : c)
- if (isAll(v, p))
+ if (p.apply(v))
return true;
return false;
@@ -3691,22 +2897,17 @@ public class GridFunc {
*
* @param c Input collection.
* @param b Optional first folding pair element.
- * @param fs Optional set of folding closures.
+ * @param fs Optional folding closure.
* @param <D> Type of the input collection elements and type of the free variable for the closure.
* @param <B> Type of the folding value and return type of the closure.
* @return Value representing folded collection.
*/
@Nullable public static <D, B> B fold(Iterable<? extends D> c, @Nullable B b,
- @Nullable IgniteBiClosure<? super D, ? super B, B>... fs) {
+ IgniteBiClosure<? super D, ? super B, B> fs) {
A.notNull(c, "c");
- if (!isEmpty(fs))
- for (D e : c) {
- assert fs != null;
-
- for (IgniteBiClosure<? super D, ? super B, B> f : fs)
- b = f.apply(e, b);
- }
+ for (D e : c)
+ b = fs.apply(e, b);
return b;
}
@@ -3832,72 +3033,6 @@ public class GridFunc {
}
/**
- * Creates vararg tuple with given values.
- *
- * @param objs Values for vararg tuple.
- * @return Vararg tuple with given values.
- */
- public static GridTupleV tv(Object... objs) {
- assert objs != null;
-
- return new GridTupl
<TRUNCATED>