From 83e216f534f74a21bd991b60fb8888de6f14825f Mon Sep 17 00:00:00 2001 From: Hongjun Li <2318996718@qq.com> Date: Thu, 21 Mar 2024 13:16:57 +0800 Subject: [PATCH] coda format & clean tools(in Java & XML files) --- .../apache/hugegraph/base/RetryManager.java | 6 +- .../apache/hugegraph/base/ToolManager.java | 10 ++-- .../hugegraph/cmd/HugeGraphCommand.java | 42 +++++++------- .../org/apache/hugegraph/cmd/SubCommands.java | 57 +++++++++++-------- .../formatter/kgdumper/ComputeSign.java | 4 +- .../formatter/kgdumper/DumpKGFormatter.java | 4 +- .../formatter/kgdumper/SignFS64.java | 8 +-- .../hugegraph/manager/BackupManager.java | 16 +++--- .../hugegraph/manager/RestoreManager.java | 2 +- .../org/apache/hugegraph/util/ToolUtil.java | 2 +- .../test/functional/FuncTestSuite.java | 7 ++- 11 files changed, 83 insertions(+), 75 deletions(-) diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/RetryManager.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/RetryManager.java index 4a19dbb66..09c1e741e 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/RetryManager.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/RetryManager.java @@ -54,8 +54,8 @@ public R retry(Supplier supplier, String description) { } catch (Exception e) { if (retries == this.retry) { throw new ToolsException( - "Exception occurred while %s(after %s retries)", - e, description, this.retry); + "Exception occurred while %s(after %s retries)", + e, description, this.retry); } // Ignore exception and retry continue; @@ -89,7 +89,7 @@ public void shutdown(String taskType) { this.pool.awaitTermination(24, TimeUnit.HOURS); } catch (InterruptedException e) { throw new ToolsException( - "Exception appears in %s threads", e, taskType); + "Exception appears in %s threads", e, taskType); } } diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolManager.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolManager.java index eaad49420..f63422a87 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolManager.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/base/ToolManager.java @@ -45,15 +45,15 @@ protected String graph() { } @SuppressWarnings("unchecked") - protected List readList(String key, Class clazz, - String content) { + protected List readList(String key, Class clazz, + String content) { ObjectMapper mapper = this.client.mapper(); try { JsonNode root = mapper.readTree(content); JsonNode element = root.get(key); if (element == null) { throw new SerializeException( - "Can't find value of the key: %s in json.", key); + "Can't find value of the key: %s in json.", key); } else { JavaType t = mapper.getTypeFactory() .constructParametricType(List.class, clazz); @@ -61,11 +61,11 @@ protected List readList(String key, Class clazz, } } catch (IOException e) { throw new SerializeException( - "Failed to deserialize %s", e, content); + "Failed to deserialize %s", e, content); } } - public void close () { + public void close() { this.client.close(); } } diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/HugeGraphCommand.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/HugeGraphCommand.java index 8a3501c74..c5f8e9ed6 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/HugeGraphCommand.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/HugeGraphCommand.java @@ -76,11 +76,11 @@ public class HugeGraphCommand { @ParametersDelegate private SubCommands.TrustStoreFile trustStoreFile = - new SubCommands.TrustStoreFile(); + new SubCommands.TrustStoreFile(); @ParametersDelegate private SubCommands.TrustStorePassword trustStorePassword = - new SubCommands.TrustStorePassword(); + new SubCommands.TrustStorePassword(); @ParametersDelegate private SubCommands.ThrowMode throwMode = new SubCommands.ThrowMode(); @@ -397,7 +397,7 @@ private void execute(String subCmd, JCommander jCommander) { break; default: throw new ParameterException(String.format( - "Invalid sub-command: %s", subCmd)); + "Invalid sub-command: %s", subCmd)); } } @@ -417,30 +417,30 @@ private void checkMainParams() { private T manager(Class clz) { try { ToolClient.ConnectionInfo info = new ToolClient.ConnectionInfo(this.url(), this.graph(), - this.username(), - this.password(), - this.timeout(), - this.trustStoreFile(), - this.trustStorePassword()); + this.username(), + this.password(), + this.timeout(), + this.trustStoreFile(), + this.trustStorePassword()); T toolManager = clz.getConstructor(ToolClient.ConnectionInfo.class) .newInstance(info); this.taskManagers.add(toolManager); return toolManager; } catch (Exception e) { throw new RuntimeException(String.format( - "Construct manager failed for class '%s', please make " + - "sure global arguments set correctly: " + - "--url=%s,--graph=%s,--user=%s,--password=%s," + - "--timeout=%s,--trust-store-file=%s," + - "--trust-store-password=%s", clz.getSimpleName(), - this.url(), this.graph(), this.username(), - this.password(), this.timeout(), - this.trustStoreFile(), this.trustStorePassword()), e); + "Construct manager failed for class '%s', please make " + + "sure global arguments set correctly: " + + "--url=%s,--graph=%s,--user=%s,--password=%s," + + "--timeout=%s,--trust-store-file=%s," + + "--trust-store-password=%s", clz.getSimpleName(), + this.url(), this.graph(), this.username(), + this.password(), this.timeout(), + this.trustStoreFile(), this.trustStorePassword()), e); } } private static SubCommands.Backup convMigrate2Backup( - SubCommands.Migrate migrate) { + SubCommands.Migrate migrate) { SubCommands.Backup backup = new SubCommands.Backup(); backup.splitSize(migrate.splitSize()); backup.directory(migrate.directory()); @@ -452,8 +452,8 @@ private static SubCommands.Backup convMigrate2Backup( } private static SubCommands.Restore convMigrate2Restore( - SubCommands.Migrate migrate, - String directory) { + SubCommands.Migrate migrate, + String directory) { SubCommands.Restore restore = new SubCommands.Restore(); restore.clean(!migrate.keepData()); restore.directory(directory); @@ -488,7 +488,7 @@ public JCommander parseCommand(String[] args) { String subCommand = jCommander.getParsedCommand(); if (subCommand == null) { throw ExitException.normal(ToolUtil.commandsCategory( - jCommander), + jCommander), "No sub-command found"); } return jCommander; @@ -518,7 +518,7 @@ public boolean parseHelp(String[] args, JCommander jCommander) { Map commands = jCommander.getCommands(); if (commands.containsKey(subCommand)) { throw ExitException.normal(ToolUtil.commandUsage( - commands.get(subCommand)), + commands.get(subCommand)), "Command : hugegragh help %s", subCommand); } else { diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/SubCommands.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/SubCommands.java index 449bde630..15530ae58 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/SubCommands.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/cmd/SubCommands.java @@ -217,6 +217,7 @@ public void properties(List properties) { "if needed. For example:" + "-Dfs.default.name=hdfs://localhost:9000") public static class Restore extends BackupRestore { + @Parameter(names = {"--clean"}, description = "Whether to remove the directory of " + "graph data after restored") @@ -412,10 +413,12 @@ public String cloneGraphName() { @Parameters(commandDescription = "List all graphs") public static class GraphList { + } @Parameters(commandDescription = "Get graph info") public static class GraphGet { + } @Parameters(commandDescription = "Clear graph schema and data") @@ -453,6 +456,7 @@ public GraphMode mode() { @Parameters(commandDescription = "Get graph mode") public static class GraphModeGet { + } @Parameters(commandDescription = "Execute Gremlin statements") @@ -621,10 +625,12 @@ public static class Clear { @Parameters(commandDescription = "Stop HugeGraph-Server and " + "HugeGraph-Studio") public static class StopAll { + } @Parameters(commandDescription = "Print usage") public static class Help { + } public static class BackupRestore { @@ -962,6 +968,7 @@ public void hdfsConf(Map hdfsConf) { } public static class AuthBackup extends AuthBackupRestore { + } public static class AuthRestore extends AuthBackupRestore { @@ -1017,7 +1024,7 @@ public static class AuthTypes { } public static class GraphModeConverter - implements IStringConverter { + implements IStringConverter { @Override public GraphMode convert(String value) { @@ -1028,7 +1035,7 @@ public GraphMode convert(String value) { } public static class HugeTypeListConverter - implements IStringConverter> { + implements IStringConverter> { public static final List ALL_TYPES = ImmutableList.of( HugeType.PROPERTY_KEY, HugeType.VERTEX_LABEL, @@ -1058,9 +1065,9 @@ public List convert(String value) { hugeTypes.add(HugeType.valueOf(type.toUpperCase())); } catch (IllegalArgumentException e) { throw new ParameterException(String.format( - "Invalid --type '%s', valid value is 'all' or " + - "combination of 'vertex,edge,vertex_label," + - "edge_label,property_key,index_label'", type)); + "Invalid --type '%s', valid value is 'all' or " + + "combination of 'vertex,edge,vertex_label," + + "edge_label,property_key,index_label'", type)); } } return hugeTypes; @@ -1068,7 +1075,7 @@ public List convert(String value) { } public static class AuthHugeTypeConverter - implements IStringConverter> { + implements IStringConverter> { public static final List AUTH_ALL_TYPES = ImmutableList.of( HugeType.TARGET, HugeType.GROUP, @@ -1101,9 +1108,9 @@ public List convert(String value) { hugeTypes.add(HugeType.valueOf(type.toUpperCase())); } catch (IllegalArgumentException e) { throw new IllegalArgumentException(String.format( - "Invalid --type '%s', valid value is 'all' or " + - "combination of [user,group,target," + - "belong,access]", type)); + "Invalid --type '%s', valid value is 'all' or " + + "combination of [user,group,target," + + "belong,access]", type)); } } return hugeTypes; @@ -1111,10 +1118,10 @@ public List convert(String value) { } public static class AuthStrategyConverter - implements IStringConverter { + implements IStringConverter { public static final AuthRestoreConflictStrategy STRATEGY = - AuthRestoreConflictStrategy.STOP; + AuthRestoreConflictStrategy.STOP; @Override public AuthRestoreConflictStrategy convert(String value) { @@ -1128,7 +1135,7 @@ public AuthRestoreConflictStrategy convert(String value) { } public static class MapConverter - implements IStringConverter> { + implements IStringConverter> { @Override public Map convert(String value) { @@ -1148,21 +1155,21 @@ public Map convert(String value) { } public static class FileNameToContentConverter - implements IStringConverter { + implements IStringConverter { @Override public String convert(String value) { File file = FileUtils.getFile(value); if (!file.exists() || !file.isFile() || !file.canRead()) { throw new ParameterException(String.format( - "'%s' must be existed readable file", value)); + "'%s' must be existed readable file", value)); } String content; try { content = FileUtils.readFileToString(file, API.CHARSET); } catch (IOException e) { throw new ParameterException(String.format( - "Read file '%s' error", value), e); + "Read file '%s' error", value), e); } return content; } @@ -1178,8 +1185,8 @@ public static class FormatValidator implements IParameterValidator { public void validate(String name, String value) { if (!FORMATS.contains(value.toUpperCase())) { throw new ParameterException(String.format( - "Invalid --format '%s', valid value is %s", - value, FORMATS)); + "Invalid --format '%s', valid value is %s", + value, FORMATS)); } } } @@ -1194,8 +1201,8 @@ public static class ProtocolValidator implements IParameterValidator { public void validate(String name, String value) { if (!PROTOCOLS.contains(value.toUpperCase())) { throw new ParameterException(String.format( - "Invalid --protocol '%s', valid value is %s", - value, PROTOCOLS)); + "Invalid --protocol '%s', valid value is %s", + value, PROTOCOLS)); } } } @@ -1206,8 +1213,8 @@ public static class TaskStatusValidator implements IParameterValidator { public void validate(String name, String value) { if (!TasksManager.TASK_STATUSES.contains(value.toUpperCase())) { throw new ParameterException(String.format( - "Invalid --status '%s', valid value is %s", - value, TasksManager.TASK_STATUSES)); + "Invalid --status '%s', valid value is %s", + value, TasksManager.TASK_STATUSES)); } } } @@ -1227,7 +1234,7 @@ public void validate(String name, String value) { ":([0-9]|[1-9]\\d{1,3}|[1-5]\\d{4}|6[0-5]{2}[0-3][0-5])$"; if (!value.matches(regex)) { throw new ParameterException(String.format( - "Invalid url value of args '%s': '%s'", name, value)); + "Invalid url value of args '%s': '%s'", name, value)); } } } @@ -1239,7 +1246,7 @@ public void validate(String name, String value) { File file = new File(value); if (!file.exists() || !file.isDirectory()) { throw new ParameterException(String.format( - "Invalid value of argument '%s': '%s'", name, value)); + "Invalid value of argument '%s': '%s'", name, value)); } } } @@ -1251,8 +1258,8 @@ public void validate(String name, String value) { int retry = Integer.parseInt(value); if (retry <= 0) { throw new ParameterException( - "Parameter " + name + " should be positive, " + - "but got " + value); + "Parameter " + name + " should be positive, " + + "but got " + value); } } } diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/ComputeSign.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/ComputeSign.java index 984028eb5..4b67bd114 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/ComputeSign.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/ComputeSign.java @@ -34,7 +34,7 @@ public class ComputeSign { private String inputEncoding; public ComputeSign(String tradeValueFile, String inputEncode) - throws IOException { + throws IOException { File file = new File(tradeValueFile); Long fileLen = file.length(); @@ -65,7 +65,7 @@ protected boolean removeEldestEntry(Map.Entry e) { } public synchronized String computeSeqNum(String entPlain) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { String seqNum = "0"; if (entPlain2Id.containsKey(entPlain)) { seqNum = entPlain2Id.get(entPlain); diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/DumpKGFormatter.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/DumpKGFormatter.java index 9f66b0e75..d01fc4e82 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/DumpKGFormatter.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/DumpKGFormatter.java @@ -55,7 +55,7 @@ public String dump(JsonGraph.JsonVertex vertex) throws Exception { } private String dumpEntity(JsonGraph.JsonVertex vertex) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { if (vertex == null) { return ""; } @@ -113,7 +113,7 @@ private String dumpEntity(JsonGraph.JsonVertex vertex) } private String dumpMemtion(JsonGraph.JsonVertex vertex) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { if (vertex == null) { return ""; } diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/SignFS64.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/SignFS64.java index 1a330fe5f..0871fa4d0 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/SignFS64.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/formatter/kgdumper/SignFS64.java @@ -99,7 +99,7 @@ public class SignFS64 { private static long getSigns24(String text, String encode, List primes) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { long sign = 0; byte[] textBytes = text.getBytes(encode); int textLen = textBytes.length; @@ -112,12 +112,12 @@ private static long getSigns24(String text, } private static long getSigns241(String text, String encode) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { return getSigns24(text, encode, _MOD_PRIME_LIST_1); } private static long getSigns242(String text, String encode) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { return getSigns24(text, encode, _MOD_PRIME_LIST_2); } @@ -135,7 +135,7 @@ private static String longBytes2String(ByteBuffer buffer) { } public static String createSignFs64(String text, String encode) - throws UnsupportedEncodingException { + throws UnsupportedEncodingException { int byteLen = text.getBytes(encode).length; diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/BackupManager.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/BackupManager.java index eaa916d79..aa4b23f74 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/BackupManager.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/BackupManager.java @@ -68,7 +68,7 @@ public class BackupManager extends BackupRestoreBaseManager { private static final String BACKEND = "backend"; private static final Set BACKENDS_NO_PAGING = - ImmutableSet.of("memory"); + ImmutableSet.of("memory"); private static final String PAGE_NONE = ""; private static final AtomicInteger NEXT_ID = new AtomicInteger(0); @@ -151,7 +151,7 @@ public void doBackup(List types) { break; default: throw new AssertionError(String.format( - "Bad backup type: %s", type)); + "Bad backup type: %s", type)); } } this.printSummary(); @@ -161,8 +161,8 @@ protected void backupVertices() { Printer.print("Vertices backup started"); Printer.printInBackward("Vertices has been backup: "); List shards = retry(() -> - this.client.traverser().vertexShards(splitSize()), - "querying shards of vertices"); + this.client.traverser().vertexShards(splitSize()), + "querying shards of vertices"); this.writeShards(this.allShardsLog(HugeType.VERTEX), shards); for (Shard shard : shards) { this.backupVertexShardAsync(shard); @@ -178,8 +178,8 @@ protected void backupEdges() { Printer.print("Edges backup started"); Printer.printInBackward("Edges has been backup: "); List shards = retry(() -> - this.client.traverser().edgeShards(splitSize()), - "querying shards of edges"); + this.client.traverser().edgeShards(splitSize()), + "querying shards of edges"); this.writeShards(this.allShardsLog(HugeType.EDGE), shards); for (Shard shard : shards) { this.backupEdgeShardAsync(shard); @@ -342,8 +342,8 @@ private void exceptionHandler(ToolsException e, HugeType type, break; default: throw new AssertionError(String.format( - "Only VERTEX or EDGE exception is expected, " + - "but got '%s' exception", type)); + "Only VERTEX or EDGE exception is expected, " + + "but got '%s' exception", type)); } if (isLimitExceedException(e)) { this.logLimitExceedShard(type, shard); diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/RestoreManager.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/RestoreManager.java index 4ae16af87..5a1524ff5 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/RestoreManager.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/manager/RestoreManager.java @@ -92,7 +92,7 @@ public void doRestore(List types) { break; default: throw new AssertionError(String.format( - "Bad restore type: %s", type)); + "Bad restore type: %s", type)); } } this.printSummary(); diff --git a/hugegraph-tools/src/main/java/org/apache/hugegraph/util/ToolUtil.java b/hugegraph-tools/src/main/java/org/apache/hugegraph/util/ToolUtil.java index e39cf72b7..ee2658459 100644 --- a/hugegraph-tools/src/main/java/org/apache/hugegraph/util/ToolUtil.java +++ b/hugegraph-tools/src/main/java/org/apache/hugegraph/util/ToolUtil.java @@ -32,7 +32,7 @@ public static void printOrThrow(Throwable e, boolean throwMode) { Printer.print("Failed to execute %s", e.getMessage()); if (throwMode) { if (e instanceof RuntimeException) { - throw (RuntimeException) e; + throw (RuntimeException) e; } throw new RuntimeException(e); } diff --git a/hugegraph-tools/src/test/java/org/apache/hugegraph/test/functional/FuncTestSuite.java b/hugegraph-tools/src/test/java/org/apache/hugegraph/test/functional/FuncTestSuite.java index 30517025e..2ca973de2 100644 --- a/hugegraph-tools/src/test/java/org/apache/hugegraph/test/functional/FuncTestSuite.java +++ b/hugegraph-tools/src/test/java/org/apache/hugegraph/test/functional/FuncTestSuite.java @@ -22,9 +22,10 @@ @RunWith(Suite.class) @Suite.SuiteClasses({ - AuthBackupTest.class, - AuthRestoreTest.class, - CommandTest.class + AuthBackupTest.class, + AuthRestoreTest.class, + CommandTest.class }) public class FuncTestSuite { + }