Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>A char array in java is nothing more than a <code>String</code> in java. You can use string in switch-cases in Java7, but I don't know the efficiency of the comparisions.</p> <p>Because only the last element of you char array seems to have a meaning, you could do a switch case with it. Something like</p> <pre><code>private static final int VERSION_INDEX = 3; ... char[] version = // get it somehow switch (version[VERSION_INDEX]) { case '5': break; // etc } ... </code></pre> <p><strong>EDIT</strong> More object oriented version.</p> <pre><code> public interface Command { void execute(); } public class Version { private final Integer versionRepresentation; private Version (Integer versionRep) { this.versionRepresentation = versionRep; } public static Version get(char[] version) { return new Version(Integer.valueOf(new String(version, "US-ASCII"))); } @Override public int hashCode() { return this.versionRepresentation.hashCode(); } @Override public boolean equals(Object obj) { if (obj instanceof Version) { Version that = (Version) obj; return that.versionRepresentation.equals(this.versionRepresentation); } return false; } } public class VersionOrientedCommandSet { private final Command EMPTY_COMMAND = new Command() { public void execute() {}}; private final Map&lt;Version, Command&gt; versionOrientedCommands; private class VersionOrientedCommandSet() { this.versionOrientedCommands = new HashMap&lt;Version, Command&gt;(); } public void add(Version version, Command command) { this.versionOrientedCommands.put(version, command); } public void execute(Version version) throw CommandNotFoundException { Command command = this.versionOrientedCommands.get(version); if (command != null) { command.execute(); } else { throw new CommandNotFoundException("No command registered for version " + version); } } } // register you commands to VersionOrientedCommandSet char[] versionChar = // got it from somewhere Version version = Version.get(versionChar); versionOrientedCommandSet.execute(version); </code></pre> <p>lots of code hehe You will have a little cost of warm-up, but if you program is executed multiple times, you will gain efficiency with the map :P</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload