// Path: plugin-lib/src/java/net/stevechaloner/idea/util/properties/converters/Converter.java
// public interface Converter<T>
// {
//     /**
//      * Encapsulate the given object in an {@link Element}.  If the
//      * given object can't be converted to a valid string, its default
//      * value will be used.
//      *
//      * @param name the name of the element
//      * @param t the object to encapsulate
//      * @return an element containing a string representation of the given object
//      */
//     @NotNull
//     Element toElement(@NotNull @NonNls String name,
//                       @Nullable T t);
// 
//     /**
//      * Convert the given object to a string.  If the object
//      * cannot be converted, an empty string is returned.
//      *
//      * @param t the object to convert
//      * @return a string representation of the object.
//      */
//     @NotNull
//     String toString(@Nullable T t);
// 
//     /**
//      * Convert the string to the required type.  If the string cannot
//      * be converted, the default value of the type will be returned.
//      *
//      * @param s the string to convert
//      * @return an object created from the string
//      */
//     @NotNull
//     T toType(@Nullable String s);
// 
//     /**
//      * Convert the string value encapsulated in the element to the
//      * required type.  If the string cannot be converted, the default
//      * value of the type will be returned.
//      *
//      * @param e the element containing the value
//      * @return an object created from the encapsulated string
//      */
//     @NotNull
//     T toType(@Nullable Element e);
// 
//     /**
//      * Gets the content type the converter works with.
//      *
//      * @return the content type
//      */
//     DOMableCollectionContentType getContentType();
// }
// 
// Path: plugin-lib/src/java/net/stevechaloner/idea/util/properties/converters/ConverterFactory.java
// public class ConverterFactory
// {
//     private static final Converter<Boolean> BOOLEAN_CONVERTER = new AbstractConverter<Boolean>()
//     {
//         @NotNull
//         public String toString(@Nullable Boolean t)
//         {
//             return t == null ? Boolean.FALSE.toString() : t.toString();
//         }
// 
//         @NotNull
//         public Boolean toType(@Nullable String s)
//         {
//             return Boolean.parseBoolean(s);
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.BOOLEAN;
//         }
//     };
// 
//     private static final Converter<Integer> INTEGER_CONVERTER = new AbstractConverter<Integer>()
//     {
//         private final Integer standardInteger = 0;
// 
//         @NotNull
//         public String toString(@Nullable Integer t)
//         {
//             return t == null ? standardInteger.toString() : t.toString();
//         }
// 
//         @NotNull
//         public Integer toType(@Nullable String s)
//         {
//             Integer i = standardInteger;
//             if (s != null)
//             {
//                 try
//                 {
//                    i = Integer.parseInt(s);
//                 }
//                 catch (NumberFormatException e)
//                 {
//                     i = standardInteger;
//                 }
//             }
//             return i;
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.INTEGER;
//         }
//     };
// 
//     private static final Converter<String> STRING_CONVERTER = new AbstractConverter<String>()
//     {
//         @NotNull
//         public String toString(@Nullable String t)
//         {
//             return t == null ?  "" : t;
//         }
// 
//         @NotNull
//         public String toType(@Nullable String s)
//         {
//             return toString(s);
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.STRING;
//         }
//     };
// 
//     private ConverterFactory(){}
// 
//     public static Converter<Boolean> getBooleanConverter()
//     {
//         return BOOLEAN_CONVERTER;
//     }
// 
//     public static Converter<Integer> getIntegerConverter()
//     {
//         return INTEGER_CONVERTER;
//     }
// 
//     public static Converter<String> getStringConverter()
//     {
//         return STRING_CONVERTER;
//     }
// }


import net.stevechaloner.idea.util.properties.converters.Converter;
import net.stevechaloner.idea.util.properties.converters.ConverterFactory;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/*
 * Copyright 2007 Steve Chaloner
 *
 * 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 net.stevechaloner.idea.util.properties;



/**
 * @author Steve Chaloner
 */
public class DOMableMap<V> extends AbstractDOMableCollection<V>
{
    /**
     * The standard name of a persisted item.
     */
    private static final String ELEMENT_NAME = "item";

    /**
     * The standard name of a persisted key.
     */
    private static final String KEY_NAME = "key";

    /**
     * The standard name of a persisted value.
     */
    private static final String VALUE_NAME = "value";

    private static final Converter<String> KEY_CONVERTER = ConverterFactory.getStringConverter();

    /**
     * The map.
     */
    private final Map<String, V> map = new HashMap<String, V>();

