Comparator for different classes

I have a crazy need to be able to hold a few hundred thousand objects in a Set. These objects can vary from Integers, Doubles to Strings. Normally it seems a HashSet would be the perfect implementation for this, however, this Set is built once and searched through several million times. So it makes sense to have a SortedSet available for this to improve search times. Having different sets for each Class type is not an option.
I've come up with this code, which works fairly well as far as I can tell, but would like your general opinions on how it can be improved. I can't find a failing point, yet, and would like the eyes of many to tell me that I'm wrong - and that it can fail somehow.
public class DifferentObjectComparator implements Comparator, Serializable
     public int compare(Object o1, Object o2)
          if (o1 == null && o2 == null) return 0;
          if (o1 == null && o2 != null) return 1;
          if (o1 != null && o2 == null) return -1;
          if (o1.getClass() == o2.getClass())
               return ((Comparable) o1).compareTo(o2);
          if (o1 instanceof Number && o2 instanceof Number)
               double retVal = ((Number) o1).doubleValue() - ((Number) o2).doubleValue();
               if (retVal < 0) return -1;
               if (retVal > 0) return 1;
               return 0;
          return -1;
}If you know of and/or can think of a better way to do this, please tell. Keep in mind it must use a SortedSet implementation.

cvweiss__ wrote:
After a couple of tweaks and some extensive testing I am now satisfied that the following code fully complies with the specifications given in the javadoc for java.util.Comparator. I'm posting this here for those in the future who have this requirement.
public class DifferentObjectComparator implements Comparator, Serializable
     public int compare(Object o1, Object o2)
          if (o1 == o2) return 0; // good for two nulls or exact same Object
          if (o1 == null && o2 != null) return 1;
          if (o1 != null && o2 == null) return -1;
          if (o1.getClass() == o2.getClass())
               return ((Comparable) o1).compareTo(o2);
          if (o1 instanceof Number && o2 instanceof Number)
               double retVal = ((Number) o1).doubleValue() - ((Number) o2).doubleValue();
               if (retVal < 0) return -1;
               if (retVal > 0) return 1;
               return 0;
          return o1.getClass().getName().compareTo(o2.getClass().getName());
if they ALL implements Comparable, wouldn't the Set be
Set<? extends Comparable> theSet;? In which case, the Comparator could be more elegantly written using similar generics, like
public class MyComparator implements Comparator<Comparable> {
  public int compare(Comparable c1, Comparable c2) {
              if (c1 == c2) return 0;
          if (c1 == null && c2 != null) return 1;
          if (c1 != null && c2 == null) return -1;
          if (c1.getClass() == c2.getClass())
               return c1.compareTo(c2);
          if (c1 instanceof Number && c2 instanceof Number)
               double retVal = ((Number) c1).doubleValue() - ((Number) c2).doubleValue();
               if (retVal < 0) return -1;
               if (retVal > 0) return 1;
               return 0;
          return c1.getClass().getName().compareTo(c2.getClass().getName());   // looks weird to me
}no more ugly castings! (well, except for casting to Number, but that's inherent to the weird spec to begin with)

Similar Messages

  • Different classes problems

    I posted a topic asking for feedback on a Vigenere Cipher program I made. It was said that I shouldn't have the entire program in one class, and should have different class... or methods?
    I've been reading the tutorial for different classes, but I just can't seem to pick it up. I anticipate I'm gonna get a few replies with people saying 'you should read this smelly student' but I've tried, so I figure this may be a way to break me in :).
    So, here's my code:
    public class VigenereCipherComplete
         public static void main(String[] args)
         String key, message;
         String encrMessage = "";
         String[] options = new String[] {"Encrypter", "Decrypter", "Cancel"};
         int progChoice, keyLength, length, encrCharValue;
         int index;
         int keyIndex = 0;
         char keyChar;
         char messageChar;
         char encrChar;
         boolean shouldEncrypt = true;
         // Choice of whether to use the encrypter of decrypter
            progChoice = JOptionPane.showOptionDialog(null, "Which would you like to run?", "Program choice",
                 JOptionPane.DEFAULT_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
            if(progChoice == 0)
                 shouldEncrypt = true;
            else if(progChoice == 1)
                shouldEncrypt = false;
        else
           System.exit(0);
         // Input of key and converting it to upper case
         key = JOptionPane.showInputDialog(null, "Please input the key you wish to use:",
              "Key input", JOptionPane.QUESTION_MESSAGE);
         key = key.toUpperCase();
         // Input of message and converting it to upper case
         message = JOptionPane.showInputDialog(null, "Please input the plaintext you wish to use:",
              "Plaintext input", JOptionPane.QUESTION_MESSAGE);
         message = message.toUpperCase();     
         keyLength = key.length();
         length = message.length();
         // Encryption/decryption
         for(index = 0; index < length; index++)
              keyChar = key.charAt(keyIndex);
              messageChar = message.charAt(index);
              if(messageChar >= 'A' && messageChar <= 'Z')
                   // Encryption
                   if(shouldEncrypt)     
                        encrCharValue = (keyChar - 'A') + messageChar;
                   // Decryption
                   else
                        if(messageChar >= keyChar)
                             encrCharValue = (messageChar + 'A') - keyChar;
                        else
                             encrCharValue = ((('Z' - keyChar) + messageChar) + 1);
                   // Loops ascii char value larger than 90 so it stays within the 65-90 ascii char range
                   if(encrCharValue > 'Z')
                        encrCharValue = (encrCharValue - 'Z') + 'A' - 1;
                   // Converts the char value to a char and adds it to the converted string
                   encrChar = (char)encrCharValue;
                   encrMessage = encrMessage + encrChar;
                   keyIndex++;     
              // If the char is not a letter, it leaves it as it is and adds it to the converted string     
              else
                   encrCharValue = messageChar;
                   encrChar = (char)encrCharValue;
                   encrMessage = encrMessage + encrChar;
              // Resets key so it will loop for the full string wanting to be converted
              if (keyIndex >= keyLength)
                   keyIndex = 0;
         // Output for encryption
         if(shouldEncrypt)
              System.out.println("Plaintext:\t" + message + "\nKey:\t\t" + key + "\nCiphertext:\t" + encrMessage);
         // Outfor for decryption
         else
              System.out.println("Ciphertext:\t" + message + "\nKey:\t\t" + key + "\nPlaintext:\t" + encrMessage);
    }I just can't grasp how I'd do this... Sorry for the ambigious question.

