revised Java 6 checks to test for the presence of specific Java 6 interfaces/classes only
This commit is contained in:
@@ -26,8 +26,6 @@ import java.util.LinkedHashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.NavigableMap;
|
||||
import java.util.NavigableSet;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.SortedSet;
|
||||
@@ -36,6 +34,7 @@ import java.util.TreeSet;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.CopyOnWriteArraySet;
|
||||
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
|
||||
/**
|
||||
@@ -53,21 +52,34 @@ import org.springframework.util.LinkedCaseInsensitiveMap;
|
||||
*/
|
||||
public abstract class CollectionFactory {
|
||||
|
||||
private static final String NAVIGABLE_SET_CLASS_NAME = "java.util.NavigableSet";
|
||||
|
||||
private static final String NAVIGABLE_MAP_CLASS_NAME = "java.util.NavigableMap";
|
||||
|
||||
private static final Set<Class> approximableCollectionTypes = new HashSet<Class>(10);
|
||||
|
||||
private static final Set<Class> approximableMapTypes = new HashSet<Class>(6);
|
||||
|
||||
|
||||
static {
|
||||
// Standard collection interfaces
|
||||
approximableCollectionTypes.add(Collection.class);
|
||||
approximableCollectionTypes.add(List.class);
|
||||
approximableCollectionTypes.add(Set.class);
|
||||
approximableCollectionTypes.add(SortedSet.class);
|
||||
approximableMapTypes.add(Map.class);
|
||||
approximableMapTypes.add(SortedMap.class);
|
||||
if (JdkVersion.isAtLeastJava16()) {
|
||||
approximableCollectionTypes.add(NavigableSet.class);
|
||||
approximableMapTypes.add(NavigableMap.class);
|
||||
|
||||
// New Java 6 collection interfaces
|
||||
try {
|
||||
approximableCollectionTypes.add(ClassUtils.forName(NAVIGABLE_SET_CLASS_NAME, CollectionFactory.class.getClassLoader()));
|
||||
approximableMapTypes.add(ClassUtils.forName(NAVIGABLE_MAP_CLASS_NAME, CollectionFactory.class.getClassLoader()));
|
||||
}
|
||||
catch (ClassNotFoundException ex) {
|
||||
// not running on Java 6 or above...
|
||||
}
|
||||
|
||||
// Common concrete collection classes
|
||||
approximableCollectionTypes.add(ArrayList.class);
|
||||
approximableCollectionTypes.add(LinkedList.class);
|
||||
approximableCollectionTypes.add(HashSet.class);
|
||||
@@ -78,6 +90,7 @@ public abstract class CollectionFactory {
|
||||
approximableMapTypes.add(TreeMap.class);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Create a linked Set if possible: This implementation always
|
||||
* creates a {@link java.util.LinkedHashSet}, since Spring 2.5
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2008 the original author or authors.
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -17,11 +17,11 @@
|
||||
package org.springframework.core;
|
||||
|
||||
/**
|
||||
* Internal helper class used to find the Java/JDK version
|
||||
* Internal helper class used to find the Java/JVM version
|
||||
* that Spring is operating on, to allow for automatically
|
||||
* adapting to the present platform's capabilities.
|
||||
*
|
||||
* <p>Note that Spring requires JVM 1.4 or higher, as of Spring 2.5.
|
||||
* <p>Note that Spring requires JVM 1.5 or higher, as of Spring 3.0.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
@@ -62,10 +62,10 @@ public abstract class JdkVersion {
|
||||
static {
|
||||
javaVersion = System.getProperty("java.version");
|
||||
// version String should look like "1.4.2_10"
|
||||
if (javaVersion.indexOf("1.7.") != -1) {
|
||||
if (javaVersion.contains("1.7.")) {
|
||||
majorJavaVersion = JAVA_17;
|
||||
}
|
||||
else if (javaVersion.indexOf("1.6.") != -1) {
|
||||
else if (javaVersion.contains("1.6.")) {
|
||||
majorJavaVersion = JAVA_16;
|
||||
}
|
||||
else {
|
||||
@@ -99,6 +99,7 @@ public abstract class JdkVersion {
|
||||
return majorJavaVersion;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Convenience method to determine if the current JVM is at least Java 1.4.
|
||||
* @return <code>true</code> if the current JVM is at least Java 1.4
|
||||
@@ -133,12 +134,15 @@ public abstract class JdkVersion {
|
||||
* Convenience method to determine if the current JVM is at least
|
||||
* Java 1.6 (Java 6).
|
||||
* @return <code>true</code> if the current JVM is at least Java 1.6
|
||||
* @deprecated as of Spring 3.0, in favor of reflective checks for
|
||||
* the specific Java 1.6 classes of interest
|
||||
* @see #getMajorJavaVersion()
|
||||
* @see #JAVA_16
|
||||
* @see #JAVA_17
|
||||
*/
|
||||
@Deprecated
|
||||
public static boolean isAtLeastJava16() {
|
||||
return getMajorJavaVersion() >= JAVA_16;
|
||||
return (majorJavaVersion >= JAVA_16);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user