|
@@ -1,54 +1,54 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.forms.server.support.nonpublic; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.commonfoundation.typeutils.Objects; |
5 |
|
- |
import org.litesoft.core.simpletypes.*; |
6 |
|
- |
|
7 |
|
- |
import java.io.*; |
8 |
|
- |
import java.util.*; |
9 |
|
- |
|
10 |
|
- |
public abstract class AbstractSendableKeyValuePairConverter extends AbstractSendableDataConverter { |
11 |
|
- |
protected Serializable convertNotNullToPassable( Object pValue ) { |
12 |
|
- |
return createSimpleKeyValuePair( pValue ); |
13 |
|
- |
} |
14 |
|
- |
|
15 |
|
- |
protected Object convertNotNullNotBoxedTypeFromPassable( Serializable pValue ) { |
16 |
|
- |
return (pValue instanceof SimpleKeyValuePair) ? // |
17 |
|
- |
convertSimpleKeyValuePairKey( ((SimpleKeyValuePair) pValue).getKey() ) : // |
18 |
|
- |
pValue.toString(); |
19 |
|
- |
} |
20 |
|
- |
|
21 |
|
- |
protected Object convertSimpleKeyValuePairKey( Object pKey ) { |
22 |
|
- |
return pKey; |
23 |
|
- |
} |
24 |
|
- |
|
25 |
|
- |
abstract protected SimpleKeyValuePair createSimpleKeyValuePair( Object pOption ); |
26 |
|
- |
|
27 |
|
- |
public SimpleKeyValuePair[] createValidOptions( Object[] pValidOptions, |
28 |
|
- |
String[] pAltOrLimitingValidOptions ) { |
29 |
|
- |
if ( Objects.isNullOrEmpty( pValidOptions ) ) { |
30 |
|
- |
if ( Objects.isNullOrEmpty( pValidOptions = pAltOrLimitingValidOptions ) ) { |
31 |
|
- |
return SimpleKeyValuePair.EMPTY_ARRAY; |
32 |
|
- |
} |
33 |
|
- |
} |
34 |
|
- |
if ( (pValidOptions == pAltOrLimitingValidOptions) || (pAltOrLimitingValidOptions == null) ) { |
35 |
|
- |
SimpleKeyValuePair[] rv = new SimpleKeyValuePair[pValidOptions.length]; |
36 |
|
- |
for ( int i = 0; i < pValidOptions.length; i++ ) { |
37 |
|
- |
rv[i] = createSimpleKeyValuePair( pValidOptions[i] ); |
38 |
|
- |
} |
39 |
|
- |
return rv; |
40 |
|
- |
} |
41 |
|
- |
Set<String> zLimitTo = new HashSet<String>(); |
42 |
|
- |
for ( String option : pAltOrLimitingValidOptions ) { |
43 |
|
- |
zLimitTo.add( createSimpleKeyValuePair( option ).toStringValue() ); |
44 |
|
- |
} |
45 |
|
- |
List<SimpleKeyValuePair> rv = new ArrayList<SimpleKeyValuePair>(); |
46 |
|
- |
for ( Object option : pValidOptions ) { |
47 |
|
- |
SimpleKeyValuePair possibleEntry = createSimpleKeyValuePair( option ); |
48 |
|
- |
if ( zLimitTo.contains( possibleEntry.toStringValue() ) ) { |
49 |
|
- |
rv.add( possibleEntry ); |
50 |
|
- |
} |
51 |
|
- |
} |
52 |
|
- |
return rv.toArray( new SimpleKeyValuePair[rv.size()] ); |
53 |
|
- |
} |
54 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.forms.server.support.nonpublic; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
5 |
+ |
import org.litesoft.core.simpletypes.*; |
|
6 |
+ |
|
|
7 |
+ |
import java.io.*; |
|
8 |
+ |
import java.util.*; |
|
9 |
+ |
|
|
10 |
+ |
public abstract class AbstractSendableKeyValuePairConverter extends AbstractSendableDataConverter { |
|
11 |
+ |
protected Serializable convertNotNullToPassable( Object pValue ) { |
|
12 |
+ |
return createSimpleKeyValuePair( pValue ); |
|
13 |
+ |
} |
|
14 |
+ |
|
|
15 |
+ |
protected Object convertNotNullNotBoxedTypeFromPassable( Serializable pValue ) { |
|
16 |
+ |
return (pValue instanceof SimpleKeyValuePair) ? // |
|
17 |
+ |
convertSimpleKeyValuePairKey( ((SimpleKeyValuePair) pValue).getKey() ) : // |
|
18 |
+ |
pValue.toString(); |
|
19 |
+ |
} |
|
20 |
+ |
|
|
21 |
+ |
protected Object convertSimpleKeyValuePairKey( Object pKey ) { |
|
22 |
+ |
return pKey; |
|
23 |
+ |
} |
|
24 |
+ |
|
|
25 |
+ |
abstract protected SimpleKeyValuePair createSimpleKeyValuePair( Object pOption ); |
|
26 |
+ |
|
|
27 |
+ |
public SimpleKeyValuePair[] createValidOptions( Object[] pValidOptions, |
|
28 |
+ |
String[] pAltOrLimitingValidOptions ) { |
|
29 |
+ |
if ( Currently.isNullOrEmpty( pValidOptions ) ) { |
|
30 |
+ |
if ( Currently.isNullOrEmpty( pValidOptions = pAltOrLimitingValidOptions ) ) { |
|
31 |
+ |
return SimpleKeyValuePair.EMPTY_ARRAY; |
|
32 |
+ |
} |
|
33 |
+ |
} |
|
34 |
+ |
if ( (pValidOptions == pAltOrLimitingValidOptions) || (pAltOrLimitingValidOptions == null) ) { |
|
35 |
+ |
SimpleKeyValuePair[] rv = new SimpleKeyValuePair[pValidOptions.length]; |
|
36 |
+ |
for ( int i = 0; i < pValidOptions.length; i++ ) { |
|
37 |
+ |
rv[i] = createSimpleKeyValuePair( pValidOptions[i] ); |
|
38 |
+ |
} |
|
39 |
+ |
return rv; |
|
40 |
+ |
} |
|
41 |
+ |
Set<String> zLimitTo = new HashSet<String>(); |
|
42 |
+ |
for ( String option : pAltOrLimitingValidOptions ) { |
|
43 |
+ |
zLimitTo.add( createSimpleKeyValuePair( option ).toStringValue() ); |
|
44 |
+ |
} |
|
45 |
+ |
List<SimpleKeyValuePair> rv = new ArrayList<SimpleKeyValuePair>(); |
|
46 |
+ |
for ( Object option : pValidOptions ) { |
|
47 |
+ |
SimpleKeyValuePair possibleEntry = createSimpleKeyValuePair( option ); |
|
48 |
+ |
if ( zLimitTo.contains( possibleEntry.toStringValue() ) ) { |
|
49 |
+ |
rv.add( possibleEntry ); |
|
50 |
+ |
} |
|
51 |
+ |
} |
|
52 |
+ |
return rv.toArray( new SimpleKeyValuePair[rv.size()] ); |
|
53 |
+ |
} |
|
54 |
+ |
} |