Moved CollectionUtils back to shiro-core It really should stay in lang, but we cannot move it until 2.0 due to its dependency on PrincipalCollection
Project: http://git-wip-us.apache.org/repos/asf/shiro/repo Commit: http://git-wip-us.apache.org/repos/asf/shiro/commit/d44204a4 Tree: http://git-wip-us.apache.org/repos/asf/shiro/tree/d44204a4 Diff: http://git-wip-us.apache.org/repos/asf/shiro/diff/d44204a4 Branch: refs/heads/master Commit: d44204a4378f73e17be2e58097ba09d33c1cff3e Parents: 3a23929 Author: Brian Demers <[email protected]> Authored: Mon Nov 7 13:25:31 2016 -0500 Committer: Brian Demers <[email protected]> Committed: Mon Nov 7 16:49:38 2016 -0500 ---------------------------------------------------------------------- .../java/org/apache/shiro/cache/MapCache.java | 4 +- .../main/java/org/apache/shiro/config/Ini.java | 3 +- .../apache/shiro/config/ReflectionBuilder.java | 20 ++- .../shiro/config/ReflectionBuilderTest.groovy | 29 ++-- core/pom.xml | 4 - .../org/apache/shiro/util/CollectionUtils.java | 141 +++++++++++++++++++ .../main/java/org/apache/shiro/util/Assert.java | 18 ++- .../org/apache/shiro/util/CollectionUtils.java | 124 ---------------- .../java/org/apache/shiro/util/StringUtils.java | 22 ++- .../org/apache/shiro/cache/ehcache/EhCache.java | 14 +- 10 files changed, 221 insertions(+), 158 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/cache/src/main/java/org/apache/shiro/cache/MapCache.java ---------------------------------------------------------------------- diff --git a/cache/src/main/java/org/apache/shiro/cache/MapCache.java b/cache/src/main/java/org/apache/shiro/cache/MapCache.java index 04db6ec..024f5ef 100644 --- a/cache/src/main/java/org/apache/shiro/cache/MapCache.java +++ b/cache/src/main/java/org/apache/shiro/cache/MapCache.java @@ -18,8 +18,6 @@ */ package org.apache.shiro.cache; -import org.apache.shiro.util.CollectionUtils; - import java.util.Collection; import java.util.Collections; import java.util.Map; @@ -84,7 +82,7 @@ public class MapCache<K, V> implements Cache<K, V> { public Collection<V> values() { Collection<V> values = map.values(); - if (!CollectionUtils.isEmpty(values)) { + if (!map.isEmpty()) { return Collections.unmodifiableCollection(values); } return Collections.emptySet(); http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/config/core/src/main/java/org/apache/shiro/config/Ini.java ---------------------------------------------------------------------- diff --git a/config/core/src/main/java/org/apache/shiro/config/Ini.java b/config/core/src/main/java/org/apache/shiro/config/Ini.java index 46bdce4..d3d93cd 100644 --- a/config/core/src/main/java/org/apache/shiro/config/Ini.java +++ b/config/core/src/main/java/org/apache/shiro/config/Ini.java @@ -19,7 +19,6 @@ package org.apache.shiro.config; import org.apache.shiro.io.ResourceUtils; -import org.apache.shiro.util.CollectionUtils; import org.apache.shiro.util.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -438,7 +437,7 @@ public class Ini implements Map<String, Ini.Section> { } public String toString() { - if (CollectionUtils.isEmpty(this.sections)) { + if (this.sections == null || this.sections.isEmpty()) { return "<empty INI>"; } else { StringBuilder sb = new StringBuilder("sections="); http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java ---------------------------------------------------------------------- diff --git a/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java b/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java index b2da6a8..a39cc02 100644 --- a/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java +++ b/config/ogdl/src/main/java/org/apache/shiro/config/ReflectionBuilder.java @@ -34,7 +34,6 @@ import org.apache.shiro.event.support.DefaultEventBus; import org.apache.shiro.util.Assert; import org.apache.shiro.util.ByteSource; import org.apache.shiro.util.ClassUtils; -import org.apache.shiro.util.CollectionUtils; import org.apache.shiro.util.Factory; import org.apache.shiro.util.LifecycleUtils; import org.apache.shiro.util.Nameable; @@ -126,7 +125,7 @@ public class ReflectionBuilder { } private void apply(Map<String, ?> objects) { - if(!CollectionUtils.isEmpty(objects)) { + if(!isEmpty(objects)) { this.objects.putAll(objects); } EventBus found = findEventBus(this.objects); @@ -183,13 +182,13 @@ public class ReflectionBuilder { //@since 1.3 private boolean isEventSubscriber(Object bean, String name) { List annotatedMethods = ClassUtils.getAnnotatedMethods(bean.getClass(), Subscribe.class); - return !CollectionUtils.isEmpty(annotatedMethods); + return !isEmpty(annotatedMethods); } //@since 1.3 protected EventBus findEventBus(Map<String,?> objects) { - if (CollectionUtils.isEmpty(objects)) { + if (isEmpty(objects)) { return null; } @@ -989,4 +988,17 @@ public class ReflectionBuilder { } } + ////////////////////////// + // From CollectionUtils // + ////////////////////////// + // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a dependency on PrincipalCollection + + private static boolean isEmpty(Map m) { + return m == null || m.isEmpty(); + } + + private static boolean isEmpty(Collection c) { + return c == null || c.isEmpty(); + } + } http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/config/ogdl/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy ---------------------------------------------------------------------- diff --git a/config/ogdl/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy b/config/ogdl/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy index 5b12d4c..211e2fa 100644 --- a/config/ogdl/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy +++ b/config/ogdl/src/test/groovy/org/apache/shiro/config/ReflectionBuilderTest.groovy @@ -22,7 +22,6 @@ import org.apache.shiro.codec.Base64 import org.apache.shiro.codec.CodecSupport import org.apache.shiro.codec.Hex import org.apache.shiro.config.event.BeanEvent -import org.apache.shiro.util.CollectionUtils import org.junit.Test import static org.junit.Assert.* @@ -277,7 +276,7 @@ class ReflectionBuilderTest { defs.put("compositeBean.simpleBeanSet", '$simpleBean1, $simpleBean2, $simpleBean2'); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); Set<SimpleBean> simpleBeans = cBean.getSimpleBeanSet(); @@ -297,7 +296,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(['set': set]); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); Set<SimpleBean> simpleBeans = cBean.getSimpleBeanSet(); @@ -318,7 +317,7 @@ class ReflectionBuilderTest { defs.put("compositeBean.simpleBeanList", '$simpleBean1, $simpleBean2, $simpleBean2'); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); List<SimpleBean> simpleBeans = cBean.getSimpleBeanList(); @@ -338,7 +337,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(['list': list]); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); def simpleBeans = cBean.getSimpleBeanList(); @@ -358,7 +357,7 @@ class ReflectionBuilderTest { defs.put("compositeBean.simpleBeanCollection", '$simpleBean1, $simpleBean2, $simpleBean2'); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); Collection<SimpleBean> simpleBeans = cBean.getSimpleBeanCollection(); @@ -379,7 +378,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(['collection': c]); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); def simpleBeans = cBean.getSimpleBeanCollection(); @@ -403,7 +402,7 @@ class ReflectionBuilderTest { defs.put("simpleBean.byteArrayProp", hexValue); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) SimpleBean bean = (SimpleBean) objects.get("simpleBean"); assertNotNull(bean); byte[] beanBytes = bean.getByteArrayProp(); @@ -440,7 +439,7 @@ class ReflectionBuilderTest { defs.put("compositeBean.simpleBeanMap", 'simpleBean1:$simpleBean1, simpleBean2:$simpleBean2'); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); Map map = cBean.getSimpleBeanMap(); @@ -464,7 +463,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(['map': map]); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); def simpleBeansMap = cBean.getSimpleBeanMap(); @@ -486,7 +485,7 @@ class ReflectionBuilderTest { defs.put("compositeBean.simpleBean.simpleBeans", '$simpleBean2, $simpleBean3'); ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean cBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(cBean); SimpleBean nested = cBean.getSimpleBean(); @@ -519,7 +518,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean compositeBean = (CompositeBean) objects.get("compositeBean"); SimpleBean bean = compositeBean.getSimpleBean(); assertNotNull(bean); @@ -546,7 +545,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(); Map<String, ?> objects = builder.buildObjects(ini.getSections().iterator().next()); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) assertInstantiatedEvents("listenerOne", objects, 4) //3 beans following + its own instantiated event assertConfiguredEvents("listenerOne", objects, 4) //3 beans following + its own configured event @@ -578,7 +577,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean compositeBean = (CompositeBean) objects.get("compositeBean"); SimpleBean bean = compositeBean.getSimpleBean(); assertNotNull(bean); @@ -604,7 +603,7 @@ class ReflectionBuilderTest { ReflectionBuilder builder = new ReflectionBuilder(); Map objects = builder.buildObjects(defs); - assertFalse(CollectionUtils.isEmpty(objects)); + assertThat(objects, aMapWithSize(greaterThan(0))) CompositeBean compositeBean = (CompositeBean) objects.get("compositeBean"); assertNotNull(compositeBean); http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/core/pom.xml ---------------------------------------------------------------------- diff --git a/core/pom.xml b/core/pom.xml index a9343c5..39ea570 100644 --- a/core/pom.xml +++ b/core/pom.xml @@ -93,10 +93,6 @@ <groupId>org.apache.shiro</groupId> <artifactId>shiro-event</artifactId> </dependency> - <dependency> - <groupId>org.slf4j</groupId> - <artifactId>slf4j-api</artifactId> - </dependency> <!-- Test dependencies --> <dependency> http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/core/src/main/java/org/apache/shiro/util/CollectionUtils.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/shiro/util/CollectionUtils.java b/core/src/main/java/org/apache/shiro/util/CollectionUtils.java new file mode 100644 index 0000000..67fc5c9 --- /dev/null +++ b/core/src/main/java/org/apache/shiro/util/CollectionUtils.java @@ -0,0 +1,141 @@ +/* + * 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.shiro.util; + +import org.apache.shiro.subject.PrincipalCollection; + +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** + * Static helper class for use dealing with Collections. + * + * @since 0.9 + */ +public class CollectionUtils { + + //TODO - complete JavaDoc + + public static <E> Set<E> asSet(E... elements) { + if (elements == null || elements.length == 0) { + return Collections.emptySet(); + } + + if (elements.length == 1) { + return Collections.singleton(elements[0]); + } + + LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); + Collections.addAll(set, elements); + return set; + } + + /** + * Returns {@code true} if the specified {@code Collection} is {@code null} or {@link Collection#isEmpty empty}, + * {@code false} otherwise. + * + * @param c the collection to check + * @return {@code true} if the specified {@code Collection} is {@code null} or {@link Collection#isEmpty empty}, + * {@code false} otherwise. + * @since 1.0 + */ + public static boolean isEmpty(Collection c) { + return c == null || c.isEmpty(); + } + + /** + * Returns {@code true} if the specified {@code Map} is {@code null} or {@link Map#isEmpty empty}, + * {@code false} otherwise. + * + * @param m the {@code Map} to check + * @return {@code true} if the specified {@code Map} is {@code null} or {@link Map#isEmpty empty}, + * {@code false} otherwise. + * @since 1.0 + */ + public static boolean isEmpty(Map m) { + return m == null || m.isEmpty(); + } + + /** + * Returns the size of the specified collection or {@code 0} if the collection is {@code null}. + * + * @param c the collection to check + * @return the size of the specified collection or {@code 0} if the collection is {@code null}. + * @since 1.2 + */ + public static int size(Collection c) { + return c != null ? c.size() : 0; + } + + /** + * Returns the size of the specified map or {@code 0} if the map is {@code null}. + * + * @param m the map to check + * @return the size of the specified map or {@code 0} if the map is {@code null}. + * @since 1.2 + */ + public static int size(Map m) { + return m != null ? m.size() : 0; + } + + + /** + * Returns {@code true} if the specified {@code PrincipalCollection} is {@code null} or + * {@link PrincipalCollection#isEmpty empty}, {@code false} otherwise. + * + * @param principals the principals to check. + * @return {@code true} if the specified {@code PrincipalCollection} is {@code null} or + * {@link PrincipalCollection#isEmpty empty}, {@code false} otherwise. + * @since 1.0 + * @deprecated Use PrincipalCollection.isEmpty() directly. + */ + @Deprecated + public static boolean isEmpty(PrincipalCollection principals) { + return principals == null || principals.isEmpty(); + } + + public static <E> List<E> asList(E... elements) { + if (elements == null || elements.length == 0) { + return Collections.emptyList(); + } + + // Integer overflow does not occur when a large array is passed in because the list array already exists + return Arrays.asList(elements); + } + + /*public static <E> Deque<E> asDeque(E... elements) { + if (elements == null || elements.length == 0) { + return new ArrayDeque<E>(); + } + // Avoid integer overflow when a large array is passed in + int capacity = computeListCapacity(elements.length); + ArrayDeque<E> deque = new ArrayDeque<E>(capacity); + Collections.addAll(deque, elements); + return deque; + }*/ + + static int computeListCapacity(int arraySize) { + return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE); + } +} http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/lang/src/main/java/org/apache/shiro/util/Assert.java ---------------------------------------------------------------------- diff --git a/lang/src/main/java/org/apache/shiro/util/Assert.java b/lang/src/main/java/org/apache/shiro/util/Assert.java index d580247..689f720 100644 --- a/lang/src/main/java/org/apache/shiro/util/Assert.java +++ b/lang/src/main/java/org/apache/shiro/util/Assert.java @@ -270,7 +270,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the collection is <code>null</code> or has no elements */ public static void notEmpty(Collection collection, String message) { - if (CollectionUtils.isEmpty(collection)) { + if (isEmpty(collection)) { throw new IllegalArgumentException(message); } } @@ -296,7 +296,7 @@ public abstract class Assert { * @throws IllegalArgumentException if the map is <code>null</code> or has no entries */ public static void notEmpty(Map map, String message) { - if (CollectionUtils.isEmpty(map)) { + if (isEmpty(map)) { throw new IllegalArgumentException(message); } } @@ -404,4 +404,18 @@ public abstract class Assert { state(expression, "[Assertion failed] - this state invariant must be true"); } + + ////////////////////////// + // From CollectionUtils // + ////////////////////////// + // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a dependency on PrincipalCollection + + private static boolean isEmpty(Map m) { + return m == null || m.isEmpty(); + } + + private static boolean isEmpty(Collection c) { + return c == null || c.isEmpty(); + } + } http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java ---------------------------------------------------------------------- diff --git a/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java b/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java deleted file mode 100644 index 67e9901..0000000 --- a/lang/src/main/java/org/apache/shiro/util/CollectionUtils.java +++ /dev/null @@ -1,124 +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.shiro.util; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.LinkedHashSet; -import java.util.List; -import java.util.Map; -import java.util.Set; - -/** - * Static helper class for use dealing with Collections. - * - * @since 0.9 - */ -public class CollectionUtils { - - //TODO - complete JavaDoc - - public static <E> Set<E> asSet(E... elements) { - if (elements == null || elements.length == 0) { - return Collections.emptySet(); - } - - if (elements.length == 1) { - return Collections.singleton(elements[0]); - } - - LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); - Collections.addAll(set, elements); - return set; - } - - /** - * Returns {@code true} if the specified {@code Collection} is {@code null} or {@link Collection#isEmpty empty}, - * {@code false} otherwise. - * - * @param c the collection to check - * @return {@code true} if the specified {@code Collection} is {@code null} or {@link Collection#isEmpty empty}, - * {@code false} otherwise. - * @since 1.0 - */ - public static boolean isEmpty(Collection c) { - return c == null || c.isEmpty(); - } - - /** - * Returns {@code true} if the specified {@code Map} is {@code null} or {@link Map#isEmpty empty}, - * {@code false} otherwise. - * - * @param m the {@code Map} to check - * @return {@code true} if the specified {@code Map} is {@code null} or {@link Map#isEmpty empty}, - * {@code false} otherwise. - * @since 1.0 - */ - public static boolean isEmpty(Map m) { - return m == null || m.isEmpty(); - } - - /** - * Returns the size of the specified collection or {@code 0} if the collection is {@code null}. - * - * @param c the collection to check - * @return the size of the specified collection or {@code 0} if the collection is {@code null}. - * @since 1.2 - */ - public static int size(Collection c) { - return c != null ? c.size() : 0; - } - - /** - * Returns the size of the specified map or {@code 0} if the map is {@code null}. - * - * @param m the map to check - * @return the size of the specified map or {@code 0} if the map is {@code null}. - * @since 1.2 - */ - public static int size(Map m) { - return m != null ? m.size() : 0; - } - - - public static <E> List<E> asList(E... elements) { - if (elements == null || elements.length == 0) { - return Collections.emptyList(); - } - - // Integer overflow does not occur when a large array is passed in because the list array already exists - return Arrays.asList(elements); - } - - /*public static <E> Deque<E> asDeque(E... elements) { - if (elements == null || elements.length == 0) { - return new ArrayDeque<E>(); - } - // Avoid integer overflow when a large array is passed in - int capacity = computeListCapacity(elements.length); - ArrayDeque<E> deque = new ArrayDeque<E>(capacity); - Collections.addAll(deque, elements); - return deque; - }*/ - - static int computeListCapacity(int arraySize) { - return (int) Math.min(5L + arraySize + (arraySize / 10), Integer.MAX_VALUE); - } -} http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/lang/src/main/java/org/apache/shiro/util/StringUtils.java ---------------------------------------------------------------------- diff --git a/lang/src/main/java/org/apache/shiro/util/StringUtils.java b/lang/src/main/java/org/apache/shiro/util/StringUtils.java index 15fd9e1..70ee06d 100644 --- a/lang/src/main/java/org/apache/shiro/util/StringUtils.java +++ b/lang/src/main/java/org/apache/shiro/util/StringUtils.java @@ -475,7 +475,7 @@ public class StringUtils { return null; } String[] split = split(delimited, separator.charAt(0)); - return CollectionUtils.asSet(split); + return asSet(split); } /** @@ -499,4 +499,24 @@ public class StringUtils { return sb.toString(); } + ////////////////////////// + // From CollectionUtils // + ////////////////////////// + // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a dependency on PrincipalCollection + + + private static <E> Set<E> asSet(E... elements) { + if (elements == null || elements.length == 0) { + return Collections.emptySet(); + } + + if (elements.length == 1) { + return Collections.singleton(elements[0]); + } + + LinkedHashSet<E> set = new LinkedHashSet<E>(elements.length * 4 / 3 + 1); + Collections.addAll(set, elements); + return set; + } + } http://git-wip-us.apache.org/repos/asf/shiro/blob/d44204a4/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java ---------------------------------------------------------------------- diff --git a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java index 9393e74..c8a3be8 100644 --- a/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java +++ b/support/ehcache/src/main/java/org/apache/shiro/cache/ehcache/EhCache.java @@ -21,7 +21,6 @@ package org.apache.shiro.cache.ehcache; import net.sf.ehcache.Element; import org.apache.shiro.cache.Cache; import org.apache.shiro.cache.CacheException; -import org.apache.shiro.util.CollectionUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -152,7 +151,7 @@ public class EhCache<K, V> implements Cache<K, V> { try { @SuppressWarnings({"unchecked"}) List<K> keys = cache.getKeys(); - if (!CollectionUtils.isEmpty(keys)) { + if (!isEmpty(keys)) { return Collections.unmodifiableSet(new LinkedHashSet<K>(keys)); } else { return Collections.emptySet(); @@ -166,7 +165,7 @@ public class EhCache<K, V> implements Cache<K, V> { try { @SuppressWarnings({"unchecked"}) List<K> keys = cache.getKeys(); - if (!CollectionUtils.isEmpty(keys)) { + if (!isEmpty(keys)) { List<V> values = new ArrayList<V>(keys.size()); for (K key : keys) { V value = get(key); @@ -238,4 +237,13 @@ public class EhCache<K, V> implements Cache<K, V> { public String toString() { return "EhCache [" + cache.getName() + "]"; } + + ////////////////////////// + // From CollectionUtils // + ////////////////////////// + // CollectionUtils cannot be removed from shiro-core until 2.0 as it has a dependency on PrincipalCollection + + private static boolean isEmpty(Collection c) { + return c == null || c.isEmpty(); + } }