    /**
     * Initialises a new instance of this class.
     *
     * @param propertyDescriptor the property descriptor of the map
     * @param converter the persistence converter for values
     */
    public DOMableMap(@NotNull PropertyDescriptor propertyDescriptor,
// Path: plugin-lib/src/java/net/stevechaloner/idea/util/properties/converters/Converter.java
// public interface Converter<T>
// {
//     /**
//      * Encapsulate the given object in an {@link Element}.  If the
//      * given object can't be converted to a valid string, its default
//      * value will be used.
//      *
//      * @param name the name of the element
//      * @param t the object to encapsulate
//      * @return an element containing a string representation of the given object
//      */
//     @NotNull
//     Element toElement(@NotNull @NonNls String name,
//                       @Nullable T t);
// 
//     /**
//      * Convert the given object to a string.  If the object
//      * cannot be converted, an empty string is returned.
//      *
//      * @param t the object to convert
//      * @return a string representation of the object.
//      */
//     @NotNull
//     String toString(@Nullable T t);
// 
//     /**
//      * Convert the string to the required type.  If the string cannot
//      * be converted, the default value of the type will be returned.
//      *
//      * @param s the string to convert
//      * @return an object created from the string
//      */
//     @NotNull
//     T toType(@Nullable String s);
// 
//     /**
//      * Convert the string value encapsulated in the element to the
//      * required type.  If the string cannot be converted, the default
//      * value of the type will be returned.
//      *
//      * @param e the element containing the value
//      * @return an object created from the encapsulated string
//      */
//     @NotNull
//     T toType(@Nullable Element e);
// 
//     /**
//      * Gets the content type the converter works with.
//      *
//      * @return the content type
//      */
//     DOMableCollectionContentType getContentType();
// }
// 
// Path: plugin-lib/src/java/net/stevechaloner/idea/util/properties/converters/ConverterFactory.java
// public class ConverterFactory
// {
//     private static final Converter<Boolean> BOOLEAN_CONVERTER = new AbstractConverter<Boolean>()
//     {
//         @NotNull
//         public String toString(@Nullable Boolean t)
//         {
//             return t == null ? Boolean.FALSE.toString() : t.toString();
//         }
// 
//         @NotNull
//         public Boolean toType(@Nullable String s)
//         {
//             return Boolean.parseBoolean(s);
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.BOOLEAN;
//         }
//     };
// 
//     private static final Converter<Integer> INTEGER_CONVERTER = new AbstractConverter<Integer>()
//     {
//         private final Integer standardInteger = 0;
// 
//         @NotNull
//         public String toString(@Nullable Integer t)
//         {
//             return t == null ? standardInteger.toString() : t.toString();
//         }
// 
//         @NotNull
//         public Integer toType(@Nullable String s)
//         {
//             Integer i = standardInteger;
//             if (s != null)
//             {
//                 try
//                 {
//                    i = Integer.parseInt(s);
//                 }
//                 catch (NumberFormatException e)
//                 {
//                     i = standardInteger;
//                 }
//             }
//             return i;
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.INTEGER;
//         }
//     };
// 
//     private static final Converter<String> STRING_CONVERTER = new AbstractConverter<String>()
//     {
//         @NotNull
//         public String toString(@Nullable String t)
//         {
//             return t == null ?  "" : t;
//         }
// 
//         @NotNull
//         public String toType(@Nullable String s)
//         {
//             return toString(s);
//         }
// 
//         /** {@inheritDoc} */
//         public DOMableCollectionContentType getContentType()
//         {
//             return DOMableCollectionContentType.STRING;
//         }
//     };
// 
//     private ConverterFactory(){}
// 
//     public static Converter<Boolean> getBooleanConverter()
//     {
//         return BOOLEAN_CONVERTER;
//     }
// 
//     public static Converter<Integer> getIntegerConverter()
//     {
//         return INTEGER_CONVERTER;
//     }
// 
//     public static Converter<String> getStringConverter()
//     {
//         return STRING_CONVERTER;
//     }
// }


// Path: plugin-lib/src/java/net/stevechaloner/idea/util/properties/DOMableMap.java
import net.stevechaloner.idea.util.properties.converters.Converter;
import net.stevechaloner.idea.util.properties.converters.ConverterFactory;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/*
 * Copyright 2007 Steve Chaloner
 *
 * 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 net.stevechaloner.idea.util.properties;



/**
 * @author Steve Chaloner
 */
public class DOMableMap<V> extends AbstractDOMableCollection<V>
{
    /**
     * The standard name of a persisted item.
     */
    private static final String ELEMENT_NAME = "item";

    /**
     * The standard name of a persisted key.
     */
    private static final String KEY_NAME = "key";

    /**
     * The standard name of a persisted value.
     */
    private static final String VALUE_NAME = "value";

    private static final Converter<String> KEY_CONVERTER = ConverterFactory.getStringConverter();

    /**
     * The map.
     */
    private final Map<String, V> map = new HashMap<String, V>();

    /**
     * Initialises a new instance of this class.
     *
     * @param propertyDescriptor the property descriptor of the map
     * @param converter the persistence converter for values
     */
    public DOMableMap(@NotNull PropertyDescriptor propertyDescriptor,
                      @NotNull Converter<V> converter)