-
Notifications
You must be signed in to change notification settings - Fork 4
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
Refactor Blocks #35
Refactor Blocks #35
Conversation
Thanks for this PR 👍 Because I merged other PRs, there are conflicts :( Please fix them. |
Following changes are made in this commit: * Rename classes As we discussed offline * Extract common functions among block classes Changed NumberTextHolder interface for better encapsulation * Change return value type of BlockBase#getKind The previous code uses Class class, which does not represent actual use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class). Replaced Class<? extends Block> type with Enum. * Remove locale-dependent code on parsing numbers The previous code relies on the Locale.US no matter what locale this app runs on. This commit fixes the locale dependent code by extracting the parsing logic. * Fix the unspoken rule that using scaled values for communicating between blocks and number pickers. The previous code scaled values so that the value has no radix point, which was confusing code. Fixed by replacing the type with BigDecimal and explicitly use the raw value. In accordance with it, changed the type of "number" in ProgramDataSpec for saving without data loss * Remove code in Unit class for handling quantities, which was ugly and cannot be used widely. Changed second string ("second/s" -> just "s")
Hey @tiwanari, resolved conflicts. |
Thanks for notifying me :) Please give me a little time to check them. |
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.
I made comments but before seeing them, please make the PR enable to be built. There are errors with merged code (ExecutionCondition).
try { | ||
return (Class<T>) Class.forName(className); | ||
|
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.
I don't think this blank line makes this program more readable. Is there any specific reason to keep blank lines like this? If no, please remove such lines.
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.
Seriously? I DO THINK SO.
but this is kinda religious war and here's your realm.
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.
I'm sorry, I didn't want to mean it :( I agree that adequate blank lines help code reading.
I couldn't see the consistency between these blank lines here and previous codes at review but now I'm guessing you added blank lines between long lines. It can give a kind of tender impression to codes I think. I wanted to know some of rules, i.e. why you added it here and didn't there.
We haven't talked enough about blank lines beforehand and formatters never specify it. I really appreciate if you share your thoughts :)
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.
Don't take my comment seriously and offensive, please.
For consistency you are right.
And topics of the format are bit off from here.
Anyway I'll merge this. Thanks.
incidentally you can witch-hunt with
$ grep -ElR "catch \(.*\) {" app | xargs perl -0777 -pe 's/\n(\s*} catch \(.*\) {)\n/$1/g'
for making your realm calm and getting rid of "pagans"
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.
Thanks. The one-liner seems to illustrate a rule "add blank lines before & after a catch clause" :)
btw, `realm' has a bit overwhelmed impression for me... 😓
public static final int UNDO = 3; | ||
public static final int LOAD = 4; | ||
|
||
/** |
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 is just a question. Did you remove Javadocs from here because the method is private
, right?
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.
The answer is Yes
@@ -29,14 +30,14 @@ | |||
*/ | |||
public abstract class RepetitionBlock extends BlockBase { | |||
|
|||
public static final int FOREVER_WHILE_OFFSET = -1000; | |||
static final int FOREVER_WHILE_OFFSET = -1000; |
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.
I found this cannot be package private
here because it is used in ExecuteCodition. This may be controversial.
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.
Moved to ExecutionCondition, since this field is irrelevant for the operation of blocks.
(btw ExecutionCondition is no longer "condition")
@@ -38,131 +38,93 @@ | |||
public static final int SEQUENCE = 0; | |||
public static final int REPETITION = 1; | |||
public static final int SELECTION = 2; | |||
@Deprecated |
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.
Sorry, this is my fault. I forgot to remove this constant. Please remove it and I will add it in #12 .
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.
Removed
import java.math.BigDecimal; | ||
import java.util.Locale; | ||
|
||
public class NumberTextViewDelegate { |
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.
Could you give a short description of this class as a Javadoc here?
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.
Added
import java.text.ParseException; | ||
import java.util.Locale; | ||
|
||
public class ParseUtil { |
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 class also has many blank lines. It's okay if it has reasons.
} | ||
} | ||
|
||
public static BigDecimal bigDecimalValueOf(String value) throws NumberFormatException { |
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.
Please give a Javadocs as you made above.
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.
Added
* @param context an application context | ||
* @param integralPart the length of integral part | ||
* @param decimalPart the length of decimal part | ||
* * Constructor. |
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.
nit: double *.
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.
Removed
return Integer.parseInt(numText.getText().toString()); | ||
} | ||
// TODO: set from preference | ||
private static final int PRECISION = 1; |
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.
1 is okay but it was 0.
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.
Changed
public double getMin() { | ||
return 0.0; | ||
public Range<BigDecimal> getRange() { | ||
return range; | ||
} | ||
|
||
@Override | ||
public int action( |
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.
I know this is my fault but if you have time, please remove break lines... (this is not mandatory)
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.
Fixed
Overall, they are really good and cleaned 👍 |
* remove UNDO in BlockFactory.java * move FOREVER_WHILE_OFFSET in RepetitionBlock.java to ExecutionCondition.java * add Javadocs on NumberTextDelegate * change the signature of BlockSpaceManagerBase#placeBlock (ArrayList to List) * rename OnTouchNumTextListener to OnTouchNumberTextListener * remove OnNumberTextListener#context and rename holder to mHolder * rename Unit#getUnitString to decorateValue and introduce new class NumberUtil
for the following classes: * NumberTextViewDelegate * Unit * NumberUtil * ParseUtil And cradle.build in the root directory is modified to add the dexmaker libraries which are necessary for mockito
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.
LGTM!
* Refactor Blocks Following changes are made in this commit: * Rename classes As we discussed offline * Extract common functions among block classes Changed NumberTextHolder interface for better encapsulation * Change return value type of BlockBase#getKind The previous code uses Class class, which does not represent actual use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class). Replaced Class<? extends Block> type with Enum. * Remove locale-dependent code on parsing numbers The previous code relies on the Locale.US no matter what locale this app runs on. This commit fixes the locale dependent code by extracting the parsing logic. * Fix the unspoken rule that using scaled values for communicating between blocks and number pickers. The previous code scaled values so that the value has no radix point, which was confusing code. Fixed by replacing the type with BigDecimal and explicitly use the raw value. In accordance with it, changed the type of "number" in ProgramDataSpec for saving without data loss * Remove code in Unit class for handling quantities, which was ugly and cannot be used widely. Changed second string ("second/s" -> just "s") * Fix PR according to the comments on #35 * remove UNDO in BlockFactory.java * move FOREVER_WHILE_OFFSET in RepetitionBlock.java to ExecutionCondition.java * add Javadocs on NumberTextDelegate * change the signature of BlockSpaceManagerBase#placeBlock (ArrayList to List) * rename OnTouchNumTextListener to OnTouchNumberTextListener * remove OnNumberTextListener#context and rename holder to mHolder * rename Unit#getUnitString to decorateValue and introduce new class NumberUtil * Add and fix tests for the following classes: * NumberTextViewDelegate * Unit * NumberUtil * ParseUtil And cradle.build in the root directory is modified to add the dexmaker libraries which are necessary for mockito * Remove superfluous line-breaks * Add constructor guards for util classes
Following changes are made in this commit:
As we discussed offline
Changed NumberTextHolder interface for better encapsulation
The previous code uses Class class, which does not represent actual
use case (e.g., ForwardSecBlock#getKind returns SequenceBlock.class).
Replaced Class<? extends Block> type with Enum.
The previous code relies on the Locale.US no matter what locale
this app runs on.
This commit fixes the locale dependent code by extracting the parsing
logic.
for communicating between blocks and number pickers.
The previous code scaled values so that the value has no radix
point, which was confusing code.
Fixed by replacing the type with BigDecimal and explicitly use the raw
value.
In accordance with it, changed the type of "number"
in ProgramDataSpec for saving without data loss
Changed second string ("second/s" -> just "s")