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

import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

/**
 * Container for various authentication data.
 */
public class UserAuthenticationData
{
    /**
     * Inner class to represent portions of the user authentication data.
     */
    public static class Type implements Comparable<Type>
    {
        /** The type name */
        private final String type;

        public Type(String type)
        {
            this.type = type;
        }

        @Override
        public boolean equals(Object o)
        {
            if (this == o)
            {
                return true;
            }
            if (o == null || getClass() != o.getClass())
            {
                return false;
            }

            Type type1 = (Type) o;

            if (type != null ? !type.equals(type1.type) : type1.type != null)
            {
                return false;
            }

            return true;
        }

        public int compareTo(Type o)
        {
            return type.compareTo(o.type);
        }

        /**
         * @return The hash code.
         * @since 2.0
         * */
        @Override
        public int hashCode()
        {
            return type != null ? type.hashCode() : 0;
        }

        /**
         * @return The type.
         * @since 2.0
         * */
        @Override
        public String toString()
        {
            return type;
        }
    }

    /** The user name. */
    public static final Type USERNAME = new Type("username");

    /** The password. */
    public static final Type PASSWORD = new Type("password");

    /** The user's domain. */
    public static final Type DOMAIN = new Type("domain");

    /** The authentication data. */
    private final Map<Type, char[]> authenticationData = new TreeMap<Type, char[]>();

    public UserAuthenticationData()
    {
    }

    /**
     * set a data to this collection.
     * @param type The Type to add
     * @param data The data associated with the Type
     */
    public void setData(Type type, char[] data)
    {
        authenticationData.put(type, data);
    }

    /**
     * get a data from the collection.
     * @param type The Type to retrieve.
     * @return a character array containing the data associated with the type.
     */
    public char[] getData(Type type)
    {
        return authenticationData.get(type);
    }

    /**
     * deleted all data stored within this authenticator.
     */
    public void cleanup()
    {
        // step 1: nullify character buffers
        Iterator<char[]> iterAuthenticationData = authenticationData.values().iterator();
        while (iterAuthenticationData.hasNext())
        {
            char[] data = iterAuthenticationData.next();
            if (data == null || data.length < 0)
            {
                continue;
            }

            for (int i = 0; i < data.length; i++)
            {
                data[i] = 0;
            }
        }
        // step 2: allow data itself to gc
        authenticationData.clear();
    }
}

@@ -924,14 +924,9 @@
 tain
-er for
+s
  var
@@ -1012,48 +1012,20 @@
   * 
-Inner class to represent portions of the
+Represents a
  use
@@ -1041,20 +1041,20 @@
 ication 
-data
+item
 .%0A     *
@@ -1183,16 +1183,114 @@
  type;%0A%0A
+        /**%0A         * Creates a new Type%0A         * %0A         * @param type the type%0A         */%0A
         
@@ -2714,24 +2714,85 @@
 char%5B%5D%3E();%0A%0A
+    /**%0A     * Creates a new uninitialized instance.%0A     */%0A
     public U
@@ -2817,24 +2817,46 @@
 ata()%0A    %7B%0A
+        // do nothing%0A
     %7D%0A%0A    /
@@ -2865,19 +2865,20 @@
 %0A     * 
-s
+S
 et
+s
  a data 
@@ -3113,19 +3113,20 @@
 %0A     * 
-g
+G
 et
+s
  a data 
@@ -3388,15 +3388,15 @@
   * 
-d
+D
 elete
-d
+s
  all

Jaavdoc.