    I'm not going to read all your code. However, it's reasonable to put the code for one encryption algorithm into one class. If you were writing an entire encryption library, you might find that several of your algorithms (each in their own class) are all using the same code, and you're copying it from one class to another. In this case, you might extract that common code out to a utility class that various algorithms make use of.
    Now, if we assume that your question is, "How can I break this code into smaller pieces?" here are a few suggestions, based on a cursory skimming of your code. Note that these are only guidelines, to give you an idea of the kinds of things that make sense to break out as pieces.
    1. Keep the GUI separate from the encryption. You should have a VigenereEncryption or somesuch class that actually does the work of encrypting and decrypting, and this class should not know or care if there even is a GUI.
    2. In the VE class, I would imagine you'd want an encrypt() method and a decrypt() method.
    3. Anywhere you see multiple levels of nesting, one or more of those levels might be a candidate to pull out into its own method.
    4. Anywhere you have repeated code that's more than a couple lines, put it in its own method.
    5. Anywhere you have a comment like // perform such and such step above a block of code, that block is a good candidate to get pulled out into its own method, named similar to whatever that step is in your comments.
    6. Similarly, when you learn what the high-level algorithm is that you're to be implementing, the steps of that algorithm are candidates to be their own methods.
    Again, note that this is not carved in stone and is not meant to be taken literally as "do exactly all of these things." Rather, it is to give you ideas about the kinds of things that make for separation of classes and methods.

  • How to use the different class for each screen as well as function.

    Hi Experts,
    How to use the different class for each screen as well as function.
    With BestRegards,
    M.Thippa Reddy.

    Hi ThippaReddy,
    see this sample code
    Public Class ClsMenInBlack
    #Region "Declarations"
        'Class objects
        'UI and Di objects
        Dim objForm As SAPbouiCOM.Form
        'Variables
        Dim strQuery As String
    #End Region
    #Region "Methods"
        Private Function GeRate() As Double
                Return Double
        End Function
    #End Region
    Public Sub SBO_Appln_MenuEvent(ByRef pVal As SAPbouiCOM.MenuEvent, ByRef BubbleEvent As Boolean)
            If pVal.BeforeAction = True Then
                If pVal.MenuUID = "ENV_Menu_MIB" Then
                End If
            Else ' Before Action False
                End If
        End Sub
    #End Region
    End Class
    End Class
    Rgds
    Micheal
    Vasu Anna Regional Feeling a???? Just Kidding
    Edited by: micheal willis on Jul 27, 2009 5:49 PM
    Edited by: micheal willis on Jul 27, 2009 5:50 PM

  • How to assign a class for different colored links

