Skip to content

style: do not suppress lossy-conversions #6206

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 31, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<arg>-Xlint:-auxiliaryclass</arg>
<arg>-Xlint:-rawtypes</arg>
<arg>-Xlint:-unchecked</arg>
<arg>-Xlint:-lossy-conversions</arg>
<arg>-Werror</arg>
</compilerArgs>
</configuration>
Expand Down
15 changes: 9 additions & 6 deletions src/main/java/com/thealgorithms/ciphers/Caesar.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
* @author khalil2535
*/
public class Caesar {
private static char normalizeShift(final int shift) {
return (char) (shift % 26);
}

/**
* Encrypt text by shifting every Latin char by add number shift for ASCII
Expand All @@ -19,7 +22,7 @@ public class Caesar {
public String encode(String message, int shift) {
StringBuilder encoded = new StringBuilder();

shift %= 26;
final char shiftChar = normalizeShift(shift);

final int length = message.length();
for (int i = 0; i < length; i++) {
Expand All @@ -29,10 +32,10 @@ public String encode(String message, int shift) {
char current = message.charAt(i); // Java law : char + int = char

if (isCapitalLatinLetter(current)) {
current += shift;
current += shiftChar;
encoded.append((char) (current > 'Z' ? current - 26 : current)); // 26 = number of latin letters
} else if (isSmallLatinLetter(current)) {
current += shift;
current += shiftChar;
encoded.append((char) (current > 'z' ? current - 26 : current)); // 26 = number of latin letters
} else {
encoded.append(current);
Expand All @@ -50,16 +53,16 @@ public String encode(String message, int shift) {
public String decode(String encryptedMessage, int shift) {
StringBuilder decoded = new StringBuilder();

shift %= 26;
final char shiftChar = normalizeShift(shift);

final int length = encryptedMessage.length();
for (int i = 0; i < length; i++) {
char current = encryptedMessage.charAt(i);
if (isCapitalLatinLetter(current)) {
current -= shift;
current -= shiftChar;
decoded.append((char) (current < 'A' ? current + 26 : current)); // 26 = number of latin letters
} else if (isSmallLatinLetter(current)) {
current -= shift;
current -= shiftChar;
decoded.append((char) (current < 'a' ? current + 26 : current)); // 26 = number of latin letters
} else {
decoded.append(current);
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/thealgorithms/maths/AliquotSum.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public static int getAliquotSum(int n) {
// if n is a perfect square then its root was added twice in above loop, so subtracting root
// from sum
if (root == (int) root) {
sum -= root;
sum -= (int) root;
}
return sum;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/com/thealgorithms/maths/PerfectNumber.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public static boolean isPerfectNumber2(int n) {
// if n is a perfect square then its root was added twice in above loop, so subtracting root
// from sum
if (root == (int) root) {
sum -= root;
sum -= (int) root;
}

return sum == n;
Expand Down