|
| 1 | +/*Copyright ©2016 TommyLemon(https://github.com/TommyLemon/APIJSON) |
| 2 | +
|
| 3 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +you may not use this file except in compliance with the License. |
| 5 | +You may obtain a copy of the License at |
| 6 | +
|
| 7 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +
|
| 9 | +Unless required by applicable law or agreed to in writing, software |
| 10 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +See the License for the specific language governing permissions and |
| 13 | +limitations under the License.*/ |
| 14 | + |
| 15 | +package zuo.biao.apijson; |
| 16 | + |
| 17 | +import java.io.Serializable; |
| 18 | +import java.util.Collection; |
| 19 | +import java.util.Map; |
| 20 | + |
| 21 | +/**base model for reduce model codes |
| 22 | + * @author Lemon |
| 23 | + * @use extends BaseModel |
| 24 | + */ |
| 25 | +@SuppressWarnings("serial") |
| 26 | +public abstract class BaseModel implements Serializable { |
| 27 | + |
| 28 | + private Long id; |
| 29 | + private Long date; |
| 30 | + |
| 31 | + public Long getId() { |
| 32 | + return id; |
| 33 | + } |
| 34 | + public BaseModel setId(Long id) { |
| 35 | + this.id = id; |
| 36 | + return this; |
| 37 | + } |
| 38 | + public Long getDate() { |
| 39 | + return date; |
| 40 | + } |
| 41 | + public BaseModel setDate(Long date) { |
| 42 | + this.date = date; |
| 43 | + return this; |
| 44 | + } |
| 45 | + |
| 46 | + //判断是否为空 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 47 | + /**判断collection是否为空 |
| 48 | + * @param collection |
| 49 | + * @return |
| 50 | + */ |
| 51 | + public static <T> boolean isEmpty(Collection<T> collection) { |
| 52 | + return collection == null || collection.isEmpty(); |
| 53 | + } |
| 54 | + /**判断map是否为空 |
| 55 | + * @param <K> |
| 56 | + * @param <V> |
| 57 | + * @param map |
| 58 | + * @return |
| 59 | + */ |
| 60 | + public static <K, V> boolean isEmpty(Map<K, V> map) { |
| 61 | + return map == null || map.isEmpty(); |
| 62 | + } |
| 63 | + //判断是否为空 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 64 | + |
| 65 | + //判断是否包含 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 66 | + /**判断collection是否包含object |
| 67 | + * @param collection |
| 68 | + * @param object |
| 69 | + * @return |
| 70 | + */ |
| 71 | + public static <T> boolean isContain(Collection<T> collection, T object) { |
| 72 | + return collection != null && collection.contains(object); |
| 73 | + } |
| 74 | + /**判断map是否包含key |
| 75 | + * @param <K> |
| 76 | + * @param <V> |
| 77 | + * @param map |
| 78 | + * @param key |
| 79 | + * @return |
| 80 | + */ |
| 81 | + public static <K, V> boolean isContainKey(Map<K, V> map, K key) { |
| 82 | + return map != null && map.containsKey(key); |
| 83 | + } |
| 84 | + /**判断map是否包含value |
| 85 | + * @param <K> |
| 86 | + * @param <V> |
| 87 | + * @param map |
| 88 | + * @param value |
| 89 | + * @return |
| 90 | + */ |
| 91 | + public static <K, V> boolean isContainValue(Map<K, V> map, V value) { |
| 92 | + return map != null && map.containsValue(value); |
| 93 | + } |
| 94 | + //判断是否为包含 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 95 | + |
| 96 | + |
| 97 | + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 98 | + /**获取数量 |
| 99 | + * @param <T> |
| 100 | + * @param array |
| 101 | + * @return |
| 102 | + */ |
| 103 | + public static <T> int count(T[] array) { |
| 104 | + return array == null ? 0 : array.length; |
| 105 | + } |
| 106 | + /**获取数量 |
| 107 | + * @param <T> |
| 108 | + * @param collection List, Vector, Set等都是Collection的子类 |
| 109 | + * @return |
| 110 | + */ |
| 111 | + public static <T> int count(Collection<T> collection) { |
| 112 | + return collection == null ? 0 : collection.size(); |
| 113 | + } |
| 114 | + /**获取数量 |
| 115 | + * @param <K> |
| 116 | + * @param <V> |
| 117 | + * @param map |
| 118 | + * @return |
| 119 | + */ |
| 120 | + public static <K, V> int count(Map<K, V> map) { |
| 121 | + return map == null ? 0 : map.size(); |
| 122 | + } |
| 123 | + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 124 | + |
| 125 | + |
| 126 | + //获取集合长度 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 127 | + /**获取 |
| 128 | + * @param <T> |
| 129 | + * @param array |
| 130 | + * @return |
| 131 | + */ |
| 132 | + public static <T> T get(T[] array, int position) { |
| 133 | + return position < 0 || position >= count(array) ? null : array[position]; |
| 134 | + } |
| 135 | + /**获取 |
| 136 | + * @param <T> |
| 137 | + * @param collection List, Vector, Set等都是Collection的子类 |
| 138 | + * @return |
| 139 | + */ |
| 140 | + @SuppressWarnings("unchecked") |
| 141 | + public static <T> T get(Collection<T> collection, int position) { |
| 142 | + return (T) (collection == null ? null : get(collection.toArray(), position)); |
| 143 | + } |
| 144 | + /**获取 |
| 145 | + * @param <K> |
| 146 | + * @param <V> |
| 147 | + * @param map null ? null |
| 148 | + * @param key null ? null : map.get(key); |
| 149 | + * @return |
| 150 | + */ |
| 151 | + public static <K, V> V get(Map<K, V> map, K key) { |
| 152 | + return key == null || map == null ? null : map.get(key); |
| 153 | + } |
| 154 | + //获取集合长度 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 155 | + |
| 156 | + |
| 157 | + |
| 158 | + //获取非基本类型对应基本类型的非空值 <<<<<<<<<<<<<<<<<<<<<<<<<<<<< |
| 159 | + /**获取非空值 |
| 160 | + * @param value |
| 161 | + * @return |
| 162 | + */ |
| 163 | + public static boolean value(Boolean value) { |
| 164 | + return value == null ? false : value; |
| 165 | + } |
| 166 | + /**获取非空值 |
| 167 | + * @param value |
| 168 | + * @return |
| 169 | + */ |
| 170 | + public static int value(Integer value) { |
| 171 | + return value == null ? 0 : value; |
| 172 | + } |
| 173 | + /**获取非空值 |
| 174 | + * @param value |
| 175 | + * @return |
| 176 | + */ |
| 177 | + public static long value(Long value) { |
| 178 | + return value == null ? 0 : value; |
| 179 | + } |
| 180 | + /**获取非空值 |
| 181 | + * @param value |
| 182 | + * @return |
| 183 | + */ |
| 184 | + public static float value(Float value) { |
| 185 | + return value == null ? 0 : value; |
| 186 | + } |
| 187 | + /**获取非空值 |
| 188 | + * @param value |
| 189 | + * @return |
| 190 | + */ |
| 191 | + public static double value(Double value) { |
| 192 | + return value == null ? 0 : value; |
| 193 | + } |
| 194 | + //获取非基本类型对应基本类型的非空值 >>>>>>>>>>>>>>>>>>>>>>>>>>>>> |
| 195 | + |
| 196 | +} |
0 commit comments