Java Code Examples for cn.hutool.core.util.ArrayUtil#isEmpty()
The following examples show how to use
cn.hutool.core.util.ArrayUtil#isEmpty() .
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: DictionaryItemServiceImpl.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
@Override public Map<String, Map<String, String>> map(String[] types) { if (ArrayUtil.isEmpty(types)) { return Collections.emptyMap(); } LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ() .in(DictionaryItem::getDictionaryType, types) .eq(DictionaryItem::getStatus, true) .orderByAsc(DictionaryItem::getSortValue); List<DictionaryItem> list = super.list(query); //key 是类型 Map<String, List<DictionaryItem>> typeMap = list.stream().collect(groupingBy(DictionaryItem::getDictionaryType, LinkedHashMap::new, toList())); //需要返回的map Map<String, Map<String, String>> typeCodeNameMap = new LinkedHashMap<>(typeMap.size()); typeMap.forEach((key, items) -> { ImmutableMap<String, String> itemCodeMap = MapHelper.uniqueIndex(items, DictionaryItem::getCode, DictionaryItem::getName); typeCodeNameMap.put(key, itemCodeMap); }); return typeCodeNameMap; }
Example 2
Source File: OauthGeneralController.java From zuihou-admin-cloud with Apache License 2.0 | 6 votes |
@ApiOperation(value = "获取当前系统指定枚举", notes = "获取当前系统指定枚举") @GetMapping("/enums") public R<Map<String, Map<String, String>>> enums(@RequestParam(value = "codes[]", required = false) String[] codes) { if (ArrayUtil.isEmpty(codes)) { return R.success(ENUM_MAP); } Map<String, Map<String, String>> map = new HashMap<>(codes.length); for (String code : codes) { if (ENUM_MAP.containsKey(code)) { map.put(code, ENUM_MAP.get(code)); } } return R.success(map); }
Example 3
Source File: SpelUtil.java From mall4j with GNU Affero General Public License v3.0 | 6 votes |
/** * 支持 #p0 参数索引的表达式解析 * @param rootObject 根对象,method 所在的对象 * @param spel 表达式 * @param method ,目标方法 * @param args 方法入参 * @return 解析后的字符串 */ public static String parse(Object rootObject,String spel, Method method, Object[] args) { if (StrUtil.isBlank(spel)) { return StrUtil.EMPTY; } //获取被拦截方法参数名列表(使用Spring支持类库) LocalVariableTableParameterNameDiscoverer u = new LocalVariableTableParameterNameDiscoverer(); String[] paraNameArr = u.getParameterNames(method); if (ArrayUtil.isEmpty(paraNameArr)) { return spel; } //使用SPEL进行key的解析 ExpressionParser parser = new SpelExpressionParser(); //SPEL上下文 StandardEvaluationContext context = new MethodBasedEvaluationContext(rootObject,method,args,u); //把方法参数放入SPEL上下文中 for (int i = 0; i < paraNameArr.length; i++) { context.setVariable(paraNameArr[i], args[i]); } return parser.parseExpression(spel).getValue(context, String.class); }
Example 4
Source File: DataMigrationUtils.java From v-mock with MIT License | 6 votes |
/** * 获取所有历史DB文件集合 * * @return List<File>集合 */ private static List<File> getHistoryDataFileList() { // 历史数据库文件都是存在临时目录下 String tempFilePath = System.getProperty("java.io.tmpdir"); File[] tempFileArr = FileUtil.ls(tempFilePath); // 临时目录没文件,返回 null if (ArrayUtil.isEmpty(tempFileArr)) { return null; } // 过滤掉非db文件 Stream<File> filesStream = Arrays.stream(tempFileArr) .filter(file -> file.isFile() && file.getName().matches("sqlite-jdbc-tmp-.*\\.db")); // 转为List返回 List<File> fileList = filesStream.collect(Collectors.toList()); return fileList; }
Example 5
Source File: DictionaryItemServiceImpl.java From zuihou-admin-boot with Apache License 2.0 | 6 votes |
@Override public Map<String, Map<String, String>> map(String[] types) { if (ArrayUtil.isEmpty(types)) { return Collections.emptyMap(); } LbqWrapper<DictionaryItem> query = Wraps.<DictionaryItem>lbQ() .in(DictionaryItem::getDictionaryType, types) .eq(DictionaryItem::getStatus, true) .orderByAsc(DictionaryItem::getSortValue); List<DictionaryItem> list = super.list(query); //key 是类型 Map<String, List<DictionaryItem>> typeMap = list.stream().collect(groupingBy(DictionaryItem::getDictionaryType, LinkedHashMap::new, toList())); //需要返回的map Map<String, Map<String, String>> typeCodeNameMap = new LinkedHashMap<>(typeMap.size()); typeMap.forEach((key, items) -> { ImmutableMap<String, String> itemCodeMap = MapHelper.uniqueIndex(items, DictionaryItem::getCode, DictionaryItem::getName); typeCodeNameMap.put(key, itemCodeMap); }); return typeCodeNameMap; }
Example 6
Source File: AuthorityGeneralController.java From zuihou-admin-boot with Apache License 2.0 | 6 votes |
@ApiOperation(value = "获取当前系统指定枚举", notes = "获取当前系统指定枚举") @GetMapping("/enums") public R<Map<String, Map<String, String>>> enums(@RequestParam(value = "codes[]", required = false) String[] codes) { if (ArrayUtil.isEmpty(codes)) { return R.success(ENUM_MAP); } Map<String, Map<String, String>> map = new HashMap<>(codes.length); for (String code : codes) { if (ENUM_MAP.containsKey(code)) { map.put(code, ENUM_MAP.get(code)); } } return R.success(map); }
Example 7
Source File: ZooLockAspect.java From spring-boot-demo with MIT License | 5 votes |
/** * 构造分布式锁的键 * * @param lock 注解 * @param method 注解标记的方法 * @param args 方法上的参数 * @return * @throws NoSuchFieldException * @throws IllegalAccessException */ private String buildLockKey(ZooLock lock, Method method, Object[] args) throws NoSuchFieldException, IllegalAccessException { StringBuilder key = new StringBuilder(KEY_SEPARATOR + KEY_PREFIX + lock.key()); // 迭代全部参数的注解,根据使用LockKeyParam的注解的参数所在的下标,来获取args中对应下标的参数值拼接到前半部分key上 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { // 循环该参数全部注解 for (Annotation annotation : parameterAnnotations[i]) { // 注解不是 @LockKeyParam if (!annotation.annotationType().isInstance(LockKeyParam.class)) { continue; } // 获取所有fields String[] fields = ((LockKeyParam) annotation).fields(); if (ArrayUtil.isEmpty(fields)) { // 普通数据类型直接拼接 if (ObjectUtil.isNull(args[i])) { throw new RuntimeException("动态参数不能为null"); } key.append(KEY_SEPARATOR).append(args[i]); } else { // @LockKeyParam的fields值不为null,所以当前参数应该是对象类型 for (String field : fields) { Class<?> clazz = args[i].getClass(); Field declaredField = clazz.getDeclaredField(field); declaredField.setAccessible(true); Object value = declaredField.get(clazz); key.append(KEY_SEPARATOR).append(value); } } } } return key.toString(); }
Example 8
Source File: SettingUtil.java From openAGV with Apache License 2.0 | 5 votes |
public static List<String> getStringList(String key) { String[] strings = SETTING.getStrings(key); if (ArrayUtil.isEmpty(strings)) { return new ArrayList<>(); } List<String> list = new ArrayList<>(strings.length); for (String str : strings) { list.add(str); } return list; }
Example 9
Source File: ResponseEntityBuilder.java From albedo with GNU Lesser General Public License v3.0 | 5 votes |
public static ResponseEntity<Result> buildFail(Object data, HttpStatus httpStatus, String... messages) { if (ArrayUtil.isEmpty(messages)) { messages = new String[]{"failed"}; } Result warn = Result.buildFailData(data, messages); warn.setHttpStatus(httpStatus); return new ResponseEntity(warn, httpStatus != null ? httpStatus : HttpStatus.OK); }
Example 10
Source File: ZooLockAspect.java From spring-boot-demo with MIT License | 5 votes |
/** * 构造分布式锁的键 * * @param lock 注解 * @param method 注解标记的方法 * @param args 方法上的参数 * @return * @throws NoSuchFieldException * @throws IllegalAccessException */ private String buildLockKey(ZooLock lock, Method method, Object[] args) throws NoSuchFieldException, IllegalAccessException { StringBuilder key = new StringBuilder(KEY_SEPARATOR + KEY_PREFIX + lock.key()); // 迭代全部参数的注解,根据使用LockKeyParam的注解的参数所在的下标,来获取args中对应下标的参数值拼接到前半部分key上 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { // 循环该参数全部注解 for (Annotation annotation : parameterAnnotations[i]) { // 注解不是 @LockKeyParam if (!annotation.annotationType().isInstance(LockKeyParam.class)) { continue; } // 获取所有fields String[] fields = ((LockKeyParam) annotation).fields(); if (ArrayUtil.isEmpty(fields)) { // 普通数据类型直接拼接 if (ObjectUtil.isNull(args[i])) { throw new RuntimeException("动态参数不能为null"); } key.append(KEY_SEPARATOR).append(args[i]); } else { // @LockKeyParam的fields值不为null,所以当前参数应该是对象类型 for (String field : fields) { Class<?> clazz = args[i].getClass(); Field declaredField = clazz.getDeclaredField(field); declaredField.setAccessible(true); Object value = declaredField.get(clazz); key.append(KEY_SEPARATOR).append(value); } } } } return key.toString(); }
Example 11
Source File: MethodParser.java From WeBASE-Codegen-Monkey with Apache License 2.0 | 5 votes |
public List<MethodMetaInfo> parseToInfoList(Class<?> clazz) { AbiDefinition[] abiDefinitions = getContractAbiList(clazz); if (ArrayUtil.isEmpty(abiDefinitions)) { return null; } List<MethodMetaInfo> lists = Lists.newArrayList(); for (AbiDefinition abiDefinition : abiDefinitions) { String abiType = abiDefinition.getType(); if (abiType.equals(AbiTypeConstants.ABI_EVENT_TYPE) || abiDefinition.isConstant()) { continue; } List<NamedType> inputs = abiDefinition.getInputs(); if (CollectionUtils.isEmpty(inputs) || StringUtils.isEmpty(inputs.get(0).getName())) { continue; } List<NamedType> outputs = abiDefinition.getOutputs(); MethodMetaInfo method = new MethodMetaInfo(); method.setType("method").setContractName(clazz.getSimpleName()); log.debug("method name : {}", abiDefinition.getName()); if (abiType.equals(AbiTypeConstants.ABI_CONSTRUCTOR_TYPE)) { method.setName(clazz.getSimpleName()); } else { method.setName(abiDefinition.getName()); } String generatedFlag = PropertiesUtils.getGlobalProperty(ParserConstants.MONITOR, method.getContractName(), method.getName(), "generated", "on"); if (generatedFlag != null && generatedFlag.equalsIgnoreCase("off")) { continue; } int shardingNO = Integer.parseInt(PropertiesUtils.getGlobalProperty(ParserConstants.SYSTEM, method.getContractName(), method.getName(), ParserConstants.SHARDINGNO, "1")); method.setShardingNO(shardingNO).setList(getFieldList(method, inputs)) .setOutputList(getOutputList(method, outputs)); lists.add(method); } return lists; }
Example 12
Source File: ZooLockAspect.java From spring-boot-demo with MIT License | 5 votes |
/** * 构造分布式锁的键 * * @param lock 注解 * @param method 注解标记的方法 * @param args 方法上的参数 * @return * @throws NoSuchFieldException * @throws IllegalAccessException */ private String buildLockKey(ZooLock lock, Method method, Object[] args) throws NoSuchFieldException, IllegalAccessException { StringBuilder key = new StringBuilder(KEY_SEPARATOR + KEY_PREFIX + lock.key()); // 迭代全部参数的注解,根据使用LockKeyParam的注解的参数所在的下标,来获取args中对应下标的参数值拼接到前半部分key上 Annotation[][] parameterAnnotations = method.getParameterAnnotations(); for (int i = 0; i < parameterAnnotations.length; i++) { // 循环该参数全部注解 for (Annotation annotation : parameterAnnotations[i]) { // 注解不是 @LockKeyParam if (!annotation.annotationType().isInstance(LockKeyParam.class)) { continue; } // 获取所有fields String[] fields = ((LockKeyParam) annotation).fields(); if (ArrayUtil.isEmpty(fields)) { // 普通数据类型直接拼接 if (ObjectUtil.isNull(args[i])) { throw new RuntimeException("动态参数不能为null"); } key.append(KEY_SEPARATOR).append(args[i]); } else { // @LockKeyParam的fields值不为null,所以当前参数应该是对象类型 for (String field : fields) { Class<?> clazz = args[i].getClass(); Field declaredField = clazz.getDeclaredField(field); declaredField.setAccessible(true); Object value = declaredField.get(clazz); key.append(KEY_SEPARATOR).append(value); } } } } return key.toString(); }
Example 13
Source File: ProjectInfoModel.java From Jpom with MIT License | 5 votes |
/** * 拼接java 执行的jar路径 * * @param projectInfoModel 项目 * @return classpath 或者 jar */ public static String getClassPathLib(ProjectInfoModel projectInfoModel) { List<File> files = listJars(projectInfoModel); if (files.size() <= 0) { return ""; } // 获取lib下面的所有jar包 StringBuilder classPath = new StringBuilder(); RunMode runMode = projectInfoModel.getRunMode(); int len = files.size(); if (runMode == RunMode.ClassPath) { classPath.append("-classpath "); } else if (runMode == RunMode.Jar || runMode == RunMode.JarWar) { classPath.append("-jar "); // 只取一个jar文件 len = 1; } else if (runMode == RunMode.JavaExtDirsCp) { classPath.append("-Djava.ext.dirs="); String javaExtDirsCp = projectInfoModel.getJavaExtDirsCp(); String[] split = StrUtil.split(javaExtDirsCp, StrUtil.COLON); if (ArrayUtil.isEmpty(split)) { classPath.append(". -cp "); } else { classPath.append(split[0]).append(" -cp "); if (split.length > 1) { classPath.append(split[1]).append(FileUtils.getJarSeparator()); } } } else { return StrUtil.EMPTY; } for (int i = 0; i < len; i++) { File file = files.get(i); classPath.append(file.getAbsolutePath()); if (i != len - 1) { classPath.append(FileUtils.getJarSeparator()); } } return classPath.toString(); }
Example 14
Source File: StorageController.java From runscore with Apache License 2.0 | 5 votes |
@PostMapping("/uploadPic") @ResponseBody public Result uploadPic(@RequestParam("file_data") MultipartFile[] files) throws IOException { if (ArrayUtil.isEmpty(files)) { return Result.fail("请选择要上传的图片"); } List<String> storageIds = new ArrayList<>(); for (MultipartFile file : files) { String filename = file.getOriginalFilename(); String storageId = storageService.uploadGatheringCode(file.getInputStream(), file.getSize(), file.getContentType(), filename); storageIds.add(storageId); } return Result.success().setData(storageIds); }
Example 15
Source File: StorageController.java From runscore with Apache License 2.0 | 5 votes |
@PostMapping("/uploadPic") @ResponseBody public Result uploadPic(@RequestParam("file_data") MultipartFile[] files) throws IOException { if (ArrayUtil.isEmpty(files)) { return Result.fail("请选择要上传的图片"); } List<String> storageIds = new ArrayList<>(); for (MultipartFile file : files) { String filename = file.getOriginalFilename(); String storageId = storageService.uploadGatheringCode(file.getInputStream(), file.getSize(), file.getContentType(), filename); storageIds.add(storageId); } return Result.success().setData(storageIds); }
Example 16
Source File: StorageController.java From runscore with Apache License 2.0 | 5 votes |
@PostMapping("/uploadPic") @ResponseBody public Result uploadPic(@RequestParam("file_data") MultipartFile[] files) throws IOException { if (ArrayUtil.isEmpty(files)) { return Result.fail("请选择要上传的图片"); } List<String> storageIds = new ArrayList<>(); for (MultipartFile file : files) { String filename = file.getOriginalFilename(); String storageId = storageService.uploadGatheringCode(file.getInputStream(), file.getSize(), file.getContentType(), filename); storageIds.add(storageId); } return Result.success().setData(storageIds); }
Example 17
Source File: Wrapper.java From yue-library with Apache License 2.0 | 5 votes |
/** * 包装字段名<br> * 有时字段与SQL的某些关键字冲突,导致SQL出错,因此需要将字段名用单引号或者反引号包装起来,避免冲突 * @param fields 字段名 * @return 包装后的字段名 */ public String[] wrap(String... fields){ if(ArrayUtil.isEmpty(fields)) { return fields; } String[] wrappedFields = new String[fields.length]; for(int i = 0; i < fields.length; i++) { wrappedFields[i] = wrap(fields[i]); } return wrappedFields; }
Example 18
Source File: SettingUtil.java From openAGV with Apache License 2.0 | 5 votes |
public static Set<String> getStringsToSet(String key, String group) { String[] stringArray = getStringArray(key, group); Set<String> set = new HashSet<>(); if (ArrayUtil.isEmpty(stringArray)) { return set; } for (String str : stringArray) { set.add(str); } return set; }