What's a good way to dynamically allow shortened commands?

I have a BufferedReader set up that attaches to System.in.
so, when I check the BufferedReader, it will retreive any commands put in by a user.
I will have a hash table for commands set up like so:
"north", "dn"
"west", "dw"
"south", "ds"
"east", "de"
"follow", "follow"
"flee", "flee"
"flip", "flip"
So, what I want is to be able to check all the commands and shorten them to the lowest amount of chars before they're the same.
Therefore, for the example hash list, if I typed in "fle", the code would select "flee". Or, if I typed "fo", the code would select "follow". But, if I typed in "f", then the code would respond with a "command not found" error, because "f" could be follow, flip or flee. I want to make it so that I can type "follow", "follo", "foll", "fol", "fo", and "fo" to select the same "follow" command.
Has anyone found a good way of going about this? If my description is confusing, I'll try to re-explain in greater detail.

Demo: I'm using the nul character to represent the end of the word, so that the data structure can represent that "hell" and "hello" are both in the vocabulary:
import java.util.*;
class Node {
    private SortedMap<Character, Node> children = new TreeMap<Character, Node>();
    //0 <= index <= word.length()
    private void add(String word, int index) {
        if (index == word.length()) {
            children.put(Character.valueOf('\u0000'), null);
        } else {
            char ch = word.charAt(index);
            Node child = children.get(ch);
            if (child == null) {
                children.put(ch, child = new Node());
            child.add(word, index+1);
    public void add(String word) {
        if (word == null || word.length()==0)
            throw new IllegalArgumentException();
        add(word, 0);
    public String toString() {
        return children.toString();
public class Example {
    public static void main(String[] args) throws Exception {
        Node root = new Node();
        root.add("hello");
        root.add("how");
        root.add("who");
        root.add("hell");
        System.out.println(root.toString());
}

Similar Messages

  • What are the good ways to send a big file( 20MB-100MB) file to my friend?

    what are the good ways to send a big file( 20MB-100MB) file to my friend?
    Thanks in advance

    if this is with the internet, iChat is probly your best bet,
    but if you just want a transfer,
    plug a firewire into both of your computers, shutdown one of them, hold "T" and press the power button, the restarted computer should pop up as an external drive on the second computer.

  • What's a good way to manage custom schema for DS  5.1?

    What's a good way to manage custom schema?
    Custom Schema for Object Class and Attributes
    The reason I ask this is because there might be a need in the future where I need to export those custome schema into different branded directory server. I just want to make this as painless as possible.
    Right now, I thought of 2 options
    1) Create my own LDIF file with my custom attributes and object classes, so if one day I need to export to another directory server, I can just copy that custom created LDIF file over. (Will this work?)
    2) Create a JAVA application using JNDI. What this Java App. will do is read through a XML file and create those object classes and attributes on-the-fly. (of course, the XML structure will be predefined by me, so that my Java App. will be able to parse through it correctly. Will this work?)
    Anymore suggestion? I would want to hear more advices and suggestions.
    Also, I assume that will work even with replication. All I need to update is the master server, and the slaves will replicate automatically.
    Thank you very much! :)

    Demo: I'm using the nul character to represent the end of the word, so that the data structure can represent that "hell" and "hello" are both in the vocabulary:
    import java.util.*;
    class Node {
        private SortedMap<Character, Node> children = new TreeMap<Character, Node>();
        //0 <= index <= word.length()
        private void add(String word, int index) {
            if (index == word.length()) {
                children.put(Character.valueOf('\u0000'), null);
            } else {
                char ch = word.charAt(index);
                Node child = children.get(ch);
                if (child == null) {
                    children.put(ch, child = new Node());
                child.add(word, index+1);
        public void add(String word) {
            if (word == null || word.length()==0)
                throw new IllegalArgumentException();
            add(word, 0);
        public String toString() {
            return children.toString();
    public class Example {
        public static void main(String[] args) throws Exception {
            Node root = new Node();
            root.add("hello");
            root.add("how");
            root.add("who");
            root.add("hell");
            System.out.println(root.toString());
    }

  • What's a good way to do a thread dump into a separate file

    What is a good way to do a thread dump automatically into a separate file.
    Example. I run a script to do the thread dump, but unfortunetly, it goes into my stdout log file with the rest of my weblogic errors.
    Any ideas? I want it in a separate file when I run my script?

    Do a Google search on "Drobo S" "benchmark."  I don't have a Drobo S, only the regular Drobo.  But here's a guy who tested one on Windows:
    http://mansurovs.com/drobo-s-review-usb-3-0-2nd-generation
    This one has it a bit faster:
    http://the-gadgeteer.com/2011/12/31/drobo-s-storage-array-review/
    Do read up on a few reviews of it, and be absolutely clear that interface speed (i.e. eSATA versus Firewire versus Thunderbolt) is NOT the same as the performance of the system.  The Drobo cannot keep up with any interfaces... at least the Drobo and the Drobo S cannot.
    I am not using the FS model which is a NAS.  I am using the plain old "Drobo" which is slower than the Drobo S, but that's not to say that the Drobo S is fast, because it is not.
    The Drobo in theory is really attractive: Dead simple to manage, can mix and match drive sizes, offers you some data protection, etc.  However do note that protected storage is not, in and of itself, a backup.  You need other backups besides just the data on the Drobo.  And, because it's so slow, it's really not a great fit for photo storage.  See this review from a guy who used to think the Drobo was great for that and then appended his review:
    http://www.stuckincustoms.com/drobo-review/
    To be as clear as possible, IMO the BEST backup strategy with something like Aperture (so long as your managed Aperture library is of a manageable size, like < 800 GB), is to get a few small portable Firewire 800 drives and keep vaults on each one.  They are great because they are easy to use, to have with you, are bus powered, and you WILL offsite them.

  • What is a good way to load 80 million documents in DocumentDB?

    I am having problems loading a large set of data.  We want to load 80 million documents.  We are trying to do testing for an IOT solution that will end up having a lot of data in it.  I followed the instructions to use a stored procedure to
    do a bulk load provided by Ryan CrawCour on the Microsoft Site:
    https://code.msdn.microsoft.com/windowsazure/Azure-DocumentDB-NET-Code-6b3da8af
    But it throws exceptions when we load 2,000 - 5,000 documents.  Our documents are only about 80 characters.
    Error: One or more errors occurred., Message: Exception: Microsoft.Azure.Documen
    ts.RequestRateTooLargeException, message: {"Errors":["Request rate is large"]},
    What is a good way to load large datasets?  ( Load backups, migrate data, ... )  Or is DocumentDB just a wrong choice when you have millions of rows to load?
    Thanks

    Hi,
    I had been working on this from around one month and I am happy to say that my code works. Was able to upload around 0.5 million documents in 20 min. 
    The configuration was Document DB with S3 , I scaled out for 16 collection for sharding, I think you need to shard out more. This will depend on how much each document takes.
    So the Calculation goes like if each document is lets say on an average 2Kb of Size and you have 80 million documents that will come out to be 160GB
    That means you will need more than 16 collections to store as at Max 1 collection can have 10GB of Data. So to be on the safer side I would say lets go for 3 times the storage so 48 collections . If all of them are at S3 than you have 2500 RUs spread across
    48 collections and I am sure if you do insertion now you will not get Request Rate too large exception.
    I have come up with this code hopefully it will help you as well.
    https://social.msdn.microsoft.com/Forums/azure/en-US/d036afe2-78ec-45ee-8b0d-297f0f5320fe/azure-documentdb-bulk-insert-using-stored-procedure.
    For Sharding you can have look at
    https://msdn.microsoft.com/en-us/library/dn589797.aspx?f=255&MSPPError=-2147217396.

  • What is the good way to charge the battery

    I don't know if this topic been answered before.
    I want to know what is the good way to charge the battery on Macbook pro? Should I start charging battery when it's 50% or 20% or 10% left? and Is it good to leave the charge plug in after it fully charged?
    thanks guys

    Everything you need to know about your battery is explained here:
    http://discussions.apple.com/thread.jspa?threadID=1764220

  • What is a good way for a heavy iMovie HD user to learn iMovie'09 ?

    Hi Guys,
    I have been using iMovie HD to edit my videos since mid 2005. I understand that Apple will, sooner or later, stop supporting iMovie HD with updates etc (it may have done so already).
    I'm doing event and safety videos for the company I'm working for. I tried to edit a video in iMovie'08 and found it too different from iMovie HD and it was difficult for me to "unlearn" iMovie HD.
    What would be a good way to learn iMovie '09 ?
    I would appreciate any tips & pointers. Thanks in advance.
    Sincerely,
    Azman

    I think the best way is to jump in and make a movie. If you get frustrated about something you know you should be able to do, there is probably a way to do it and you can ask here.
    Also, there are some [very good video tutorials here|http://www.apple.com/findouthow/movies>
    I recommend you start with the iMovie 08 videos because they cover some of the basics, and Apple has not gotten around to doing some of these topics for iMovie 09. Especially watch the videos for handling audio and keywords. Then watch the iMovie 9 videos.
    The biggest thing is getting used to a different metaphor. iMovie 6 uses the timeline, scotch tape and scissors metaphor, while iMovie 09 uses a storyboard, copy and paste metaphor more like a word processing program. Both metaphors work. Both do the same thing. But it can be frustrating making the switch. Good luck.

  • What is a good way to check if sql select basd cursor return anything

    Hello everyone,
    I am trying to find a good way to identify that a SQL select based cursor return nothing.
    I know that or we use exception when no data found, or count(*) to check how many rows are returned.
    I have a cursor based on quite a long select statement.
    Like
    CREATE OR REPLACE PROCEDURE aaa (v_input IN NUMBER, v_output OUT VARCHAR2)
         CURSOR long_cursor IS
              --long select statement(with input variable) ;
    BEGIN
         Select count(*)
         Into v_count
      From
      -- a long select statment with input again ;
      IF v_count > 0 then
        For record in long_cursor loop
         --Get information from cursor
            --other processing for output
        End loop;
      END IF;
    END;Is there any other way than the above ?
    I would love to reduce the amount of typing. I know that repetition in code is not good.
    Thanks in advance,
    Ann
    Edited by: Ann586341 on Feb 28, 2013 2:29 PM

    >
    Not sure I understand your point. I am still a new bie here.
    >
    A flag is just a piece of data. By itself it doesn't prevent anyone from changing the data. And in a multiuser system anything you try to check is based on the COMMITTED data in the system. Two users can be changing two different rows at the same time but neither user will see the other change.
    So if you try to count how many rows meet a particular condition you may get a count of 8 but after the other user commits the count might be 7 or 9. So if you use 8 it may not be valid for very long.
    >
    But the app we use is Oracle Application Express 4.0.
    I assume when the data is read, there will be some kind of lock on these rows so other users cannot change it, right ?
    Or should I use SELECT for update even I do not update anything here.
    >
    I can't help you with that one. That would be a question for the application express forum.
    Oracle Application Express (APEX)
    You don't need to use FOR UPDATE if you don't plan to change the data. But, as explained above, you can't rely on any data you query being the same because another user could be changing it while you are looking at it.

  • What's a good way to search in Leopard when I'm used to Panther's CMD-F?

    I need advice on how to search for files now that I'm using Leopard (instead of Panther) - it's beginning to wear my nerves thin. It was so incredibly easy to search under Panther but under Leopard I find it takes a lot more effort and gives inferior results. I've only had Leopard a few months and I must be missing something obvious.
    In Panther I could type CMD-F and it would open up a separate window where I could put in my search criteria and it would search and present the results in a separate window, sorted in list view. It would let me by default, set up my search criteria, e.g. filename, and always search by file name in designated place(s).
    In Panther if I wanted to search for an item in the active Finder window I could type in the search box in the upper right corner and after I found what I wanted I could click the x and it would go back to being the normal Finder window.
    Not so in Leopard.
    Now in Leopard, if I hit CMD-F it takes whatever window I was working in and turns it into some kind of search dialog. No thanks! If I wanted to search in that Window I would have.
    The problem is that there is apparently no keyboard command to undo this unwanted behavior - I have to take my hands off the keyboard and use the trackpad to click the browser back arrow to get my window back, then I have to open a new window for this search dialog to operate in.
    Next up in unwanted behavior, this search dialog never remembers that 100% of the time I am searching on the file name, and that I never ever ever want to search the "contents". So each time I do the search, I have to again take my hands off the keyboard and click "File Name", and then once again, I have to switch from icons to list view every single time since looking at an Icon with an abbreviated "File Name..." (without all the metadata about the file that one should be able to see in list view) is not as helpful as looking at the list view.
    To make matters worse though, in list view, there's a totally useless column called "Last opened" and there doesn't seem to be any way to change these columns to something useful, such as last modified or created date.
    What do I need to do to make my searches simple and efficient?
    Thanks.

    Start with http://www.pinkmutant.com/articles/Leopard/leospot.html and http://www.thexlab.com/faqs/stopspotlightindex.html, then my mod to Finder's Find at http://www.macosxhints.com/article.php?story=20080229204517495 for what you can change so you can find stuff excluded by the default structure.

  • What's a good way to handle this conversion to a QUAN field?

    Good day everyone,
    I developed an RFC that receives data from XI.  I assign this data to a BAPI, and one of the fields is a field with a data type of QUAN(length 13, decimals 3).  All works fine if XI passes me a numeric value in this field.
    Here's the problem:  In running some test cases through XI and into the RFC, we ran a test case where the quantity field had a value of "test" (e.g. no numeric value).  Incredibly, XI transforms the text value of "test" into the value of 4534 and sends it to my RFC.  So my RFC thinks everything's fine when, in fact, that number was derived from a text field and is completely wrong.
    What we need to do is change the field to something that will "kick out" in XI when it tries to call my RFC.  I thought I could change it to a type of NUMC, but that doesn't let me use decimals.  We've already sent out the file layout to vendors, so we expect them to include numeric values with decimal places if need be.
    Is my best bet changing this to a character field with a length of 17, then checking to make sure it consists only of 0-9, a space, or a decimal?  I then need to assign it to the BAPI's field with the data type of QUAN(13,3) -- am I going to have issues trying to do this from a character field?  Do I need to worry whether or not they include a decimal (it might be implied -- in other words, they might just say quantity is "20" which becomes "20.000" to the BAPI).  Is there a nifty routine I can use to do all this easily?
    Thanks everyone.  Points awarded as always for ALL helpful answers.

    Ravi, that's kinda what I was thinking, but if it's true (i.e. a proper amount) can I just move the contents directly to my QUAN field?  Will SAP automatically do the conversion for me such that it ends up in the right place?  I've yet to have to worry about such conversions -- this is the first time I've had to deal with it -- and I want to make sure that the right value gets assigned, whether that value is "20", "54.1", "1000.25", or "986.500".

  • What is a good way to transfer files from an old hard drive to a new one.

    I am running low on space on my 80GB hard drive. I want to replace it with a 320GB hard drive. I was wondering what the best way is to transfer all of my files from the 30GB hard drive to my new 320GB hard drive. Not looking for any secure ways. I dont have many important things. Would appreciate help. Thanks.

    HI,
    Freeing space on your Mac OS X startup disk
    Carolyn

  • What's a good way to show attributes in a JTree made from DOM?

    I'm doing a pretty simple project that's basically just taking an XML document, making a DOM out of it, and then I want to represent the document in a JTree. The code I have now works swimmingly, except it doesn't do anything about attributes. Ideally (for the purposes of the tree), I'd like the attributes to show up as children of the node of which they are an attribute, and then each attribute node would itself have a child representing the value.
    basically I want to go from this:
    <xmlNode attribute=value>
       <child>
       </child>
    </xmlNode>To a JTree like this ('v' being the expansion arrow on the tree):
    v xmlNode
       v attribute
          v value
       v childI realize they're not of equivalent meaning, but for my purposes representing the true structure of the XML is not as important as meaningfully representing the information it contains.
    My question is basically, is there a more straightforward way to accomplish this than to manually add children nodes for all of the attributes? How would you approach this problem? I'm not looking for code or for someone to give me the "answer," I just wanted to get a second opinion.

    camickr and DrClap, thanks for your ideas! Both of those solutions seem pretty reasonable for what I'm doing, I'll experiment with them (I do indeed already have a custom Tree model, so adding this in wouldn't actually be too difficult... I don't know why that didn't occur to me!).
    Thanks for the replies!

  • What is the correct way to dynamically change the View?

    hi @,
    In my application I have a radiobuttonbyKey UI element and based upon the key I have to hide and/or show a particular UI combination placed in the group UI element basically dynamicallly modifying the view.
    I have 2 option one on radio button action I will change the visibilkity property of the group or in the wdModifyView method of the View.
    I want to know which is the best way in such situation as per MVC concepts to dynamically modify view in UI action or in wdModifyView method.
    Regards,
    Amit

    I would just bind the "visible"-property of the Group to a context attribute (DDIC type "Visibility") and set the value of that attribute from the onSelect-handler of the drop-down list. No need for code in wdDoModifyView().
    Armin

  • What's a good way to keep track of competed work within Organize

    I tag and I have albums but within photo browser I see only a row of stars and a date line under each photo. Wouldn't it be more efficient to see for instance finished and or crop size under each edited photo? That way you have a visual telling you to move on to another image.

    As far as I know, there is no such capability in PSE. You could create a tag named "Finished" if you want.
    Something similar to what your request can be done in Lightroom using Smart Collections.

  • Inherited a Mess - Exchange - What is a good way to start over?

    I inherited a mess of an Exchange 2013 Server (yes singular, not plural). Keeping the thing operational has been a nightmare.It is not virtual, it is physical. The hardware it resides on is way over taxed--it serves as a Domain Controller, as well as a dozen other things I'm too ashamed to admit. The mailboxes go to one massive database instead of being broken up into smaller ones. I'm at my whits ends and ready to say: "Screw it" and start over, which with our new network and server expansion I have an opportunity to do so.
    Could someone point me in the right direction on what would be the best way to rebuild? 
    And no, between the amount of system corruption and my user-base, Office 365 is not an option.

    Asnew technologies come online and existing ones grow more complex, the world ofinformation technology expands and grows. If you’re a specialist in the ITfield, you already know how critical it is to keep pace with new developmentsand advances. Learning more also makes you more competitive: By growing yourskills and knowledge base, you become more adept at what you do—and morevaluable to a current or future employer.Earninga certification or getting a degree are both excellent ways to expand your abilitiesand boost your earning potential. If you’re looking for quick results,certification may be the best first step. Clickhere to view a rundown of 4 common IT certifications that may help you getahead.

Maybe you are looking for

  • Whitespaces in XML during message mapping not preserved

    I use a twostep mapping process during Interface Mapping. The first one is the standard message mapping and the second one is a Java mapping. However, during the second step, the white spaces that should be preserved from the output of the first mapp

  • Oracle BI coreapplication down

    Hello, I have a weird problem with the Oracle BI installation and am wondering if anyone can shed some light on it. I have done two separate installations of Oracle BI on two separate machines. The installation procedure on both was the same: I have

  • Can the cheques automatically assigned to Down payment F-48

    Is it possible automatic cheque assignnment of next cheque from the cheque lot. I know we need to assign the cheque FCH5  in another transaction or we need to pay from F-58 or for manual cheque payment we can use f-53 and FCH5 . How to assign cheque

  • My feedback tab disappeared in version 10 & 11.

    There used to be a tab for entering feedback, but it has vanished in version 10 and 11.

  • Clarification regarding " " & ""  - Help

    The below code produces $ java t103 Hello World! HelloWorld! is there any logical or any difference in using the two ways of declaring c and cc, because in one of the program that I was writing i was figuring out the problem for a long time and this