/** * <p>Checks if the array is not null or empty. <p/> * * @param array th array to check * @return {@code true} if the array is not null or empty. */ public static boolean isNotEmpty(final Object[] array) { return !isEmpty(array); } }
/** * @param values * @param value * @return contains */ public static boolean isContains(String[] values, String value) { if (isNotEmpty(value) && ArrayUtils.isNotEmpty(values)) { for (String v : values) { if (value.equals(v)) { return true; } } } return false; }
/** * <p>Checks if the array is not null or empty. <p/> * * @param array th array to check * @return {@code true} if the array is not null or empty. */ public static boolean isNotEmpty(final Object[] array) { return !isEmpty(array); } }
/** * @param values * @param value * @return contains */ public static boolean isContains(String[] values, String value) { if (isNotEmpty(value) && ArrayUtils.isNotEmpty(values)) { for (String v : values) { if (value.equals(v)) { return true; } } } return false; }
static Throwable getThrowableCandidate(Object[] argArray) { if (ArrayUtils.isEmpty(argArray)) { return null; } final Object lastEntry = argArray[argArray.length - 1]; if (lastEntry instanceof Throwable) { return (Throwable) lastEntry; } return null; }
public ClassGenerator addConstructor(int mod, Class<?>[] pts, Class<?>[] ets, String body) { StringBuilder sb = new StringBuilder(); sb.append(modifier(mod)).append(' ').append(SIMPLE_NAME_TAG); sb.append('('); for (int i = 0; i < pts.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(pts[i])); sb.append(" arg").append(i); } sb.append(')'); if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(ets[i])); } } sb.append('{').append(body).append('}'); return addConstructor(sb.toString()); }
@Override public int[] merge(int[]... items) { if (ArrayUtils.isEmpty(items)) { return new int[0]; } int totalLen = 0; for (int[] array : items) { if (array != null) { totalLen += array.length; } } int[] result = new int[totalLen]; int index = 0; for (int[] array : items) { if (array != null) { for (int item : array) { result[index++] = item; } } } return result; }
public String getBackupAddress(int defaultPort) { StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort)); String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]); if (ArrayUtils.isNotEmpty(backups)) { for (String backup : backups) { address.append(","); address.append(appendDefaultPort(backup, defaultPort)); } } return address.toString(); }
@Override public byte[] merge(byte[]... items) { if (ArrayUtils.isEmpty(items)) { return new byte[0]; } int total = 0; for (byte[] array : items) { if (array != null) { total += array.length; } } byte[] result = new byte[total]; int index = 0; for (byte[] array : items) { if (array != null) { for (byte item : array) { result[index++] = item; } } } return result; }
public String getBackupAddress(int defaultPort) { StringBuilder address = new StringBuilder(appendDefaultPort(getAddress(), defaultPort)); String[] backups = getParameter(Constants.BACKUP_KEY, new String[0]); if (ArrayUtils.isNotEmpty(backups)) { for (String backup : backups) { address.append(","); address.append(appendDefaultPort(backup, defaultPort)); } } return address.toString(); }
@Override public boolean[] merge(boolean[]... items) { if (ArrayUtils.isEmpty(items)) { return new boolean[0]; } int totalLen = 0; for (boolean[] array : items) { if (array != null) { totalLen += array.length; } } boolean[] result = new boolean[totalLen]; int index = 0; for (boolean[] array : items) { if (array != null) { for (boolean item : array) { result[index++] = item; } } } return result; }
public ClassGenerator addConstructor(int mod, Class<?>[] pts, Class<?>[] ets, String body) { StringBuilder sb = new StringBuilder(); sb.append(modifier(mod)).append(' ').append(SIMPLE_NAME_TAG); sb.append('('); for (int i = 0; i < pts.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(pts[i])); sb.append(" arg").append(i); } sb.append(')'); if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(ets[i])); } } sb.append('{').append(body).append('}'); return addConstructor(sb.toString()); }
@Override public int[] merge(int[]... items) { if (ArrayUtils.isEmpty(items)) { return new int[0]; } int totalLen = 0; for (int[] array : items) { if (array != null) { totalLen += array.length; } } int[] result = new int[totalLen]; int index = 0; for (int[] array : items) { if (array != null) { for (int item : array) { result[index++] = item; } } } return result; }
public ClassGenerator addMethod(String name, int mod, Class<?> rt, Class<?>[] pts, Class<?>[] ets, String body) { StringBuilder sb = new StringBuilder(); sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name); sb.append('('); for (int i = 0; i < pts.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(pts[i])); sb.append(" arg").append(i); } sb.append(')'); if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(ets[i])); } } sb.append('{').append(body).append('}'); return addMethod(sb.toString()); }
@Override public char[] merge(char[]... items) { if (ArrayUtils.isEmpty(items)) { return new char[0]; } int total = 0; for (char[] array : items) { if (array != null) { total += array.length; } } char[] result = new char[total]; int index = 0; for (char[] array : items) { if (array != null) { for (char item : array) { result[index++] = item; } } } return result; } }
public ClassGenerator addMethod(String name, int mod, Class<?> rt, Class<?>[] pts, Class<?>[] ets, String body) { StringBuilder sb = new StringBuilder(); sb.append(modifier(mod)).append(' ').append(ReflectUtils.getName(rt)).append(' ').append(name); sb.append('('); for (int i = 0; i < pts.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(pts[i])); sb.append(" arg").append(i); } sb.append(')'); if (ArrayUtils.isNotEmpty(ets)) { sb.append(" throws "); for (int i = 0; i < ets.length; i++) { if (i > 0) { sb.append(','); } sb.append(ReflectUtils.getName(ets[i])); } } sb.append('{').append(body).append('}'); return addMethod(sb.toString()); }
@Override public short[] merge(short[]... items) { if (ArrayUtils.isEmpty(items)) { return new short[0]; } int total = 0; for (short[] array : items) { if (array != null) { total += array.length; } } short[] result = new short[total]; int index = 0; for (short[] array : items) { if (array != null) { for (short item : array) { result[index++] = item; } } } return result; } }
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception { Object value = null; if ("empty".equals(mock)) { value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null); } else if ("null".equals(mock)) { value = null; } else if ("true".equals(mock)) { value = true; } else if ("false".equals(mock)) { value = false; } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"") || mock.startsWith("\'") && mock.endsWith("\'"))) { value = mock.subSequence(1, mock.length() - 1); } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) { value = mock; } else if (StringUtils.isNumeric(mock)) { value = JSON.parse(mock); } else if (mock.startsWith("{")) { value = JSON.parseObject(mock, Map.class); } else if (mock.startsWith("[")) { value = JSON.parseObject(mock, List.class); } else { value = mock; } if (ArrayUtils.isNotEmpty(returnTypes)) { value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null); } return value; }
@Override public char[] merge(char[]... items) { if (ArrayUtils.isEmpty(items)) { return new char[0]; } int total = 0; for (char[] array : items) { if (array != null) { total += array.length; } } char[] result = new char[total]; int index = 0; for (char[] array : items) { if (array != null) { for (char item : array) { result[index++] = item; } } } return result; } }
public static Object parseMockValue(String mock, Type[] returnTypes) throws Exception { Object value = null; if ("empty".equals(mock)) { value = ReflectUtils.getEmptyObject(returnTypes != null && returnTypes.length > 0 ? (Class<?>) returnTypes[0] : null); } else if ("null".equals(mock)) { value = null; } else if ("true".equals(mock)) { value = true; } else if ("false".equals(mock)) { value = false; } else if (mock.length() >= 2 && (mock.startsWith("\"") && mock.endsWith("\"") || mock.startsWith("\'") && mock.endsWith("\'"))) { value = mock.subSequence(1, mock.length() - 1); } else if (returnTypes != null && returnTypes.length > 0 && returnTypes[0] == String.class) { value = mock; } else if (StringUtils.isNumeric(mock)) { value = JSON.parse(mock); } else if (mock.startsWith("{")) { value = JSON.parseObject(mock, Map.class); } else if (mock.startsWith("[")) { value = JSON.parseObject(mock, List.class); } else { value = mock; } if (ArrayUtils.isNotEmpty(returnTypes)) { value = PojoUtils.realize(value, (Class<?>) returnTypes[0], returnTypes.length > 1 ? returnTypes[1] : null); } return value; }