http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesTransformerWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesTransformerWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesTransformerWrapper.java new file mode 100644 index 0000000..9803ba8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesTransformerWrapper.java @@ -0,0 +1,168 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import org.apache.ignite.internal.util.GridSerializableMap; +import org.apache.ignite.internal.util.GridSerializableSet; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Light-weight view on given map with provided predicate and transformer. + * + * @param <K> Type of the key. + * @param <V> Type of the input map value. + * @param <V1> Type of the output map value. + */ +public class GridSerializableMapPredicatesTransformerWrapper<K, V1, V> extends GridSerializableMap<K, V1> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Map<K, V> map; + + /** */ + private final IgniteClosure<V, V1> transformer; + + /** */ + private final boolean hasPred; + + /** */ + private final IgnitePredicate<? super K>[] predicates; + + /** Entry predicate. */ + private IgnitePredicate<Entry<K, V>> ep; + + /** + * @param map Input map that serves as a base for the view. + * @param transformer Transformer for map value transformation. + * @param predicates Optional predicates. If predicates are not provided - all will be in the view. + */ + @SuppressWarnings({"unchecked"}) + public GridSerializableMapPredicatesTransformerWrapper(Map<K, V> map, IgniteClosure<V, V1> transformer, + IgnitePredicate<? super K>... predicates) { + this.map = map; + this.transformer = transformer; + this.hasPred = (predicates != null && predicates.length > 0); + this.predicates = predicates; + this.ep = new IgnitePredicateEvaluateEntryByKey(predicates); + } + + /** {@inheritDoc} */ + @NotNull @Override public Set<Entry<K, V1>> entrySet() { + return new GridSerializableSet<Entry<K, V1>>() { + @NotNull + @Override public Iterator<Entry<K, V1>> iterator() { + return new Iterator<Entry<K, V1>>() { + private Iterator<Entry<K, V>> it = GridFunc.iterator0(map.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 transformer.apply(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 hasPred ? F.size(map.keySet(), predicates) : map.size(); + } + + @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((Entry<K, V>)o, ep) && map.entrySet().contains(o); + } + + @Override public boolean isEmpty() { + return hasPred ? !iterator().hasNext() : map.isEmpty(); + } + }; + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return hasPred ? entrySet().isEmpty() : map.isEmpty(); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Nullable @Override public V1 get(Object key) { + if (GridFunc.isAll((K)key, predicates)) { + V v = map.get(key); + + if (v != null) + return transformer.apply(v); + } + + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public V1 put(K key, V1 val) { + throw new UnsupportedOperationException("Put is not supported for readonly map view."); + } + + /** {@inheritDoc} */ + @Override public V1 remove(Object key) { + throw new UnsupportedOperationException("Remove is not supported for readonly map view."); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public boolean containsKey(Object key) { + return GridFunc.isAll((K)key, predicates) && map.containsKey(key); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableMapPredicatesTransformerWrapper.class, this); + } +}
http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesWrapper.java new file mode 100644 index 0000000..3528ae8 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapPredicatesWrapper.java @@ -0,0 +1,121 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import org.apache.ignite.internal.util.GridSerializableMap; +import org.apache.ignite.internal.util.GridSerializableSet; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Light-weight view on given map with provided predicate. + * + * @param <K> Type of the key. + * @param <V> Type of the value. + */ +public class GridSerializableMapPredicatesWrapper<K, V> extends GridSerializableMap<K, V> { + /** */ + private static final long serialVersionUID = 5531745605372387948L; + + /** */ + private final Map<K, V> map; + + /** */ + private final IgnitePredicate<? super K>[] predicates; + + /** Entry predicate. */ + private IgnitePredicate<Entry<K, V>> entryPredicate; + + /** + * @param map Input map that serves as a base for the view. + * @param predicates Optional predicates. If predicates are not provided - all will be in the view. + */ + @SuppressWarnings({"unchecked"}) + public GridSerializableMapPredicatesWrapper(Map<K, V> map, IgnitePredicate<? super K>... predicates) { + this.map = map; + this.predicates = predicates; + this.entryPredicate = new IgnitePredicateEvaluateEntryByKey(predicates); + } + + /** {@inheritDoc} */ + @NotNull @Override public Set<Entry<K, V>> entrySet() { + return new GridSerializableSet<Entry<K, V>>() { + @NotNull + @Override public Iterator<Entry<K, V>> iterator() { + return GridFunc.iterator0(map.entrySet(), false, entryPredicate); + } + + @Override public int size() { + return F.size(map.keySet(), predicates); + } + + @SuppressWarnings({"unchecked"}) + @Override public boolean remove(Object o) { + return F.isAll((Entry<K, V>)o, entryPredicate) && map.entrySet().remove(o); + } + + @SuppressWarnings({"unchecked"}) + @Override public boolean contains(Object o) { + return F.isAll((Entry<K, V>)o, entryPredicate) && map.entrySet().contains(o); + } + + @Override public boolean isEmpty() { + return !iterator().hasNext(); + } + }; + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return entrySet().isEmpty(); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Nullable @Override public V get(Object key) { + return GridFunc.isAll((K)key, predicates) ? map.get(key) : null; + } + + /** {@inheritDoc} */ + @Nullable @Override public V put(K key, V val) { + V oldVal = get(key); + + if (GridFunc.isAll(key, predicates)) + map.put(key, val); + + return oldVal; + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public boolean containsKey(Object key) { + return GridFunc.isAll((K)key, predicates) && map.containsKey(key); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableMapPredicatesWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyClosurePredicateWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyClosurePredicateWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyClosurePredicateWrapper.java new file mode 100644 index 0000000..2782b93 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyClosurePredicateWrapper.java @@ -0,0 +1,165 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Iterator; +import java.util.Map; +import java.util.Set; +import org.apache.ignite.internal.util.GridSerializableMap; +import org.apache.ignite.internal.util.GridSerializableSet; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteBiClosure; +import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Light-weight view on given map with provided predicate and transformer. + * + * @param <K> Type of the key. + * @param <V> Type of the input map value. + * @param <V1> Type of the output map value. + */ +public class GridSerializableMapReadOnlyClosurePredicateWrapper<K, V, V1> extends GridSerializableMap<K, V1> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Map<K, V> map; + + /** */ + private final IgniteBiClosure<K, V, V1> transformer; + + /** */ + private final IgnitePredicate<? super K>[] predicates; + + /** Entry predicate. */ + private IgnitePredicate<Entry<K, V>> entryPredicate; + + /** + * @param map Input map that serves as a base for the view. + * @param transformer Transformer for map value transformation. + * @param predicates Optional predicates. If predicates are not provided - all will be in the view. + */ + @SuppressWarnings({"unchecked"}) + public GridSerializableMapReadOnlyClosurePredicateWrapper(Map<K, V> map, IgniteBiClosure<K, V, V1> transformer, + IgnitePredicate<? super K>... predicates) { + this.map = map; + this.transformer = transformer; + this.predicates = predicates; + entryPredicate = new IgnitePredicateEvaluateEntryByKey(predicates); + } + + /** {@inheritDoc} */ + @NotNull @Override public Set<Entry<K, V1>> entrySet() { + return new GridSerializableSet<Entry<K, V1>>() { + @NotNull + @Override public Iterator<Entry<K, V1>> iterator() { + return new Iterator<Entry<K, V1>>() { + private Iterator<Entry<K, V>> it = GridFunc.iterator0(map.entrySet(), true, entryPredicate); + + @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 transformer.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(map.keySet(), predicates); + } + + @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((Entry<K, V>)o, entryPredicate) && map.entrySet().contains(o); + } + + @Override public boolean isEmpty() { + return !iterator().hasNext(); + } + }; + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return entrySet().isEmpty(); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Nullable @Override public V1 get(Object key) { + if (GridFunc.isAll((K)key, predicates)) { + V v = map.get(key); + + if (v != null) + return transformer.apply((K)key, v); + } + + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public V1 put(K key, V1 val) { + throw new UnsupportedOperationException("Put is not supported for readonly map view."); + } + + /** {@inheritDoc} */ + @Override public V1 remove(Object key) { + throw new UnsupportedOperationException("Remove is not supported for readonly map view."); + } + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public boolean containsKey(Object key) { + return GridFunc.isAll((K)key, predicates) && map.containsKey(key); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableMapReadOnlyClosurePredicateWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyPredicateWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyPredicateWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyPredicateWrapper.java new file mode 100644 index 0000000..10c36ef --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableMapReadOnlyPredicateWrapper.java @@ -0,0 +1,153 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Iterator; +import java.util.Set; +import org.apache.ignite.internal.util.GridSerializableMap; +import org.apache.ignite.internal.util.GridSerializableSet; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Light-weight view on given map with provided predicates and mapping. + * + * @param <K> Key type. + * @param <V> Value type. + */ +public class GridSerializableMapReadOnlyPredicateWrapper<K, V> extends GridSerializableMap<K, V> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Set<K> set; + + /** */ + private final IgniteClosure<? super K, V> mappingClosure; + + /** */ + private final IgnitePredicate<? super K>[] predicates; + + /** Entry predicate. */ + private IgnitePredicate<K> entryPredicate; + + /** + * @param set Input collection. + * @param mappingClosure Mapping closure, that maps key to value. + * @param predicates Optional predicates to filter input collection. If predicates are not provided - all elements + * will be in + */ + @SuppressWarnings({"unchecked"}) + public GridSerializableMapReadOnlyPredicateWrapper(Set<K> set, IgniteClosure<? super K, V> mappingClosure, + IgnitePredicate<? super K>... predicates) { + this.set = set; + this.mappingClosure = mappingClosure; + this.predicates = predicates; + this.entryPredicate = new IgnitePredicateIsAll(predicates); + } + + /** {@inheritDoc} */ + @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 = GridFunc.iterator0(set, true, entryPredicate); + + @Override public boolean hasNext() { + return it.hasNext(); + } + + @Override public Entry<K, V> next() { + final K e = it.next(); + + return new Entry<K, V>() { + @Override public K getKey() { + return e; + } + + @Override public V getValue() { + return mappingClosure.apply(e); + } + + @Override public V setValue(V val) { + throw new UnsupportedOperationException( + "Put is not supported for readonly collection view."); + } + }; + } + + @Override public void remove() { + throw new UnsupportedOperationException( + "Remove is not support for readonly collection view."); + } + }; + } + + @Override public int size() { + return F.size(set, predicates); + } + + @Override public boolean remove(Object o) { + throw new UnsupportedOperationException("Remove is not support for readonly collection view."); + } + + @Override public boolean isEmpty() { + return !iterator().hasNext(); + } + }; + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return entrySet().isEmpty(); + } + + /** {@inheritDoc} */ + @Nullable @Override public V get(Object key) { + if (containsKey(key)) + return mappingClosure.apply((K)key); + + return null; + } + + /** {@inheritDoc} */ + @Nullable @Override public V put(K key, V val) { + throw new UnsupportedOperationException("Put is not supported for readonly collection view."); + } + + /** {@inheritDoc} */ + @Override public V remove(Object key) { + throw new UnsupportedOperationException("Remove is not supported for readonly collection view."); + } + + /** {@inheritDoc} */ + @Override public boolean containsKey(Object key) { + return GridFunc.isAll((K)key, predicates) && set.contains(key); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableMapReadOnlyPredicateWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionPredicateWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionPredicateWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionPredicateWrapper.java new file mode 100644 index 0000000..cce95a6 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionPredicateWrapper.java @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.Iterator; +import org.apache.ignite.internal.util.GridSerializableCollection; +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgnitePredicate; +import org.jetbrains.annotations.NotNull; + +/** + * Light-weight view on given collection with provided predicate. + * + * @param <T1> Element type after transformation. + * @param <T2> Element type. + */ +public class GridSerializableReadOnlyCollectionPredicateWrapper<T1, T2> extends GridSerializableCollection<T1> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final Collection<? extends T2> collection; + + /** */ + private final IgniteClosure<? super T2, T1> transformer; + + /** */ + private final IgnitePredicate<? super T2>[] predicates; + + /** + * @param collection Input collection that serves as a base for the view. + * @param transformer Transformation closure. + * @param predicates Optional predicated. If predicates are not provided - all elements will be in the view. + */ + public GridSerializableReadOnlyCollectionPredicateWrapper(Collection<? extends T2> collection, + IgniteClosure<? super T2, T1> transformer, IgnitePredicate<? super T2>... predicates) { + this.collection = collection; + this.transformer = transformer; + this.predicates = predicates; + } + + /** {@inheritDoc} */ + @NotNull @Override public Iterator<T1> iterator() { + return F.<T2, T1>iterator(collection, transformer, true, predicates); + } + + /** {@inheritDoc} */ + @Override public int size() { + return F.isEmpty(predicates) ? collection.size() : F.size(iterator()); + } + + /** {@inheritDoc} */ + @Override public boolean isEmpty() { + return F.isEmpty(predicates) ? collection.isEmpty() : !iterator().hasNext(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableReadOnlyCollectionPredicateWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionWrapper.java new file mode 100644 index 0000000..3bec907 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyCollectionWrapper.java @@ -0,0 +1,95 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.Iterator; +import org.apache.ignite.internal.util.GridSerializableCollection; +import org.apache.ignite.internal.util.GridSerializableIterator; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +/** + * Collection wrapper. + * A read-only view will be created over the element and given + * collections and no copying will happen. + * + * @param <T> Element type. + */ +public class GridSerializableReadOnlyCollectionWrapper<T> extends GridSerializableCollection<T> { + /** */ + private static final long serialVersionUID = 0L; + + /** Collection. */ + private final Collection<T> collection; + + /** First element in the collection. */ + private final T firstElement; + + /** + * @param collection Collection to wrap. + * @param firstElement First element. + */ + public GridSerializableReadOnlyCollectionWrapper(@NotNull Collection<T> collection, @NotNull T firstElement) { + this.collection = collection; + this.firstElement = firstElement; + } + + /** {@inheritDoc} */ + @NotNull + @Override public Iterator<T> iterator() { + return new GridSerializableIterator<T>() { + private Iterator<T> it; + + @Override public boolean hasNext() { + return it == null || it.hasNext(); + } + + @Nullable @Override public T next() { + if (it == null) { + it = collection.iterator(); + + return firstElement; + } + + return it.next(); + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + /** {@inheritDoc} */ + @Override public int size() { + return collection.size() + 1; + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + return obj instanceof Collection && GridFunc.eqNotOrdered(this, (Collection)obj); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableReadOnlyCollectionWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyTwoCollectionsWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyTwoCollectionsWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyTwoCollectionsWrapper.java new file mode 100644 index 0000000..5747d2c --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/GridSerializableReadOnlyTwoCollectionsWrapper.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.Iterator; +import org.apache.ignite.internal.util.GridSerializableCollection; +import org.apache.ignite.internal.util.GridSerializableIterator; +import org.apache.ignite.internal.util.lang.GridFunc; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.NotNull; + +/** + * Collections wrapper. + * A read-only view will be created over the element and given + * collections and no copying will happen. + * + * @param <T> Element type. + */ +public class GridSerializableReadOnlyTwoCollectionsWrapper<T> extends GridSerializableCollection<T> { + /** */ + private static final long serialVersionUID = 0L; + + /** First collection. */ + private final Collection<T> c1; + + /** SecondCollection. */ + private final Collection<T> c2; + + /** + * @param c1 First collection. + * @param c2 SecondCollection. + */ + public GridSerializableReadOnlyTwoCollectionsWrapper(Collection<T> c1, Collection<T> c2) { + this.c1 = c1; + this.c2 = c2; + } + + /** {@inheritDoc} */ + @NotNull + @Override public Iterator<T> iterator() { + return new GridSerializableIterator<T>() { + private Iterator<T> it1 = c1.iterator(); + private Iterator<T> it2 = c2.iterator(); + + @Override public boolean hasNext() { + if (it1 != null) + if (!it1.hasNext()) + it1 = null; + else + return true; + + return it2.hasNext(); + } + + @Override public T next() { + return it1 != null ? it1.next() : it2.next(); + } + + @Override public void remove() { + throw new UnsupportedOperationException(); + } + }; + } + + /** {@inheritDoc} */ + @Override public boolean contains(Object o) { + return c1.contains(o) || c2.contains(o); + } + + /** {@inheritDoc} */ + @Override public int size() { + return c1.size() + c2.size(); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + return obj instanceof Collection && GridFunc.eqNotOrdered(this, (Collection<?>)obj); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(GridSerializableReadOnlyTwoCollectionsWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableArrayListFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableArrayListFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableArrayListFactory.java new file mode 100644 index 0000000..017397d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableArrayListFactory.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.ArrayList; +import java.util.List; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Array list factory. + */ +public class IgniteCallableArrayListFactory implements IgniteCallable<List> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ArrayList call() { + return new ArrayList(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableArrayListFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicBooleanFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicBooleanFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicBooleanFactory.java new file mode 100644 index 0000000..a935471 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicBooleanFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic boolean factory. + */ +public class IgniteCallableAtomicBooleanFactory implements IgniteCallable<AtomicBoolean> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicBoolean call() { + return new AtomicBoolean(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableAtomicBooleanFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicIntegerFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicIntegerFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicIntegerFactory.java new file mode 100644 index 0000000..9a8df06 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicIntegerFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicInteger; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic integer factory. + */ +public class IgniteCallableAtomicIntegerFactory implements IgniteCallable<AtomicInteger> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicInteger call() { + return new AtomicInteger(0); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableAtomicIntegerFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicLongFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicLongFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicLongFactory.java new file mode 100644 index 0000000..7499c29 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicLongFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicLong; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic long factory. + */ +public class IgniteCallableAtomicLongFactory implements IgniteCallable<AtomicLong> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicLong call() { + return new AtomicLong(0); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableAtomicLongFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicReferenceFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicReferenceFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicReferenceFactory.java new file mode 100644 index 0000000..ed0ff58 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableAtomicReferenceFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.atomic.AtomicReference; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Atomic reference factory. + */ +public class IgniteCallableAtomicReferenceFactory implements IgniteCallable<AtomicReference> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public AtomicReference call() { + return new AtomicReference(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableAtomicReferenceFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashMapFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashMapFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashMapFactory.java new file mode 100644 index 0000000..ca50a0b --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashMapFactory.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.concurrent.ConcurrentMap; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; +import org.jsr166.ConcurrentHashMap8; + +/** + * Concurrent hash map factory. + */ +public class IgniteCallableConcurrentHashMapFactory implements IgniteCallable<ConcurrentMap> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ConcurrentMap call() { + return new ConcurrentHashMap8(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableConcurrentHashMapFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashSetFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashSetFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashSetFactory.java new file mode 100644 index 0000000..0a52e4d --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableConcurrentHashSetFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.GridConcurrentHashSet; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Concurrent hash set factory. + */ +public class IgniteCallableConcurrentHashSetFactory implements IgniteCallable<GridConcurrentHashSet> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public GridConcurrentHashSet call() { + return new GridConcurrentHashSet(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableConcurrentHashSetFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableDequeFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableDequeFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableDequeFactory.java new file mode 100644 index 0000000..9dcc3b5 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableDequeFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; +import org.jsr166.ConcurrentLinkedDeque8; + +/** + * Deque factory. + */ +public class IgniteCallableDequeFactory implements IgniteCallable<ConcurrentLinkedDeque8> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public ConcurrentLinkedDeque8 call() { + return new ConcurrentLinkedDeque8(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableDequeFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashMapFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashMapFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashMapFactory.java new file mode 100644 index 0000000..b361354 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashMapFactory.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.HashMap; +import java.util.Map; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Hash map factory. + */ +public class IgniteCallableHashMapFactory implements IgniteCallable<Map> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public Map call() { + return new HashMap(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableHashMapFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashSetFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashSetFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashSetFactory.java new file mode 100644 index 0000000..22d0d10 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableHashSetFactory.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.HashSet; +import java.util.Set; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Hash set factory. + */ +public class IgniteCallableHashSetFactory implements IgniteCallable<Set> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public Set call() { + return new HashSet(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableHashSetFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableLinkedListFactory.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableLinkedListFactory.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableLinkedListFactory.java new file mode 100644 index 0000000..34c4eab --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteCallableLinkedListFactory.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.LinkedList; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteCallable; + +/** + * Linked list factory. + */ +public class IgniteCallableLinkedListFactory implements IgniteCallable<LinkedList> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public LinkedList call() { + return new LinkedList(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteCallableLinkedListFactory.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGet.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGet.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGet.java new file mode 100644 index 0000000..2fef35e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGet.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.jetbrains.annotations.Nullable; + +/** + * Cache entry to get-value transformer closure. + */ +public class IgniteClosureCacheGet implements IgniteClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Nullable @Override public Object apply(Object o) { + return ((Cache.Entry)o).getValue(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureCacheGet.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGetKey.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGetKey.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGetKey.java new file mode 100644 index 0000000..e9cb267 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureCacheGetKey.java @@ -0,0 +1,40 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Map entry to key transformer closure. + */ +public class IgniteClosureCacheGetKey implements IgniteClosure { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public Object apply(Object o) { + return ((Cache.Entry)o).getKey(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureCacheGetKey.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId.java new file mode 100644 index 0000000..155b075 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Grid node to node ID transformer closure. + */ +public class IgniteClosureClusterNodeGetId implements IgniteClosure<ClusterNode, UUID> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public UUID apply(ClusterNode n) { + return n.id(); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureClusterNodeGetId.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId8.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId8.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId8.java new file mode 100644 index 0000000..af1641e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureClusterNodeGetId8.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Grid node to node ID8 transformer closure. + */ +public class IgniteClosureClusterNodeGetId8 implements IgniteClosure<ClusterNode, String> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public String apply(ClusterNode n) { + return U.id8(n.id()); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureClusterNodeGetId8.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureIdentity.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureIdentity.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureIdentity.java new file mode 100644 index 0000000..52d872a --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureIdentity.java @@ -0,0 +1,39 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; + +/** + * Identity closure. + */ +public class IgniteClosureIdentity implements IgniteClosure { + /** */ + private static final long serialVersionUID = -6338573080046225172L; + + /** {@inheritDoc} */ + @Override public Object apply(Object o) { + return o; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureIdentity.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureToString.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureToString.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureToString.java new file mode 100644 index 0000000..a5adfea --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureToString.java @@ -0,0 +1,42 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.C1; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.jetbrains.annotations.Nullable; + +/** + * Closure that return {@code toString()} value for its free variable. + * + * @param <T> Type of the free variable for the closure. + */ +public class IgniteClosureToString<T> implements C1<T, String> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public String apply(@Nullable T t) { + return String.valueOf(t); // This is null-safe. + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureToString.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureUUIDToId8Transformer.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureUUIDToId8Transformer.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureUUIDToId8Transformer.java new file mode 100644 index 0000000..fc5fc04 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteClosureUUIDToId8Transformer.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.UUID; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.internal.util.typedef.internal.U; +import org.apache.ignite.lang.IgniteClosure; + +/** + * UUID to ID8 transformer closure. + */ +public class IgniteClosureUUIDToId8Transformer implements IgniteClosure<UUID, String> { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @Override public String apply(UUID id) { + return U.id8(id); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteClosureUUIDToId8Transformer.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteOutClosureWrapper.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteOutClosureWrapper.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteOutClosureWrapper.java new file mode 100644 index 0000000..fdf1245 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgniteOutClosureWrapper.java @@ -0,0 +1,58 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgniteClosure; +import org.apache.ignite.lang.IgniteOutClosure; + +/** + * Wraps given closure. + * + * @param <T> Input type. + * @param <R> Output type. + */ +public class IgniteOutClosureWrapper<T, R> implements IgniteOutClosure<R> { + /** */ + private static final long serialVersionUID = 0L; + + /** */ + private final IgniteClosure<? super T, R> closure; + + /** */ + private final T closureArgument; + + /** + * @param closure Closure + * @param closureArgument Parameter + */ + public IgniteOutClosureWrapper(IgniteClosure<? super T, R> closure, T closureArgument) { + this.closure = closure; + this.closureArgument = closureArgument; + } + + /** {@inheritDoc} */ + @Override public R apply() { + return closure.apply(closureArgument); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgniteOutClosureWrapper.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysFalse.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysFalse.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysFalse.java new file mode 100644 index 0000000..297e749 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysFalse.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Defines a predicate which accepts a parameter and always returns {@code false} + * + * @param <E> Type of predicate parameter. + */ +public class IgnitePredicateAlwaysFalse<E> implements IgnitePredicate<E> { + /** */ + private static final long serialVersionUID = 0L; + + /** + * Predicate body. + * + * @param e Predicate parameter. + * @return Always <code>false</code> + */ + @Override public boolean apply(E e) { + return true; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgnitePredicateAlwaysFalse.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysTrue.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysTrue.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysTrue.java new file mode 100644 index 0000000..ff0f96e --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateAlwaysTrue.java @@ -0,0 +1,46 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Defines a predicate which accepts a parameter and always returns {@code true} + * + * @param <E> Type of predicate parameter. + */ +public class IgnitePredicateAlwaysTrue<E> implements IgnitePredicate<E> { + /** */ + private static final long serialVersionUID = 6101914246981105862L; + + /** + * Predicate body. + * + * @param e Predicate parameter. + * @return Always <code>true</code>. + */ + @Override public boolean apply(E e) { + return true; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgnitePredicateAlwaysTrue.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateCacheHasPeek.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateCacheHasPeek.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateCacheHasPeek.java new file mode 100644 index 0000000..b286f50 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateCacheHasPeek.java @@ -0,0 +1,41 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import javax.cache.Cache; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Cache entry has-peek-value predicate. + */ +public class IgnitePredicateCacheHasPeek implements IgnitePredicate { + /** */ + private static final long serialVersionUID = 0L; + + /** {@inheritDoc} */ + @SuppressWarnings({"unchecked"}) + @Override public boolean apply(Object o) { + return ((Cache.Entry)o).getValue() != null; + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgnitePredicateCacheHasPeek.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/9165b0d6/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateContainNodeId.java ---------------------------------------------------------------------- diff --git a/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateContainNodeId.java b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateContainNodeId.java new file mode 100644 index 0000000..0911e37 --- /dev/null +++ b/modules/core/src/main/java/org/apache/ignite/internal/util/lang/gridfunc/IgnitePredicateContainNodeId.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.util.lang.gridfunc; + +import java.util.Collection; +import java.util.UUID; +import org.apache.ignite.cluster.ClusterNode; +import org.apache.ignite.internal.util.typedef.internal.S; +import org.apache.ignite.lang.IgnitePredicate; + +/** + * Grid node predicate evaluating on the given node IDs. + */ +public class IgnitePredicateContainNodeId<T extends ClusterNode> implements IgnitePredicate<T> { + /** */ + private static final long serialVersionUID = -5664060422647374863L; + + /** */ + private final Collection<UUID> nodeIds; + + /** + * @param nodeIds (Collection) + */ + public IgnitePredicateContainNodeId(Collection<UUID> nodeIds) { + this.nodeIds = nodeIds; + } + + /** {@inheritDoc} */ + @Override public boolean apply(ClusterNode e) { + return nodeIds.contains(e.id()); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(IgnitePredicateContainNodeId.class, this); + } +}
