Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5a644f1

Browse files
sims-keshriohbus
andauthored
refactoring: Critical Sonar Issues (iluwatar#1833)
* Resolve Sonar Code Smell: Define a constant instead of duplicating this literal 'Space rocket <' 4 times.* Resolve Sonar Critical Code Smell: Define a constant instead of duplicating this literal 'Error connecting to MongoDB' 4 times.* Fix checkstyle violation.* Resolve Sonar Critical Code Smell: Define a constant instead of duplicating this literal 'LITERAL 0' 4 times.Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
1 parentcab9048 commit5a644f1

File tree

3 files changed

+32
-20
lines changed
  • async-method-invocation/src/main/java/com/iluwatar/async/method/invocation
  • bytecode/src/main/java/com/iluwatar/bytecode
  • caching/src/main/java/com/iluwatar/caching

3 files changed

+32
-20
lines changed

‎async-method-invocation/src/main/java/com/iluwatar/async/method/invocation/App.java

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,12 @@
5959
@Slf4j
6060
publicclassApp {
6161

62+
privatestaticfinalStringROCKET_LAUNCH_LOG_PATTERN ="Space rocket <%s> launched successfully";
63+
6264
/**
6365
* Program entry point.
6466
*/
67+
6568
publicstaticvoidmain(String[]args)throwsException {
6669
// construct a new executor that will run async tasks
6770
varexecutor =newThreadAsyncExecutor();
@@ -87,9 +90,9 @@ public static void main(String[] args) throws Exception {
8790
asyncResult5.await();
8891

8992
// log the results of the tasks, callbacks log immediately when complete
90-
log("Space rocket <" +result1 +"> launch complete");
91-
log("Space rocket <" +result2 +"> launch complete");
92-
log("Space rocket <" +result3 +"> launch complete");
93+
log(String.format(ROCKET_LAUNCH_LOG_PATTERN,result1));
94+
log(String.format(ROCKET_LAUNCH_LOG_PATTERN,result2));
95+
log(String.format(ROCKET_LAUNCH_LOG_PATTERN,result3));
9396
}
9497

9598
/**
@@ -102,7 +105,7 @@ public static void main(String[] args) throws Exception {
102105
privatestatic <T>Callable<T>lazyval(Tvalue,longdelayMillis) {
103106
return () -> {
104107
Thread.sleep(delayMillis);
105-
log("Space rocket <" +value +"> launched successfully");
108+
log(String.format(ROCKET_LAUNCH_LOG_PATTERN,value));
106109
returnvalue;
107110
};
108111
}

‎bytecode/src/main/java/com/iluwatar/bytecode/App.java

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@
4242
@Slf4j
4343
publicclassApp {
4444

45+
privatestaticfinalStringLITERAL_0 ="LITERAL 0";
46+
privatestaticfinalStringHEALTH_PATTERN ="%s_HEALTH";
47+
privatestaticfinalStringGET_AGILITY ="GET_AGILITY";
48+
privatestaticfinalStringGET_WISDOM ="GET_WISDOM";
49+
privatestaticfinalStringADD ="ADD";
50+
privatestaticfinalStringLITERAL_2 ="LITERAL 2";
51+
privatestaticfinalStringDIVIDE ="DIVIDE";
52+
4553
/**
4654
* Main app method.
4755
*
@@ -53,17 +61,17 @@ public static void main(String[] args) {
5361
newWizard(45,7,11,0,0),
5462
newWizard(36,18,8,0,0));
5563

56-
vm.execute(InstructionConverterUtil.convertToByteCode("LITERAL 0"));
57-
vm.execute(InstructionConverterUtil.convertToByteCode("LITERAL 0"));
58-
vm.execute(InstructionConverterUtil.convertToByteCode("GET_HEALTH"));
59-
vm.execute(InstructionConverterUtil.convertToByteCode("LITERAL 0"));
60-
vm.execute(InstructionConverterUtil.convertToByteCode("GET_AGILITY"));
61-
vm.execute(InstructionConverterUtil.convertToByteCode("LITERAL 0"));
62-
vm.execute(InstructionConverterUtil.convertToByteCode("GET_WISDOM"));
63-
vm.execute(InstructionConverterUtil.convertToByteCode("ADD"));
64-
vm.execute(InstructionConverterUtil.convertToByteCode("LITERAL 2"));
65-
vm.execute(InstructionConverterUtil.convertToByteCode("DIVIDE"));
66-
vm.execute(InstructionConverterUtil.convertToByteCode("ADD"));
67-
vm.execute(InstructionConverterUtil.convertToByteCode("SET_HEALTH"));
64+
vm.execute(InstructionConverterUtil.convertToByteCode(LITERAL_0));
65+
vm.execute(InstructionConverterUtil.convertToByteCode(LITERAL_0));
66+
vm.execute(InstructionConverterUtil.convertToByteCode(String.format(HEALTH_PATTERN,"GET")));
67+
vm.execute(InstructionConverterUtil.convertToByteCode(LITERAL_0));
68+
vm.execute(InstructionConverterUtil.convertToByteCode(GET_AGILITY));
69+
vm.execute(InstructionConverterUtil.convertToByteCode(LITERAL_0));
70+
vm.execute(InstructionConverterUtil.convertToByteCode(GET_WISDOM));
71+
vm.execute(InstructionConverterUtil.convertToByteCode(ADD));
72+
vm.execute(InstructionConverterUtil.convertToByteCode(LITERAL_2));
73+
vm.execute(InstructionConverterUtil.convertToByteCode(DIVIDE));
74+
vm.execute(InstructionConverterUtil.convertToByteCode(ADD));
75+
vm.execute(InstructionConverterUtil.convertToByteCode(String.format(HEALTH_PATTERN,"SET")));
6876
}
6977
}

‎caching/src/main/java/com/iluwatar/caching/DbManager.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public final class DbManager {
5050
privatestaticbooleanuseMongoDB;
5151

5252
privatestaticMap<String,UserAccount>virtualDB;
53+
privatestaticfinalStringERROR_MESSAGE_LOG ="Error connecting to MongoDB";
5354

5455
privateDbManager() {
5556
}
@@ -85,7 +86,7 @@ public static UserAccount readFromDb(String userId) {
8586
try {
8687
connect();
8788
}catch (ParseExceptione) {
88-
LOGGER.error("Error connecting to MongoDB",e);
89+
LOGGER.error(ERROR_MESSAGE_LOG,e);
8990
}
9091
}
9192
variterable =db
@@ -112,7 +113,7 @@ public static void writeToDb(UserAccount userAccount) {
112113
try {
113114
connect();
114115
}catch (ParseExceptione) {
115-
LOGGER.error("Error connecting to MongoDB",e);
116+
LOGGER.error(ERROR_MESSAGE_LOG,e);
116117
}
117118
}
118119
db.getCollection(CachingConstants.USER_ACCOUNT).insertOne(
@@ -134,7 +135,7 @@ public static void updateDb(UserAccount userAccount) {
134135
try {
135136
connect();
136137
}catch (ParseExceptione) {
137-
LOGGER.error("Error connecting to MongoDB",e);
138+
LOGGER.error(ERROR_MESSAGE_LOG,e);
138139
}
139140
}
140141
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(
@@ -155,7 +156,7 @@ public static void upsertDb(UserAccount userAccount) {
155156
try {
156157
connect();
157158
}catch (ParseExceptione) {
158-
LOGGER.error("Error connecting to MongoDB",e);
159+
LOGGER.error(ERROR_MESSAGE_LOG,e);
159160
}
160161
}
161162
db.getCollection(CachingConstants.USER_ACCOUNT).updateOne(

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp