Subversion Repository Public Repository

litesoft

Diff Revisions 947 vs 948 for /trunk/GWT_Sandbox/FormEngine/src/com/temp/shared/utils/CollectionsUtils.java

Diff revisions: vs.
  @@ -1,11 +1,6 @@
1 1 package com.temp.shared.utils;
2 2
3 - import java.util.ArrayList;
4 - import java.util.Collection;
5 - import java.util.Collections;
6 - import java.util.HashMap;
7 - import java.util.List;
8 - import java.util.Map;
3 + import java.util.*;
9 4
10 5 /**
11 6 * Utility methods around Collections / Arrays to reduce the code in other
  @@ -14,26 +9,26 @@
14 9 * @author georgs
15 10 */
16 11 public class CollectionsUtils {
17 - public static <T> List<T> deNull(List<T> list) {
18 - if (list != null) { // can not "in line" as compiler gets confused!
12 + public static <T> List<T> deNull( List<T> list ) {
13 + if ( list != null ) { // can not "in line" as compiler gets confused!
19 14 return list;
20 15 }
21 16 return Collections.emptyList();
22 17 }
23 18
24 - public static <T> List<T> noEmpty(List<T> list) {
25 - return isEmpty(list) ? null : list;
19 + public static <T> List<T> noEmpty( List<T> list ) {
20 + return isEmpty( list ) ? null : list;
26 21 }
27 22
28 - public static boolean isEmpty(Collection<?> collection) {
23 + public static boolean isEmpty( Collection<?> collection ) {
29 24 return (collection == null) || collection.isEmpty();
30 25 }
31 26
32 - public static boolean isEmpty(Map<?, ?> collection) {
27 + public static boolean isEmpty( Map<?, ?> collection ) {
33 28 return (collection == null) || collection.isEmpty();
34 29 }
35 30
36 - public static boolean isEmpty(Object[] array) {
31 + public static boolean isEmpty( Object[] array ) {
37 32 return (array == null) || (array.length == 0);
38 33 }
39 34
  @@ -51,30 +46,30 @@
51 46 return new HashMap<K, V>();
52 47 }
53 48
54 - public static Map<String, String> newMap(String... keyValuePairs) {
49 + public static Map<String, String> newMap( String... keyValuePairs ) {
55 50 Map<String, String> map = newHashMap();
56 - if (!isEmpty(keyValuePairs)) {
57 - if ((keyValuePairs.length & 1) == 1) { // Odd == Not Paired!
58 - throw new IllegalArgumentException("To construct a String String Map, must provide Strings in pairs (key, value)");
51 + if ( !isEmpty( keyValuePairs ) ) {
52 + if ( (keyValuePairs.length & 1) == 1 ) { // Odd == Not Paired!
53 + throw new IllegalArgumentException( "To construct a String String Map, must provide Strings in pairs (key, value)" );
59 54 }
60 - for (int i = 0; i < keyValuePairs.length;) {
55 + for ( int i = 0; i < keyValuePairs.length; ) {
61 56 String key = keyValuePairs[i++];
62 57 String value = keyValuePairs[i++];
63 - addNonEmptiesTo(map, key, value);
58 + addNonEmptiesTo( map, key, value );
64 59 }
65 60 }
66 61 return map;
67 62 }
68 63
69 - public static Map<String, String> addNonEmptiesTo(Map<String, String> map, String key, String value) {
70 - map.put(Assert.notNullOrEmpty("key", key), Assert.notNullOrEmpty("value", value));
64 + public static Map<String, String> addNonEmptiesTo( Map<String, String> map, String key, String value ) {
65 + map.put( Assert.notNullOrEmpty( "key", key ), Assert.notNullOrEmpty( "value", value ) );
71 66 return map;
72 67 }
73 68
74 - public static <K, V> Map<K, V> addNonNullsTo(Map<K, V> map, K key, V value) {
75 - Assert.notNull("key", key);
76 - Assert.notNull("value", value);
77 - map.put(key, value);
69 + public static <K, V> Map<K, V> addNonNullsTo( Map<K, V> map, K key, V value ) {
70 + Assert.notNull( "key", key );
71 + Assert.notNull( "value", value );
72 + map.put( key, value );
78 73 return map;
79 74 }
80 75 }