PageRenderTime 264ms CodeModel.GetById 0ms RepoModel.GetById 0ms app.codeStats 0ms

/src/main/java/com/alibaba/fastjson/serializer/FilterUtils.java

https://bitbucket.org/xiejuntao/xdesktop
Java | 297 lines | 224 code | 73 blank | 0 comment | 66 complexity | 0589426af67bc7271cdceb0f53f16095 MD5 | raw file
  1. package com.alibaba.fastjson.serializer;
  2. import java.util.List;
  3. public class FilterUtils {
  4. public static Object processValue(JSONSerializer serializer, Object object, String key, Object propertyValue) {
  5. List<ValueFilter> valueFilters = serializer.getValueFiltersDirect();
  6. if (valueFilters != null) {
  7. for (ValueFilter valueFilter : valueFilters) {
  8. propertyValue = valueFilter.process(object, key, propertyValue);
  9. }
  10. }
  11. return propertyValue;
  12. }
  13. public static String processKey(JSONSerializer serializer, Object object, String key, Object propertyValue) {
  14. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  15. if (nameFilters != null) {
  16. for (NameFilter nameFilter : nameFilters) {
  17. key = nameFilter.process(object, key, propertyValue);
  18. }
  19. }
  20. return key;
  21. }
  22. public static String processKey(JSONSerializer serializer, Object object, String key, byte intValue) {
  23. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  24. if (nameFilters != null) {
  25. Object propertyValue = Byte.valueOf(intValue);
  26. for (NameFilter nameFilter : nameFilters) {
  27. key = nameFilter.process(object, key, propertyValue);
  28. }
  29. }
  30. return key;
  31. }
  32. public static String processKey(JSONSerializer serializer, Object object, String key, short intValue) {
  33. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  34. if (nameFilters != null) {
  35. Object propertyValue = Short.valueOf(intValue);
  36. for (NameFilter nameFilter : nameFilters) {
  37. key = nameFilter.process(object, key, propertyValue);
  38. }
  39. }
  40. return key;
  41. }
  42. public static String processKey(JSONSerializer serializer, Object object, String key, int intValue) {
  43. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  44. if (nameFilters != null) {
  45. Object propertyValue = Integer.valueOf(intValue);
  46. for (NameFilter nameFilter : nameFilters) {
  47. key = nameFilter.process(object, key, propertyValue);
  48. }
  49. }
  50. return key;
  51. }
  52. public static String processKey(JSONSerializer serializer, Object object, String key, long intValue) {
  53. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  54. if (nameFilters != null) {
  55. Object propertyValue = Long.valueOf(intValue);
  56. for (NameFilter nameFilter : nameFilters) {
  57. key = nameFilter.process(object, key, propertyValue);
  58. }
  59. }
  60. return key;
  61. }
  62. public static String processKey(JSONSerializer serializer, Object object, String key, float intValue) {
  63. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  64. if (nameFilters != null) {
  65. Object propertyValue = Float.valueOf(intValue);
  66. for (NameFilter nameFilter : nameFilters) {
  67. key = nameFilter.process(object, key, propertyValue);
  68. }
  69. }
  70. return key;
  71. }
  72. public static String processKey(JSONSerializer serializer, Object object, String key, double intValue) {
  73. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  74. if (nameFilters != null) {
  75. Object propertyValue = Double.valueOf(intValue);
  76. for (NameFilter nameFilter : nameFilters) {
  77. key = nameFilter.process(object, key, propertyValue);
  78. }
  79. }
  80. return key;
  81. }
  82. public static String processKey(JSONSerializer serializer, Object object, String key, boolean intValue) {
  83. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  84. if (nameFilters != null) {
  85. Object propertyValue = Boolean.valueOf(intValue);
  86. for (NameFilter nameFilter : nameFilters) {
  87. key = nameFilter.process(object, key, propertyValue);
  88. }
  89. }
  90. return key;
  91. }
  92. public static String processKey(JSONSerializer serializer, Object object, String key, char intValue) {
  93. List<NameFilter> nameFilters = serializer.getNameFiltersDirect();
  94. if (nameFilters != null) {
  95. Object propertyValue = Character.valueOf(intValue);
  96. for (NameFilter nameFilter : nameFilters) {
  97. key = nameFilter.process(object, key, propertyValue);
  98. }
  99. }
  100. return key;
  101. }
  102. public static boolean applyName(JSONSerializer serializer, Object object, String key) {
  103. List<PropertyPreFilter> filters = serializer.getPropertyPreFiltersDirect();
  104. if (filters == null) {
  105. return true;
  106. }
  107. for (PropertyPreFilter filter : filters) {
  108. if (!filter.apply(serializer, object, key)) {
  109. return false;
  110. }
  111. }
  112. return true;
  113. }
  114. public static boolean apply(JSONSerializer serializer, Object object, String key, Object propertyValue) {
  115. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  116. if (propertyFilters == null) {
  117. return true;
  118. }
  119. for (PropertyFilter propertyFilter : propertyFilters) {
  120. if (!propertyFilter.apply(object, key, propertyValue)) {
  121. return false;
  122. }
  123. }
  124. return true;
  125. }
  126. public static boolean apply(JSONSerializer serializer, Object object, String key, byte value) {
  127. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  128. if (propertyFilters != null) {
  129. boolean apply = true;
  130. Object propertyValue = Byte.valueOf(value);
  131. for (PropertyFilter propertyFilter : propertyFilters) {
  132. if (!propertyFilter.apply(object, key, propertyValue)) {
  133. return false;
  134. }
  135. }
  136. return apply;
  137. }
  138. return true;
  139. }
  140. public static boolean apply(JSONSerializer serializer, Object object, String key, short value) {
  141. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  142. if (propertyFilters != null) {
  143. boolean apply = true;
  144. Object propertyValue = Short.valueOf(value);
  145. for (PropertyFilter propertyFilter : propertyFilters) {
  146. if (!propertyFilter.apply(object, key, propertyValue)) {
  147. return false;
  148. }
  149. }
  150. return apply;
  151. }
  152. return true;
  153. }
  154. public static boolean apply(JSONSerializer serializer, Object object, String key, int value) {
  155. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  156. if (propertyFilters != null) {
  157. boolean apply = true;
  158. Object propertyValue = Integer.valueOf(value);
  159. for (PropertyFilter propertyFilter : propertyFilters) {
  160. if (!propertyFilter.apply(object, key, propertyValue)) {
  161. return false;
  162. }
  163. }
  164. return apply;
  165. }
  166. return true;
  167. }
  168. public static boolean apply(JSONSerializer serializer, Object object, String key, char value) {
  169. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  170. if (propertyFilters != null) {
  171. boolean apply = true;
  172. Object propertyValue = Character.valueOf(value);
  173. for (PropertyFilter propertyFilter : propertyFilters) {
  174. if (!propertyFilter.apply(object, key, propertyValue)) {
  175. return false;
  176. }
  177. }
  178. return apply;
  179. }
  180. return true;
  181. }
  182. public static boolean apply(JSONSerializer serializer, Object object, String key, long value) {
  183. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  184. if (propertyFilters != null) {
  185. boolean apply = true;
  186. Object propertyValue = Long.valueOf(value);
  187. for (PropertyFilter propertyFilter : propertyFilters) {
  188. if (!propertyFilter.apply(object, key, propertyValue)) {
  189. return false;
  190. }
  191. }
  192. return apply;
  193. }
  194. return true;
  195. }
  196. public static boolean apply(JSONSerializer serializer, Object object, String key, float value) {
  197. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  198. if (propertyFilters != null) {
  199. boolean apply = true;
  200. Object propertyValue = Float.valueOf(value);
  201. for (PropertyFilter propertyFilter : propertyFilters) {
  202. if (!propertyFilter.apply(object, key, propertyValue)) {
  203. return false;
  204. }
  205. }
  206. return apply;
  207. }
  208. return true;
  209. }
  210. public static boolean apply(JSONSerializer serializer, Object object, String key, double value) {
  211. List<PropertyFilter> propertyFilters = serializer.getPropertyFiltersDirect();
  212. if (propertyFilters != null) {
  213. boolean apply = true;
  214. Object propertyValue = Double.valueOf(value);
  215. for (PropertyFilter propertyFilter : propertyFilters) {
  216. if (!propertyFilter.apply(object, key, propertyValue)) {
  217. return false;
  218. }
  219. }
  220. return apply;
  221. }
  222. return true;
  223. }
  224. }