    Hi. I'm new to CSS and HTML and Dreamweaver. I'm trying to
    get links to be different colors within the same page. I have a
    navbar with a CSS style that I've assigned colors to all my links
    there. They work. But if I attempt to change the links in the main
    content it screws up the navbar links.
    So, now, I'm trying to assign the different colors to the
    links in the main content. I have the link color down but I can't
    seem to get the visited, hover, active to work.
    So, I read somewhere you have to assign a class to be able to
    have different colors for your links on the same page. There is a
    class assigned to the links I want to change but it only assigns
    the link color, not the visit,hover,active colors. I don't know
    where I am supposed to put the code so that only the main content
    links are changed. Here is what I came up with from reading and
    studying. Can somebody tell me what's wrong with it and where I am
    supposed to put what in each page? This is just a CSS style page I
    made and I have no idea if I even did that right. Then, I can't
    figure out how to tell each page to include it for that class only.
    Thanks.
    @charset "utf-8";
    /* CSS Document */
    <class="style49"
    <style type="text/css">
    a:link {color: #3333FF}
    a:visited {color: #009900}
    a:hover {color: #6600CC}
    a:active {color: #FF0000}
    </style> </class>

    Pseudo-classes and container styles are what you need - here
    are some
    tutorials.
    http://www.thepattysite.com/linkstyles1.cfm
    http://www.projectseven.com/tutorials/pseudoclasses/index.htm
    Murray --- ICQ 71997575
    Adobe Community Expert
    (If you *MUST* email me, don't LAUGH when you do so!)
    ==================
    http://www.projectseven.com/go
    - DW FAQs, Tutorials & Resources
    http://www.dwfaq.com - DW FAQs,
    Tutorials & Resources
    ==================
    "Newbie744" <[email protected]> wrote in
    message
    news:fn3***$m6q$[email protected]..
    > Hi. I'm new to CSS and HTML and Dreamweaver. I'm trying
    to get links to
    > be
    > different colors within the same page. I have a navbar
    with a CSS style
    > that
    > I've assigned colors to all my links there. They work.
    But if I attempt
    > to
    > change the links in the main content it screws up the
    navbar links.
    >
    > So, now, I'm trying to assign the different colors to
    the links in the
    > main
    > content. I have the link color down but I can't seem to
    get the visited,
    > hover,
    > active to work.
    >
    > So, I read somewhere you have to assign a class to be
    able to have
    > different
    > colors for your links on the same page. There is a class
    assigned to the
    > links
    > I want to change but it only assigns the link color, not
    the
    > visit,hover,active
    > colors. I don't know where I am supposed to put the code
    so that only
    > the
    > main content links are changed. Here is what I came up
    with from reading
    > and
    > studying. Can somebody tell me what's wrong with it and
    where I am
    > supposed to
    > put what in each page? This is just a CSS style page I
    made and I have no
    > idea
    > if I even did that right. Then, I can't figure out how
    to tell each page
    > to
    > include it for that class only.
    >
    > Thanks.
    >
    > @charset "utf-8";
    > /* CSS Document */
    > <class="style49"
    > <style type="text/css">
    > a:link {color: #3333FF}
    > a:visited {color: #009900}
    > a:hover {color: #6600CC}
    > a:active {color: #FF0000}
    > </style> </class>
    >
    >
    >

  • TestStand create different object for singleton class

    Hi all,
    we have a singleton class which has some functions used to do testing a harware.
    Our main Exe will create an object for that singleton class(which opens Com1 port and communicate with hardware). so the Exe will do basic communication test with hardware it is working well. We are using Teststand operator interface to do various testing by using sequence files. Main exe will use teststand usercontrols to execute tests when the user clicks Testbutton. after that, teststand try to create an object for that singleton but it returns new object not the existing one which is created by EXE. So it throwing me exeception "Com1 port access denied." (since we created object for signleton class @ very first in EXE)
    My question is Since that teststand runs in a separate Appdoamin will the singltonclass create separate object for different appdomain? if so is there any solution to reslove this?
    Hope i clearly explained my probs.
    Thanks in advance
    Srini 

    Hi Srini,
    How are you calling the executable?  From a Call Executable step?  Or are you using another means of calling it?   Also, why is TestStand trying to recreate the object?  As long as you have the correct handle to the object I don't think it matters what app domain you are in.
    Regards,
    jigg
    CTA, CLA
    teststandhelp.com
    ~Will work for kudos and/or BBQ~

  • Two questions:  how do Skype and iChat compare for group video?  quality, reliability, cost, etc are important.  2) Is my MobileMe ID what I need to use in the window in making an iChat buddy?  It only says AIM above the window, online tutorial differs.

    Two questions:  1) How do Skype and iChat compare for group video?  Quality, reliability, cost, etc are important.  2) Is my MobileMe ID what I need to input in the window in making an iChat buddy?  It only says AIM above the window, online tutorial differs, saying MobileMe, AIM, GoogleTalk (Jabber) all work. Thnx

    Hi,
    IChat uses better Video Compression than Skype does.
    On a top flight Mac you can send a 640 X 480 pixel frame up to 30 frames a sec.
    Skype can't match this.
    iChat in Video is Peer to Peer. (you can actually Log out of the Buddy list)
    Skype seems to borrow something from everyone's bandwidth to make connections.
    What do you mean by Business account Tracking ?
    iChat Adds (or can add) the First Name, Last Name of your Buddies and create an Address Book Entry
    Whether you mark those cards connected with a  company is up to you.
    (I have heard of issues with earlier version of iChat and the Address Book that "saw" the Company Name as the part of the Name and linking several Screen Names to the one name
    Audio on a Mac using Skype tend to be the same as the streaming needs are less.
    However you have to rely on any PCs audio abilities from PCs which may not be to the same standard.
    Mac to PCs in iChat and AIM can be difficult though.  (It should work but it rarely as simple as Plug and go)
    Skype may suit your needs better on ocassions.
    9:11 PM      Thursday; May 5, 2011
    Please, if posting Logs, do not post any Log info after the line "Binary Images for iChat"
     G4/1GhzDual MDD (Leopard 10.5.8)
     MacBookPro 2Gb( 10.6.7)
    , Mac OS X (10.6.7),
    "Limit the Logs to the Bits above Binary Images."  No, Seriously

  • Sample CLASSES for different types of OIM components!!!

    Hi Experts
    Can any one provide me sample classes for different types of OIM components, adapters, scheduled tasks, etc. with your best practices for OIM java development and documentation? It would Help me lot.
    Please let us know Links/Documentations.
    Thanks
    \oim_user

    for schedulers
    1. Create a java class that extends the SchedulerBaseTask (see example below)
    2. Write your business logic
    3. Compile and jar
    4. Place the jar in the ScheduleTask directory in your OIM install
    5. Create a new scheduled task using the OIM developer console
    6. link in the new class into your new scheduled task.
    7. Done!
    Example code for a scheduled task:
    import com.thortech.xl.scheduler.tasks.SchedulerBaseTask;
    public class ScheduledtaskExample extends SchedulerBaseTask {
    public void init()
    //this method is run before execute by the scheduler
    public void execute() {
    //is executed by the scheduler
    runMyBusinessLogic();
    private void runMyBusinessLogic(){
    //place your business logic here
    }

  • Different footer for every package or for every classes

    Hi!
    1.How can I specify in javadoc that I want a different footer for every package or for every classes?
    2.how can I told to javadoc that I have external library used in my project (for providing javadoc comments for for these libraries )?
    I used an ant build file for generating javadoc API documentation for my packages.
    Thanks,
    Florin.

    1. Specifying a different footer for every package or class is not available
    (unless you modify the standard doclet).
    2. To generate documentation for external libraries, you must first have the
    source code to the external libraries. Then simply pass in the package names,
    using -classpath to point to them.
    You can also use -link to link to previously-generated javadoc documentation.
    -Doug Kramer
    Javadoc team

  • While running my app I get the below error  - have different Class objects for the type javax/servlet/http/HttpServletRequest used in the signature

    I am running ATG[10.1.2] app on Jboss [EAP 5.1.0 GA] I am able to open dyn/admin however when I start my app I get the below error
    java.lang.LinkageError: loader constraint violation: when resolving method "atg.servlet.ServletUtil.setSessionConfNumCacheRequest(Ljavax/servlet/http/HttpServletRequest;)Ljavax/servlet/http/HttpServletRequest;" the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) of the current class, atg/filter/dspjsp/PageFilter, and the class loader (instance of org/jboss/classloader/spi/base/BaseClassLoader) for resolved class, atg/servlet/ServletUtil, have different Class objects for the type javax/servlet/http/HttpServletRequest used in the signature
      at atg.filter.dspjsp.PageFilter.doFilter(PageFilter.java:215)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at atg.servlet.ForwardFilter.doFilter(ForwardFilter.java:263)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at atg.servlet.ErrorFilter.doFilter(ErrorFilter.java:279)
      at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
      at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
      at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:638)
      at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:446)
      at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:382)
      at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:310)
      at org.apache.catalina.core.StandardHostValve.custom(StandardHostValve.java:416)
      at org.apache.catalina.core.StandardHostValve.status(StandardHostValve.java:342)
      at org.apache.catalina.core.StandardHostValve.throwable(StandardHostValve.java:286)
      at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
      at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
      at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
      at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
      at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
      at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:829)
      at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:598)
      at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
      at java.lang.Thread.run(Thread.java:680)
    11:22:47,413 ERROR [[localhost]] Exception Processing ErrorPage[errorCode=500, location=/global/errorPage500.jsp]

    The supported JBoss version for 10.1.2 is JBoss EAP 5.1.2 but I don't think that your issue is caused because of this. Your issue is more of an environmental thing as you are probably getting two different versions getting loaded of class javax.servlet.http.HttpServletRequest and so correspondingly two different Class objects as the error shows. One reason for this could be if you include any server-specific libraries (in present case the Servlet API JAR which contains the class javax.servlet.http.HttpServletRequest) of a different version in the /WEB-INF/lib of your web application. Try removing it from there if so and see if that helps.

  • How to call to another form declare in different class ???????

    hi, i'm beginner in j2me...
    I was wondering how to call to other form(class) in the current form...
    For example,
    public class A extends MIDlet implements CommandListener
    public void commandAction(Command d,Displayable s)
    if (d==*OKCommand*)
    if press this OK command, it will be able to show another form declared in the different class...
    How to make it able to call to other form/class(eg.classB)????
    public class B
    //form that will be shown after pressed command OK in class A
    please help if you know...Thanks a lot..... =)

    you MUST have a reference to the other class or MIDlet in the current MIDlet ...
    i think that i have answered to these kind of questions a few month ago.. you should use the 'search' engine to find the topic..
    CLDC and MIDP forum is not a huge forum compare to Java Programming forum so it will be easy !

  • Comparing user defined classes ???

    class A
         int i=10;     
    class B
         int i=10;     
         //int k = 30;
    As we compare both primitive variables,
    Is it possible to compare the above A and B classes.
    since A and B consists of same variable and same data,
    i should get o/p as both are same.
    Is it possible to compare like this(classes) ????
    but when i remove comment from Class B
    the o/p should be both are not same.
    with out making a single change in the code. is it possible ?????
    i tried it with Comparator...but code need to be change when i remove comment from Class B.

    Waitaminnit.
    What you're asking for doesn't make any sense.
    You want class A and class B to compare a certain way, but then if you change the code for class B, you want them to compare a different way, without changing any other code?
    That's fairly ridiculous. Whatever is doing the comparing should know a priori about the important stuff in class B. You can't just come along later and change class B such that the set of important stuff is now different and expect other code to magically know this.
    I suppose you could have the Comparator do some weird, ugly-asss reflection and apply some rules to its result, but ick.
    Also, you shouldn't even be trying to compare A and B unless one descends from the other, or they descend from a commom ancestor that has all the fields you're going to use in the comparison.
    For instance, if B extends A, then you can get rid of the i in B. The comparison would be implemented on A only, and would treat everything as an A. This works because a B is an A.

  • What is SAP name space for different objects.

    Hi Guys,
    Kindly let me know the SAP name spaces for different objects.
    Thanks

    hi,
    Naming Conventions in ABAP Objects 
    Global classes and interfaces that you create in the Class Builder are stored in the class library and administered by the R/3 Repository: they therefore have the same namespace as all other Repository objects (database tables, structures, data elements, and so on).
    It is therefore necessary to have naming conventions for object types and their components and to use them uniformly within program development.
    The following naming convention has been conceived for use within the SAP namespace:
    If you do not observe the naming conventions for object types (classes and interfaces), conflicts will occur when the system creates persistent classes, since it will be unable to generate the necessary co-classes.
    Namespace for Components
    A single namespace within a class is shared by:
    All components of the class itself (attributes, methods, events, constructors, interfaces, internal data types in the class, and aliases)
    All public and protected components of the superclasses of the class.
    Method implementation has a local namespace. The names of the local variables can obscure those of class components.
    Naming Convention
    The naming convention has been kept as general as possible to avoid adversely influencing the naming of objects.
    General Remarks
    When you choose names for development objects, you should:
    Use English names
    Use glossary terms when possible
    For example, CL_COMPANY_CODE instead of BUKRS
    In compound names, use the underscore character (_) as a separator. Since names are not case-sensitive, this is the only character that you can use to separate names.
    Example: CL_COMPANY_CODE, CL_GENERAL_LEDGER_ACCOUNT
    Names should describe the action, not the implementation of the action.
    Example: PRINT_RECTANGLE, not RECTANGLE_TO_SPOOL
    Conventions for Object Types
    Class and interface names in the class library belong to the same namespace as data elements, tables, structures, and types. They are maintained centrally in table TADIR.
    Class in the class library
    CL_<class name>
    The class name should be made up of singular nouns.
    CL_COMPANY_CODE, CL_GENERAL_LEDGER_ACCOUNT
    Interfaces in the class library
    IF_<interface name>
    The same naming convention applies to interfaces as to classes.
    IF_STATUS_MANAGEMANT, IF_CHECKER
    Local classes in programs
    (recommendation)
    LCL_<class name>
    The class name should be made up of singular nouns.
    LCL_TREE_MANAGEMENT
    Local interfaces in programs
    (recommendation)
    LIF_<interface name>
    The sane naming convention applies to interfaces as to classes.
    LIF_PRINTER
    Recommended naming conventions are not compulsory. However, if you use prefixes for these class and interface names, you should use those listed above.
    Conventions for Components
    Method name
    <method name>
    Method names should begin with a verb:
    GET_STATUS, CREATE_ORDER, DETERMINE_PRICE
    Events
    <event name>
    Event names should have the form
    <noun>_<participle>:
    BUTTON_PUSHED, COMPANY_CODE_CHANGED, BUSINESS_PARTNER_PRINTED
    Local type definitions within a class
    (recommendation)
    TY_<type name>
    TY_INTERNAL_TYPE, TY_TREE_LIST
    Data definitions (variables)
    <variable name>
    When you name variables within a class (CLASS-DATA or DATA), avoid using verbs at the beginning of the name (to avoid conflicts with method names).
    LINE_COUNT, MARK_PRINTED, MARK_CHANGED, STATUS
    Data definitions (constants)
    (recommendation)
    CO_<constant name>
    CO_MAX_LINE, CO_DEFAULT_STATUS, CO_DEFAULT_WIDTH, CO_MAX_ROWS
    Recommended naming conventions are not compulsory. However, if you use prefixes for these class and interface names, you should use those listed above..
    Concrete Method Descriptions
    Attribute access
    SET_<attribute name>, GET_<attribute name>
    Methods that access attributes of any kind should be prefaced with GET_ or SET_.
    GET_STATUS, SET_USE_COUNT
    Event handler methods
    ON_<event name>
    Methods that handle events should begin with ON, followed by the name of the event that they handle.
    ON_BUTTON_PUSHED, ON_BUSINESS_PARTNER_PRINTED
    Methods that perform type conversions
    AS_<new type>
    AS_STRING, AS_ISOCODE
    Methods that return a Boolean value
    These methods may not return any exceptions.
    Recommendation: Use SPACE and 'X' to represent false and true respectively.
    IS_<adjective>
    IS_OPEN, IS_EMPTY, IS_ACTIVE
    Check methods
    CHECK_<objective>
    CHECK_AUTHORIZATION, CHECK_PROCESS_DATE
    Local Conventions Within Methods
    For parameters
    The parameters are regarded from the point of view of the method that implements them:
    IMPORTING parameters
    IM_<parameter name>
    EXPORTING parameters
    EX_<parameter name>
    CHANGING parameters
    CH_<parameter name>
    RESULT
    RE_<result>
    Using prefixes is NOT compulsory. However, if you do use them, use those listed above.
    For exceptions
    The following table contains a series of possible exception names, that can also be used generically (for example, NOT_FOUND could also be used as DATE_NOT_FOUND)
    EXCEPTION
    Meaning
    ACTION_NOT_SUPPORTED
    The requested action or function code is not supported.
    CANCELLED
    If a method uses a dialog to find out what has to be dome (for example, a list of choices), and the user chooses "Cancel", you can set this exception.
    EXISTING
    A new object that you want to create already exists in the database.
    FAILED
    The method could not be executed because of the current environment. This exception is intended for cases where the method cannot be executed because of variable system circumstances.
    ..._FAILED
    Part of the method could not be completed because of the current environment. (OPEN_FAILED, CLOSE_FAILED, SELECTION_FAILED, AUTHORIZATION_FAILED)
    FOREIGN_LOCK
    Data is locked by another user.
    INCONSISTENT
    Object data in the database is inconsistent.
    ..._INCONSISTENT
    The component data for … of an object in the database is inconsistent.
    INVALID
    The object data entered is incorrect (for example, company code does not exist). Compare NOT_QUALIFIED.
    ..._INVALID
    The component data entered for an object is incorrect. Compare NOT_QUALIFIED.
    INTERNAL_ERROR
    Last resort. Only use this exception if you cannot be more precise about the nature of the error.
    NOT_AUTHORIZED
    The user does not have the required authorization.
    NOT_CUSTOMIZED
    The object requested is not correctly customized.
    ..._NOT_CUSTOMIZED
    The component … of the requested object is not correctly customized.
    NOT_FOUND
    Unable to find the requested object.
    ..._NOT_FOUND
    Unable to find component … of the requested object.
    NOT_QUALIFIED
    The combination of input parameters is insufficient to run the method. Compare INVALID.
    ..._NOT_QUALIFIED
    One parameter of the method is not qualified.
    NUMBER_ERROR
    Error assigning a number.
    SYSTEM_ERROR
    This exception is set if the Basis system returns an unexpected error message.
    regards,
    sudheer.

  • Two equal objects, but different classes?

    When programming on binding Referenceable object with JDK version 1.5.0_06, I have encountered a very strange phenomenon: two objects are equal, but they belong to different classes!!!
    The source codes of the program bind_ref.java are listed as below:
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++
    import java.lang.*;
    import java.io.*;
    import java.util.*;
    import javax.naming.*;
    import javax.naming.spi.ObjectFactory;
    import java.util.Hashtable;
    public class bind_ref {
    public static void main( String[] args ) {
    // Set up environment for creating the initial context
    Hashtable env = new Hashtable();
    env.put( Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.fscontext.RefFSContextFactory" );
    env.put( Context.PROVIDER_URL, "file:/daniel/" );
    Context ctx = null;
    File f = null;
    Fruit fruit1 = null, fruit2 = null;
    byte [] b = new byte[10];
    try {
    ctx = new InitialContext( env );
    Hashtable the_env = ctx.getEnvironment();
    Object [] keys = the_env.keySet().toArray();
    int key_sz = keys.length;
    fruit1 = new Fruit( "Orange" );
         SubReference ref1 = fruit1.getReference();
    ctx.rebind( "reference", fruit1 );
         fruit2 = ( Fruit )ctx.lookup( "reference" );
         System.out.println( "ref1's class = (" + ref1.getClass().toString() + ")" );
         System.out.println( "fruit2.myRef's class = (" + fruit2.myRef.getClass().toString() + ")" );
         System.out.println( "( ref1 instanceof SubReference ) = " + ( ref1 instanceof SubReference ) );
         System.out.println( "( fruit2.myRef instanceof SubReference ) = " + ( fruit2.myRef instanceof SubReference ) );
         System.out.println( "ref1.hashCode = " + ref1.hashCode() + ", fruit2.myRef.hashCode = " + fruit2.myRef.hashCode() );
         System.out.println( "ref1.equals( fruit2.myRef ) = " + ref1.equals( fruit2.myRef ) );
    } catch( Exception ne ) {
    System.err.println( "Exception: " + ne.toString() );
    System.exit( -1 );
    +++++++++++++++++++++++++++++++++++++++++++++++++++++++
    All the outputs are shown as below:
    =======================================================
    Fruit: I am created at Mon Jun 18 11:35:13 GMT+08:00 2007
    SubReference: I am created at Mon Jun 18 11:35:13 GMT+08:00 2007
    --------- (i)subref.hashCode() = (-1759114666)
    SubReference: I am created at Mon Jun 18 11:35:13 GMT+08:00 2007
    --------- (i)subref.hashCode() = (-1759114666)
    FruitFactory: obj's class = (class javax.naming.Reference)
    FruitFactory: obj's hashCode = -1759114666
    FruitFactory: obj = (Reference Class Name: Fruit
    Type: fruit
    Content: Orange
    FruitFactory: ( obj instanceof SubReference ) = false
    FruitFactory: subref_class_name = (Fruit)
    Fruit: I am created at Mon Jun 18 11:35:13 GMT+08:00 2007
    ref1's class = (class SubReference)
    fruit2.myRef's class = (class javax.naming.Reference)
    ( ref1 instanceof SubReference ) = true
    ( fruit2.myRef instanceof SubReference ) = false
    ref1.hashCode = -1759114666, fruit2.myRef.hashCode = -1759114666
    ref1.equals( fruit2.myRef ) = true
    ========================================================
    I hightlight the critical codes and outputs related to the strangeness with bold texts.
    Who can tell me what happens? Is it really possible that two objects belonging to different classes are equal? If so, why that?

    It can also depend on how you implement the equals method.
    class Cat {
        String name;
        Cat(String n) {
            name = n;
    class Dog {
        String name;
        Dog(String n) {
            name = n;
        public boolean equals(Object o) {
            return name.equals(o.name);
        public static void main(String[] args) {
            Dog d = new Dog("Fred");
            Cat c = new Cat("Fred");
            System.out.println(d.equals(c));
    }

  • Can't call or execute of different class files in a main program

    Hi, I got a main program which can call 3 different classes. The main program have an implicit-choice List as a starting menu. If one of the file is selected, the files will call out and display it. However, i managed to call the 1st 2 files, and the 3rd files can't display anything after selected.
    I enclosed my code as below:
    import javax.microedition.midlet.*;
    import javax.microedition.lcdui.*;
    public class Catalogues extends Form implements CommandListener {
         private Displayable parent;
         private Display display;
         private List Cata;
         private Boots bo;
         private Higheels hHeels;
         private Sandals sand;
         private Slippers sp;
        private Command backCommand = new Command("Back", Command.BACK, 1);
        private Command viewCommand = new Command("View", Command.SCREEN, 1);
        private String[] options = {"Boots", "High Heels","Sandals", "Slippers"};
         public Catalogues(Display d, Displayable p) {
              super("Welcome to Footwear World");
              Cata = new List("Select Option", List.IMPLICIT, options, null);
              display = d;
            parent = p;
              addCommand(backCommand);
              addCommand(viewCommand);
              setCommandListener(this);
         public void commandAction(Command c, Displayable d) {
         if(d==parent && c==List.SELECT_COMMAND){
              switch(parent.getSelectedIndex()){
                   case 0:
                           if(bo==null){
                              bo = new Boots(display,parent);
                             display.setCurrent(bo);
                              break;
                   case 1:
                           if(hHeels==null){
                              hHeels = new Higheels(display,parent);
                             display.setCurrent(hHeels);
                              break;
                   case 2:
                           if(sand==null){
                              sand = new Sandals(display,parent);
                             display.setCurrent(sand);
                              break;
                   case 3:
                           if(sp==null){
                              sp = new Slippers(display,parent);
                             display.setCurrent(sp);
                              break;
                   default:
             else if (c==backCommand) {
                       display.setCurrent(parent);
    }If the 3rd option is selected, i'll display above mentioned layout which contain a list to select too.
    After build this project on WToolkit. It shown an error message which is as below:
    Project settings saved
    Building "SelectCustest"
    C:\WTK22\apps\SelectCustest\src\Catalogues.java:29: cannot resolve symbol
    symbol : method getSelectedIndex ()
    location: class javax.microedition.lcdui.Displayable
    switch(parent.getSelectedIndex()){
    ^
    1 error
    com.sun.kvem.ktools.ExecutionException
    Build failed
    May i know what is problem am i facing now? And how to solve it.
    Thanks.

    Thanks to all for your thoughts and replies. I liked the xargs suggestion, so I tried that first. I would have (may still) try the stdin suggestion, followed by writing the grep output to a file.
    xargs does work, in a way I didn't expect it to, but that could be due to my inexperience with the workings of the shell.
    here's a line from my test script
    cat file | grep foo | xargs java com.company.test.TEchoArghere's the contents of 'file'
    123foo
    abc
    qafoozv
    qaz
    wsx
    qwefoort
    zxcfooh
    sdfghhere's the output from the test class, which just echos any arguments
    ::number of args: 4
    ::args[0] 123foo
    ::args[1] qafoozv
    ::args[2] qwefoort
    ::args[3] zxcfoohso xargs appends all the values from grep into an argument list and call the java class once.
    when I took xargs out of the script, nothing was passed to the class:
    ::number of args: 0this was really interesting and something to keep in my back pocket for future use.
    Thanks again to all.
    Tom

  • Doing the same task for different data.. Do I need Queues? How to use them if yes?

    Hello all,
    I have created a VI which is getting data from some FTP server and then after comparing with the HDD specified folder copy the missing data from the FTP ... Description is also in the VI. There are few things I need to ask.
    1) The email sending VI gives error 1172..What could be the reason .. is it firewall.. or is there any mistake in the code?
    2) As you people are experts so I really like any suggestion to improve the VI..
    3) The most important .. Currently this VI can only perform the whole task for one FTP folder. Actually my task is I need to check for 4 different FTP folder on different servers..its not 4 different folder in one FTP .. its 4 different FTP.Now my question is how I can do this: First it compare and copy from FTP1.Then FTP2... and so on.. How can I change the data for the cluster for different FTPs? Do I need to use queues? If yes how because I don't have any experience with queues.
    I will really appreciate is someone can either provide me the relevant example or can give me some idea.
    The main VI is the 'TASK START'.VI please find the attached files.
    Thanks
    Regards,
    Naqqash
    Naqqash
    Attachments:
    Project.zip ‏151 KB

    Hi Peter,
    Thank you very much for your reply. I have understood your idea but there are few problems.
    Please see the attached "Final test.vi".. actually my top level vi should be like this.. due to this reason I need to develop the cluster like one with name "Settings" as shown in Enum FTP events.vi.. In this cluster all the data types are not constants (but can be set as constants)  and further all of them are not of same type so whenever I try to create as you created I have got error, wire broken..so what do you think i should do.. In this cluster there are different types of data .. string, path, numeric, array and a cluster with name file properties also... can't figure out what to do..I know things are little scattered and wiered but due to lack of experience, I guess, I am now a little bit confused for this matter. I
    hope guys here in the forum will help me as you guys always did.
    Naqqash
    Attachments:
    Final test.vi ‏11 KB
    Enum FTP Events.vi ‏14 KB

Maybe you are looking for

  • Removing digital signatures created in a previous version of adobe acrobat pro

    I recently installed Adobe Acrobat X Pro, which required the removal of my previous version (8 Pro). I have several PDF docs created in (8 pro) with signature fields. I reuse these docs inputting updated info. When I do I clear the signature field, a

  • Won't display pages?

    I have this PDF file that is missing pages and sections, it is a textbook PDF.  At first, I thought it was a transporting error because this was given to me over Skype, so I got it emailed and finally I transfered it directly from my friend's compute

  • Address book photo in Mail

    Is there anyway to remove the Address Book photo when printing a Mail message? I print some of my stuff to pdf and would rather not have the photo printed as well. Thanks. iMac G5 20    

  • Illustrator renaming files when saving

    I am working in Illustrator CS2 on a PC. When I open a .ai file that I created, work a bit and save again, my files are being renamed. Example: My original file that was named "planning details.ai" gets renamed to "PLANNI~5.ai." Why is this happening

  • Can't see any devices hooked up to Sata ports #5&6 on K9A2 Plat board

    Hi there, I'm new to this forum. My virgin system consists of MSI K9A2 Platinum, Bios 1.4 4 GB Corsair CoolerMaster Silent Pro M600 AMD Phenom II X4 940 Zalman CNPS9700NT Visiontek ATI Radeon 4850 SuperTalent 64GB Sata II SSD Samsung SH-223 DVD-RW, S