How to Exclude Java Reserved Words Using StringTokenizer

Hi, i'm trying to exclude identifiers and java reserved words using StringTokenizer from an input file outputting the remaining words alphabetically ordered with the line, on witch they occur, in front of the word.
So far my code does all that, except exclude those words. I'm kind on a dead end... Any suggestions?
The code:
public class Interpreter{
    /* Uses a Binary Search Tree      */
    public static void main(String args[ ]) {
        String path = null;
        for (int j = 0; j < args.length; j++) {
            try {
                // Step 1, read the input file
                path   = args[j];
                FileReader input = new FileReader(args[j]);
                BufferedReader br = new BufferedReader(input);
                String line;
                int count = 1;
                String word;
                // Step 2, create an empty Tree
                BST tree = new BST();
                while((line = br.readLine())!=null){
                    StringTokenizer str = new StringTokenizer(line);
                    while (str.hasMoreTokens()){
                        word = str.nextToken();
                        tree.insert(word,count);
                    count++;
                // We're done, print out contents of Tree!
                tree.print();
                // Error Handling
                //check for IO problem with bad file
            } catch (IOException e) {
                System.out.println("There was a problem with the filename you entered.");
                //check for no filename entered at command prompt
            } catch (ArrayIndexOutOfBoundsException e) {
                System.out.println("Please include a filename when running this program.");
}Edited by: Redol on Dec 12, 2007 8:32 PM
Edited by: Redol on Dec 12, 2007 8:33 PM

use split instead of tokenizer.
public String[] splitString( String line, String delim )
    String[] tokens = null;
    if( line != null )
        tokens = line.split( delim );
    return tokens;
}

Similar Messages

  • Use Enum to Switch on Strings where one string is a java reserved word.

    Hi,
    I'm having problems switching on a string using enums, when one of the strings is a java reserved word. Any suggestions would be appreciated. Or maybe even a suggestion that I should just be stringing together if-else if and doing string compares rather than a switch.
    I've been using the following method to switch on strings.
    public enum MyEnum
    foo, bar, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    Then I can switch like
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    break;
    Now I have run into the problem where one of the strings I need to use is "int", which is a reserved word in java, so I have to modify.
    What is the best way to handle this?
    I could just not add it to the Enum and handle it at the switch like this...
    switch(MyEnum.stringValue( someString )
    case foo:
    break;
    case bar:
    break;
    default:
    if(someString.equals("int") {  ... }
    break;
    OR...
    I could change the Enum, and return intx, by checking if the string is "int". I could check before the valueOf, or during the exception, but I know it's not good practice to use Exceptions in the normal execution of your code... as it's not really an exception.
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    if(string.equals("int") { return intx; }
    try { return valueOf(string); }
    catch (Exception e) { return novalue; }
    OR...
    public enum MyEnum
    foo, bar, intx, novalue;
    public static MyEnum stringValue(String string)
    try { return valueOf(string); }
    catch (Exception e) {
    if(string.equals("int") { return intx; }
    else return novalue;
    }

    My advice is still to not name the enum the same as the value of the string you want to test for. That page I linked to shows how to have enums with parameters. Then you could have an enum whose name is (say) JavaInt and whose string value is "int".
    But frankly if I wanted to map Strings to actions I would just use a Map<String, Action> instead of trying to force my code into an antique construction like switch.

  • How to update java.sql.Clob using javax.persistence.EntityManager?

    Hello.
    Can anyone tell me (or show me some example) how to update java.sql.Clob using javax.persistence.EntityManager.
    When I’m trying to update column (with type Clob) value is not inserting, after update column is empty. I haven’t any error during update, I’m using database Oracle 10g.
    Edited by: ernest211 on Jul 16, 2009 1:24 AM

    Post some code so we can see how you are doing it. If you are using JPA entities take a look at the @Lob annotation.
    m

  • How to call java stored procedure using RMI?

    Is it possible to make a call to java stored procedure using RMI. ?
    How can I run the RMI registry on the Oracle Server ?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Thomas Grounds ([email protected]):
    Is it possible to make a call to java stored procedure using RMI. ?
    In principle it is possible. See the Java-Doc.s of Oracle 8.1.6.
    I have successful granted the java.net.SocketPermissions in my USER_JAVA_POLICY view (see Doc.) Now I was able to use the RMI-Sockets, but following
    failure try to connect to RMI-Object via RMIregistry an Oracle Error occurs
    ORA-03113: end-of-file on communication channel
    and after that my Oracle Connection is closed.
    How can I run the RMI registry on the Oracle Server ?<HR></BLOCKQUOTE>
    I think you do not need the RMI registry on Oracle Server. It should be possible to start the RMI registry wherever you want in your network and access it via the right registry string.
    Ciao
    Margit
    null

  • How to create Java client to use WCC web services

    I'm trying to create a Java client to use web services available with Web Center Content.
    I generated stubs using "cxf-codegen-plugin" and I wrote following code (very trivial):
    DocInfo docInfo = null;
    *try {*
    docInfo = new DocInfo(new URL("http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1"));
    *} catch (MalformedURLException e) {*
    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
    DocInfoSoap docInfoSoap = docInfo.getDocInfoSoap();
    DocInfoByIDResult docInfoByIDResult =  docInfoSoap.docInfoByID(new Integer(2), null);
    At the moment I'm obtaining following error:
    Exception in thread "main" javax.xml.ws.WebServiceException: Failed to access the WSDL at: http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1. It failed with:
    *     Invalid WSDL http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1, expected {http://schemas.xmlsoap.org/wsdl/}definitions found html at (lineLine number = 3*
    Column number = 30
    System Id = http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1
    Public Id = null
    Location Uri= http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1
    CharacterOffset = 133
    *     at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.tryWithMex(RuntimeWSDLParser.java:151)*
    *     at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:127)*
    *     at com.sun.xml.internal.ws.client.WSServiceDelegate.parseWSDL(WSServiceDelegate.java:254)*
    *     at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:217)*
    *     at com.sun.xml.internal.ws.client.WSServiceDelegate.<init>(WSServiceDelegate.java:165)*
    *     at com.sun.xml.internal.ws.spi.ProviderImpl.createServiceDelegate(ProviderImpl.java:93)*
    *     at javax.xml.ws.Service.<init>(Service.java:56)*
    *     at com.stellent.docinfo.DocInfo.<init>(DocInfo.java:39)*
    *     at eu.europa.efsa.virtual.library.services.client.TestDocInfo.main(TestDocInfo.java:23)*
    *Caused by: javax.xml.stream.XMLStreamException: Invalid WSDL http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1, expected {http://schemas.xmlsoap.org/wsdl/}definitions found html at (lineLine number = 3*
    Column number = 30
    System Id = http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1
    Public Id = null
    Location Uri= http://vmxp43:16200/cs/idcplg?IdcService=GET_SOAP_WSDL_FILE&wsdlName=DocInfo&idcToken=1344065729220:B443F7C3DED844B594F32E0B3914E576&IsSoap=1
    CharacterOffset = 133
    *     at com.sun.xml.internal.ws.wsdl.parser.RuntimeWSDLParser.parse(RuntimeWSDLParser.java:120)*
    *     ... 7 more*
    Please, any comment will be appreciated.

    Now I'm trying following code.
    DocInfo docInfo = new DocInfo();
    DocInfoSoap docInfoSoap = docInfo.getDocInfoSoap();
    DocInfoByIDResult docInfoByIDResult =  docInfoSoap.docInfoByID(new Integer(2), null);
    The error I obtain is:
    Exception in thread "main" com.sun.xml.internal.ws.client.ClientTransportException: The server sent HTTP status code 401: Unauthorized
         at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.checkStatusCode(HttpTransportPipe.java:196)
         at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.process(HttpTransportPipe.java:168)
         at com.sun.xml.internal.ws.transport.http.client.HttpTransportPipe.processRequest(HttpTransportPipe.java:83)
         at com.sun.xml.internal.ws.transport.DeferredTransportPipe.processRequest(DeferredTransportPipe.java:105)
         at com.sun.xml.internal.ws.api.pipe.Fiber.__doRun(Fiber.java:587)
         at com.sun.xml.internal.ws.api.pipe.Fiber._doRun(Fiber.java:546)
         at com.sun.xml.internal.ws.api.pipe.Fiber.doRun(Fiber.java:531)
         at com.sun.xml.internal.ws.api.pipe.Fiber.runSync(Fiber.java:428)
         at com.sun.xml.internal.ws.client.Stub.process(Stub.java:211)
         at com.sun.xml.internal.ws.client.sei.SEIStub.doProcess(SEIStub.java:124)
         at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:98)
         at com.sun.xml.internal.ws.client.sei.SyncMethodHandler.invoke(SyncMethodHandler.java:78)
         at com.sun.xml.internal.ws.client.sei.SEIStub.invoke(SEIStub.java:107)
         at $Proxy28.docInfoByID(Unknown Source)
         at eu.europa.efsa.virtual.library.services.client.TestDocInfo.main(TestDocInfo.java:20)
    Is there a way to pass right username and password?
    How can I understand which the user actually used?

  • How to run java file by using another applet file  ??

    how to compile and run java file by using another applet or japplet file .

    how to understand what you are talking about.

  • How to run java servlet without using Web.xml?

    How to run servlet without using Web.xml? From a book, I know that web.xml descriptor is optional, but the book doesn't tell us how to run java servelet without web.xm descriptor. So how to do that? Thanks a lot.

    How to run servlet without using Web.xml?But Tomcat now uses a web.xml for its global server-wide configuration.
    If you'd like to invoke a servlet with:
    http://host/servlet/ServletName
    you have to enable the invoker servlet.
    [from an HTML]
      <FORM METHOD="POST" ACTION="/servlet/HGrepSearchSJ">
    [from resin.conf of Resin Web Server 2.1.12]
      <!--
         - The "invoker" servlet invokes servlet classes from the URL.
         - /examples/basic/servlet/HelloServlet will start the HelloServlet
         - class.  In general, the invoker should only be used
         - for development, not on a deployment server, because it might
         - leave open security holes.
        -->
      <servlet-mapping url-pattern='/servlet/*' servlet-name='invoker'/>
    [from TOMCAT5.0.19/conf/web.xml, a global server-wide web.xml file]
      <!-- The "invoker" servlet, which executes anonymous servlet classes      -->
      <!-- that have not been defined in a web.xml file.  Traditionally, this   -->
      <!-- servlet is mapped to URL pattern "/servlet/*", but you can map it    -->
      <!-- to other patterns as well.  The extra path info portion of such a    -->
      <!-- request must be the fully qualified class name of a Java class that  -->
      <!-- implements Servlet (or extends HttpServlet), or the servlet name     -->
      <!-- of an existing servlet definition.     This servlet supports the     -->
      <!-- following initialization parameters (default values are in square    -->
      <!-- brackets):                                                           -->
      <!--                                                                      -->
      <!--   debug               Debugging detail level for messages logged     -->
      <!--                       by this servlet.  [0]                          -->
        <servlet>
            <servlet-name>invoker</servlet-name>
            <servlet-class>
              org.apache.catalina.servlets.InvokerServlet
            </servlet-class>
            <init-param>
                <param-name>debug</param-name>
                <param-value>0</param-value>
            </init-param>
            <load-on-startup>2</load-on-startup>
        </servlet>
    ---comment out below----------------------------------------------------------
        <!-- The mapping for the invoker servlet -->
    <!--
        <servlet-mapping>
            <servlet-name>invoker</servlet-name>
            <url-pattern>/servlet/*</url-pattern>
        </servlet-mapping>
    -->

  • How do you select multiple words using a Magic Trackpad?

    I know how to select multiple words with my mouse, but cannot figure out how to do it using my new Magic Trackpad. Here's the deal:
    Let's say you want to select "cannot figure out how to" in the sentence above. With my mouse, I'd place the cursor somewhere over the word "cannot," double-left-click and keep holding the button down. Then, dragging to the right, it would select each word in its entirety as I moved along the sentence. I do this all the time since it is a very quick way to select text.
    Okay, so how do you do this with the Magic Trackpad?
    I try a similar behavior, but it doesn't work. If I double-tap on "cannot," for example, one of two things happens. Either only the word "cannot" is highlighted and dragging does nothing to highlight more text. Or, if I'm quicker with the drag (aka swipe) right, it will select one character at a time starting from the cursor position when I double-tapped and not entire words, as I want.
    I'm stumped. Anyone?

    Jeffrey,
    The only good way seems to be by using the physical click on the Trackpad. Double physical click then drag. Much the way it's done on the mouse.
    Regards
    Captfred

  • How to debug java stored procedures using jdwp with Eclipse IDE?

    I need to debug the java stored procedures loaded in Oracle 9.2.0.6. The java files are loaded into the database using dbms_java.loadjava('-force -debug -verbose -resolve lib/java_stored_procs.jar'); The jar contains .java files and the database resolves and compiles them into .class files. Works fine but I need to debug the code. I am tried of the println method since takes too much and too many iterations.
    My IDE is Eclipse 3.1. I want to use the jdwp for debugging in my IDE. Any one who knows the exact steps?
    Thanks a lot.

    I need to debug the java stored procedures loaded in Oracle 9.2.0.6. The java files are loaded into the database using dbms_java.loadjava('-force -debug -verbose -resolve lib/java_stored_procs.jar'); The jar contains .java files and the database resolves and compiles them into .class files. Works fine but I need to debug the code. I am tried of the println method since takes too much and too many iterations.
    My IDE is Eclipse 3.1. I want to use the jdwp for debugging in my IDE. Any one who knows the exact steps?
    Thanks a lot.

  • How to Exclude table like %AUDIT% using the Datapump API

    Hello,
    I am trying to use the datapump API to import table across a database link excluding table with a name like %AUDIT%. I have it all working except the table execution. I am using Oracle 11.1.0.6.

    this works in my app
    in DB R11.2
    in job_mode = 'TABLE'
              dbms_datapump.metadata_filter (
              handle          =>     job_handle,
              name          =>     'NAME_EXPR',
              value          =>     'NOT IN (''TABLENAME_1'', ''TABLENAME_2'' , ''TABLE_NAME_3'' )'
    try this works for you
              dbms_datapump.metadata_filter (
              handle          =>     job_handle,
              name          =>     'NAME_EXPR',
              value      => 'NOT LIKE ''%AUDIT%'''
    Edited by: astramare on Jul 7, 2011 2:57 PM

  • How to write to MS Word using LabWindows/CVI

    HI all
    is there any toolkit available to write to MS Word in LabWindows/CVI. like the report generation toolkit in Labview is there any option in CVI.
    regards
    Regards
    Solved!
    Go to Solution.

    Hi,
    there is an instrument driver (toolslib\activex\word\wordreport.fp) and several examples are shipped with CVI, i.e. word2000demo.cws

  • How do I save as Word, using Pages '09, Lion

    The "help" section says: go to Save, or Save as, but there is no Save or Save As under File, in Lion, Pages '09.

    Richard,
    For future reference, since Fruhulda's response solved your problem, you should mark her post as the one that was the solution, not your own post. At least give her a "helpful".
    Thanks,
    Jerry

  • How to generate Java source using clientgen WL8.1?

    Hi, does anybody know how to generate Java source code using clientgen task on WL 8.1 Sp4 or SP5? I know WL 9.0 clientgen can do this, but we are still on SP5. Basically I want to look at the source code (I was wondering why it didn't work if I initialize a service impl by passing the WSDL URL string different than the URL specified in the original WSDL file that the clientgen is run against.)
    Does anybody also know how get web service client developed on Axis work on WebLogic without conficting the web service developed on WebLgoic that is running in the same box?
    Thanks for your help!

    hi ,
    As mentioned in the Question, I am unable to find the "Java Proxy Generattion" link in the Int builder.
    Also the help doc says:
    Java proxy generation is no longer supported in subsequent releases. For new developments or when making significant changes to a service interface, use Java proxy generation in SAP NetWeaver Studio instead. More information: Creating Outside-In Web Services, SAP NetWeaver Developer Studio.
    Does that mean that I can no longer generate java proxy from Int builder?
    regards,
    Piyush

  • What to do when a table name is a reserved word?

    I know the best answer is not to use a reserved word to name a table. But I have no control over that in this situation. I have read that using all Caps and quotations will allow you to use the table name in queries, i.e. "CATEGORY" is suppose to free the table to be used. But that is certainly not working, nor any variation of that formatting.
    Does anyone know how to format a reserved word to allow queries?
    Thank You

    Use double quotes:
    SQL> create table ALTER (a number);
    create table ALTER (a number)
    ERROR at line 1:
    ORA-00903: invalid table name
    SQL> create table "ALTER" (a number);
    Table created.
    SQL> desc alter
    ERROR:
    ORA-00931: missing identifier
    SQL> desc "ALTER"
    Name                                      Null?    Type
    A                                                  NUMBER
    SQL> insert into "ALTER"
      2  select level from dual connect by level<=10;
    10 rows created.
    SQL> select * from "ALTER";
             A
             1
             2
             3
             4
             5
             6
             7
             8
             9
            10
    10 rows selected.BTW CATEGORY is not a reserved word:
    SQL> create table category (a number);
    Table created.Max
    http://oracleitalia.wordpress.com
    Edited by: Massimo Ruocchio on Feb 25, 2010 12:32 AM

  • How to create a tree structure using list items(tlist)

    HI every one,
    As we know how to create a tree structure using Hierarchy item type.
    We have a requirement to create The same tree like structure using List Item(Tlist)
    I would be so appreciated If you send with an example
    Thanks
    RangaReddy

    Hi all
    Any one help me please
    Actually our client requirement is creation of tree structure using list item,similar to what we used in oracle Application(FNDSCSGN) form.We did the tree structure using hierarchy tree using Htree and Ftree.It working excelently.For client requirement, we want to use list item.How PJC(Pluggable Java Components) is useful for using list item(Tlist).I can't understand how it is useful.
    Do you have any example please help me.
    Thanks
    RangaReddy

Maybe you are looking for

  • New AP Express working but "ignored"

    hi, Here's the basic problem - I've replaced an old Express with a new latest spec one on my existing network. The new one shows up in Airport Utility ok, and the green light on the top of the Express is on. But when the two computers that are suppos

  • Brand new iPod Touch 4G won't reconnect to WPA Enterpise wifi network

    I have a brand new iPod Touch 4G.  Wifi connection at home, where I have a WPA2 "personal" network, works great.  However, at the office, I have a WPA/WPA2 Enterprise network.  The network is not hidden, but the only way I can connect to it is via th

  • Female to female mini-displayport cable or adapter anyone?

    All that fuss about mini displayport to mini dvi adapter and even to micro dvi for the MBAs - let's face it, its not gonna happen people. Jobs has made it pretty clear about that, so lets stop hoping. Instead lets look forward, and now since mini dis

  • H97 Gaming 3 - Audio Problem

    Hello, I have a problem with the audio of my new MSI h97 gaming 3 The audio works, but is distorted. I have already installed the latest realtek audio driver (6.0.1.7293) I have already tried to change headset. Hardware Mobo: MSI H97 Gaming 3 CPU: In

  • HT201210 I was downloading IOS to my ipad 2 and now my ipad is stuck and cannot be used. HELP?

    I was downloading IOS 6.1 to my ipad and now my ipad is stuck and cannot be used. HELP. It shows on the screen that it is plugged into itunes. How do I get my ipad working again? How can I download IOS 6.1 succesfully? Thanks