/*
 * 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.Iterator;

import com.feilong.core.Validator;

/**
 * {@link Iterator} 工具类.
 *
 * @author feilong
 * @version 1.5.3 2016年4月18日 上午2:50:15
 * @see org.apache.commons.collections4.IteratorUtils
 * @since 1.5.3
 */
public final class IteratorUtil{

    /** Don't let anyone instantiate this class. */
    private IteratorUtil(){
        //AssertionError不是必须的. 但它可以避免不小心在类的内部调用构造器. 保证该类在任何情况下都不会被实例化.
        //see 《Effective Java》 2nd
        throw new AssertionError("No " + getClass().getName() + " instances for you!");
    }

    /**
     * iterator是否包含某个值.
     * 
     * <p style="color:red">
     * 注意,比较的是 {@link java.lang.Object#toString()},常常用于自定义标签或者el function
     * </p>
     * 
     * @param iterator
     *            iterator
     * @param value
     *            value
     * @return iterator是否包含某个值,如果iterator为null/empty,则返回false
     * @see Iterator#hasNext()
     * @see Iterator#next()
     * @see "org.springframework.util.CollectionUtils#contains(Iterator, Object)"
     * @see org.apache.commons.collections4.IteratorUtils#contains(Iterator, Object)
     * @deprecated 由于该方法内部实现比较特殊,将可能会移到tag里面去,
     */
    @Deprecated
    public static boolean contains(Iterator<?> iterator,Object value){
        if (Validator.isNullOrEmpty(iterator)){
            return false;
        }
        while (iterator.hasNext()){
            Object object = iterator.next();
            if (object.toString().equals(value.toString())){
                return true;
            }
        }
        return false;
    }
}

@@ -650,16 +650,88 @@
 terator;
+%0Aimport java.util.Objects;%0A%0Aimport org.apache.commons.lang3.StringUtils;
 %0A%0Aimport
@@ -1254,24 +1254,26 @@
 %0A     * 
+%E8%BF%AD%E4%BB%A3
 iterator
 %E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%9F%90%E4%B8%AA%E5%80%BC.
@@ -1264,23 +1264,59 @@
 iterator
-%E6%98%AF%E5%90%A6%E5%8C%85%E5%90%AB%E6%9F%90%E4%B8%AA%E5%80%BC
+,%E5%88%A4%E6%96%AD%E5%85%83%E7%B4%A0%E7%9A%84 %E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5%BC%8F %E6%98%AF%E5%90%A6%E5%92%8C%E4%BC%A0%E5%85%A5%E7%9A%84%E5%80%BC %7B@code value%7D %E7%9A%84%E5%AD%97%E7%AC%A6%E4%B8%B2%E6%A0%BC%E5%BC%8F%E7%9B%B8%E7%AD%89
 .%0A     *
@@ -1377,19 +1377,20 @@
 ava.
-lang
+util
 .Object
+s
 #toS
@@ -1395,16 +1395,30 @@
 oString(
+Object, String
 )%7D,%E5%B8%B8%E5%B8%B8%E7%94%A8%E4%BA%8E%E8%87%AA
@@ -1847,72 +1847,9 @@
    *
- @deprecated %E7%94%B1%E4%BA%8E%E8%AF%A5%E6%96%B9%E6%B3%95%E5%86%85%E9%83%A8%E5%AE%9E%E7%8E%B0%E6%AF%94%E8%BE%83%E7%89%B9%E6%AE%8A,%E5%B0%86%E5%8F%AF%E8%83%BD%E4%BC%9A%E7%A7%BB%E5%88%B0tag%E9%87%8C%E9%9D%A2%E5%8E%BB,%0A     */%0A    @Deprecated
+/
 %0A   
@@ -1871,32 +1871,45 @@
 boolean contains
+ByStringValue
 (Iterator%3C?%3E ite
@@ -2110,18 +2110,226 @@
     
-if (o
+//%E6%B3%A8%E6%84%8F: %E5%A6%82%E6%9E%9Cnull ,java.util.Objects#toString(Object),%E8%BF%94%E5%9B%9E %22null%22 %E5%92%8C  java.lang.String#valueOf(Object) %E4%B8%80%E6%A0%B7%0A            //%E8%80%8C org.apache.commons.lang3.ObjectUtils#toString(Object) %E8%BF%94%E5%9B%9E  %22%22  empty%0A            boolean equals = O
 bject
+s
 .toS
@@ -2334,16 +2334,41 @@
 oString(
+object, StringUtils.EMPTY
 ).equals
@@ -2368,21 +2368,23 @@
 .equals(
-value
+Objects
 .toStrin
@@ -2385,18 +2385,66 @@
 oString(
-))
+value, StringUtils.EMPTY));%0A            if (equals
 )%7B%0A     

update IteratorUtil.'boolean contains(Iterator<?> iterator,Object value)' to IteratorUtil.'boolean containsByStringValue(Iterator<?> iterator,Object value)'