List<?> list = new ArrayList<>( myQueue );? can be be the class you want to transfer
| /** | |
| * @author howechen | |
| */ | |
| @Component | |
| public class SystemCommandExecutor { | |
| private static final Logger logger = LoggerFactory.getLogger(SystemCommandExecutor.class); | |
| private ExecuteWatchdog watchdog = new ExecuteWatchdog(60000); | |
| private PluginExecuteResultHandler resultHandler = new PluginExecuteResultHandler(); |
| public String toString() throws Exception { | |
| ObjectMapper mapper = new ObjectMapper(); | |
| mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL); | |
| String result; | |
| try { | |
| result = mapper.writeValueAsString(this); | |
| } catch (JsonProcessingException e) { | |
| throw new Exception("Cannot transfer backend server info to json string"); | |
| } |
| public static <K, V> Map<K, V> zipToMap(List<K> keyList, List<V> valueList) throws Exception { | |
| Map<K, V> result = new HashMap<>(); | |
| Iterator<K> keyIterator = keyList.iterator(); | |
| Iterator<V> valueIterator = valueList.iterator(); | |
| while (keyIterator.hasNext() && valueIterator.hasNext()) { | |
| result.put(keyIterator.next(), valueIterator.next()); | |
| } | |
| if (keyIterator.hasNext() || valueIterator.hasNext()) { | |
| throw new Exception("The keyList and valueList size doesn't match."); | |
| } |
| // https://blog.csdn.net/java_zjh/article/details/80915655 | |
| public final class AesUtils { | |
| private static final String CHARSET_NAME = "UTF-8"; | |
| private static final String AES_NAME = "AES"; | |
| public static final String ALGORITHM = "AES/CBC/PKCS7Padding"; | |
| static { | |
| Security.addProvider(new BouncyCastleProvider()); | |
| } |
| // both are good to use, but cannot tolerate the situation when key or value inside the list is null | |
| public static <K, V> Map<K, V> zipToMap(List<K> keys, List<V> values) { | |
| return IntStream.range(0, keys.size()).boxed() | |
| .collect(Collectors.toMap(keys::get, values::get)); | |
| } | |
| public static <K, V> Map<K, V> zipToMap(List<K> keys, List<V> values) { |
| // should use org.apache.commons.lang3 | |
| EnumUtils.isValidEnum(enumxxx.class,str); |
| Map<String, List<Long>> capitalKeyToValueMap = procDefInfoDto.getPermissionToRole() | |
| .entrySet() | |
| .stream() | |
| .collect(Collectors.toMap(stringListEntry -> stringListEntry.getKey().toUpperCase(), Map.Entry::getValue)); |
| public class Test { | |
| public static void main(String[] args) { | |
| List<String> list1 = new ArrayList<String>(); | |
| list1.add("1"); | |
| list1.add("2"); | |
| list1.add("3"); | |
| list1.add("5"); | |
| list1.add("6"); | |
| public static strictfp String humanReadableByteCount(long bytes, boolean si) { | |
| int unit = si ? 1000 : 1024; | |
| long absBytes = bytes == Long.MIN_VALUE ? Long.MAX_VALUE : Math.abs(bytes); | |
| if (absBytes < unit) return bytes + " B"; | |
| int exp = (int) (Math.log(absBytes) / Math.log(unit)); | |
| long th = (long) (Math.pow(unit, exp) * (unit - 0.05)); | |
| if (exp < 6 && absBytes >= th - ((th & 0xfff) == 0xd00 ? 52 : 0)) exp++; | |
| String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); | |
| if (exp > 4) { | |
| bytes /= unit; |
List<?> list = new ArrayList<>( myQueue );? can be be the class you want to transfer