CINXE.COM
Diff - 942ed063adf2d75f9e8c658d52a87c6126fb902f^! - training/sample - Git at Google
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width, initial-scale=1"><title>Diff - 942ed063adf2d75f9e8c658d52a87c6126fb902f^! - training/sample - Git at Google</title><link rel="stylesheet" type="text/css" href="/+static/base.css"><!-- default customHeadTagPart --></head><body class="Site"><header class="Site-header"><div class="Header"><a class="Header-image" href="/"><img src="//www.gstatic.com/images/branding/lockups/2x/lockup_git_color_108x24dp.png" width="108" height="24" alt="Google Git"></a><div class="Header-menu"> <a class="Header-menuItem" href="https://accounts.google.com/AccountChooser?faa=1&service=gerritcodereview&continue=https://gerrit.googlesource.com/login/training/sample/%2B/942ed063adf2d75f9e8c658d52a87c6126fb902f%255E%2521/">Sign in</a> </div></div></header><div class="Site-content"><div class="Container "><div class="Breadcrumbs"><a class="Breadcrumbs-crumb" href="/?format=HTML">gerrit</a> / <a class="Breadcrumbs-crumb" href="/training/">training</a> / <a class="Breadcrumbs-crumb" href="/training/sample/">sample</a> / <a class="Breadcrumbs-crumb" href="/training/sample/+/942ed063adf2d75f9e8c658d52a87c6126fb902f%5E%21/">942ed063adf2d75f9e8c658d52a87c6126fb902f^!</a> / <span class="Breadcrumbs-crumb">.</span></div><div class="u-monospace Metadata"><table><tr><th class="Metadata-title">commit</th><td>942ed063adf2d75f9e8c658d52a87c6126fb902f</td><td><span>[<a href="/training/sample/+log/942ed063adf2d75f9e8c658d52a87c6126fb902f/">log</a>]</span> <span>[<a href="/training/sample/+archive/942ed063adf2d75f9e8c658d52a87c6126fb902f/.tar.gz">tgz</a>]</span></td></tr><tr><th class="Metadata-title">author</th><td>Matthias Sohn <matthias.sohn@sap.com></td><td>Fri Feb 25 15:18:37 2011 +0100</td></tr><tr><th class="Metadata-title">committer</th><td>Matthias Sohn <matthias.sohn@sap.com></td><td>Fri Feb 25 15:21:08 2011 +0100</td></tr><tr><th class="Metadata-title">tree</th><td><a href="/training/sample/+/942ed063adf2d75f9e8c658d52a87c6126fb902f/">42a412f10b411a0a30aff1de2f365186709e2e48</a></td></tr><tr><th class="Metadata-title">parent</th><td><a href="/training/sample/+/942ed063adf2d75f9e8c658d52a87c6126fb902f%5E">b49618df18608568fe20195bfa8cc1c06eb23c37</a> <span>[<a href="/training/sample/+/942ed063adf2d75f9e8c658d52a87c6126fb902f%5E%21/">diff</a>]</span></td></tr></table></div><pre class="u-pre u-monospace MetadataMessage">Fix redundant clear display after unary operation Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> </pre><pre class="u-pre u-monospace Diff"><a name="F0" class="Diff-fileIndex"></a>diff --git <a href="/training/sample/+/b49618df18608568fe20195bfa8cc1c06eb23c37/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java">a/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java</a> <a href="/training/sample/+/942ed063adf2d75f9e8c658d52a87c6126fb902f/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java">b/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java</a> index db032da..ff2c20f 100644 --- a/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java +++ b/org.eclipse.example.calc/src/org/eclipse/example/calc/internal/ui/Calculator.java </pre><pre class="u-pre u-monospace Diff-unified"><span class="Diff-hunk">@@ -37,14 +37,21 @@ </span><span class="Diff-change"> private static final long serialVersionUID = 1L;</span> <span class="Diff-change"> </span> <span class="Diff-change"> private String cmd;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private boolean clearDisplay;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private float value;</span> <span class="Diff-change"> </span> <span class="Diff-change"> private JTextField display;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private JPanel buttonsPanel;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private JPanel numberButtonsPanel;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private JPanel cmdButtonsPanel;</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private JButton numberButtons[];</span> <span class="Diff-insert">+</span> <span class="Diff-change"> private JButton cmdButtons[];</span> <span class="Diff-change"> </span> <span class="Diff-change"> public static void main(String args[]) {</span> <span class="Diff-hunk">@@ -162,32 +169,36 @@ </span><span class="Diff-change"> // get current value of display</span> <span class="Diff-change"> curValue = Float.parseFloat(display.getText());</span> <span class="Diff-change"> </span> <span class="Diff-delete">- if (cmd == null || cmd.equals("")) {</span> <span class="Diff-delete">- // if no command was saved previously, save this one and clear</span> <span class="Diff-insert">+ Operation currentOp = Operations.INSTANCE.getOperation(cmdName);</span> <span class="Diff-insert">+ if ((currentOp instanceof BinaryOperation) && (cmd == null)) {</span> <span class="Diff-insert">+ // if last clicked operation was binary and there is no saved</span> <span class="Diff-insert">+ // operation, store it</span> <span class="Diff-change"> cmd = cmdName;</span> <span class="Diff-change"> clearDisplay = true;</span> <span class="Diff-change"> } else {</span> <span class="Diff-delete">- // perform the saved command</span> <span class="Diff-delete">- Operation op = Operations.INSTANCE.getOperation(cmd);</span> <span class="Diff-delete">- assert (op != null);</span> <span class="Diff-delete">- if (op instanceof BinaryOperation) {</span> <span class="Diff-delete">- BinaryOperation bop = (BinaryOperation) op;</span> <span class="Diff-insert">+ // if saved command is binary perform it</span> <span class="Diff-insert">+ Operation savedOp = Operations.INSTANCE.getOperation(cmd);</span> <span class="Diff-insert">+ if (savedOp instanceof BinaryOperation) {</span> <span class="Diff-insert">+ BinaryOperation bop = (BinaryOperation) savedOp;</span> <span class="Diff-change"> newValue = bop.perform(value, curValue);</span> <span class="Diff-delete">- } else if (op instanceof UnaryOperation) {</span> <span class="Diff-delete">- UnaryOperation uop = (UnaryOperation) op;</span> <span class="Diff-insert">+ } // if current operation is unary perform it</span> <span class="Diff-insert">+ else if (currentOp instanceof UnaryOperation) {</span> <span class="Diff-insert">+ UnaryOperation uop = (UnaryOperation) currentOp;</span> <span class="Diff-change"> newValue = uop.perform(curValue);</span> <span class="Diff-change"> }</span> <span class="Diff-change"> </span> <span class="Diff-delete">- // display the result and order to clear</span> <span class="Diff-insert">+ // display the result and prepare clear on next button</span> <span class="Diff-change"> display.setText("" + newValue);</span> <span class="Diff-change"> clearDisplay = true;</span> <span class="Diff-delete">-</span> <span class="Diff-delete">- if (cmdName.equals("=")) {</span> <span class="Diff-delete">- // do not save = command</span> <span class="Diff-insert">+ if (currentOp instanceof Equals) {</span> <span class="Diff-insert">+ // do not save "=" command</span> <span class="Diff-change"> cmd = null;</span> <span class="Diff-delete">- } else {</span> <span class="Diff-delete">- // save other commands</span> <span class="Diff-insert">+ } else if (currentOp instanceof BinaryOperation) {</span> <span class="Diff-insert">+ // save binary commands as they are executed on next operation</span> <span class="Diff-change"> cmd = cmdName;</span> <span class="Diff-insert">+ } else {</span> <span class="Diff-insert">+ // clear saved command</span> <span class="Diff-insert">+ cmd = null;</span> <span class="Diff-change"> }</span> <span class="Diff-change"> }</span> <span class="Diff-change"> </span> </pre></div> <!-- Container --></div> <!-- Site-content --><footer class="Site-footer"><div class="Footer"><span class="Footer-poweredBy">Powered by <a href="https://gerrit.googlesource.com/gitiles/">Gitiles</a>| <a href="https://policies.google.com/privacy">Privacy</a>| <a href="https://policies.google.com/terms">Terms</a></span><span class="Footer-formats"><a class="u-monospace Footer-formatsItem" href="?format=TEXT">txt</a> <a class="u-monospace Footer-formatsItem" href="?format=JSON">json</a></span></div></footer></body></html>