Java tutorial
/* * Copyright (C) 2008 feilong * * Licensed 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 com.feilong.core.util; import java.util.Enumeration; import org.apache.commons.collections4.IteratorUtils; import org.apache.commons.collections4.iterators.EnumerationIterator; import static com.feilong.core.Validator.isNullOrEmpty; /** * {@link Enumeration}. * * <p> * {@link Enumeration}?JDK 1.0,?,Vector{@link Enumeration}?<br> * {@link Enumeration},JDK1.5?Enumeration,? * </p> * * <h3>?{@link Enumeration}?</h3> * * <blockquote> * <p> * {@link Enumeration}Iterator??,{@link Enumeration}??? ???,?{@link Enumeration} * </p> * <p> * ??{@link Enumeration}?<br> * Java??,??(,Web??){@link Enumeration}?,??? * </p> * <p> * IteratorJDK1.2??,HashMap?ArrayList??????<br> * Iterator?fail-fast:???,?fail-fast * </p> * </blockquote> * * @author <a href="http://feitianbenyue.iteye.com/">feilong</a> * @see org.apache.commons.collections4.EnumerationUtils * @since 1.5.3 */ public final class EnumerationUtil { /** Don't let anyone instantiate this class. */ private EnumerationUtil() { //AssertionError?. ?????. ???. //see Effective Java 2nd throw new AssertionError("No " + getClass().getName() + " instances for you!"); } /** * <code>enumeration</code>?,?<code>value</code>. * * @param <O> * the generic type * @param enumeration * the enumeration * @param value * * @return <code>enumeration</code> nullempty, false<br> * ? contains true,<br> * false * @see "org.springframework.util.CollectionUtils#contains(Enumeration, Object)" * @see org.apache.commons.collections4.iterators.EnumerationIterator * @see org.apache.commons.collections4.IteratorUtils#contains(java.util.Iterator, Object) */ public static <O> boolean contains(Enumeration<O> enumeration, O value) { return isNullOrEmpty(enumeration) ? false : IteratorUtils.contains(new EnumerationIterator<O>(enumeration), value); } }