Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 566405
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:58:26+00:00 2026-05-13T12:58:26+00:00

My Java is extremely rusty and I’m stuck trying to make a user interface

  • 0

My Java is extremely rusty and I’m stuck trying to make a user interface that simplifies the execution of shell scripts or batch files depending on whether it’s Linus or Win32 respectively. The files have the following naming convention.

  module-verb-object-etc [args-list]
  mysql-connect-grid
  mysql-connect-rds
  mysql-dump-grid
  mysql-dump-grid-se314

ultimately I would like it to parse unambiguous terms so I can:

  1. tokenize the commands (e.g delimited by “-“) & shorten them into simplified terms soemthing like foxpro’s command window or cisco’s IOS (eg “my co gr” executes “mysql-connect-grid” in unix and *.cmd in win32)
  2. and also in the style of IOS allow the user to enter abbreviated commands so that they can type in a question mark (?) and it will give them a hint as to the unique remaining (or next) command options (e.g. “my?” returns mysql & “my ?” returns connect, or dump). Othr return values would be “ambiguous” or “unknown” for commands that are not unique or could not be matched. It may seem trivial but there are many hundreds of commands in each folder and my users don’t want to think…

I wrote a function to pull the list of files from a directory & retun an array of fileanmes. Then I convert that into a 2 dimensional array using the method below which returns a dynamicly sized grid of potential commands.

    /**********************************************************************************
     *  MAKE GRID: Parses array of filenames and tokenizes AWS cmds.
     * @param strs  Array of filenames
     **********************************************************************************/
     public static String [][] makeGrid(String strs[], boolean bPrint) {
       String tmpGrid[][];
       int nMaxCols = 0;
       int nRows = uniqueCount(strs);
       int nGridRow = 0; 
       tmpGrid = new String [nRows][]; 
       for (int nRow=0; nRow<nRows; nRow++) { 
 String cFilename = strs[nRow];
                if (!cFilename.endsWith(".cmd") // just list unix files (filter for batch files)
    && cFilename.indexOf("-") > 0 ) // make sure there's a dash in the filename
    {
           String strTokens[] = tokenize(strs[nRow], "-"); // the dash is our token deliminator
           int nCols = strTokens.length; 
           if (nCols>nMaxCols) nMaxCols=nCols;
           tmpGrid[nGridRow] = new String [nCols];
           for (int nCol=0; nCol<nCols; nCol++) { 
               tmpGrid[nGridRow][nCol] = strTokens[nCol];
               if (bPrint) System.out.print(" "+tmpGrid[nGridRow][nCol]);
             }
            nGridRow++;
            if (bPrint) System.out.println("");
     } //end-if
         }
       String[][] cmdGrid = new String[nGridRow][nMaxCols];
       System.arraycopy(tmpGrid, 0, cmdGrid, 0, nGridRow); // removes null rows  (&NPEs!)
       return cmdGrid;
      }

This returns a 2-d array (below), so grid[Row-N][Col-0] is a match. I’d like to pull only distinct values where row[0] is a wildcard match for cmdToken[0] && row[1] is “like” cmdToken[1] so that my users can piece together a command until "my du gr ?" returns "ENTER, [se314]" – if that makes sense…

String[][] makeGrid:
    mysql dump grid se314
    mysql connect grid
    mysql dump grid
    mysql connect rds

My Challenge: I cant seem to get my head around my matcher function in java. If it was SQL it would be something like:

"SELECT DISTINCT col2 FROM cmd_Grid
   WHERE col1 LIKE 'cmdToken1%' " 

or even better: recursively setting a int depthmark for each consecutive column

`SELECT DISTINCT col+str(depthmark+1) FROM cmd_Grid 
    WHERE col+str(depthmark) LIKE 'cmdMatchedTokens%' " 

until you have an exact match.

I found a package called joSQL that I tried out of desperation but I cant seem to get it to work in Java6. Anyway: I was also hoping for a pure java solution so that everything could be contained in a single class…

Maybe using scanner or something to parse my multidimentional array for unique values… I know I’m probably making it way more complex than it needs to be.

a gentle nudge in the right direction would be appreciated.

TIA

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T12:58:26+00:00Added an answer on May 13, 2026 at 12:58 pm

    One exhaustive solution could be to contruct a hashMap so that the key is a possible short command like ‘my co gr” and the corresponding value is “mysql-connect-grid”.
    So there would be values in the hash map that will have “mysql-connect-grid” as the value.

    But this is a feasible solution only if there is a finite number of possible keys.
    If that’s not the case, then you can use the built in string parsing methods.

    For example:

        String[][] makeGrid = new String[][]{{"mysql", "dump", "grid", "se314"}, 
                  {"mysql", "connect", "grid", ""},
                  {"mysql",  "dump", "grid", ""},
                  {"mysql", "connect", "rds", ""}
                  };
         String[] query2 = new String[]{"my", "du", "gr"};
    
      String[][] matchingCommands = new String[4][4];
      int resultSize = 0;
         for(int i=0; i<makeGrid.length; i++)
      {
          String[] commandColumn = makeGrid[i];
       boolean matches = false;
          for(int cnt=0; cnt<commandColumn.length; cnt++)
          {
           String commandPart = commandColumn[cnt];
           if(cnt < query2.length){
            String queryPart = query2[cnt];
         if(commandPart.startsWith(queryPart) || queryPart.equals("?")){
             matches = true;
            }else{
             matches = false;
             break;
            }
           }
          }
          if(matches){
           matchingCommands[resultSize] = commandColumn;
           resultSize++;
          }
      }
    

    This code snippet should give you some idea of how to go about it. There is one thing to note here though. The matchingCommands array has been initialized to the 4 rows and 4 columns which is wasteful because the matches will be lesser than that. Let me know if you need help making this more efficient. Otherwise, this is a working piece of code which I think does what you want.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 376k
  • Answers 376k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're mixing two distinct issues here: Header files, handled by… May 14, 2026 at 8:25 pm
  • Editorial Team
    Editorial Team added an answer Here is a workaround for too long ReturnUrl querystring parameter.… May 14, 2026 at 8:25 pm
  • Editorial Team
    Editorial Team added an answer According to Windows Explorer Command-Line Options you just need to… May 14, 2026 at 8:25 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.