Calling a certain object

If you have lots of objects created in a class, how can you easilly call a certain object based on the user's input?
All I can think of is an awfully long if-structure. For example:
private Creature xA = new Creature();
private Creature xB = new Creature();
private Creature xC = new Creature();
private Creature xD = new Creature();
private Creature xE = new Creature();
String what = this.textfield.getText();
if (what.equals("a"))
    xA.doSomething();
if (what.equals("b"))
    xB.doSomething();
if (what.equals("c"))
    xC.doSomething();
...and so on...
Is there any shorter way to do this?

You could maybe have an HashMap of Creature objects. Then pick the correct object out based on the letter received from getText(),
e.g. for a HashMap the key could be related to 'a', 'b', 'c', ...
// fill HashMap with entries xA, xB, ... and keys hashCode("a"), ...
// Then ...
if(map.containsKey(what.hashCode())) {  
   (map.get(what.hashCode())).doSomething();
}

Similar Messages

  • When opening certain websites or clicking links from google results, I get this popup message "Error: 'setTimeout' called on an object that does not implement i

    The message says: "Error: 'setTimeout' called on an object that does not implement interface Windows" Multiple message windows for this get open. And there is an OK button under it. I have to click on OK button on all the windows to be able to continue with working on the browser again.

    hello, can you try to replicate this behaviour when you launch firefox in safe mode once? if not, maybe an addon is interfering here...
    [[Troubleshoot extensions, themes and hardware acceleration issues to solve common Firefox problems]]

  • How can I call a COM object from a PL/SQL CODE

    Hi everyone,
    Does anyone know how to call a COM object from a stored procedure in oracle.
    a sample of code
    please help,
    Hilaire

    Are you familiar with external procedures? Basically, you can expose functions exported by a shared library (i.e. a DLL on Windows) to the Oracle database. My assumption is that you'd probably need to write a wrapper DLL around the COM object, since I believe you can only pass fundamental data types back and forth (i.e. no object references). You'd expose the method(s) of that wrapper DLL to the database via external procedures.
    Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • How to call a COM object from an Oracle Form?

    Hi All,
    Pls advice. How to call a COM object from an Oracle Form?
    Thanks.

    try asking the "Form" forum

  • Need to get the list of all procedures called in an object

    Hi,
    I am trying to find the list of all proceudres called in an object. I can get the list of packages and individual procedures/functions using dba_dependencies, all_dependencies or user_dependencies. However this would not give me the list of procedures of a package that are used in my object.
    How to find the procedures of a package (and not just the package name) being called in another object?
    Thanks in advance
    Upendra

    You can take the package name from user_depencies and query the USER_SOURCE table for the object name where the package name exists.
    Eg code, here PKemp is the package name.
    SELECT SUBSTR(TEXT,INSTR(TEXT,'PKEMP'))
    FROM USER_SOURCE
    WHERE NAME = 'PROCEMP'
    AND INSTR(TEXT,'PKEMP') >=1
    SUBSTR(TEXT,INSTR(TEXT,'PKEMP'))
    PKEMP.SALUP;

  • How to call GOS(Generic Object service) attachment ( BMP file ) into SAP

    How to call GOS(Generic Object service) attachment ( BMP file ) into SAP script
    Example: MM02 Service object there attaching the bmp file the same file i need to call script based on the material number
    Please provide the procedure and  coding.
    Thanks in advance
    Raju

    Hi,
    The following link may be useful to u.
    help.sap.com/printdocu/.../BCSRVOBS.pdf

  • ExternalInterface.call problem with object-orientation

    Hi
    I am using an swf inside a PDF. In a PDF-context the ExternalInterface-class works much the same as it does within a website. So far calling a function in the document-script works.
    The thing now is, that I really try to use an object-oriented approach as often as I can. In this case I have a function I could call using
    var jsCaller:Object = ExternalInterface.call("myFunction",parameters);
    This works as expected.
    However, I have now made that function a method in an object, so I can access it within JS using dot-notation: myCoolObject.myFunction(); This works as well, so the problem is not the function itself. However, the call
    var jsCaller:Object = ExternalInterface.call("myCoolObject.myFunction",parameters);
    does not work.
    This means there's either something I'm missing, or it's a limitation of ExternalInterface, or it's a limitation of externalInterface in a pdf-context.
    Anyone to enlighten me?

    If EI calls eval it should be able to resolve the object-path. However, this doesn't seem to be the case. Also note that my parameter is an array, so this probably wouldn't work, even if the syntax did.
    Anyway, I tested your syntax in my PDF, and it showed the same behaviour as before (i.e. the function in which the EI-call was placed could not be executed, and acrobat claimed there was no such function). It didn't work with my normal function, and not even with a simple console.println-statement that way. So in PDFs it definitely doesn't work like that.
    But thanks for the suggestion!

  • Calling a Flash object HTTPS (  only in IE, not loading the first time )

    Hi everyone !
    I'm trying to call a flash object from a bsp page, I've uploaded the flash into the mime repository (via the SE80). It works quiet well in Firefox, but with IE, i need to refresh the page, it won't load the first time i access the page.
    Does anyone has any idea ?? do i have to customize something within the SICF ?
    thx for the help
    merry Xmas
    Quentin

    Solved it, I created a page to call the flex from the MIME
    here it is :
    DATA: w_xstring TYPE xstring.
    DATA: w_mimetype TYPE string.
    * References
    DATA: w_url TYPE string.
    CONCATENATE 'sap/bc/bsp/sap/Z0008/' url  INTO w_url.
    CALL FUNCTION 'Z_FLEX_MIME'
      DESTINATION sy-sysid
      EXPORTING
        url        = w_url
      IMPORTING
        l_xstring  = w_xstring
        l_mimetype = w_mimetype.
    response->set_data( w_xstring ).
    navigation->response_complete( ).
    EventHandler Oninitialization :
    sap/bc/bsp/sap/Z0008/ is the url to my swf file in the SICF
    Module Function  Z_FLEX_MIME
    FUNCTION Z_FLEX_MIME.
    *"*"Interface locale :
    *"  IMPORTING
    *"     VALUE(URL) TYPE  STRING
    *"  EXPORTING
    *"     VALUE(L_XSTRING) TYPE  XSTRING
    *"     VALUE(L_MIMETYPE) TYPE  STRING
    * References
    DATA: lo_mr_api TYPE REF TO if_mr_api.
    * instantiate MIME API class
    CALL METHOD cl_mime_repository_api=>if_mr_api~get_api
      RECEIVING
        r_mr_api = lo_mr_api.
    * Get file from MIME repository
    CALL METHOD lo_mr_api->get
      EXPORTING
       i_url             = url
      IMPORTING
        e_content         = l_xstring
        e_mime_type       = l_mimetype
      EXCEPTIONS
        parameter_missing  = 1
        error_occured      = 2
        not_found          = 3
        permission_failure = 4
        OTHERS             = 5.
    ENDFUNCTION.
    If you have any questions please fell free to ask
    good day
    Quentin
    Edited by: Quentin Dubois on Feb 6, 2008 5:55 PM

  • Will subsequent calls to an object running in a thread run in the thread?

    Hi,
    If I start a thread with an empty run method and then make a call to the object that I started in the thread, will the method call run in the other thread? For example:
    class ThreadClass implements Runnable {
        public void someMethod() {
        public void run() {
    class ThreadCaller {
        private ThreadClass threadClass;
        public ThreadCaller() {
            threadClass = new ThreadClass();
            Thread thread = new Thread(threadClass);
            thread.start();
        public blah() {
            threadClass.someMethod();
    }Will the method call in blah() run in the same thread as ThreadCaller, or will it run in the thread that was started in ThreadCaller's constructor?
    Thanks,
    Dan

    Djaunl wrote:
    vanilla_lorax wrote:
    Djaunl wrote:
    Is there a way to keep the thread alive until the object that started the thread is terminated,Objects don't get terminated. What do you mean?I want the thread to stay alive indefinitely until I arbitrarily terminate it makes more sense. The thread will stay alive until its run method completes. The canonical approaches are
    public void run() {
      while (!Thread.interrupted()) { // NOT isInterrupted()
        // do stuff
        // if you need to catch InterruptedException, do this:
        try {
        catch (InterruptedException exc) {
          Thread.currentThread().interrupt();
    }And then from another thread, call theAboveThread.interrupt() when it's time to stop. Read the docs in interrupt(), interrupted(), the interrupt flag, etc.
    OR
    while (!done()) {
      // do stuff
    }and then another thread calls setDone(true) or somesuch when it's time to stop. Note that all access to done--both get and set--must be synchronized, or done must be declared volatile. Also note that you may still have to handle interrupts, so you may have some repeated code with this approach--testing both done() and interrupted().
    Let me give the end-goal of this.
    Currently, I have a "main" thread which the user can input commands into, and another thread which occasionally runs in the background. When I want something to run in the background, I just create a new thread. However, I figured it'd be more efficient to have one thread running in the background to do something as opposed to spawning hundreds of new threads to do the same task over and over. If the task happens VERY frequently and what it does is VERY small and quick, then the overhead of thread creation may make this a valid approach. Otherwise, don't overcomplicate it. Since you're new to threads, first get it working where you spawn one thread for each background task. Then move on to thread pooling. Look into ThreadPoolExecutor and related classes.
    http://java.sun.com/javase/6/docs/api/java/util/concurrent/ThreadPoolExecutor.html

  • Certain objects are transparent in flash movie

    I've been getting reports from users that certain objects are invisible in my flash banner. The browser culprit is IE 8 (but someone also reported seeing this in IE 6). I have been unable to duplicate this and therefore, find it very difficult to troubleshoot. I do have the Wmode set to transparent, but I've made it opaque and still had the "invisible" reports. Here is the site:
    http://tekkytoys.com
    The objects reported as invisible are the robot's body and head. If someone out there can see this and give me a clue, it would be very helpful.
    Thanks!
    Mark

    First guess here is that some elements may require a certain version of the player, and they don't have it!

  • Problem resizing certain objects

    I converted a project from Captivate 1 to 2. I noticed that I
    am having trouble resizing certain objects. For example, by
    clicking on a highlight box, I expected the sizing handles to show
    up on the object so I could resize it. The handles weren't there. I
    ended up having to delete the object and create a new one.
    Constrain Proportions is "unchecked." By the way, this doesn't
    happen everytime. Sometimes it works; sometimes it doesn't. Is
    there a patch for Captivate 2 I could install?

    Hi Jerilyn
    Indeed a patch does exist for Captivate 2. However, I'm very
    doubtful it will have any effect on what you reported.
    Unfortunately, we see many such reports here in the forums with odd
    behavior related to projects that were "converted" from version 1.
    If you are interested,
    click here to see the
    Technical Note regarding the hot fix.
    Cheers... Rick

  • Where to call the BOR objects in the wokr flow builder

    where do we call  the BOR objects in the workflow builder
    suppose we need to trigger the even bus7015 or some thing like that in the workflow to find if the manger is terminated or not
    where do we call a bor object in work flow.

    <img src="https://weblogs.sdn.sap.com/weblogs/images/37984/ChangeWF.JPG">
    Second icon from the right...looks like a silver hat with a red brim.

  • Tracking every time a method is called in some object?

    Hi,
    I would like to use reflection to log every time some method is called in an object.
    Example;
    public class A {
    public void x () { }
    public void y () { }
    I would like some automatic mechanism that would allow me to register this object such that every time method x() is called, I have a System.out.println (or some other logging) saying "method 'x' called" and the same for every time method y() is called ... without having to modify the body of each method I want to track. If I have to put my logging calls into every method, then it defeats the purpose of what I'm trying to accomplish.
    Thank you,
    Gene

    If your method calls are through an interface, set up a proxy that logs the calls using java.lang.reflect.Proxy.
    If they're through a class, you can't use reflection and need to either use code generation or bytecode manipulation (either roll your own or use an aspect oriented programming kit - logging is the canonical AOP example).
    Pete

  • Why java is called as true object oriented language?

    HI Friends,
    Though few oops concepts is not supported , why java is called as truly object oriented language and C++ as not a purely object oriented language???? Please, if any one know , give me the answer.
    Thanks to all.

    few oops concepts is not supportedwhich concepts?
    as far as i know...to be OO, you must supports
    encapsulation, abstraction, inheritancxe, composition (aggretration, et all) and polymorphism. Java supports all those comcept..now..Java is a hybrid due to what Jverd has pointed out.
    the only pure OO language that i know of is SmallTalk. they have Meta class that can create Class object. and all their primitaives are object.
    C# comes close, but their Class are not object.

  • Calling a Script Object after remove instance index[0]

         I have created a LiveCycle document that has a repeatable subform as url linked below. The form will not let me call a Script Object after removing an instance at index[0]. Regardless of the number of instances remaining. I use a script object to show and hide buttons. Adding an instance is not a problem. What to do?
    Script on Delete Subform Button (Error):
    xfa.form.recalculate(1);
    this.resolveNode('fifteenSubform._CorrectiveActionWrapper').removeInstance(this.parent.ind ex);
    if (xfa.host.version < 8) {
    //deleteing a [0] index seems to create a problem for executing the function in this Script Object
    SOremove.fxremove();
    https://files.acrobat.com/a/preview/03389d79-9020-45d9-ba4f-fb4cbdc21f77

    Hi,
    What seems to happen when you remove a form object that has code that is currently executing is that it can't find the next line.  You might want to put all your code in the script object.
    so in the click event you have;
    SOremove.fxremove(this);
    Then your script object will start
    function fxremove(button) {
        button.resolveNode('fifteenSubform._CorrectiveActionWrapper').removeInstance(button.parent.index);
        if (xfa.host.version < 8) {
            xfa.form.recalculate(1);
        console.println("The SOremove.fxremove fired");
    Regards
    Bruce

Maybe you are looking for

  • Income Tax deducted for withdrawn employee

    Hi Experts In my Client One employee is withdrawn on 31.04.2011n he got final settelement in that month,But in the june payroll for that employee income tax deducted,we have cheked all his prevoius payroll cluster but not able to get the solution.Can

  • Report for Customer and Material list

    Dear Experts,   Is there any Std. reprot to list all customers under particular sales org and also the material for each customer deals with.   Input only sales org. Please advise, Regards, Siva

  • How can i change an existed apple id with credit card in a none credit card?

    ??

  • Yoga 2 11 WLAN upgrade

    With the new BIOS 92CN33WW is there now a possibility to upgrade the WLAN of  Yoga 2 11 e.g. by using a new Wireless-AC 7260 module ? Up to now this was not possible due to the Whitelist in the BIOS.

  • I'm problem in Host Credentials  password

    my os is window server 2003 user login= administrator (logon window ) password=44111704 db 10g and i connect db with user system password 44111704 at oem i want to export table to export file with funtion data movement-->export to export files --> se