litesoft
@ 943
litesoft / trunk / Java / ScarPlus / src / com / esotericsoftware / scar / support / Parameter.java
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
package com.esotericsoftware.scar.support; import com.esotericsoftware.utils.*; import java.util.*; @SuppressWarnings({"UnusedDeclaration"}) public class Parameter { public enum Form { STRING, STRING_LIST, PATHS } public static Parameter def( String pName, Form pForm, String pDescription, String pDescriptionForDefaulting ) { return new Parameter( pName, pForm, pDescription, pDescriptionForDefaulting ); } public static Parameter def( String pName, Form pForm, String pDescription ) { return def( pName, pForm, pDescription, null ); } public static Set<String> reservedNames() { return Collections.unmodifiableSet( RESERVED_NAMES ); } public String getName() { return mName; } public Form getForm() { return mForm; } public String getDescription() { return mDescription; } public String getDescriptionForDefaulting() { return mDescriptionForDefaulting; } private final String mName; private final Form mForm; private final String mDescription; private final String mDescriptionForDefaulting; private Parameter( String pName, Form pForm, String pDescription, String pDescriptionForDefaulting ) { mName = Util.assertNotEmpty( "Name", pName ).toLowerCase(); mForm = pForm; mDescription = pDescription; mDescriptionForDefaulting = pDescriptionForDefaulting; if ( !RESERVED_NAMES.add( mName ) ) { throw new IllegalArgumentException( "Duplicate Parameter declared with name: " + mName ); } } private static final Set<String> RESERVED_NAMES = new HashSet<String>(); public static class Manager { private final Map<Object, Object> mData = new HashMap<Object, Object>(); private final Map<Object, Object> mCachedResponses = new HashMap<Object, Object>(); public Manager( Manager them ) { this( them.mData ); } public Manager( Map<Object, Object> pData ) { if ( pData != null ) { Object zValue; for ( Object key : pData.keySet() ) { if ( null != (zValue = normalizeValue( pData.get( key ) )) ) { mData.put( normalizeKey( key ), zValue ); } } } } public Object normalizeKey( Object pKey ) { if ( pKey instanceof String ) { pKey = Util.noEmpty( pKey.toString().toLowerCase() ); } Util.assertNotNull( "key", pKey ); return pKey; } public Object normalizeValue( Object pValue ) { return (pValue instanceof String) ? Util.noEmpty( pValue.toString() ) : pValue; } public synchronized <T> T getCachedResponse( Object pKey ) { //noinspection unchecked return (T) mCachedResponses.get( pKey ); } public synchronized void addCachedResponse( Object pKey, Object pValue ) { mCachedResponses.put( pKey, pValue ); } public synchronized void put( Object pKey, Object pValue ) { if ( pValue != null ) { mData.put( pKey, pValue ); } else if ( null == mData.remove( pKey ) ) { return; // Nothing Changed } mCachedResponses.remove( pKey ); } /** * Removes an item from a list or map. If the mData under the specified key is a list, the entry equal to the specified value is * removed. If the mData under the specified key is a map, the entry with the key specified by value is removed. */ public synchronized void remove( Object pKey, Object pValue ) { boolean zUpdate; Object object = mData.get( pKey ); if ( object instanceof Map ) { zUpdate = (null != ((Map) object).remove( pValue )); } else if ( object instanceof List ) { zUpdate = ((List) object).remove( pValue ); } else { zUpdate = (null != mData.remove( pKey )); } if ( zUpdate ) { mCachedResponses.remove( pKey ); } } public synchronized Object get( Object pKey ) { return mData.get( pKey ); } public synchronized Object[] keys() { return mData.keySet().toArray(); } } } |
Commits for litesoft/trunk/Java/ScarPlus/src/com/esotericsoftware/scar/support/Parameter.java
Revision | Author | Commited | Message |
---|---|---|---|
943 Diff | GeorgeS | Tue 03 Jun, 2014 04:25:50 +0000 | Extracting commonfoundation |
939 Diff | GeorgeS | Mon 02 Jun, 2014 21:30:31 +0000 | Extracting commonfoundation |
357 Diff | GeorgeS | Fri 05 Aug, 2011 14:25:00 +0000 | |
315 Diff | GeorgeS | Sun 17 Jul, 2011 15:48:36 +0000 | |
293 Diff | GeorgeS | Fri 24 Jun, 2011 00:52:20 +0000 | |
291 Diff | GeorgeS | Wed 22 Jun, 2011 00:33:37 +0000 | |
290 Diff | GeorgeS | Tue 21 Jun, 2011 14:58:27 +0000 | |
289 | GeorgeS | Tue 21 Jun, 2011 00:43:29 +0000 |