-
Notifications
You must be signed in to change notification settings - Fork 2
Fix SpecsStrings.normalizeFileContents() to always trim lines #27
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
Open
joaobispo
wants to merge
3
commits into
staging
Choose a base branch
from
fix/specs-strings-normalization
base: staging
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,6 +13,12 @@ | |
|
|
||
| package pt.up.fe.specs.util; | ||
|
|
||
| import pt.up.fe.specs.util.collections.MultiMap; | ||
| import pt.up.fe.specs.util.exceptions.OverflowException; | ||
| import pt.up.fe.specs.util.parsing.LineParser; | ||
| import pt.up.fe.specs.util.utilities.LineStream; | ||
| import pt.up.fe.specs.util.utilities.StringLines; | ||
|
|
||
| import java.io.File; | ||
| import java.io.UnsupportedEncodingException; | ||
| import java.lang.reflect.ParameterizedType; | ||
|
|
@@ -22,17 +28,7 @@ | |
| import java.text.DecimalFormatSymbols; | ||
| import java.text.NumberFormat; | ||
| import java.text.ParseException; | ||
| import java.util.ArrayList; | ||
| import java.util.Arrays; | ||
| import java.util.Collection; | ||
| import java.util.Collections; | ||
| import java.util.HashMap; | ||
| import java.util.List; | ||
| import java.util.Locale; | ||
| import java.util.Map; | ||
| import java.util.Objects; | ||
| import java.util.Optional; | ||
| import java.util.StringJoiner; | ||
| import java.util.*; | ||
| import java.util.concurrent.TimeUnit; | ||
| import java.util.function.Predicate; | ||
| import java.util.function.Supplier; | ||
|
|
@@ -41,12 +37,6 @@ | |
| import java.util.regex.PatternSyntaxException; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import pt.up.fe.specs.util.collections.MultiMap; | ||
| import pt.up.fe.specs.util.exceptions.OverflowException; | ||
| import pt.up.fe.specs.util.parsing.LineParser; | ||
| import pt.up.fe.specs.util.utilities.LineStream; | ||
| import pt.up.fe.specs.util.utilities.StringLines; | ||
|
|
||
| /** | ||
| * Utility methods for parsing of values which, instead of throwing an | ||
| * exception, return a default value if a parsing | ||
|
|
@@ -67,6 +57,7 @@ public class SpecsStrings { | |
| } | ||
|
|
||
| private static final Map<TimeUnit, String> TIME_UNIT_SYMBOL; | ||
|
|
||
| static { | ||
| TIME_UNIT_SYMBOL = new HashMap<>(); | ||
| SpecsStrings.TIME_UNIT_SYMBOL.put(TimeUnit.DAYS, "days"); | ||
|
|
@@ -94,7 +85,7 @@ public static boolean isPrintableChar(char c) { | |
| * | ||
| * @param integer a String representing an integer. | ||
| * @return the intenger represented by the string, or 0 if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static int parseInt(String integer) { | ||
| int intResult = 0; | ||
|
|
@@ -113,7 +104,7 @@ public static int parseInt(String integer) { | |
| * | ||
| * @param integer a String representing an integer. | ||
| * @return the integer represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Integer parseInteger(String integer) { | ||
| try { | ||
|
|
@@ -128,7 +119,7 @@ public static Integer parseInteger(String integer) { | |
| * | ||
| * @param doublefloat a String representing a double. | ||
| * @return the double represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Optional<Double> valueOfDouble(String doublefloat) { | ||
| try { | ||
|
|
@@ -147,7 +138,7 @@ public static short parseShort(String s) { | |
| * | ||
| * @param afloat a String representing a float. | ||
| * @return the float represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Float parseFloat(String afloat) { | ||
| return parseFloat(afloat, true); | ||
|
|
@@ -176,7 +167,7 @@ public static Float parseFloat(String afloat, boolean isStrict) { | |
| * | ||
| * @param aDouble a String representing a double. | ||
| * @return the double represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Double parseDouble(String aDouble) { | ||
| return parseDouble(aDouble, true); | ||
|
|
@@ -188,7 +179,7 @@ public static Double parseDouble(String aDouble) { | |
| * | ||
| * @param aDouble a String representing a double. | ||
| * @return the double represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Double parseDouble(String aDouble, boolean isStrict) { | ||
| try { | ||
|
|
@@ -244,7 +235,7 @@ public static BigInteger parseBigInteger(String intNumber) { | |
| * | ||
| * @param booleanString a String representing a Boolean. | ||
| * @return the Boolean represented by the string, or null if it couldn't be | ||
| * parsed. | ||
| * parsed. | ||
| */ | ||
| public static Boolean parseBoolean(String booleanString) { | ||
| booleanString = booleanString.toLowerCase(); | ||
|
|
@@ -320,7 +311,7 @@ public static String toHexString(long decimalLong, int stringSize) { | |
| /** | ||
| * @param string a string | ||
| * @return the index of the first whitespace found in the given String, or -1 if | ||
| * none is found. | ||
| * none is found. | ||
| */ | ||
| public static int indexOfFirstWhitespace(String string) { | ||
| return indexOf(string, Character::isWhitespace, false); | ||
|
|
@@ -1587,13 +1578,12 @@ public static String normalizeFileContents(String fileContents, boolean ignoreEm | |
| // Normalize new lines | ||
| String normalizedString = fileContents.replaceAll("\r\n", "\n"); | ||
|
|
||
| // Remove empty lines | ||
| if (ignoreEmptyLines) { | ||
| normalizedString = StringLines.getLines(normalizedString).stream() | ||
| .map(String::trim) | ||
| .filter(line -> !line.isEmpty()) | ||
| .collect(Collectors.joining("\n")); | ||
| } | ||
| // Trim strings | ||
| normalizedString = StringLines.getLines(normalizedString).stream() | ||
| .map(String::trim) | ||
| // Remove empty lines | ||
| .filter(line -> !(ignoreEmptyLines && line.isEmpty())) | ||
| .collect(Collectors.joining("\n")); | ||
|
Comment on lines
+1582
to
+1586
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Added a
Committed in the latest push. |
||
|
|
||
| return normalizedString; | ||
|
|
||
|
|
@@ -1683,7 +1673,7 @@ public static String toDecimal(long number) { | |
| * Splits the given String according to a separator, and removes blank String | ||
| * that can be created from the splitting. | ||
| * | ||
| * @param strip if true, strips each splitted String | ||
| * @param strip if true, strips each splitted String | ||
| */ | ||
| public static List<String> splitNonEmpty(String string, String separator, boolean strip) { | ||
| return Arrays.stream(string.split(separator)) | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This meaningful changes the behaviour of this function. Check if all uses in the specs-feup org use this with ignoreEmptyLines on. If that is not the case, there should be a path without filtering the empty lines.
It's a 2 line change by not applying the filter to the stream, conditionally.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nevermind. Reread the new filter function. Go ahead and merge