Browse Source

fix issue#503

Looly 6 years ago
parent
commit
3928cbb21f

+ 17 - 14
hutool-core/src/main/java/cn/hutool/core/getter/BasicTypeGetter.java

@@ -7,18 +7,20 @@ import java.util.Date;
 /**
  * 基本类型的getter接口<br>
  * 提供一个统一的接口定义返回不同类型的值(基本类型)<br>
+ * 
  * @author Looly
  */
 public interface BasicTypeGetter<K> {
 	/*-------------------------- 基本类型 start -------------------------------*/
-	
+
 	/**
 	 * 获取Object属性值
+	 * 
 	 * @param key 属性名
 	 * @return 属性值
 	 */
 	Object getObj(K key);
-	
+
 	/**
 	 * 获取字符串型属性值
 	 * 
@@ -26,7 +28,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	String getStr(K key);
-	
+
 	/**
 	 * 获取int型属性值
 	 * 
@@ -34,7 +36,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Integer getInt(K key);
-	
+
 	/**
 	 * 获取short型属性值
 	 * 
@@ -42,7 +44,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Short getShort(K key);
-	
+
 	/**
 	 * 获取boolean型属性值
 	 * 
@@ -50,7 +52,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Boolean getBool(K key);
-	
+
 	/**
 	 * 获取long型属性值
 	 * 
@@ -58,7 +60,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Long getLong(K key);
-	
+
 	/**
 	 * 获取char型属性值
 	 * 
@@ -66,7 +68,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Character getChar(K key);
-	
+
 	/**
 	 * 获取float型属性值<br>
 	 * 
@@ -74,7 +76,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Float getFloat(K key);
-	
+
 	/**
 	 * 获取double型属性值
 	 * 
@@ -82,7 +84,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Double getDouble(K key);
-	
+
 	/**
 	 * 获取byte型属性值
 	 * 
@@ -90,7 +92,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	Byte getByte(K key);
-	
+
 	/**
 	 * 获取BigDecimal型属性值
 	 * 
@@ -98,7 +100,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	BigDecimal getBigDecimal(K key);
-	
+
 	/**
 	 * 获取BigInteger型属性值
 	 * 
@@ -106,7 +108,7 @@ public interface BasicTypeGetter<K> {
 	 * @return 属性值
 	 */
 	BigInteger getBigInteger(K key);
-	
+
 	/**
 	 * 获得Enum类型的值
 	 * 
@@ -116,9 +118,10 @@ public interface BasicTypeGetter<K> {
 	 * @return Enum类型的值,无则返回Null
 	 */
 	<E extends Enum<E>> E getEnum(Class<E> clazz, K key);
-	
+
 	/**
 	 * 获取Date类型值
+	 * 
 	 * @param key 属性名
 	 * @return Date类型属性值
 	 */

+ 19 - 6
hutool-core/src/main/java/cn/hutool/core/lang/Dict.java

@@ -26,7 +26,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 
 	static final float DEFAULT_LOAD_FACTOR = 0.75f;
 	static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
-	
+
 	/** 是否大小写不敏感 */
 	private boolean caseInsensitive;
 
@@ -59,7 +59,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 	public Dict() {
 		this(false);
 	}
-	
+
 	/**
 	 * 构造
 	 * 
@@ -77,7 +77,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 	public Dict(int initialCapacity) {
 		this(initialCapacity, false);
 	}
-	
+
 	/**
 	 * 构造
 	 * 
@@ -87,7 +87,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 	public Dict(int initialCapacity, boolean caseInsensitive) {
 		this(initialCapacity, DEFAULT_LOAD_FACTOR, caseInsensitive);
 	}
-	
+
 	/**
 	 * 构造
 	 * 
@@ -304,6 +304,19 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 	 * @param attr 字段名
 	 * @param defaultValue 默认值
 	 * @return 字段值
+	 * @since 4.6.3
+	 */
+	public <T> T getBean(String attr) {
+		return get(attr, null);
+	}
+
+	/**
+	 * 获得特定类型值
+	 * 
+	 * @param <T> 值类型
+	 * @param attr 字段名
+	 * @param defaultValue 默认值
+	 * @return 字段值
 	 */
 	@SuppressWarnings("unchecked")
 	public <T> T get(String attr, T defaultValue) {
@@ -439,7 +452,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 		return get(attr, null);
 	}
 	// -------------------------------------------------------------------- Get end
-	
+
 	@Override
 	public Object put(String key, Object value) {
 		return super.put(customKey(key), value);
@@ -449,7 +462,7 @@ public class Dict extends LinkedHashMap<String, Object> implements BasicTypeGett
 	public Dict clone() {
 		return (Dict) super.clone();
 	}
-	
+
 	/**
 	 * 将Key转为小写
 	 * 

+ 12 - 1
hutool-core/src/main/java/cn/hutool/core/swing/DesktopUtil.java

@@ -3,6 +3,7 @@ package cn.hutool.core.swing;
 import java.awt.Desktop;
 import java.io.File;
 import java.io.IOException;
+import java.net.URI;
 
 import cn.hutool.core.io.IORuntimeException;
 import cn.hutool.core.util.URLUtil;
@@ -31,9 +32,19 @@ public class DesktopUtil {
 	 * @param url URL地址
 	 */
 	public static void browse(String url) {
+		browse(URLUtil.toURI(url));
+	}
+	
+	/**
+	 * 使用平台默认浏览器打开指定URI地址
+	 * 
+	 * @param uri URI地址
+	 * @since 4.6.3
+	 */
+	public static void browse(URI uri) {
 		final Desktop dsktop = getDsktop();
 		try {
-			dsktop.browse(URLUtil.toURI(url));
+			dsktop.browse(uri);
 		} catch (IOException e) {
 			throw new IORuntimeException(e);
 		}

+ 1 - 1
hutool-extra/src/main/java/cn/hutool/extra/ssh/JschUtil.java

@@ -285,7 +285,7 @@ public class JschUtil {
 		} catch (IOException e) {
 			throw new IORuntimeException(e);
 		} catch (JSchException e) {
-			throw new IORuntimeException(e);
+			throw new JschRuntimeException(e);
 		} finally {
 			IoUtil.close(in);
 			close(channel);