Skip to content

Commit 2219d8d

Browse files
authored
I18n v2 (@NonNls + Locals for toLowerCase/toUpperCase) (triplea-game#12840)
* i18n_v2 #1 annotate I18n classes with @NonNls * i18n_v2 #2 annotate @NonNls with .-pattern (.*String .+ *= "\w+\.[A-Za-z]+[A-Za-z\.]*) * i18n_v2 #3 fix via @NonNls imports * i18n_v2 #4 add @NonNls to Strings based on review with pattern (.*String .* = .*\+.*") * i18n_v2 #5 add @NonNls import to AbstractConditionsAttachment.java AbstractImageFactory.java AutoPlacementFinder.java ClipPlayer.java CliProperties.java CommentPanel.java DownloadFile.java FileNameUtils.java FlagIconImageFactory.java GameParser.java GameRunner.java InGameLobbyWatcher.java MapData.java NodeBbForumPoster.java NotificationMessages.java ObjectiveProperties.java PoliticsText.java ProductionRepairPanel.java ProductionTabsProperties.java TooltipProperties.java UnitIconProperties.java UnitImageFactory.java * i18n_v2.1 #6 add @NonNls to Strings based on review with static-String-pattern (.*static final String .* = ") * i18n_v2.1 #7 add @NonNls and Locals to getUpperCase() calls (toUpperCase\()\) * i18n_v2.1 #7 add @NonNls and Locals to toLowerCase() or toUpperCase() calls (?<!NonNls) (p.* static final String) * i18n_v2.1 #8 fix checkstyle error and spotlessJavaApply
1 parent a26ea62 commit 2219d8d

File tree

134 files changed

+734
-511
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

134 files changed

+734
-511
lines changed

game-app/domain-data/src/main/java/org/triplea/domain/data/PlayerEmailValidation.java

+8-7
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.triplea.domain.data;
22

33
import lombok.experimental.UtilityClass;
4+
import org.jetbrains.annotations.NonNls;
45

56
/** Utility class to validates user email to check if it looks valid. */
67
@UtilityClass
@@ -13,13 +14,13 @@ public static boolean isValid(final String emailAddress) {
1314
/** Allow multiple fully qualified email addresses separated by spaces, or a blank string. */
1415
public static String validate(final String emailAddress) {
1516
final String quotedString = "\"(?:[^\"\\\\]|\\\\\\p{ASCII})*\"";
16-
final String atom = "[^()<>@,;:\\\\\".\\[\\] \\x28\\p{Cntrl}]+";
17-
final String word = "(?:" + atom + "|" + quotedString + ")";
18-
final String subdomain = "(?:" + atom + "|\\[(?:[^\\[\\]\\\\]|\\\\\\p{ASCII})*\\])";
19-
final String domain = subdomain + "(?:\\." + subdomain + ")*";
20-
final String localPart = word + "(?:\\." + word + ")*";
21-
final String email = localPart + "@" + domain;
22-
final String regex = "(\\s*" + email + "\\s*)*";
17+
@NonNls final String atom = "[^()<>@,;:\\\\\".\\[\\] \\x28\\p{Cntrl}]+";
18+
@NonNls final String word = "(?:" + atom + "|" + quotedString + ")";
19+
@NonNls final String subdomain = "(?:" + atom + "|\\[(?:[^\\[\\]\\\\]|\\\\\\p{ASCII})*\\])";
20+
@NonNls final String domain = subdomain + "(?:\\." + subdomain + ")*";
21+
@NonNls final String localPart = word + "(?:\\." + word + ")*";
22+
@NonNls final String email = localPart + "@" + domain;
23+
@NonNls final String regex = "(\\s*" + email + "\\s*)*";
2324
if (!emailAddress.matches(regex)) {
2425
return "Invalid email address";
2526
}

game-app/domain-data/src/main/java/org/triplea/domain/data/SystemIdLoader.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
import lombok.Setter;
1111
import lombok.experimental.UtilityClass;
1212
import lombok.extern.slf4j.Slf4j;
13+
import org.jetbrains.annotations.NonNls;
1314

1415
/** Loads a SystemId from persistence. */
1516
@UtilityClass
1617
@Slf4j
1718
public class SystemIdLoader {
18-
private static final String SYSTEM_KEY = "system-id-key";
19+
@NonNls private static final String SYSTEM_KEY = "system-id-key";
1920

2021
@Setter(value = AccessLevel.PACKAGE, onMethod_ = @VisibleForTesting)
2122
private static PreferencesPersistence preferencesPersistence =

game-app/game-core/src/main/java/games/strategy/engine/ClientFileSystemHelper.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,15 @@
1212
import java.util.function.Supplier;
1313
import javax.annotation.Nullable;
1414
import lombok.extern.slf4j.Slf4j;
15+
import org.jetbrains.annotations.NonNls;
1516
import org.triplea.game.ApplicationContext;
1617
import org.triplea.io.FileUtils;
1718
import org.triplea.util.Services;
1819

1920
/** Provides methods to work with common file locations in a client installation. */
2021
@Slf4j
2122
public final class ClientFileSystemHelper {
22-
public static final String USER_ROOT_FOLDER_NAME = "triplea";
23+
@NonNls public static final String USER_ROOT_FOLDER_NAME = "triplea";
2324

2425
@VisibleForTesting static final String MAPS_FOLDER_NAME = "downloadedMaps";
2526
private static Path codeSourceLocation;

game-app/game-core/src/main/java/games/strategy/engine/chat/ChatController.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,16 @@
1515
import java.util.concurrent.TimeUnit;
1616
import java.util.stream.Collectors;
1717
import lombok.extern.slf4j.Slf4j;
18+
import org.jetbrains.annotations.NonNls;
1819
import org.triplea.domain.data.ChatParticipant;
1920
import org.triplea.domain.data.PlayerChatId;
2021
import org.triplea.domain.data.UserName;
2122

2223
/** Default implementation of {@link IChatController}. */
2324
@Slf4j
2425
public class ChatController implements IChatController {
25-
private static final String CHAT_REMOTE = "_ChatRemote_";
26-
private static final String CHAT_CHANNEL = "_ChatControl_";
26+
@NonNls private static final String CHAT_REMOTE = "_ChatRemote_";
27+
@NonNls private static final String CHAT_CHANNEL = "_ChatControl_";
2728
private final Messengers messengers;
2829
private final ServerMessenger serverMessenger;
2930

game-app/game-core/src/main/java/games/strategy/engine/chat/ChatPlayerPanel.java

+5-2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import java.util.Collection;
1616
import java.util.Comparator;
1717
import java.util.List;
18+
import java.util.Locale;
1819
import java.util.function.BiConsumer;
1920
import javax.swing.Action;
2021
import javax.swing.DefaultListCellRenderer;
@@ -28,6 +29,7 @@
2829
import javax.swing.JScrollPane;
2930
import javax.swing.ListCellRenderer;
3031
import javax.swing.UIManager;
32+
import org.jetbrains.annotations.NonNls;
3133
import org.triplea.domain.data.ChatParticipant;
3234
import org.triplea.domain.data.UserName;
3335
import org.triplea.java.StringUtils;
@@ -36,7 +38,7 @@
3638

3739
/** A UI component that displays the players participating in a chat. */
3840
public class ChatPlayerPanel extends JPanel implements ChatPlayerListener {
39-
private static final String TAG_MODERATOR = "[Mod]";
41+
@NonNls private static final String TAG_MODERATOR = "[Mod]";
4042
private static final long serialVersionUID = -3153022965393962945L;
4143
private static final Icon ignoreIcon;
4244

@@ -270,7 +272,8 @@ public synchronized void updatePlayerList(final Collection<ChatParticipant> upda
270272
updatedPlayers.stream()
271273
.sorted(
272274
Comparator.comparing(
273-
chatParticipant -> chatParticipant.getUserName().getValue().toUpperCase()))
275+
chatParticipant ->
276+
chatParticipant.getUserName().getValue().toUpperCase(Locale.ENGLISH)))
274277
.forEach(listModel::addElement);
275278
});
276279
}

game-app/game-core/src/main/java/games/strategy/engine/data/GameData.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
import java.util.function.Predicate;
3939
import lombok.Getter;
4040
import lombok.Setter;
41+
import org.jetbrains.annotations.NonNls;
4142
import org.triplea.io.FileUtils;
4243
import org.triplea.io.IoUtils;
4344
import org.triplea.java.ObjectUtils;
@@ -73,7 +74,7 @@ public class GameData implements Serializable, GameState {
7374
private static final long serialVersionUID = -2612710634080125728L;
7475

7576
/** When we load a game from a save file, this property will be the name of that file. */
76-
private static final String SAVE_GAME_FILE_NAME_PROPERTY = "save.game.file.name";
77+
@NonNls private static final String SAVE_GAME_FILE_NAME_PROPERTY = "save.game.file.name";
7778

7879
private transient ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
7980
private transient volatile boolean forceInSwingEventThread = false;

game-app/game-core/src/main/java/games/strategy/engine/data/GamePlayer.java

+6-5
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,15 @@
1818
import lombok.AllArgsConstructor;
1919
import lombok.EqualsAndHashCode;
2020
import lombok.Getter;
21+
import org.jetbrains.annotations.NonNls;
2122
import org.triplea.java.RemoveOnNextMajorRelease;
2223

2324
/** A game player (nation, power, etc.). */
2425
public class GamePlayer extends NamedAttachable implements NamedUnitHolder {
2526
private static final long serialVersionUID = -2284878450555315947L;
2627

27-
private static final String DEFAULT_TYPE_AI = "AI";
28-
private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";
28+
@NonNls private static final String DEFAULT_TYPE_AI = "AI";
29+
@NonNls private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";
2930

3031
@RemoveOnNextMajorRelease @Deprecated
3132
private static final GamePlayer NULL_PLAYERID =
@@ -127,12 +128,12 @@ public String getType() {
127128
}
128129

129130
/**
130-
* First string is "Human" or "AI" or "null" (case insensitive), while second string is the name
131+
* First string is "Human" or "AI" or "null" (case-insensitive), while second string is the name
131132
* of the player, separated with a colon. For example, it could be "AI:Hard (AI)".
132133
*
133134
* @throws IllegalArgumentException If {@code encodedType} does not contain two strings separated
134-
* by a colon; or if the first string is not one of "AI", "Human", or "null" (case
135-
* insensitive).
135+
* by a colon; or if the first string is not one of "AI", "Human", or "null"
136+
* (case-insensitive).
136137
*/
137138
public void setWhoAmI(final String encodedType) {
138139
final List<String> tokens = tokenizeEncodedType(encodedType);

game-app/game-core/src/main/java/games/strategy/engine/data/Unit.java

+44-42
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import com.google.common.annotations.VisibleForTesting;
66
import com.google.common.collect.ImmutableList;
7+
import games.strategy.triplea.Constants;
78
import games.strategy.triplea.Properties;
89
import games.strategy.triplea.attachments.TerritoryAttachment;
910
import games.strategy.triplea.attachments.UnitAttachment;
@@ -19,6 +20,7 @@
1920
import lombok.Getter;
2021
import lombok.Setter;
2122
import lombok.extern.slf4j.Slf4j;
23+
import org.jetbrains.annotations.NonNls;
2224
import org.triplea.java.collections.CollectionUtils;
2325

2426
/**
@@ -31,24 +33,24 @@
3133
@Getter
3234
@EqualsAndHashCode(of = "id", callSuper = false)
3335
public class Unit extends GameDataComponent implements DynamicallyModifiable {
34-
public static final String TRANSPORTED_BY = "transportedBy";
35-
public static final String UNLOADED = "unloaded";
36-
public static final String LOADED_THIS_TURN = "wasLoadedThisTurn";
37-
public static final String UNLOADED_TO = "unloadedTo";
38-
public static final String UNLOADED_IN_COMBAT_PHASE = "wasUnloadedInCombatPhase";
39-
public static final String ALREADY_MOVED = "alreadyMoved";
40-
public static final String BONUS_MOVEMENT = "bonusMovement";
41-
public static final String SUBMERGED = "submerged";
42-
public static final String WAS_IN_COMBAT = "wasInCombat";
43-
public static final String LOADED_AFTER_COMBAT = "wasLoadedAfterCombat";
44-
public static final String UNLOADED_AMPHIBIOUS = "wasAmphibious";
45-
public static final String ORIGINATED_FROM = "originatedFrom";
46-
public static final String WAS_SCRAMBLED = "wasScrambled";
47-
public static final String MAX_SCRAMBLE_COUNT = "maxScrambleCount";
48-
public static final String WAS_IN_AIR_BATTLE = "wasInAirBattle";
49-
public static final String LAUNCHED = "launched";
50-
public static final String AIRBORNE = "airborne";
51-
public static final String CHARGED_FLAT_FUEL_COST = "chargedFlatFuelCost";
36+
@NonNls public static final String TRANSPORTED_BY = "transportedBy";
37+
@NonNls public static final String UNLOADED = "unloaded";
38+
@NonNls public static final String LOADED_THIS_TURN = "wasLoadedThisTurn";
39+
@NonNls public static final String UNLOADED_TO = "unloadedTo";
40+
@NonNls public static final String UNLOADED_IN_COMBAT_PHASE = "wasUnloadedInCombatPhase";
41+
@NonNls public static final String ALREADY_MOVED = "alreadyMoved";
42+
@NonNls public static final String BONUS_MOVEMENT = "bonusMovement";
43+
@NonNls public static final String SUBMERGED = "submerged";
44+
@NonNls public static final String WAS_IN_COMBAT = "wasInCombat";
45+
@NonNls public static final String LOADED_AFTER_COMBAT = "wasLoadedAfterCombat";
46+
@NonNls public static final String UNLOADED_AMPHIBIOUS = "wasAmphibious";
47+
@NonNls public static final String ORIGINATED_FROM = "originatedFrom";
48+
@NonNls public static final String WAS_SCRAMBLED = "wasScrambled";
49+
@NonNls public static final String MAX_SCRAMBLE_COUNT = "maxScrambleCount";
50+
@NonNls public static final String WAS_IN_AIR_BATTLE = "wasInAirBattle";
51+
@NonNls public static final String LAUNCHED = "launched";
52+
@NonNls public static final String AIRBORNE = "airborne";
53+
@NonNls public static final String CHARGED_FLAT_FUEL_COST = "chargedFlatFuelCost";
5254

5355
private static final long serialVersionUID = -79061939642779999L;
5456

@@ -222,7 +224,7 @@ private static void printError(final String errorMessage) {
222224
}
223225

224226
@Override
225-
public @Nullable MutableProperty<?> getPropertyOrNull(String propertyName) {
227+
public @Nullable MutableProperty<?> getPropertyOrNull(@NonNls String propertyName) {
226228
switch (propertyName) {
227229
case "owner":
228230
return MutableProperty.ofSimple(this::setOwner, this::getOwner);
@@ -232,49 +234,49 @@ private static void printError(final String errorMessage) {
232234
return MutableProperty.ofSimple(this::setHits, this::getHits);
233235
case "type":
234236
return MutableProperty.ofReadOnlySimple(this::getType);
235-
case "transportedBy":
237+
case TRANSPORTED_BY:
236238
return MutableProperty.ofSimple(this::setTransportedBy, this::getTransportedBy);
237-
case "unloaded":
239+
case UNLOADED:
238240
return MutableProperty.ofSimple(this::setUnloaded, this::getUnloaded);
239-
case "wasLoadedThisTurn":
241+
case LOADED_THIS_TURN:
240242
return MutableProperty.ofSimple(this::setWasLoadedThisTurn, this::getWasLoadedThisTurn);
241-
case "unloadedTo":
243+
case UNLOADED_TO:
242244
return MutableProperty.ofSimple(this::setUnloadedTo, this::getUnloadedTo);
243-
case "wasUnloadedInCombatPhase":
245+
case UNLOADED_IN_COMBAT_PHASE:
244246
return MutableProperty.ofSimple(
245247
this::setWasUnloadedInCombatPhase, this::getWasUnloadedInCombatPhase);
246-
case "alreadyMoved":
248+
case ALREADY_MOVED:
247249
return MutableProperty.ofSimple(this::setAlreadyMoved, this::getAlreadyMoved);
248-
case "bonusMovement":
250+
case BONUS_MOVEMENT:
249251
return MutableProperty.ofSimple(this::setBonusMovement, this::getBonusMovement);
250252
case "unitDamage":
251253
return MutableProperty.ofSimple(this::setUnitDamage, this::getUnitDamage);
252-
case "submerged":
254+
case SUBMERGED:
253255
return MutableProperty.ofSimple(this::setSubmerged, this::getSubmerged);
254-
case "originalOwner":
256+
case Constants.ORIGINAL_OWNER:
255257
return MutableProperty.ofSimple(this::setOriginalOwner, this::getOriginalOwner);
256-
case "wasInCombat":
258+
case WAS_IN_COMBAT:
257259
return MutableProperty.ofSimple(this::setWasInCombat, this::getWasInCombat);
258-
case "wasLoadedAfterCombat":
260+
case LOADED_AFTER_COMBAT:
259261
return MutableProperty.ofSimple(
260262
this::setWasLoadedAfterCombat, this::getWasLoadedAfterCombat);
261-
case "wasAmphibious":
263+
case UNLOADED_AMPHIBIOUS:
262264
return MutableProperty.ofSimple(this::setWasAmphibious, this::getWasAmphibious);
263-
case "originatedFrom":
265+
case ORIGINATED_FROM:
264266
return MutableProperty.ofSimple(this::setOriginatedFrom, this::getOriginatedFrom);
265-
case "wasScrambled":
267+
case WAS_SCRAMBLED:
266268
return MutableProperty.ofSimple(this::setWasScrambled, this::getWasScrambled);
267-
case "maxScrambleCount":
269+
case MAX_SCRAMBLE_COUNT:
268270
return MutableProperty.ofSimple(this::setMaxScrambleCount, this::getMaxScrambleCount);
269-
case "wasInAirBattle":
271+
case WAS_IN_AIR_BATTLE:
270272
return MutableProperty.ofSimple(this::setWasInAirBattle, this::getWasInAirBattle);
271273
case "disabled":
272274
return MutableProperty.ofSimple(this::setDisabled, this::getDisabled);
273-
case "launched":
275+
case LAUNCHED:
274276
return MutableProperty.ofSimple(this::setLaunched, this::getLaunched);
275-
case "airborne":
277+
case AIRBORNE:
276278
return MutableProperty.ofSimple(this::setAirborne, this::getAirborne);
277-
case "chargedFlatFuelCost":
279+
case CHARGED_FLAT_FUEL_COST:
278280
return MutableProperty.ofSimple(this::setChargedFlatFuelCost, this::getChargedFlatFuelCost);
279281
default:
280282
return null;
@@ -377,11 +379,11 @@ public void setTransportedBy(final Unit transportedBy) {
377379
}
378380

379381
/**
380-
* This is a very slow method because it checks all territories on the map. Try not to use this
381-
* method if possible.
382+
* Try not to use this method if possible.
382383
*
383384
* @return Unmodifiable collection of units that this unit is transporting in the same territory
384385
* it is located in
386+
* @deprecated This is a very slow method because it checks all territories on the map.
385387
*/
386388
@Deprecated
387389
public List<Unit> getTransporting() {
@@ -488,11 +490,11 @@ public boolean canTakeHitWithoutBeingKilled() {
488490
}
489491

490492
/**
491-
* Avoid calling this method, it checks every territory on the map. To undeprecate we should
493+
* Avoid calling this method, it checks every territory on the map. To avoid deprecation we should
492494
* optimize this to halt on the first territory we have found with a transporting unit, or
493495
* otherwise optimize this to not check every territory.
494496
*
495-
* @deprecated Avoid callling this method, it calls {@link #getTransporting()} which is slow and
497+
* @deprecated Avoid calling this method, it calls {@link #getTransporting()} which is slow and
496498
* needs optimization.
497499
*/
498500
@Deprecated

game-app/game-core/src/main/java/games/strategy/engine/data/battle/phase/BattlePhaseList.java

+5-4
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import java.util.Map;
99
import java.util.Optional;
1010
import lombok.Getter;
11+
import org.jetbrains.annotations.NonNls;
1112

1213
/**
1314
* Stores all of the {@link BattlePhase}s that will be used during a battle
@@ -17,10 +18,10 @@
1718
@Getter
1819
public class BattlePhaseList {
1920

20-
public static final String DEFAULT_AA_PHASE = "AA";
21-
public static final String DEFAULT_BOMBARD_PHASE = "Bombard";
22-
public static final String DEFAULT_FIRST_STRIKE_PHASE = "First Strike";
23-
public static final String DEFAULT_GENERAL_PHASE = "General";
21+
@NonNls public static final String DEFAULT_AA_PHASE = "AA";
22+
@NonNls public static final String DEFAULT_BOMBARD_PHASE = "Bombard";
23+
@NonNls public static final String DEFAULT_FIRST_STRIKE_PHASE = "First Strike";
24+
@NonNls public static final String DEFAULT_GENERAL_PHASE = "General";
2425

2526
private final Collection<BattlePhase> phases = new ArrayList<>();
2627

0 commit comments

Comments
 (0)