diff --git a/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java b/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java deleted file mode 100644 index 8255a38395308e901986e8b5c4d272a6db50af59..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/classpath/CachedClassForNameResolver.java +++ /dev/null @@ -1,58 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.classpath; - -import java.util.concurrent.ConcurrentHashMap; -import java.util.concurrent.ConcurrentMap; - -/** - * @param <T> - * the type that is used to cast a type that was found in the class path - * - * @author Christian Wulf - */ -public final class CachedClassForNameResolver<T> { - - private final ConcurrentMap<String, Class<? extends T>> cachedClasses = new ConcurrentHashMap<String, Class<? extends T>>(); // NOCS - private final ClassForNameResolver<T> classForNameResolver; - - public CachedClassForNameResolver(final ClassForNameResolver<T> classForNameResolver) { - this.classForNameResolver = classForNameResolver; - } - - /** - * This method tries to find a class with the given name. - * - * @param classname - * The name of the class. - * - * @return A {@link Class} instance corresponding to the given name, if it exists. - * - * @throws ClassNotFoundException - * thrown iff no class was found for the given <b>classname</b> - */ - public final Class<? extends T> classForName(final String classname) throws ClassNotFoundException { - Class<? extends T> clazz = this.cachedClasses.get(classname); - if (clazz == null) { - clazz = this.classForNameResolver.classForName(classname); - final Class<? extends T> previousClass = this.cachedClasses.putIfAbsent(classname, clazz); - if (null != previousClass) { - clazz = previousClass; - } - } - return clazz; - } -} diff --git a/src/main/java/teetime/util/classpath/ClassForNameResolver.java b/src/main/java/teetime/util/classpath/ClassForNameResolver.java deleted file mode 100644 index 349efcdfd3806d2f8e7730914215c4cffde3b103..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/classpath/ClassForNameResolver.java +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.classpath; - -/** - * @param <T> - * the type that is used to cast a type that was found in the class path - * - * @author Christian Wulf - * @since 1.11 - */ -public final class ClassForNameResolver<T> { - - private final Class<T> classToCast; - - public ClassForNameResolver(final Class<T> classToCast) { - this.classToCast = classToCast; - } - - /** - * This method tries to find a class with the given name. - * - * @param classname - * The name of the class. - * - * @return A {@link Class} instance corresponding to the given name, if it exists. - * @throws ClassNotFoundException - * thrown iff no class was found for the given <b>classname</b> - * - */ - public final Class<? extends T> classForName(final String classname) throws ClassNotFoundException { - final Class<?> clazz = Class.forName(classname); - return clazz.asSubclass(this.classToCast); - } -} diff --git a/src/main/java/teetime/util/classpath/FileSearcher.java b/src/main/java/teetime/util/classpath/FileSearcher.java deleted file mode 100644 index 413bcf4dbf9037f5fb9a0ec91d1a2a59224266dc..0000000000000000000000000000000000000000 --- a/src/main/java/teetime/util/classpath/FileSearcher.java +++ /dev/null @@ -1,41 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.classpath; - -import java.io.IOException; -import java.net.URL; -import java.util.ArrayList; -import java.util.Enumeration; -import java.util.List; - -public final class FileSearcher { - - private static final ClassLoader CLASS_LOADER = ClassLoader.getSystemClassLoader(); - - private FileSearcher() { - // utility class - } - - public static List<URL> loadResources(final String name) throws IOException { - final List<URL> urls = new ArrayList<URL>(); - - final Enumeration<URL> systemRes = CLASS_LOADER.getResources(name); - while (systemRes.hasMoreElements()) { - urls.add(systemRes.nextElement()); - } - return urls; - } -} diff --git a/src/test/java/teetime/util/classpath/FileSearcherTest.java b/src/test/java/teetime/util/classpath/FileSearcherTest.java deleted file mode 100644 index 05eedee1ace93401af3a3d155bb35e79b2d09bb8..0000000000000000000000000000000000000000 --- a/src/test/java/teetime/util/classpath/FileSearcherTest.java +++ /dev/null @@ -1,49 +0,0 @@ -/** - * Copyright (C) 2015 Christian Wulf, Nelson Tavares de Sousa (http://teetime.sourceforge.net) - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package teetime.util.classpath; - -import java.io.IOException; -import java.net.URL; -import java.util.List; - -import org.junit.Assert; -import org.junit.Test; - -import teetime.util.classpath.FileSearcher; - -public class FileSearcherTest { - - public FileSearcherTest() {} - - @Test - public void fileInClasspath() throws IOException { - final List<URL> urls = FileSearcher.loadResources("pipe-factories.conf"); - Assert.assertEquals(false, urls.isEmpty()); - } - - @Test - public void multipleFiles() throws IOException { - final List<URL> urls = FileSearcher.loadResources("LICENSE.txt"); - Assert.assertEquals(true, urls.size() > 1); - } - - @Test - public void missingFile() throws IOException { - final List<URL> urls = FileSearcher.loadResources("filethatdoesnotexistinanyproject.nope"); - Assert.assertEquals(true, urls.isEmpty()); - } - -}