Skip to content

Commit c04875f

Browse files
committed
Bulk automated cleanup
Signed-off-by: Peter Ansell <p_ansell@yahoo.com>
1 parent 25d6e91 commit c04875f

File tree

7 files changed

+57
-50
lines changed

7 files changed

+57
-50
lines changed

core/src/main/java/com/github/jsonldjava/core/DocumentLoader.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,15 @@ public class DocumentLoader {
1717
private final Map<String, Object> m_injectedDocs = new HashMap<>();
1818

1919
/**
20-
* Identifies a system property that can be set to "true" in order to disallow
21-
* remote context loading.
20+
* Identifies a system property that can be set to "true" in order to
21+
* disallow remote context loading.
2222
*/
2323
public static final String DISALLOW_REMOTE_CONTEXT_LOADING = "com.github.jsonldjava.disallowRemoteContextLoading";
2424

2525
/**
2626
* Avoid resolving a document by instead using the given serialised
2727
* representation.
28-
*
28+
*
2929
* @param url
3030
* The URL this document represents.
3131
* @param doc
@@ -45,13 +45,13 @@ public DocumentLoader addInjectedDoc(String url, String doc) throws JsonLdError
4545

4646
/**
4747
* Loads the URL if possible, returning it as a RemoteDocument.
48-
*
48+
*
4949
* @param url
5050
* The URL to load
5151
* @return The resolved URL as a RemoteDocument
5252
* @throws JsonLdError
53-
* If there are errors loading or remote context loading has been
54-
* disallowed.
53+
* If there are errors loading or remote context loading has
54+
* been disallowed.
5555
*/
5656
public RemoteDocument loadDocument(String url) throws JsonLdError {
5757
if (m_injectedDocs.containsKey(url)) {
@@ -79,9 +79,9 @@ public RemoteDocument loadDocument(String url) throws JsonLdError {
7979
private volatile CloseableHttpClient httpClient;
8080

8181
/**
82-
* Get the {@link CloseableHttpClient} which will be used by this DocumentLoader
83-
* to resolve HTTP and HTTPS resources.
84-
*
82+
* Get the {@link CloseableHttpClient} which will be used by this
83+
* DocumentLoader to resolve HTTP and HTTPS resources.
84+
*
8585
* @return The {@link CloseableHttpClient} which this DocumentLoader uses.
8686
*/
8787
public CloseableHttpClient getHttpClient() {
@@ -100,7 +100,7 @@ public CloseableHttpClient getHttpClient() {
100100
/**
101101
* Call this method to override the default CloseableHttpClient provided by
102102
* JsonUtils.getDefaultHttpClient.
103-
*
103+
*
104104
* @param nextHttpClient
105105
* The {@link CloseableHttpClient} to replace the default with.
106106
*/

core/src/main/java/com/github/jsonldjava/core/RemoteDocument.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
/**
44
* Encapsulates a URL along with the parsed resource matching the URL.
5-
*
5+
*
66
* @author Tristan King
77
*/
88
public class RemoteDocument {
@@ -12,7 +12,7 @@ public class RemoteDocument {
1212
/**
1313
* Create a new RemoteDocument with the URL and the parsed resource for the
1414
* document.
15-
*
15+
*
1616
* @param url
1717
* The URL
1818
* @param document
@@ -25,7 +25,7 @@ public RemoteDocument(String url, Object document) {
2525

2626
/**
2727
* Get the URL for this document.
28-
*
28+
*
2929
* @return The URL for this document, as a String
3030
*/
3131
public String getDocumentUrl() {
@@ -34,7 +34,7 @@ public String getDocumentUrl() {
3434

3535
/**
3636
* Get the parsed resource for this document.
37-
*
37+
*
3838
* @return The parsed resource for this document
3939
*/
4040
public Object getDocument() {

core/src/main/java/com/github/jsonldjava/utils/JarCacheStorage.java

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -43,17 +43,17 @@
4343
* Implementation of the Apache HttpClient {@link HttpCacheStorage} interface
4444
* using {@code jarcache.json} files on the classpath to identify static JSON-LD
4545
* resources on the classpath, to avoid retrieving them.
46-
*
46+
*
4747
* @author Stian Soiland-Reyes
4848
* @author Peter Ansell p_ansell@yahoo.com
4949
*/
5050
public class JarCacheStorage implements HttpCacheStorage {
5151

5252
/**
5353
* The classpath location that is searched inside of the classloader set for
54-
* this cache. Note this search is also done on the Thread contextClassLoader if
55-
* none is explicitly set, and the System classloader if there is no
56-
* contextClassLoader.
54+
* this cache. Note this search is also done on the Thread
55+
* contextClassLoader if none is explicitly set, and the System classloader
56+
* if there is no contextClassLoader.
5757
*/
5858
private static final String JARCACHE_JSON = "jarcache.json";
5959

@@ -62,15 +62,15 @@ public class JarCacheStorage implements HttpCacheStorage {
6262
private final CacheConfig cacheConfig;
6363

6464
/**
65-
* The classloader to use, defaults to null which will use the thread context
66-
* classloader.
65+
* The classloader to use, defaults to null which will use the thread
66+
* context classloader.
6767
*/
6868
private ClassLoader classLoader = null;
6969

7070
/**
7171
* A holder for the case where the System class loader needs to be used, but
7272
* cannot be directly identified in another way.
73-
*
73+
*
7474
* Used as a key in cachedResourceList.
7575
*/
7676
private static final Object NULL_CLASS_LOADER = new Object();
@@ -101,7 +101,7 @@ public JsonNode load(URL url) throws IOException {
101101
/**
102102
* Cached URLs from the given ClassLoader to identified locations of
103103
* jarcache.json resources on the classpath
104-
*
104+
*
105105
* Uses a Guava concurrent weak reference key map to avoid holding onto
106106
* ClassLoader instances after they are otherwise unavailable.
107107
*/
@@ -120,7 +120,7 @@ public JarCacheStorage(ClassLoader classLoader, CacheConfig cacheConfig,
120120
}
121121

122122
public ClassLoader getClassLoader() {
123-
ClassLoader nextClassLoader = classLoader;
123+
final ClassLoader nextClassLoader = classLoader;
124124
if (nextClassLoader != null) {
125125
return nextClassLoader;
126126
}
@@ -129,9 +129,9 @@ public ClassLoader getClassLoader() {
129129

130130
/**
131131
* Sets the ClassLoader used internally to a new value, or null to use
132-
* {@link Thread#currentThread()} and {@link Thread#getContextClassLoader()} for
133-
* each access.
134-
*
132+
* {@link Thread#currentThread()} and {@link Thread#getContextClassLoader()}
133+
* for each access.
134+
*
135135
* @param classLoader
136136
* The classloader to use, or null to use the thread context
137137
* classloader
@@ -168,16 +168,20 @@ public HttpCacheEntry getEntry(String key) throws IOException {
168168
log.trace("Failed to normalise URI port before looking in cache: "
169169
+ requestedUri, e);
170170
}
171-
// Ignore syntax error and use the original URI directly instead
172-
// This shouldn't happen as we already attempted to parse the URI earlier and
171+
// Ignore syntax error and use the original URI directly
172+
// instead
173+
// This shouldn't happen as we already attempted to parse
174+
// the URI earlier and
173175
// would not come here if that failed
174176
}
175177
}
176178

177-
// getResources uses a cache to avoid scanning the classpath again for the
179+
// getResources uses a cache to avoid scanning the classpath again
180+
// for the
178181
// current classloader
179182
for (final URL url : getResources()) {
180-
// getJarCache attempts to use already parsed in-memory locations to avoid
183+
// getJarCache attempts to use already parsed in-memory
184+
// locations to avoid
181185
// retrieving and parsing again
182186
final JsonNode tree = getJarCache(url);
183187
for (final JsonNode node : tree) {
@@ -194,9 +198,11 @@ public HttpCacheEntry getEntry(String key) throws IOException {
194198
}
195199

196200
/**
197-
* Get all of the {@code jarcache.json} resources that exist on the classpath
198-
*
199-
* @return A cached list of jarcache.json classpath resources as {@link URL}s
201+
* Get all of the {@code jarcache.json} resources that exist on the
202+
* classpath
203+
*
204+
* @return A cached list of jarcache.json classpath resources as
205+
* {@link URL}s
200206
* @throws IOException
201207
* If there was an IO error while scanning the classpath
202208
*/
@@ -207,7 +213,8 @@ private List<URL> getResources() throws IOException {
207213
// key
208214
final Object key = cl == null ? NULL_CLASS_LOADER : cl;
209215

210-
// computeIfAbsent requires unchecked exceptions for the creation process, so we
216+
// computeIfAbsent requires unchecked exceptions for the creation
217+
// process, so we
211218
// cannot easily use it directly, instead using get and putIfAbsent
212219
List<URL> newValue = cachedResourceList.get(key);
213220
if (newValue != null) {
@@ -223,15 +230,16 @@ private List<URL> getResources() throws IOException {
223230
}
224231

225232
final List<URL> oldValue = cachedResourceList.putIfAbsent(key, newValue);
226-
// We are not synchronising access to the ConcurrentMap, so if there were
233+
// We are not synchronising access to the ConcurrentMap, so if there
234+
// were
227235
// multiple classpath scans, we always choose the first one
228236
return oldValue != null ? oldValue : newValue;
229237
}
230238

231239
protected JsonNode getJarCache(URL url) throws IOException {
232240
try {
233241
return jarCaches.get(url);
234-
} catch (ExecutionException e) {
242+
} catch (final ExecutionException e) {
235243
throw new IOException("Failed to retrieve jar cache for URL: " + url, e);
236244
}
237245
}

core/src/main/java/com/github/jsonldjava/utils/JsonUtils.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -420,15 +420,15 @@ public static CloseableHttpClient createDefaultHttpClient() {
420420
}
421421

422422
public static CacheConfig createDefaultCacheConfig() {
423-
return CacheConfig.custom().setMaxCacheEntries(500)
424-
.setMaxObjectSize(1024 * 256).setSharedCache(false)
425-
.setHeuristicCachingEnabled(true).setHeuristicDefaultLifetime(86400).build();
423+
return CacheConfig.custom().setMaxCacheEntries(500).setMaxObjectSize(1024 * 256)
424+
.setSharedCache(false).setHeuristicCachingEnabled(true)
425+
.setHeuristicDefaultLifetime(86400).build();
426426
}
427427

428428
public static CloseableHttpClient createDefaultHttpClient(final CacheConfig cacheConfig) {
429429
return createDefaultHttpClientBuilder(cacheConfig).build();
430430
}
431-
431+
432432
public static HttpClientBuilder createDefaultHttpClientBuilder(final CacheConfig cacheConfig) {
433433
// Common CacheConfig for both the JarCacheStorage and the underlying
434434
// BasicHttpCacheStorage

core/src/test/java/com/github/jsonldjava/core/DocumentLoaderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -413,12 +413,12 @@ public void injectContext() throws Exception {
413413
@Test
414414
public void testRemoteContextCaching() throws Exception {
415415
final String[] urls = { "http://schema.org/", "http://schema.org/docs/jsonldcontext.json" };
416-
for (String url : urls) {
417-
long start = System.currentTimeMillis();
416+
for (final String url : urls) {
417+
final long start = System.currentTimeMillis();
418418
for (int i = 1; i <= 1000; i++) {
419419
documentLoader.loadDocument(url);
420420

421-
long seconds = (System.currentTimeMillis() - start) / 1000;
421+
final long seconds = (System.currentTimeMillis() - start) / 1000;
422422

423423
if (seconds > 60) {
424424
fail(String.format("Took %s seconds to access %s %s times", seconds, url, i));

core/src/test/java/com/github/jsonldjava/core/JsonLdPerformanceTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -623,18 +623,18 @@ public final void duplicatedTriplesInAnRDFDataset() throws Exception {
623623
options.useNamespaces = true;
624624

625625
// System.out.println("\nJSON-LD output is OK:\n");
626-
Object fromRDF1 = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),
626+
final Object fromRDF1 = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf),
627627
inputRdf.getContext(), options);
628628

629-
String jsonld1 = JsonUtils.toPrettyString(fromRDF1);
629+
final String jsonld1 = JsonUtils.toPrettyString(fromRDF1);
630630
// System.out.println(jsonld1);
631631

632632
// System.out.println(
633633
// "\nWouldn't be the case assuming there is no duplicated triple in
634634
// RDFDataset:\n");
635-
Object fromRDF2 = JsonLdProcessor.compact(new JsonLdApi(options).fromRDF(inputRdf, true),
636-
inputRdf.getContext(), options);
637-
String jsonld2 = JsonUtils.toPrettyString(fromRDF2);
635+
final Object fromRDF2 = JsonLdProcessor.compact(
636+
new JsonLdApi(options).fromRDF(inputRdf, true), inputRdf.getContext(), options);
637+
final String jsonld2 = JsonUtils.toPrettyString(fromRDF2);
638638
// System.out.println(jsonld2);
639639

640640
}

core/src/test/java/com/github/jsonldjava/core/MinimalSchemaOrgRegressionTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.io.StringWriter;
1010
import java.net.HttpURLConnection;
1111
import java.net.URL;
12-
import java.nio.charset.Charset;
1312
import java.nio.charset.StandardCharsets;
1413

1514
import org.apache.commons.io.IOUtils;
@@ -36,7 +35,7 @@ public class MinimalSchemaOrgRegressionTest {
3635
@Test
3736
public void testHttpURLConnection() throws Exception {
3837
final URL url = new URL("http://schema.org/");
39-
boolean followRedirectsSetting = HttpURLConnection.getFollowRedirects();
38+
final boolean followRedirectsSetting = HttpURLConnection.getFollowRedirects();
4039
try {
4140
HttpURLConnection.setFollowRedirects(true);
4241
final HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();

0 commit comments

Comments
 (0)