001/** 002 * Copyright (c) 2015-2022, Michael Yang 杨福海 (fuhai999@gmail.com). 003 * <p> 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * <p> 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * <p> 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package io.jboot.utils; 017 018 019import io.jboot.app.config.JbootConfigKit; 020 021public class AnnotationUtil { 022 023 public static String get(String value) { 024 return get(value, StrUtil.EMPTY); 025 } 026 027 public static String get(String value, String defaultValue) { 028 if (StrUtil.isNotBlank(value)) { 029 String ret = JbootConfigKit.parseValue(value.trim()); 030 if (StrUtil.isNotBlank(ret)) { 031 return ret; 032 } 033 } 034 return defaultValue; 035 } 036 037 public static String[] get(String[] value) { 038 if (ArrayUtil.isNullOrEmpty(value)) { 039 return null; 040 } 041 042 String[] rets = new String[value.length]; 043 for (int i = 0; i < rets.length; i++) { 044 rets[i] = get(value[i]); 045 } 046 return rets; 047 } 048 049 050 051 public static Integer getInt(String value) { 052 String intValue = get(value); 053 return intValue == null ? null : Integer.parseInt(intValue); 054 } 055 056 public static Integer getInt(String value, int defaultValue) { 057 String intValue = get(value); 058 return intValue == null ? defaultValue : Integer.parseInt(intValue); 059 } 060 061 public static Long getLong(String value) { 062 String longValue = get(value); 063 return longValue == null ? null : Long.parseLong(longValue); 064 } 065 066 public static Long getLong(String value, long defaultValue) { 067 String longValue = get(value); 068 return longValue == null ? defaultValue : Long.parseLong(longValue); 069 } 070 071 public static Boolean getBool(String value) { 072 String boolValue = get(value); 073 return boolValue == null ? null : Boolean.parseBoolean(boolValue); 074 } 075 076 public static Boolean getBool(String value, boolean defaultValue) { 077 String boolValue = get(value); 078 return boolValue == null ? defaultValue : Boolean.parseBoolean(boolValue); 079 } 080 081 082 083}