Skip to content

Commit

Permalink
I18n v2 (@NonNls + Locals for toLowerCase/toUpperCase) (#12840)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
frigoref authored Aug 17, 2024
1 parent a26ea62 commit 2219d8d
Show file tree
Hide file tree
Showing 134 changed files with 734 additions and 511 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.triplea.domain.data;

import lombok.experimental.UtilityClass;
import org.jetbrains.annotations.NonNls;

/** Utility class to validates user email to check if it looks valid. */
@UtilityClass
Expand All @@ -13,13 +14,13 @@ public static boolean isValid(final String emailAddress) {
/** Allow multiple fully qualified email addresses separated by spaces, or a blank string. */
public static String validate(final String emailAddress) {
final String quotedString = "\"(?:[^\"\\\\]|\\\\\\p{ASCII})*\"";
final String atom = "[^()<>@,;:\\\\\".\\[\\] \\x28\\p{Cntrl}]+";
final String word = "(?:" + atom + "|" + quotedString + ")";
final String subdomain = "(?:" + atom + "|\\[(?:[^\\[\\]\\\\]|\\\\\\p{ASCII})*\\])";
final String domain = subdomain + "(?:\\." + subdomain + ")*";
final String localPart = word + "(?:\\." + word + ")*";
final String email = localPart + "@" + domain;
final String regex = "(\\s*" + email + "\\s*)*";
@NonNls final String atom = "[^()<>@,;:\\\\\".\\[\\] \\x28\\p{Cntrl}]+";
@NonNls final String word = "(?:" + atom + "|" + quotedString + ")";
@NonNls final String subdomain = "(?:" + atom + "|\\[(?:[^\\[\\]\\\\]|\\\\\\p{ASCII})*\\])";
@NonNls final String domain = subdomain + "(?:\\." + subdomain + ")*";
@NonNls final String localPart = word + "(?:\\." + word + ")*";
@NonNls final String email = localPart + "@" + domain;
@NonNls final String regex = "(\\s*" + email + "\\s*)*";
if (!emailAddress.matches(regex)) {
return "Invalid email address";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@
import lombok.Setter;
import lombok.experimental.UtilityClass;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NonNls;

/** Loads a SystemId from persistence. */
@UtilityClass
@Slf4j
public class SystemIdLoader {
private static final String SYSTEM_KEY = "system-id-key";
@NonNls private static final String SYSTEM_KEY = "system-id-key";

@Setter(value = AccessLevel.PACKAGE, onMethod_ = @VisibleForTesting)
private static PreferencesPersistence preferencesPersistence =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,15 @@
import java.util.function.Supplier;
import javax.annotation.Nullable;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NonNls;
import org.triplea.game.ApplicationContext;
import org.triplea.io.FileUtils;
import org.triplea.util.Services;

/** Provides methods to work with common file locations in a client installation. */
@Slf4j
public final class ClientFileSystemHelper {
public static final String USER_ROOT_FOLDER_NAME = "triplea";
@NonNls public static final String USER_ROOT_FOLDER_NAME = "triplea";

@VisibleForTesting static final String MAPS_FOLDER_NAME = "downloadedMaps";
private static Path codeSourceLocation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NonNls;
import org.triplea.domain.data.ChatParticipant;
import org.triplea.domain.data.PlayerChatId;
import org.triplea.domain.data.UserName;

/** Default implementation of {@link IChatController}. */
@Slf4j
public class ChatController implements IChatController {
private static final String CHAT_REMOTE = "_ChatRemote_";
private static final String CHAT_CHANNEL = "_ChatControl_";
@NonNls private static final String CHAT_REMOTE = "_ChatRemote_";
@NonNls private static final String CHAT_CHANNEL = "_ChatControl_";
private final Messengers messengers;
private final ServerMessenger serverMessenger;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.util.Collection;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;
import java.util.function.BiConsumer;
import javax.swing.Action;
import javax.swing.DefaultListCellRenderer;
Expand All @@ -28,6 +29,7 @@
import javax.swing.JScrollPane;
import javax.swing.ListCellRenderer;
import javax.swing.UIManager;
import org.jetbrains.annotations.NonNls;
import org.triplea.domain.data.ChatParticipant;
import org.triplea.domain.data.UserName;
import org.triplea.java.StringUtils;
Expand All @@ -36,7 +38,7 @@

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

Expand Down Expand Up @@ -270,7 +272,8 @@ public synchronized void updatePlayerList(final Collection<ChatParticipant> upda
updatedPlayers.stream()
.sorted(
Comparator.comparing(
chatParticipant -> chatParticipant.getUserName().getValue().toUpperCase()))
chatParticipant ->
chatParticipant.getUserName().getValue().toUpperCase(Locale.ENGLISH)))
.forEach(listModel::addElement);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.function.Predicate;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NonNls;
import org.triplea.io.FileUtils;
import org.triplea.io.IoUtils;
import org.triplea.java.ObjectUtils;
Expand Down Expand Up @@ -73,7 +74,7 @@ public class GameData implements Serializable, GameState {
private static final long serialVersionUID = -2612710634080125728L;

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

private transient ReadWriteLock readWriteLock = new ReentrantReadWriteLock();
private transient volatile boolean forceInSwingEventThread = false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.Getter;
import org.jetbrains.annotations.NonNls;
import org.triplea.java.RemoveOnNextMajorRelease;

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

private static final String DEFAULT_TYPE_AI = "AI";
private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";
@NonNls private static final String DEFAULT_TYPE_AI = "AI";
@NonNls private static final String DEFAULT_TYPE_DOES_NOTHING = "DoesNothing";

@RemoveOnNextMajorRelease @Deprecated
private static final GamePlayer NULL_PLAYERID =
Expand Down Expand Up @@ -127,12 +128,12 @@ public String getType() {
}

/**
* First string is "Human" or "AI" or "null" (case insensitive), while second string is the name
* First string is "Human" or "AI" or "null" (case-insensitive), while second string is the name
* of the player, separated with a colon. For example, it could be "AI:Hard (AI)".
*
* @throws IllegalArgumentException If {@code encodedType} does not contain two strings separated
* by a colon; or if the first string is not one of "AI", "Human", or "null" (case
* insensitive).
* by a colon; or if the first string is not one of "AI", "Human", or "null"
* (case-insensitive).
*/
public void setWhoAmI(final String encodedType) {
final List<String> tokens = tokenizeEncodedType(encodedType);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.common.collect.ImmutableList;
import games.strategy.triplea.Constants;
import games.strategy.triplea.Properties;
import games.strategy.triplea.attachments.TerritoryAttachment;
import games.strategy.triplea.attachments.UnitAttachment;
Expand All @@ -19,6 +20,7 @@
import lombok.Getter;
import lombok.Setter;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NonNls;
import org.triplea.java.collections.CollectionUtils;

/**
Expand All @@ -31,24 +33,24 @@
@Getter
@EqualsAndHashCode(of = "id", callSuper = false)
public class Unit extends GameDataComponent implements DynamicallyModifiable {
public static final String TRANSPORTED_BY = "transportedBy";
public static final String UNLOADED = "unloaded";
public static final String LOADED_THIS_TURN = "wasLoadedThisTurn";
public static final String UNLOADED_TO = "unloadedTo";
public static final String UNLOADED_IN_COMBAT_PHASE = "wasUnloadedInCombatPhase";
public static final String ALREADY_MOVED = "alreadyMoved";
public static final String BONUS_MOVEMENT = "bonusMovement";
public static final String SUBMERGED = "submerged";
public static final String WAS_IN_COMBAT = "wasInCombat";
public static final String LOADED_AFTER_COMBAT = "wasLoadedAfterCombat";
public static final String UNLOADED_AMPHIBIOUS = "wasAmphibious";
public static final String ORIGINATED_FROM = "originatedFrom";
public static final String WAS_SCRAMBLED = "wasScrambled";
public static final String MAX_SCRAMBLE_COUNT = "maxScrambleCount";
public static final String WAS_IN_AIR_BATTLE = "wasInAirBattle";
public static final String LAUNCHED = "launched";
public static final String AIRBORNE = "airborne";
public static final String CHARGED_FLAT_FUEL_COST = "chargedFlatFuelCost";
@NonNls public static final String TRANSPORTED_BY = "transportedBy";
@NonNls public static final String UNLOADED = "unloaded";
@NonNls public static final String LOADED_THIS_TURN = "wasLoadedThisTurn";
@NonNls public static final String UNLOADED_TO = "unloadedTo";
@NonNls public static final String UNLOADED_IN_COMBAT_PHASE = "wasUnloadedInCombatPhase";
@NonNls public static final String ALREADY_MOVED = "alreadyMoved";
@NonNls public static final String BONUS_MOVEMENT = "bonusMovement";
@NonNls public static final String SUBMERGED = "submerged";
@NonNls public static final String WAS_IN_COMBAT = "wasInCombat";
@NonNls public static final String LOADED_AFTER_COMBAT = "wasLoadedAfterCombat";
@NonNls public static final String UNLOADED_AMPHIBIOUS = "wasAmphibious";
@NonNls public static final String ORIGINATED_FROM = "originatedFrom";
@NonNls public static final String WAS_SCRAMBLED = "wasScrambled";
@NonNls public static final String MAX_SCRAMBLE_COUNT = "maxScrambleCount";
@NonNls public static final String WAS_IN_AIR_BATTLE = "wasInAirBattle";
@NonNls public static final String LAUNCHED = "launched";
@NonNls public static final String AIRBORNE = "airborne";
@NonNls public static final String CHARGED_FLAT_FUEL_COST = "chargedFlatFuelCost";

private static final long serialVersionUID = -79061939642779999L;

Expand Down Expand Up @@ -222,7 +224,7 @@ private static void printError(final String errorMessage) {
}

@Override
public @Nullable MutableProperty<?> getPropertyOrNull(String propertyName) {
public @Nullable MutableProperty<?> getPropertyOrNull(@NonNls String propertyName) {
switch (propertyName) {
case "owner":
return MutableProperty.ofSimple(this::setOwner, this::getOwner);
Expand All @@ -232,49 +234,49 @@ private static void printError(final String errorMessage) {
return MutableProperty.ofSimple(this::setHits, this::getHits);
case "type":
return MutableProperty.ofReadOnlySimple(this::getType);
case "transportedBy":
case TRANSPORTED_BY:
return MutableProperty.ofSimple(this::setTransportedBy, this::getTransportedBy);
case "unloaded":
case UNLOADED:
return MutableProperty.ofSimple(this::setUnloaded, this::getUnloaded);
case "wasLoadedThisTurn":
case LOADED_THIS_TURN:
return MutableProperty.ofSimple(this::setWasLoadedThisTurn, this::getWasLoadedThisTurn);
case "unloadedTo":
case UNLOADED_TO:
return MutableProperty.ofSimple(this::setUnloadedTo, this::getUnloadedTo);
case "wasUnloadedInCombatPhase":
case UNLOADED_IN_COMBAT_PHASE:
return MutableProperty.ofSimple(
this::setWasUnloadedInCombatPhase, this::getWasUnloadedInCombatPhase);
case "alreadyMoved":
case ALREADY_MOVED:
return MutableProperty.ofSimple(this::setAlreadyMoved, this::getAlreadyMoved);
case "bonusMovement":
case BONUS_MOVEMENT:
return MutableProperty.ofSimple(this::setBonusMovement, this::getBonusMovement);
case "unitDamage":
return MutableProperty.ofSimple(this::setUnitDamage, this::getUnitDamage);
case "submerged":
case SUBMERGED:
return MutableProperty.ofSimple(this::setSubmerged, this::getSubmerged);
case "originalOwner":
case Constants.ORIGINAL_OWNER:
return MutableProperty.ofSimple(this::setOriginalOwner, this::getOriginalOwner);
case "wasInCombat":
case WAS_IN_COMBAT:
return MutableProperty.ofSimple(this::setWasInCombat, this::getWasInCombat);
case "wasLoadedAfterCombat":
case LOADED_AFTER_COMBAT:
return MutableProperty.ofSimple(
this::setWasLoadedAfterCombat, this::getWasLoadedAfterCombat);
case "wasAmphibious":
case UNLOADED_AMPHIBIOUS:
return MutableProperty.ofSimple(this::setWasAmphibious, this::getWasAmphibious);
case "originatedFrom":
case ORIGINATED_FROM:
return MutableProperty.ofSimple(this::setOriginatedFrom, this::getOriginatedFrom);
case "wasScrambled":
case WAS_SCRAMBLED:
return MutableProperty.ofSimple(this::setWasScrambled, this::getWasScrambled);
case "maxScrambleCount":
case MAX_SCRAMBLE_COUNT:
return MutableProperty.ofSimple(this::setMaxScrambleCount, this::getMaxScrambleCount);
case "wasInAirBattle":
case WAS_IN_AIR_BATTLE:
return MutableProperty.ofSimple(this::setWasInAirBattle, this::getWasInAirBattle);
case "disabled":
return MutableProperty.ofSimple(this::setDisabled, this::getDisabled);
case "launched":
case LAUNCHED:
return MutableProperty.ofSimple(this::setLaunched, this::getLaunched);
case "airborne":
case AIRBORNE:
return MutableProperty.ofSimple(this::setAirborne, this::getAirborne);
case "chargedFlatFuelCost":
case CHARGED_FLAT_FUEL_COST:
return MutableProperty.ofSimple(this::setChargedFlatFuelCost, this::getChargedFlatFuelCost);
default:
return null;
Expand Down Expand Up @@ -377,11 +379,11 @@ public void setTransportedBy(final Unit transportedBy) {
}

/**
* This is a very slow method because it checks all territories on the map. Try not to use this
* method if possible.
* Try not to use this method if possible.
*
* @return Unmodifiable collection of units that this unit is transporting in the same territory
* it is located in
* @deprecated This is a very slow method because it checks all territories on the map.
*/
@Deprecated
public List<Unit> getTransporting() {
Expand Down Expand Up @@ -488,11 +490,11 @@ public boolean canTakeHitWithoutBeingKilled() {
}

/**
* Avoid calling this method, it checks every territory on the map. To undeprecate we should
* Avoid calling this method, it checks every territory on the map. To avoid deprecation we should
* optimize this to halt on the first territory we have found with a transporting unit, or
* otherwise optimize this to not check every territory.
*
* @deprecated Avoid callling this method, it calls {@link #getTransporting()} which is slow and
* @deprecated Avoid calling this method, it calls {@link #getTransporting()} which is slow and
* needs optimization.
*/
@Deprecated
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import java.util.Map;
import java.util.Optional;
import lombok.Getter;
import org.jetbrains.annotations.NonNls;

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

public static final String DEFAULT_AA_PHASE = "AA";
public static final String DEFAULT_BOMBARD_PHASE = "Bombard";
public static final String DEFAULT_FIRST_STRIKE_PHASE = "First Strike";
public static final String DEFAULT_GENERAL_PHASE = "General";
@NonNls public static final String DEFAULT_AA_PHASE = "AA";
@NonNls public static final String DEFAULT_BOMBARD_PHASE = "Bombard";
@NonNls public static final String DEFAULT_FIRST_STRIKE_PHASE = "First Strike";
@NonNls public static final String DEFAULT_GENERAL_PHASE = "General";

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

Expand Down
Loading

0 comments on commit 2219d8d

Please sign in to comment.