Accumulo
  1. Accumulo
  2. ACCUMULO-2647

Replace String comparison if-then-else with switch

    Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 1.6.0
    • Fix Version/s: 1.7.0
    • Component/s: start
    • Labels:

      Description

      In o.a.a.start.Main we have a giant if-then-else ladder for determining which class to use. With Java 7, we can replace this with a switch statement.

      The switch statement compares the String object in its expression with the expressions associated with each case label as if it were using the String.equals method; consequently, the comparison of String objects in switch statements is case sensitive. The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

      1. ACCUMULO-2647.patch.txt
        7 kB
        Jeffrey S Schwartz

        Issue Links

          Activity

          Hide
          Christopher Tubbs added a comment -

          In the code for ACCUMULO-1496, I've used annotations and searched for annotated classes. That was slow, due to the indexing of the annotations. For this ticket, we could adopt a hybrid approach, looping over a set of known classes, reading the annotations, rather than doing all the if statements. (It would also simplify the merge if we revisit ACCUMULO-1496.)

          Show
          Christopher Tubbs added a comment - In the code for ACCUMULO-1496 , I've used annotations and searched for annotated classes. That was slow, due to the indexing of the annotations. For this ticket, we could adopt a hybrid approach, looping over a set of known classes, reading the annotations, rather than doing all the if statements. (It would also simplify the merge if we revisit ACCUMULO-1496 .)
          Hide
          ASF subversion and git services added a comment -

          Commit 6c30e6b8e2f3da3e4a96dd1d2767712805a4e7c2 in accumulo's branch refs/heads/master from Jeffrey S Schwartz
          [ https://git-wip-us.apache.org/repos/asf?p=accumulo.git;h=6c30e6b ]

          ACCUMULO-2647 changed if/then/else to switch statement

          Signed-off-by: Sean Busbey <busbey@cloudera.com>

          Show
          ASF subversion and git services added a comment - Commit 6c30e6b8e2f3da3e4a96dd1d2767712805a4e7c2 in accumulo's branch refs/heads/master from Jeffrey S Schwartz [ https://git-wip-us.apache.org/repos/asf?p=accumulo.git;h=6c30e6b ] ACCUMULO-2647 changed if/then/else to switch statement Signed-off-by: Sean Busbey <busbey@cloudera.com>
          Hide
          Sean Busbey added a comment -

          Thanks Jeffrey!

          Do you want to be listed on the contributors list? If so, how would you like your employer displayed (if at all)?

          Show
          Sean Busbey added a comment - Thanks Jeffrey! Do you want to be listed on the contributors list ? If so, how would you like your employer displayed (if at all)?

            People

            • Assignee:
              Jeffrey S Schwartz
              Reporter:
              Mike Drob
            • Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved:

                Development