Skip to content

Commit 597e92a

Browse files
committed
Java 5 code style
1 parent 9e419da commit 597e92a

File tree

17 files changed

+217
-303
lines changed

17 files changed

+217
-303
lines changed

org.springframework.core/src/main/java/org/springframework/core/io/support/PathMatchingResourcePatternResolver.java

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525
import java.net.URLConnection;
2626
import java.util.Collections;
2727
import java.util.Enumeration;
28-
import java.util.Iterator;
2928
import java.util.LinkedHashSet;
3029
import java.util.Set;
3130
import java.util.jar.JarEntry;
@@ -297,12 +296,12 @@ protected Resource[] findAllClassPathResources(String location) throws IOExcepti
297296
path = path.substring(1);
298297
}
299298
Enumeration resourceUrls = getClassLoader().getResources(path);
300-
Set result = new LinkedHashSet(16);
299+
Set<Resource> result = new LinkedHashSet<Resource>(16);
301300
while (resourceUrls.hasMoreElements()) {
302301
URL url = (URL) resourceUrls.nextElement();
303302
result.add(convertClassLoaderURL(url));
304303
}
305-
return (Resource[]) result.toArray(new Resource[result.size()]);
304+
return result.toArray(new Resource[result.size()]);
306305
}
307306

308307
/**
@@ -332,9 +331,9 @@ protected Resource[] findPathMatchingResources(String locationPattern) throws IO
332331
String rootDirPath = determineRootDir(locationPattern);
333332
String subPattern = locationPattern.substring(rootDirPath.length());
334333
Resource[] rootDirResources = getResources(rootDirPath);
335-
Set result = new LinkedHashSet(16);
336-
for (int i = 0; i < rootDirResources.length; i++) {
337-
Resource rootDirResource = resolveRootDirResource(rootDirResources[i]);
334+
Set<Resource> result = new LinkedHashSet<Resource>(16);
335+
for (Resource rootDirResource : rootDirResources) {
336+
rootDirResource = resolveRootDirResource(rootDirResource);
338337
if (isJarResource(rootDirResource)) {
339338
result.addAll(doFindPathMatchingJarResources(rootDirResource, subPattern));
340339
}
@@ -345,7 +344,7 @@ protected Resource[] findPathMatchingResources(String locationPattern) throws IO
345344
if (logger.isDebugEnabled()) {
346345
logger.debug("Resolved location pattern [" + locationPattern + "] to resources " + result);
347346
}
348-
return (Resource[]) result.toArray(new Resource[result.size()]);
347+
return result.toArray(new Resource[result.size()]);
349348
}
350349

351350
/**
@@ -416,7 +415,9 @@ protected boolean isJarResource(Resource resource) throws IOException {
416415
* @see java.net.JarURLConnection
417416
* @see org.springframework.util.PathMatcher
418417
*/
419-
protected Set doFindPathMatchingJarResources(Resource rootDirResource, String subPattern) throws IOException {
418+
protected Set<Resource> doFindPathMatchingJarResources(Resource rootDirResource, String subPattern)
419+
throws IOException {
420+
420421
URLConnection con = rootDirResource.getURL().openConnection();
421422
JarFile jarFile = null;
422423
String jarFileUrl = null;
@@ -461,7 +462,7 @@ protected Set doFindPathMatchingJarResources(Resource rootDirResource, String su
461462
// The Sun JRE does not return a slash here, but BEA JRockit does.
462463
rootEntryPath = rootEntryPath + "/";
463464
}
464-
Set result = new LinkedHashSet(8);
465+
Set<Resource> result = new LinkedHashSet<Resource>(8);
465466
for (Enumeration entries = jarFile.entries(); entries.hasMoreElements();) {
466467
JarEntry entry = (JarEntry) entries.nextElement();
467468
String entryPath = entry.getName();
@@ -511,7 +512,9 @@ protected JarFile getJarFile(String jarFileUrl) throws IOException {
511512
* @see #retrieveMatchingFiles
512513
* @see org.springframework.util.PathMatcher
513514
*/
514-
protected Set doFindPathMatchingFileResources(Resource rootDirResource, String subPattern) throws IOException {
515+
protected Set<Resource> doFindPathMatchingFileResources(Resource rootDirResource, String subPattern)
516+
throws IOException {
517+
515518
File rootDir = null;
516519
try {
517520
rootDir = rootDirResource.getFile().getAbsoluteFile();
@@ -521,7 +524,7 @@ protected Set doFindPathMatchingFileResources(Resource rootDirResource, String s
521524
logger.debug("Cannot search for matching files underneath " + rootDirResource +
522525
" because it does not correspond to a directory in the file system", ex);
523526
}
524-
return Collections.EMPTY_SET;
527+
return Collections.emptySet();
525528
}
526529
return doFindMatchingFileSystemResources(rootDir, subPattern);
527530
}
@@ -536,14 +539,13 @@ protected Set doFindPathMatchingFileResources(Resource rootDirResource, String s
536539
* @see #retrieveMatchingFiles
537540
* @see org.springframework.util.PathMatcher
538541
*/
539-
protected Set doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
542+
protected Set<Resource> doFindMatchingFileSystemResources(File rootDir, String subPattern) throws IOException {
540543
if (logger.isDebugEnabled()) {
541544
logger.debug("Looking for matching resources in directory tree [" + rootDir.getPath() + "]");
542545
}
543-
Set matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
544-
Set result = new LinkedHashSet(matchingFiles.size());
545-
for (Iterator it = matchingFiles.iterator(); it.hasNext();) {
546-
File file = (File) it.next();
546+
Set<File> matchingFiles = retrieveMatchingFiles(rootDir, subPattern);
547+
Set<Resource> result = new LinkedHashSet<Resource>(matchingFiles.size());
548+
for (File file : matchingFiles) {
547549
result.add(new FileSystemResource(file));
548550
}
549551
return result;
@@ -558,7 +560,7 @@ protected Set doFindMatchingFileSystemResources(File rootDir, String subPattern)
558560
* @return the Set of matching File instances
559561
* @throws IOException if directory contents could not be retrieved
560562
*/
561-
protected Set retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
563+
protected Set<File> retrieveMatchingFiles(File rootDir, String pattern) throws IOException {
562564
if (!rootDir.isDirectory()) {
563565
throw new IllegalArgumentException("Resource path [" + rootDir + "] does not denote a directory");
564566
}
@@ -567,7 +569,7 @@ protected Set retrieveMatchingFiles(File rootDir, String pattern) throws IOExcep
567569
fullPattern += "/";
568570
}
569571
fullPattern = fullPattern + StringUtils.replace(pattern, File.separator, "/");
570-
Set result = new LinkedHashSet(8);
572+
Set<File> result = new LinkedHashSet<File>(8);
571573
doRetrieveMatchingFiles(fullPattern, rootDir, result);
572574
return result;
573575
}
@@ -581,7 +583,7 @@ protected Set retrieveMatchingFiles(File rootDir, String pattern) throws IOExcep
581583
* @param result the Set of matching File instances to add to
582584
* @throws IOException if directory contents could not be retrieved
583585
*/
584-
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set result) throws IOException {
586+
protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set<File> result) throws IOException {
585587
if (logger.isDebugEnabled()) {
586588
logger.debug("Searching directory [" + dir.getAbsolutePath() +
587589
"] for files matching pattern [" + fullPattern + "]");
@@ -590,8 +592,7 @@ protected void doRetrieveMatchingFiles(String fullPattern, File dir, Set result)
590592
if (dirContents == null) {
591593
throw new IOException("Could not retrieve contents of directory [" + dir.getAbsolutePath() + "]");
592594
}
593-
for (int i = 0; i < dirContents.length; i++) {
594-
File content = dirContents[i];
595+
for (File content : dirContents) {
595596
String currPath = StringUtils.replace(content.getAbsolutePath(), File.separator, "/");
596597
if (content.isDirectory() && getPathMatcher().matchStart(fullPattern, currPath + "/")) {
597598
doRetrieveMatchingFiles(fullPattern, content, result);

org.springframework.orm/src/main/java/org/springframework/orm/hibernate3/LocalSessionFactoryBean.java

Lines changed: 35 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import java.sql.Statement;
2424
import java.util.Collection;
2525
import java.util.Enumeration;
26-
import java.util.Iterator;
2726
import java.util.Map;
2827
import java.util.Properties;
2928
import javax.sql.DataSource;
@@ -52,7 +51,6 @@
5251
import org.springframework.jdbc.datasource.TransactionAwareDataSourceProxy;
5352
import org.springframework.jdbc.support.JdbcUtils;
5453
import org.springframework.jdbc.support.lob.LobHandler;
55-
import org.springframework.util.Assert;
5654
import org.springframework.util.ClassUtils;
5755
import org.springframework.util.StringUtils;
5856

@@ -108,13 +106,17 @@
108106
*/
109107
public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implements BeanClassLoaderAware {
110108

111-
private static final ThreadLocal configTimeDataSourceHolder = new ThreadLocal();
109+
private static final ThreadLocal<DataSource> configTimeDataSourceHolder =
110+
new ThreadLocal<DataSource>();
112111

113-
private static final ThreadLocal configTimeTransactionManagerHolder = new ThreadLocal();
112+
private static final ThreadLocal<TransactionManager> configTimeTransactionManagerHolder =
113+
new ThreadLocal<TransactionManager>();
114114

115-
private static final ThreadLocal configTimeCacheProviderHolder = new ThreadLocal();
115+
private static final ThreadLocal<CacheProvider> configTimeCacheProviderHolder =
116+
new ThreadLocal<CacheProvider>();
116117

117-
private static final ThreadLocal configTimeLobHandlerHolder = new ThreadLocal();
118+
private static final ThreadLocal<LobHandler> configTimeLobHandlerHolder =
119+
new ThreadLocal<LobHandler>();
118120

119121
/**
120122
* Return the DataSource for the currently configured Hibernate SessionFactory,
@@ -126,7 +128,7 @@ public class LocalSessionFactoryBean extends AbstractSessionFactoryBean implemen
126128
* @see LocalDataSourceConnectionProvider
127129
*/
128130
public static DataSource getConfigTimeDataSource() {
129-
return (DataSource) configTimeDataSourceHolder.get();
131+
return configTimeDataSourceHolder.get();
130132
}
131133

132134
/**
@@ -139,7 +141,7 @@ public static DataSource getConfigTimeDataSource() {
139141
* @see LocalTransactionManagerLookup
140142
*/
141143
public static TransactionManager getConfigTimeTransactionManager() {
142-
return (TransactionManager) configTimeTransactionManagerHolder.get();
144+
return configTimeTransactionManagerHolder.get();
143145
}
144146

145147
/**
@@ -151,7 +153,7 @@ public static TransactionManager getConfigTimeTransactionManager() {
151153
* @see #setCacheProvider
152154
*/
153155
public static CacheProvider getConfigTimeCacheProvider() {
154-
return (CacheProvider) configTimeCacheProviderHolder.get();
156+
return configTimeCacheProviderHolder.get();
155157
}
156158

157159
/**
@@ -166,7 +168,7 @@ public static CacheProvider getConfigTimeCacheProvider() {
166168
* @see org.springframework.orm.hibernate3.support.BlobSerializableType
167169
*/
168170
public static LobHandler getConfigTimeLobHandler() {
169-
return (LobHandler) configTimeLobHandlerHolder.get();
171+
return configTimeLobHandlerHolder.get();
170172
}
171173

172174

@@ -204,7 +206,7 @@ public static LobHandler getConfigTimeLobHandler() {
204206

205207
private Properties collectionCacheStrategies;
206208

207-
private Map eventListeners;
209+
private Map<String, Object> eventListeners;
208210

209211
private boolean schemaUpdate = false;
210212

@@ -484,7 +486,7 @@ public void setCollectionCacheStrategies(Properties collectionCacheStrategies) {
484486
* listener objects as values
485487
* @see org.hibernate.cfg.Configuration#setListener(String, Object)
486488
*/
487-
public void setEventListeners(Map eventListeners) {
489+
public void setEventListeners(Map<String, Object> eventListeners) {
488490
this.eventListeners = eventListeners;
489491
}
490492

@@ -506,6 +508,7 @@ public void setBeanClassLoader(ClassLoader beanClassLoader) {
506508

507509

508510
@Override
511+
@SuppressWarnings("unchecked")
509512
protected SessionFactory buildSessionFactory() throws Exception {
510513
// Create Configuration instance.
511514
Configuration config = newConfiguration();
@@ -576,23 +579,22 @@ protected SessionFactory buildSessionFactory() throws Exception {
576579
if (this.typeDefinitions != null) {
577580
// Register specified Hibernate type definitions.
578581
Mappings mappings = config.createMappings();
579-
for (int i = 0; i < this.typeDefinitions.length; i++) {
580-
TypeDefinitionBean typeDef = this.typeDefinitions[i];
582+
for (TypeDefinitionBean typeDef : this.typeDefinitions) {
581583
mappings.addTypeDef(typeDef.getTypeName(), typeDef.getTypeClass(), typeDef.getParameters());
582584
}
583585
}
584586

585587
if (this.filterDefinitions != null) {
586588
// Register specified Hibernate FilterDefinitions.
587-
for (int i = 0; i < this.filterDefinitions.length; i++) {
588-
config.addFilterDefinition(this.filterDefinitions[i]);
589+
for (FilterDefinition filterDef : this.filterDefinitions) {
590+
config.addFilterDefinition(filterDef);
589591
}
590592
}
591593

592594
if (this.configLocations != null) {
593-
for (int i = 0; i < this.configLocations.length; i++) {
595+
for (Resource resource : this.configLocations) {
594596
// Load Hibernate configuration from given location.
595-
config.configure(this.configLocations[i].getURL());
597+
config.configure(resource.getURL());
596598
}
597599
}
598600

@@ -620,42 +622,40 @@ else if (config.getProperty(Environment.TRANSACTION_MANAGER_STRATEGY) != null) {
620622

621623
if (this.mappingResources != null) {
622624
// Register given Hibernate mapping definitions, contained in resource files.
623-
for (int i = 0; i < this.mappingResources.length; i++) {
624-
Resource resource = new ClassPathResource(this.mappingResources[i].trim(), this.beanClassLoader);
625+
for (String mapping : this.mappingResources) {
626+
Resource resource = new ClassPathResource(mapping.trim(), this.beanClassLoader);
625627
config.addInputStream(resource.getInputStream());
626628
}
627629
}
628630

629631
if (this.mappingLocations != null) {
630632
// Register given Hibernate mapping definitions, contained in resource files.
631-
for (int i = 0; i < this.mappingLocations.length; i++) {
632-
config.addInputStream(this.mappingLocations[i].getInputStream());
633+
for (Resource resource : this.mappingLocations) {
634+
config.addInputStream(resource.getInputStream());
633635
}
634636
}
635637

636638
if (this.cacheableMappingLocations != null) {
637639
// Register given cacheable Hibernate mapping definitions, read from the file system.
638-
for (int i = 0; i < this.cacheableMappingLocations.length; i++) {
639-
config.addCacheableFile(this.cacheableMappingLocations[i].getFile());
640+
for (Resource resource : this.cacheableMappingLocations) {
641+
config.addCacheableFile(resource.getFile());
640642
}
641643
}
642644

643645
if (this.mappingJarLocations != null) {
644646
// Register given Hibernate mapping definitions, contained in jar files.
645-
for (int i = 0; i < this.mappingJarLocations.length; i++) {
646-
Resource resource = this.mappingJarLocations[i];
647+
for (Resource resource : this.mappingJarLocations) {
647648
config.addJar(resource.getFile());
648649
}
649650
}
650651

651652
if (this.mappingDirectoryLocations != null) {
652653
// Register all Hibernate mapping definitions in the given directories.
653-
for (int i = 0; i < this.mappingDirectoryLocations.length; i++) {
654-
File file = this.mappingDirectoryLocations[i].getFile();
654+
for (Resource resource : this.mappingDirectoryLocations) {
655+
File file = resource.getFile();
655656
if (!file.isDirectory()) {
656657
throw new IllegalArgumentException(
657-
"Mapping directory location [" + this.mappingDirectoryLocations[i] +
658-
"] does not denote a directory");
658+
"Mapping directory location [" + resource + "] does not denote a directory");
659659
}
660660
config.addDirectory(file);
661661
}
@@ -698,13 +698,11 @@ else if (strategyAndRegion.length > 0) {
698698

699699
if (this.eventListeners != null) {
700700
// Register specified Hibernate event listeners.
701-
for (Iterator it = this.eventListeners.entrySet().iterator(); it.hasNext();) {
702-
Map.Entry entry = (Map.Entry) it.next();
703-
Assert.isTrue(entry.getKey() instanceof String, "Event listener key needs to be of type String");
704-
String listenerType = (String) entry.getKey();
701+
for (Map.Entry<String, Object> entry : this.eventListeners.entrySet()) {
702+
String listenerType = entry.getKey();
705703
Object listenerObject = entry.getValue();
706704
if (listenerObject instanceof Collection) {
707-
Collection listeners = (Collection) listenerObject;
705+
Collection<Object> listeners = (Collection<Object>) listenerObject;
708706
EventListeners listenerRegistry = config.getEventListeners();
709707
Object[] listenerArray =
710708
(Object[]) Array.newInstance(listenerRegistry.getListenerClassFor(listenerType), listeners.size());
@@ -979,8 +977,8 @@ protected void executeSchemaScript(Connection con, String[] sql) throws SQLExcep
979977
try {
980978
Statement stmt = con.createStatement();
981979
try {
982-
for (int i = 0; i < sql.length; i++) {
983-
executeSchemaStatement(stmt, sql[i]);
980+
for (String sqlStmt : sql) {
981+
executeSchemaStatement(stmt, sqlStmt);
984982
}
985983
}
986984
finally {

0 commit comments

Comments
 (0)