Java Code Examples for org.apache.commons.lang3.ArrayUtils#nullToEmpty()
The following examples show how to use
org.apache.commons.lang3.ArrayUtils#nullToEmpty() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestNGTestReader.java From testgrid with Apache License 2.0 | 6 votes |
/** * This method goes through the file structure and create an object model of the tests. * * @param file File object for the test folder. * @param testScenario test scenario associated with the test * @return a List of Test objects. */ private List<Test> processTestStructure(File file, TestScenario testScenario) throws TestAutomationException { List<Test> testsList = new ArrayList<>(); File tests = new File(file.getAbsolutePath()); List<String> testNGList = new ArrayList<>(); if (tests.exists()) { for (String testFile : ArrayUtils.nullToEmpty(tests.list())) { if (testFile.endsWith(JAR_EXTENSION)) { testNGList.add(Paths.get(tests.getAbsolutePath(), testFile).toString()); } } } Collections.sort(testNGList); Test test = new Test(file.getName(), TestEngine.TESTNG, testNGList, testScenario); testsList.add(test); return testsList; }
Example 2
Source File: ClassUtil.java From j360-dubbo-app-all with Apache License 2.0 | 6 votes |
/** * 循环向上转型, 获取对象的DeclaredMethod, 并强制设置为可访问. * * 如向上转型到Object仍无法找到, 返回null. * * 匹配函数名+参数类型. * * 因为class.getMethod() 不能获取父类的private函数, 因此采用循环向上的getDeclaredMethod(); */ public static Method getAccessibleMethod(final Class<?> clazz, final String methodName, Class<?>... parameterTypes) { Validate.notNull(clazz, "class can't be null"); Validate.notEmpty(methodName, "methodName can't be blank"); Class[] theParameterTypes = ArrayUtils.nullToEmpty(parameterTypes); // 处理原子类型与对象类型的兼容 ClassUtil.wrapClassses(theParameterTypes); for (Class<?> searchType = clazz; searchType != Object.class; searchType = searchType.getSuperclass()) { try { Method method = searchType.getDeclaredMethod(methodName, theParameterTypes); ClassUtil.makeAccessible(method); return method; } catch (NoSuchMethodException e) { // Method不在当前类定义,继续向上转型 } } return null; }
Example 3
Source File: GhidraFileChooserTest.java From ghidra with Apache License 2.0 | 5 votes |
private File[] listFiles(File dir, String namePattern) { File[] newFolderFiles = homeDir.listFiles((FileFilter) fileToCheck -> { if (!fileToCheck.isDirectory()) { return false; } if (!fileToCheck.getName().startsWith(namePattern)) { return false; } return true; }); return ArrayUtils.nullToEmpty(newFolderFiles, File[].class); }
Example 4
Source File: AionTxReceipt.java From aion with MIT License | 5 votes |
public AionTxReceipt(byte[] rlp) { RLPList params = RLP.decode2(rlp); RLPList receipt = (RLPList) params.get(0); RLPItem postTxStateRLP = (RLPItem) receipt.get(0); RLPItem bloomRLP = (RLPItem) receipt.get(1); RLPList logs = (RLPList) receipt.get(2); RLPItem result = (RLPItem) receipt.get(3); postTxState = ArrayUtils.nullToEmpty(postTxStateRLP.getRLPData()); bloomFilter = new Bloom(bloomRLP.getRLPData()); executionResult = (executionResult = result.getRLPData()) == null ? EMPTY_BYTE_ARRAY : executionResult; energyUsed = ByteUtil.byteArrayToLong(receipt.get(4).getRLPData()); if (receipt.size() > 5) { byte[] errBytes = receipt.get(5).getRLPData(); error = errBytes != null ? new String(errBytes, StandardCharsets.UTF_8) : ""; } for (RLPElement log : logs) { Log logInfo = LogUtility.decodeLog(log.getRLPData()); if (logInfo != null) { logInfoList.add(logInfo); } } rlpEncoded = rlp; }
Example 5
Source File: InternalTransaction.java From gsc-core with GNU Lesser General Public License v3.0 | 5 votes |
/** * Construct a child InternalTransaction */ public InternalTransaction(byte[] parentHash, int deep, int index, byte[] sendAddress, byte[] transferToAddress, long value, byte[] data, String note, long nonce, Map<String, Long> tokenInfo) { this.parentHash = parentHash.clone(); this.deep = deep; this.index = index; this.note = note; this.sendAddress = ArrayUtils.nullToEmpty(sendAddress); this.transferToAddress = ArrayUtils.nullToEmpty(transferToAddress); if ("create".equalsIgnoreCase(note)) { this.receiveAddress = ByteUtil.EMPTY_BYTE_ARRAY; } else { this.receiveAddress = ArrayUtils.nullToEmpty(transferToAddress); } // in this case, value also can represent a tokenValue when tokenId is not null, otherwise it is a gsc callvalue. this.value = value; this.data = ArrayUtils.nullToEmpty(data); this.nonce = nonce; this.hash = getHash(); // in a contract call contract case, only one value should be used. gsc or a token. can't be both. We should avoid using // tokenValue in this case. if (tokenInfo != null) { this.tokenInfo.putAll(tokenInfo); } }
Example 6
Source File: ReflectionUtil.java From j360-dubbo-app-all with Apache License 2.0 | 4 votes |
/** * 直接调用对象方法, 无视private/protected修饰符. * * 根据传入参数的实际类型进行匹配 */ public static <T> T invokeMethod(Object obj, String methodName, Object... args) { Object[] theArgs = ArrayUtils.nullToEmpty(args); final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs); return (T) invokeMethod(obj, methodName, theArgs, parameterTypes); }
Example 7
Source File: CharData.java From riiablo with Apache License 2.0 | 4 votes |
public byte[] serialize() { Validate.isTrue(isManaged(), "Cannot serialize unmanaged data"); // TODO: replace temp check with D2S.serialize(CharData) return ArrayUtils.nullToEmpty(data); }
Example 8
Source File: ReflectionUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 反射调用对象方法, 无视private/protected修饰符. * * 根据传入参数的实际类型进行匹配, 支持方法参数定义是接口,父类,原子类型等情况 * * 性能较差,仅用于单次调用. */ public static <T> T invokeMethod(Object obj, String methodName, Object... args) { Object[] theArgs = ArrayUtils.nullToEmpty(args); final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs); return invokeMethod(obj, methodName, theArgs, parameterTypes); }
Example 9
Source File: ReflectionUtil.java From vjtools with Apache License 2.0 | 2 votes |
/** * 反射调用对象方法, 无视private/protected修饰符. * * 根据传入参数的实际类型进行匹配, 支持方法参数定义是接口,父类,原子类型等情况 * * 性能较差,仅用于单次调用. */ public static <T> T invokeMethod(Object obj, String methodName, Object... args) { Object[] theArgs = ArrayUtils.nullToEmpty(args); final Class<?>[] parameterTypes = ClassUtils.toClass(theArgs); return invokeMethod(obj, methodName, theArgs, parameterTypes); }