Skip to content

Commit

Permalink
Chore: more idiomatic java 17, remove "i" prefix (#1916)
Browse files Browse the repository at this point in the history
  • Loading branch information
robfrank authored Jan 24, 2025
1 parent b450b04 commit 4bd7adc
Show file tree
Hide file tree
Showing 362 changed files with 3,578 additions and 3,596 deletions.
4 changes: 2 additions & 2 deletions console/src/main/java/com/arcadedb/console/Console.java
Original file line number Diff line number Diff line change
Expand Up @@ -798,7 +798,7 @@ private void output(final int level, final String text, final Object... args) {

if (args.length > 0) {
if (output != null)
output.onOutput(String.format(text, args));
output.onOutput(text.formatted(args));
else
terminal.writer().printf(text, args);
} else {
Expand Down Expand Up @@ -1019,7 +1019,7 @@ private void outputError(final Throwable e) {

private String getPrompt() {
final String databaseName = databaseProxy != null ? databaseProxy.getName() : null;
return String.format(PROMPT, databaseName != null ? "{" + databaseName + "}" : "");
return PROMPT.formatted(databaseName != null ? "{" + databaseName + "}" : "");
}

private static boolean setGlobalConfiguration(final String key, final String value, final boolean printError) {
Expand Down
8 changes: 4 additions & 4 deletions engine/src/main/java/com/arcadedb/ContextConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ public boolean getValueAsBoolean(final GlobalConfiguration iConfig) {
final Object v = getValue(iConfig);
if (v == null)
return false;
return v instanceof Boolean ? (Boolean) v : Boolean.parseBoolean(v.toString());
return v instanceof Boolean b ? b : Boolean.parseBoolean(v.toString());
}

public String getValueAsString(final String iName, final String iDefaultValue) {
Expand All @@ -179,21 +179,21 @@ public int getValueAsInteger(final GlobalConfiguration iConfig) {
final Object v = getValue(iConfig);
if (v == null)
return 0;
return v instanceof Integer ? (Integer) v : Integer.parseInt(v.toString());
return v instanceof Integer i ? i : Integer.parseInt(v.toString());
}

public long getValueAsLong(final GlobalConfiguration iConfig) {
final Object v = getValue(iConfig);
if (v == null)
return 0;
return v instanceof Long ? (Long) v : Long.parseLong(v.toString());
return v instanceof Long l ? l : Long.parseLong(v.toString());
}

public float getValueAsFloat(final GlobalConfiguration iConfig) {
final Object v = getValue(iConfig);
if (v == null)
return 0;
return v instanceof Float ? (Float) v : Float.parseFloat(v.toString());
return v instanceof Float f ? f : Float.parseFloat(v.toString());
}

public Set<String> getContextKeys() {
Expand Down
29 changes: 14 additions & 15 deletions engine/src/main/java/com/arcadedb/GlobalConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,9 +145,9 @@ public Object call(final Object value) {
FileUtils.getSizeAsString(Runtime.getRuntime().maxMemory()), FileUtils.getSizeAsString(newValue));
else
System.out.println(
String.format("Setting '%s=%s' is > than 80%% of maximum heap (%s). Decreasing it to %s", MAX_PAGE_RAM.key,
FileUtils.getSizeAsString(maxRAM), FileUtils.getSizeAsString(Runtime.getRuntime().maxMemory()),
FileUtils.getSizeAsString(newValue)));
"Setting '%s=%s' is > than 80%% of maximum heap (%s). Decreasing it to %s".formatted(MAX_PAGE_RAM.key,
FileUtils.getSizeAsString(maxRAM), FileUtils.getSizeAsString(Runtime.getRuntime().maxMemory()),
FileUtils.getSizeAsString(newValue)));

return newValue;
}
Expand All @@ -161,9 +161,9 @@ public Object call(final Object value) {
DATE_IMPLEMENTATION("arcadedb.dateImplementation", SCOPE.DATABASE,
"Default date implementation to use on deserialization. By default java.util.Date is used, but the following are supported: java.util.Calendar, java.time.LocalDate",
Class.class, java.util.Date.class, value -> {
if (value instanceof String) {
if (value instanceof String string) {
try {
return Class.forName((String) value);
return Class.forName(string);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Date implementation '" + value + "' not found", e);
}
Expand All @@ -177,9 +177,9 @@ public Object call(final Object value) {
DATE_TIME_IMPLEMENTATION("arcadedb.dateTimeImplementation", SCOPE.DATABASE,
"Default datetime implementation to use on deserialization. By default java.util.Date is used, but the following are supported: java.util.Calendar, java.time.LocalDateTime, java.time.ZonedDateTime",
Class.class, java.util.Date.class, value -> {
if (value instanceof String) {
if (value instanceof String string) {
try {
return Class.forName((String) value);
return Class.forName(string);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("Date implementation '" + value + "' not found", e);
}
Expand Down Expand Up @@ -576,8 +576,8 @@ public static String toJSON() {

for (final GlobalConfiguration k : values()) {
Object v = (Object) k.getValue();
if (v instanceof Class)
v = ((Class<?>) v).getName();
if (v instanceof Class<?> class1)
v = class1.getName();
cfg.put(k.key.substring(PREFIX.length()), v);
}

Expand Down Expand Up @@ -696,8 +696,7 @@ else if (type.isEnum()) {
if (type.isInstance(iValue)) {
value = iValue;
accepted = true;
} else if (iValue instanceof String) {
final String string = (String) iValue;
} else if (iValue instanceof String string) {

for (final Object constant : type.getEnumConstants()) {
final Enum<?> enumConstant = (Enum<?>) constant;
Expand Down Expand Up @@ -740,7 +739,7 @@ else if (type.isEnum()) {

public boolean getValueAsBoolean() {
final Object v = value != nullValue && value != null ? value : defValue;
return v instanceof Boolean ? (Boolean) v : Boolean.parseBoolean(v.toString());
return v instanceof Boolean b ? b : Boolean.parseBoolean(v.toString());
}

public String getValueAsString() {
Expand All @@ -751,17 +750,17 @@ public String getValueAsString() {

public int getValueAsInteger() {
final Object v = value != nullValue && value != null ? value : defValue;
return (int) (v instanceof Number ? ((Number) v).intValue() : FileUtils.getSizeAsNumber(v.toString()));
return (int) (v instanceof Number n ? n.intValue() : FileUtils.getSizeAsNumber(v.toString()));
}

public long getValueAsLong() {
final Object v = value != nullValue && value != null ? value : defValue;
return v instanceof Number ? ((Number) v).longValue() : FileUtils.getSizeAsNumber(v.toString());
return v instanceof Number n ? n.longValue() : FileUtils.getSizeAsNumber(v.toString());
}

public float getValueAsFloat() {
final Object v = value != nullValue && value != null ? value : defValue;
return v instanceof Float ? (Float) v : Float.parseFloat(v.toString());
return v instanceof Float f ? f : Float.parseFloat(v.toString());
}

public String getKey() {
Expand Down
55 changes: 27 additions & 28 deletions engine/src/main/java/com/arcadedb/Profiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,7 @@ public synchronized void dumpMetrics(final PrintStream out) {
walTotalFiles += (Long) walStats.get("logFiles");
}

buffer.append(String.format("ARCADEDB %s Profiler", Constants.getRawVersion()));
buffer.append("ARCADEDB %s Profiler".formatted(Constants.getRawVersion()));

final Runtime runtime = Runtime.getRuntime();

Expand All @@ -339,10 +339,10 @@ public synchronized void dumpMetrics(final PrintStream out) {
final long osTotalMem = ((Number) mbs.getAttribute(osMBeanName, "TotalPhysicalMemorySize")).longValue();
final long osUsedMem = osTotalMem - ((Number) mbs.getAttribute(osMBeanName, "FreePhysicalMemorySize")).longValue();

buffer.append(String.format("%n JVM heap=%s/%s os=%s/%s gc=%dms",
FileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()),
FileUtils.getSizeAsString(runtime.maxMemory()), FileUtils.getSizeAsString(osUsedMem),
FileUtils.getSizeAsString(osTotalMem), gcTime));
buffer.append("%n JVM heap=%s/%s os=%s/%s gc=%dms".formatted(
FileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()),
FileUtils.getSizeAsString(runtime.maxMemory()), FileUtils.getSizeAsString(osUsedMem),
FileUtils.getSizeAsString(osTotalMem), gcTime));

dumpWithJmx = true;
}
Expand All @@ -352,40 +352,39 @@ public synchronized void dumpMetrics(final PrintStream out) {

if (!dumpWithJmx)
buffer.append(
String.format("%n JVM heap=%s/%s gc=%dms", FileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()),
FileUtils.getSizeAsString(runtime.maxMemory()), gcTime));
"%n JVM heap=%s/%s gc=%dms".formatted(FileUtils.getSizeAsString(runtime.totalMemory() - runtime.freeMemory()),
FileUtils.getSizeAsString(runtime.maxMemory()), gcTime));

buffer.append(String.format("%n PAGE-CACHE read=%s (pages=%d) max=%s readOps=%d (%s) writeOps=%d (%s)",
FileUtils.getSizeAsString(readCacheUsed), readCachePages,
FileUtils.getSizeAsString(cacheMax), pagesRead, FileUtils.getSizeAsString(pagesReadSize), pagesWritten,
FileUtils.getSizeAsString(pagesWrittenSize)));
buffer.append("%n PAGE-CACHE read=%s (pages=%d) max=%s readOps=%d (%s) writeOps=%d (%s)".formatted(
FileUtils.getSizeAsString(readCacheUsed), readCachePages,
FileUtils.getSizeAsString(cacheMax), pagesRead, FileUtils.getSizeAsString(pagesReadSize), pagesWritten,
FileUtils.getSizeAsString(pagesWrittenSize)));

buffer.append(
String.format("%n DB databases=%d asyncParallelLevel=%d asyncQueue=%d txCommits=%d txRollbacks=%d queries=%d commands=%d",
databases.size(),
asyncParallelLevel, asyncQueueLength, txCommits, txRollbacks, queries, commands));
buffer.append(String.format("%n createRecord=%d readRecord=%d updateRecord=%d deleteRecord=%d", createRecord, readRecord,
updateRecord, deleteRecord));
"%n DB databases=%d asyncParallelLevel=%d asyncQueue=%d txCommits=%d txRollbacks=%d queries=%d commands=%d".formatted(
databases.size(),
asyncParallelLevel, asyncQueueLength, txCommits, txRollbacks, queries, commands));
buffer.append("%n createRecord=%d readRecord=%d updateRecord=%d deleteRecord=%d".formatted(createRecord, readRecord,
updateRecord, deleteRecord));
buffer.append(
String.format("%n scanType=%d scanBucket=%d iterateType=%d iterateBucket=%d countType=%d countBucket=%d", scanType,
scanBucket, iterateType,
iterateBucket, countType, countBucket));
"%n scanType=%d scanBucket=%d iterateType=%d iterateBucket=%d countType=%d countBucket=%d".formatted(scanType,
scanBucket, iterateType,
iterateBucket, countType, countBucket));

buffer.append(String.format("%n INDEXES compactions=%d", indexCompactions));
buffer.append("%n INDEXES compactions=%d".formatted(indexCompactions));

buffer.append(
String.format(
"%n PAGE-MANAGER flushQueue=%d cacheHits=%d cacheMiss=%d concModExceptions=%d evictionRuns=%d pagesEvicted=%d",
pageFlushQueueLength,
pageCacheHits, pageCacheMiss, concurrentModificationExceptions, evictionRuns, pagesEvicted));
"%n PAGE-MANAGER flushQueue=%d cacheHits=%d cacheMiss=%d concModExceptions=%d evictionRuns=%d pagesEvicted=%d".formatted(
pageFlushQueueLength,
pageCacheHits, pageCacheMiss, concurrentModificationExceptions, evictionRuns, pagesEvicted));

buffer.append(
String.format("%n WAL totalFiles=%d pagesWritten=%d bytesWritten=%s", walTotalFiles, walPagesWritten,
FileUtils.getSizeAsString(walBytesWritten)));
"%n WAL totalFiles=%d pagesWritten=%d bytesWritten=%s".formatted(walTotalFiles, walPagesWritten,
FileUtils.getSizeAsString(walBytesWritten)));

buffer.append(
String.format("%n FILE-MANAGER FS=%s/%s openFiles=%d maxFilesOpened=%d", FileUtils.getSizeAsString(freeSpaceInMB),
FileUtils.getSizeAsString(totalSpaceInMB), totalOpenFiles, maxOpenFiles));
"%n FILE-MANAGER FS=%s/%s openFiles=%d maxFilesOpened=%d".formatted(FileUtils.getSizeAsString(freeSpaceInMB),
FileUtils.getSizeAsString(totalSpaceInMB), totalOpenFiles, maxOpenFiles));

out.println(buffer);
} catch (final Exception e) {
Expand Down
1 change: 1 addition & 0 deletions engine/src/main/java/com/arcadedb/database/BaseRecord.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.database;

import com.arcadedb.database.Record;
import com.arcadedb.exception.RecordNotFoundException;
import com.arcadedb.graph.Edge;
import com.arcadedb.graph.Vertex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package com.arcadedb.database;

import com.arcadedb.ContextConfiguration;
import com.arcadedb.database.Record;
import com.arcadedb.database.async.ErrorCallback;
import com.arcadedb.database.async.OkCallback;
import com.arcadedb.exception.RecordNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class DatabaseComparator {

static public class DatabaseAreNotIdentical extends ArcadeDBException {
public DatabaseAreNotIdentical(final String text, final Object... args) {
super(String.format(text, args));
super(text.formatted(args));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import java.io.*;
import java.nio.charset.*;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
import java.util.concurrent.*;

Expand Down Expand Up @@ -133,7 +132,7 @@ public void registerCallback(final DatabaseInternal.CALLBACK_EVENT event, final
}

private static Path getNormalizedPath(final String path) {
return Paths.get(path).toAbsolutePath().normalize();
return Path.of(path).toAbsolutePath().normalize();
}

public static Database getActiveDatabaseInstance(final String databasePath) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.database;

import com.arcadedb.database.Record;
import com.arcadedb.engine.FileManager;
import com.arcadedb.engine.PageManager;
import com.arcadedb.engine.TransactionManager;
Expand Down
18 changes: 9 additions & 9 deletions engine/src/main/java/com/arcadedb/database/DetachedDocument.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ private void init(final Document sourceDocument) {
for (final Map.Entry<String, Object> entry : sourceMap.entrySet()) {
Object value = entry.getValue();

if (value instanceof List) {
for (int i = 0; i < ((List) value).size(); i++) {
final Object embValue = ((List) value).get(i);
if (embValue instanceof EmbeddedDocument)
((List) value).set(i, ((EmbeddedDocument) embValue).detach());
if (value instanceof List list) {
for (int i = 0; i < list.size(); i++) {
final Object embValue = list.get(i);
if (embValue instanceof EmbeddedDocument document)
((List) value).set(i, document.detach());
}
} else if (value instanceof Map) {
final Map<String, Object> map = (Map<String, Object>) value;

for (final Map.Entry<String, Object> subentry : map.entrySet()) {
final Object embValue = subentry.getValue();
if (embValue instanceof EmbeddedDocument)
map.put(subentry.getKey(), ((EmbeddedDocument) embValue).detach());
if (embValue instanceof EmbeddedDocument document)
map.put(subentry.getKey(), document.detach());
}

} else if (value instanceof EmbeddedDocument)
value = ((EmbeddedDocument) value).detach();
} else if (value instanceof EmbeddedDocument document)
value = document.detach();

this.map.put(entry.getKey(), value);
}
Expand Down
1 change: 1 addition & 0 deletions engine/src/main/java/com/arcadedb/database/Document.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
*/
package com.arcadedb.database;

import com.arcadedb.database.Record;
import com.arcadedb.schema.DocumentType;
import com.arcadedb.serializer.json.JSONObject;
import com.arcadedb.utility.ExcludeFromJacocoGeneratedReport;
Expand Down
14 changes: 7 additions & 7 deletions engine/src/main/java/com/arcadedb/database/DocumentIndexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,8 @@ public void updateDocument(final Document originalRecord, final Document modifie
continue;

final BucketSelectionStrategy bucketSelectionStrategy = modifiedRecord.getType().getBucketSelectionStrategy();
if (bucketSelectionStrategy instanceof PartitionedBucketSelectionStrategy) {
if (!List.of(((PartitionedBucketSelectionStrategy) bucketSelectionStrategy).getProperties())
if (bucketSelectionStrategy instanceof PartitionedBucketSelectionStrategy strategy) {
if (!List.of(strategy.getProperties())
.equals(index.getPropertyNames()))
throw new IndexException("Cannot modify primary key when the bucket selection is partitioned");
}
Expand All @@ -132,9 +132,9 @@ public void deleteDocument(final Document record) {

final List<IndexInternal> metadata = type.getPolymorphicBucketIndexByBucketId(bucketId, null);
if (metadata != null && !metadata.isEmpty()) {
if (record instanceof RecordInternal)
if (record instanceof RecordInternal internal)
// FORCE RESET OF ANY PROPERTY TEMPORARY SET
((RecordInternal) record).unsetDirty();
internal.unsetDirty();

final List<IndexInternal> allIndexes = new ArrayList(metadata);
for (final IndexInternal index : metadata) {
Expand All @@ -156,12 +156,12 @@ public void deleteDocument(final Document record) {
}

private Object getPropertyValue(final Document record, final String propertyName) {
if (record instanceof Edge) {
if (record instanceof Edge edge) {
// EDGE: CHECK FOR SPECIAL CASES @OUT AND @IN
if ("@out".equals(propertyName))
return ((Edge) record).getOut();
return edge.getOut();
else if ("@in".equals(propertyName))
return ((Edge) record).getIn();
return edge.getIn();
}
return record.get(propertyName);
}
Expand Down
Loading

0 comments on commit 4bd7adc

Please sign in to comment.