Passing Enum Values to a common method.Please see

How do I pass the value of an Enum to a method?
I have an Enum called myEnums with several values to a common method
public enum MYEnums {
        FULL,
        EMPTY,
        PARTIAL
        CPTY_CODE;
//Invoke
isEmpty(myEnums.FULL)
isEmpty(myEnums.EMPTY)
// common method
isEmpty(String enumValue){
myEnum.enumValue
ERROR: enumValue cannot be resolved

You could also write this:
public enum FillLevel
    FULL,
    EMPTY,
    PARTIAL;
    public boolean isEmpty() {
      return this == EMPTY;
    public boolean isFull() {
      return this == FULL;
}By the way. What does CPTY_CODE mean? It doesn't seem as if it belongs into the enum. Also, why doesn't the enum have a name that tells us what it's all about?

Similar Messages

  • How to pass calculated value to Application Module method?

    I am a newbie to ADF. Ithink I am missing something very basic:
    In JDeveloper 10.1.3.3 using ADF, I am trying to pass the session ID to a method in my App Mod, but the method receives a null value. I think I a getting the session ID too late in the process, but do not know where else to get it.
    Here are the details:
    I am passing 3 argument to a method called ProcessReport:
    public String ProcessReport(Number reportNumber, Double caratWeight, String sessionID)
    In my PageDef I have:
    <p>
    &lt;executables&gt;
    &lt;variableIterator id="variables"&gt;
    &lt;variable Type="oracle.jbo.domain.Number"
    Name="ProcessReport_reportNumber" IsQueriable="false"/&gt;
    &lt;variable Type="java.lang.Double" Name="ProcessReport_caratWeight"
    IsQueriable="false"/&gt;
    &lt;variable Type="java.lang.String" Name="ProcessReport_sessionID"
    IsQueriable="false"/&gt;
    &lt;/variableIterator&gt;
    &lt;/executables&gt;
    &lt;bindings&gt;
    </p>
    <p>
    &lt;methodAction id="ProcessReport" MethodName="ProcessReport"
    RequiresUpdateModel="true" Action="999"
    IsViewObjectMethod="false" DataControl="RC2DataControl"
    InstanceName="RC2DataControl.dataProvider"
    ReturnName="RC2DataControl.methodResults.RC2DataControl_dataProvider_ProcessReport_result"&gt;
    &lt;NamedData NDName="reportNumber" NDType="oracle.jbo.domain.Number"
    NDValue="${bindings.ProcessReport_reportNumber}"/&gt;
    &lt;NamedData NDName="caratWeight" NDType="java.lang.Double"
    NDValue="${bindings.ProcessReport_caratWeight}"/&gt;
    &lt;NamedData NDName="sessionID" NDType="java.lang.String"
    NDValue="${bindings.ProcessReport_sessionID}"/&gt;
    &lt;/methodAction&gt;
    &lt;attributeValues id="reportNumber" IterBinding="variables"&gt;
    &lt;AttrNames&gt;
    &lt;Item Value="ProcessReport_reportNumber"/&gt;
    &lt;/AttrNames&gt;
    &lt;/attributeValues&gt;
    &lt;attributeValues id="caratWeight" IterBinding="variables"&gt;
    &lt;AttrNames&gt;
    &lt;Item Value="ProcessReport_caratWeight"/&gt;
    &lt;/AttrNames&gt;
    &lt;/attributeValues&gt;
    &lt;attributeValues id="sessionID" IterBinding="variables"&gt;
    &lt;AttrNames&gt;
    &lt;Item Value="ProcessReport_sessionID"/&gt;
    &lt;/AttrNames&gt;
    &lt;/attributeValues&gt;
    &lt;/bindings&gt;
    </p>
    On my page I have added an outputText control called sessionID to hold the session ID.
    In my command Button to submit the page I have and action to call a method in my backing bean:
    The code is:
    FacesContext ctx = FacesContext.getCurrentInstance();
    ExternalContext ectx = ctx.getExternalContext();
    HttpSession mySession = (HttpSession) ectx.getSession(false);
    String theSessionID = mySession.getId();
    sessionID.setValue(theSessoinID) // I hope it populates the outputText control and is added to the binding to be passed to the ProcessReport method
    BindingContainer bindings = getBindings();
    OperationBinding operationBinding = bindings.getOperationBinding("ProcessReport");
    Object result = operationBinding.execute();
    if (!operationBinding.getErrors().isEmpty()) {
    return null;
    String resultStr = (String) result;
    return resultStr;
    No luck! I think I should get the sesson ID earlier, when the page loads, but I do not know where to put the code.
    Any suggestions would be appreciated.
    John

    Hi,
    here's what I would do
    1. Create a managed bean as follows
    import javax.faces.context.ExternalContext;
    import javax.faces.context.FacesContext;
    import javax.servlet.http.HttpSession;
    public class HTTPSessionAccessBean {
        public HTTPSessionAccessBean() {
        public void setHttpSessionId(String httpSessionId) {
        public String getHttpSessionId() {
            FacesContext ctx = FacesContext.getCurrentInstance();
            ExternalContext ectx = ctx.getExternalContext();
            HttpSession mySession = (HttpSession) ectx.getSession(false);
            String sessionId = mySession.getId();
            return sessionId;
    }2. In the ApplicationModule Impl class create the following method and expose it as a clientInterface
        public void setSession(String sessionId){
           ((SessionImpl)this.getSession()).getEnvironment().put("http_session",sessionId);
        }3) In the pageDef File create a method binding as
    <methodAction id="setSession"
                      InstanceName="AppModuleDataControl.dataProvider"
                      DataControl="AppModuleDataControl" MethodName="setSession"
                      RequiresUpdateModel="true" Action="999"
                      IsViewObjectMethod="false">
          <NamedData NDName="sessionId"
                     NDValue="${HttpSession.httpSessionId}"
                     NDType="java.lang.String"/>4) In the same pageDef file create an invokeAction
        <invokeAction id="setSessionInAM" Binds="setSession"
                      RefreshCondition="#{!adfFacesContext.postback}"/>The session ID is now accessible from the ApplicationModule as
            Hashtable env = ((SessionImpl)this.getSession()).getEnvironment();
            String sessonId =(String) env.get("session);
            }This maintains the separation of model/view layer
    Frank

  • How to pass a value to a BC4J method from JSP/ADF and get a return value.

    How i can access and application module method from my jsp using JSTL passing a value and hope a return value from BC4J method already exposed using interfase and droped from data control to my jsp page
    Any suggestions ?
    Mensaje editado por:
    mr2k

    Hi,
    Check the size of that Window in which you are displaying this Text of 130 characters.
    May be it is less
    in that case split that string into 2 strings and pass the two strings from ITCSY structure to script and use.
    reward if useful
    regards,
    ANJI

  • How to pass attribute values after ExecuteWithParam to method call

    Hi,
    I am using Jdev 11.1.1.6.
    My use case is that I have mainPage BTF which has ExecuteWithParam as the default activity. This filters the VO using params. I have a requirement to store some of the attributes from current row to pageFlowScope which needs to be passed to multiple child taskflows.
    I can introduce a method call after ExecuteWithParam activity and before the page renders but not sure how should I pass the current row (or something) to this method call to store the values on pageFlowScope.
    What should I pass to this managed bean to store the values on pageFlowScope? Is there any alternative?
    Thanks,
    Jai

    I see two possible ways to get to the attributes. First you can get the iterator current row and get the attributes from there. Second you add attribute bindings to the methods pageDef file for all attributes you are interested in. Then you access them using the attribute binding. I never tested the 2nd method but I guess the framework will fill the attribute bindings like it does in a normal page.
    Sorry, can't give you sample code on this add I'm not in front of a PC.
    Timo

  • Passing enums as arguments within a jni function

    I am trying to pass enum arguments from a Java/JNI function to a C function. For example,
    public native void java_func(enum pname);
    java_jni_func(JNIEnv * env, jobject panel, enum pname)
    c_func(pname);
    where
    c_func(enum pname);
    But I get the error message "illegal use of this type as an expression"
    Any ideas on how I go about solving my problem.

    Hi DavidBray,
    Your task is very simple, you can pass enum value as argument ( do not pay attention to the message above ). You need only to get the name of an enum value in native method. I wrote you a simple example in MS Windows.
    Here is the code in Java:
    package test;
    public class JEnumToJNI {
         static {
              System.loadLibrary("JNIJEnumToJNI");
         public enum JEnum {
             Ok,
             Cancel
         public static void main(String[] args) {
              PrintEnumValue(JEnum.Ok);
              PrintEnumValue(JEnum.Cancel);
         static native void PrintEnumValue(JEnum val);
    }The native method extracts the name of enum value and prints it. This is code of JNI module:
    #define WIN32_LEAN_AND_MEAN
    #include <windows.h>
    #include <stdio.h>
    #include <string>
    #include "test_JEnumToJNI.h"
    using namespace std;
    // Converts jstring to string object
    string jstring2string(JNIEnv *env, jstring js)
        string result;
        long len = env->GetStringUTFLength(js);
        char* p = (char*)malloc(len + 1);
        memset(p, 0, len + 1);
        if(len > 0)
            env->GetStringUTFRegion(js, 0, len, p);
        result = p;
        free(p);
        return result;
    BOOL APIENTRY DllMain( HANDLE hModule,
                           DWORD  ul_reason_for_call,
                           LPVOID lpReserved
        return TRUE;
    JNIEXPORT void JNICALL Java_test_JEnumToJNI_PrintEnumValue(JNIEnv* env, jclass, jobject enumVal)
        // Get enum class
        jclass jclassEnum = env->GetObjectClass(enumVal);
        if(jclassEnum != 0)
             //Get toString() method
            jmethodID toString_ID = env->GetMethodID(jclassEnum, "toString", "()Ljava/lang/String;");
            //Get enumVal name
            jstring jstrEnum = (jstring)env->CallObjectMethod(enumVal, toString_ID);
            fprintf(stdout, "enum value: %s\n", jstring2string(env, jstrEnum).c_str());
            // Delete local references created
            env->DeleteLocalRef(jstrEnum);
            env->DeleteLocalRef(jclassEnum);
        else
            // If jclassEnum == 0 clear Java Exception
            env->ExceptionClear();
    }The header generated with javah.exe
    /* DO NOT EDIT THIS FILE - it is machine generated */
    #include <jni.h>
    /* Header for class test_JEnumToJNI */
    #ifndef _Included_test_JEnumToJNI
    #define _Included_test_JEnumToJNI
    #ifdef __cplusplus
    extern "C" {
    #endif
    * Class:     test_JEnumToJNI
    * Method:    PrintEnumValue
    * Signature: (Ltest/JEnumToJNI/JEnum;)V
    JNIEXPORT void JNICALL Java_test_JEnumToJNI_PrintEnumValue
      (JNIEnv *, jclass, jobject);
    #ifdef __cplusplus
    #endif
    #endifYour task is very simple and you need not to substitute enum values with numbers.

  • How to pass the value of the return type parameters in teststand sequence file programatically through c#

    I have used the method LoadProtoTypeFromMeteDataToken(tokenvalue,options).with this i cant set the value in the return parameters. How can I pass the value.with the above method it displays parameter Name,Type,In/Out. how can i set the value in the return parameters.

    Or here
    http://forums.ni.com/ni/board/message?board.id=330&thread.id=26979
    =s=i=g=n=a=t=u=r=e= Click on the Star and see what happens :-) =s=i=g=n=a=t=u=r=e=

  • Passing array values to methods & Classes

    Hi,
    I have written the following two classes, I want to pass the value from one class - insersortest to the other class what kind of return statement do I do ? I am not sure what does this Comparable object do in this program ? I am trying the program (algorithm specfieid) from one of the Data Structure book.
    import java.io.*;
    import java.lang.*;
    public class Insersortest
    public static void main(String args[]) throws IOException
    Insersort ghl = new Insersort();
              Comparable a[] = {1, 3, 5, 9, 1};          
                   System.out.println("Detecting duplicates"+ ghl.insertA(a));               
    -=-=-=-
    class Insersort
    public static int insertA( Comparable [ ] a )
    for( int p = 1; p < a.length; p++ )
    Comparable tmp = a[ p ];
    int j = p;
    for( ; j > 0 && tmp.compareTo( a[ j - 1 ] ) < 0; j-- )
    a[ j ] = a[ j - 1 ];
    a[ j ] = tmp;
    Could somebody provide their view please.
    PK

    You return arrays just like any object:
    public Object[] getArray()Comparable is an interface. Any object that implements Comparable (and can therefore be stored in a Comparable's reference) is guarenteed to have a compareTo method.
    Does that help?

  • Please Help !!!How to pass variable defined in Event Listener Method outside it.

    Hi, everybody
    I have 3-4 swf those i want to load one after another like a slideshow.What i  want to do is get the total frames of loaded swf and want to pass that value to Timer object's delay parameter.  i have converted total frames to milliseconds so i can use it in timer constructor. But i am not getting the value of that variable outside of my Event.COMPLETE listener method. Here is my code what i have done, Please have a look and guide me what i am missing.
    var fr = stage.frameRate;
    var m:MovieClip = new MovieClip();
    var ms;
    var swf:XML =
                       <swfs>
                                 <swf filename="1.swf"/>
                            <swf filename="2.swf"/>
                            <swf filename="3.swf"/>
                    </swfs>;
    import flash.display.*;
    import flash.net.URLRequest;
    function loadSwf(num)
       var ldr:Loader = new Loader();
        var url:String = swf.swf[num].attribute("filename");
        var urlReq:URLRequest = new URLRequest(url);
        ldr.load(urlReq);
       ldr.loaderInfo.addEventListener(Event.COMPLETE, onC);
    function onC(e:Event):void
       var m:MovieClip = e.target.content as MovieClip;
       ms = m.totalFrames/fr;
       ms = ms * 1000;
    var timer:Timer = new Timer(ms);
    timer.addEventListener(TimerEvent.TIMER, onT);
    function onT(e:TimerEvent)

    Hi Ned,
    Thanks for your reply. i want to call loadSwf method in timerEvent. My aim is to load next swf movie after playhead play all frames of loaded swf. I hope you are getting my point. My aim is to play a slide show of swfs with not equal interval but after completion of each swf's animation, those total frames may differ. Am i going right or if you can suggest me a  better way then please tell me.

  • How To Pass A Value Read By A Loop To Main Method

    Hey everybody,
    I'm at this with my code.I'm reading the values of a text file in a loop.I want to pass these values to main method.The importhant point is I want to do this without using a field. The code is below. Thanks.
    //Main
    public static void main(String[] args)throws FileNotFoundException
              DoubleClass AvgScore=new DoubleClass();
    IntClass Messenger=new IntClass();
              PrintWriter writer1=new PrintWriter("D:\\JavaExercises\\CH07EX14out.txt");
              Scanner scan1=new Scanner(new FileReader("D:\\JavaExercises\\CH07EX14data.txt"));
         //1 ogrencinin notlarini okut ve ortalamas&#305;n&#305; hesaplat
         while(scan1.hasNext())
              writer1.print(scan1.next()+" ");
    calcAvg(AvgScore,scan1,Messenger);
    //AvgScore formatlanarak yazdirilacak
    writer1.print(""+AvgScore+" ");
    writer1.print(""+calcGrade(AvgScore)+"\n");
    writer1.close();
    //calcAvg
    public static void calcAvg(DoubleClass x,Scanner y,IntClass z)
         int counter=0;
         double TotalScore=0;
    int NumTests=1;
    int Score=0;
    //Bir ogrenci icin toplam notu ve test sayisini bul.
         while(counter<=4)
              Score=y.nextInt();
    TotalScore+=Score;
    counter++;
    NumTests++;
    //Bir ogrenci icin not ortalamsi bul.
    x.setNum(TotalScore/NumTests);
              }

    Malkavian187 wrote:
    Guys please pay attention,
    I already said I can't use a field(class scoped variable)and can't use a return type method.
    I ve heard that it can be done by passing a reference or primitive variable to my calcAvg method.And than assignin the read values back to this variable.
    But I can't figure out how to make it. I need a complete solution.Including modifications to calcAvg and main method.
    Take care,Malkavian187,
    Maybe you haven't seen other posters asking homework to be done for them, so here is basically what we tell them: DO IT YOURSELF.
    And we realize that very possibly you could fail your class from that and have to drop out. This may be a good thing because it will help keep the demand for technical workers up, and thus, keep the pay high.
    On the other hand, if you choose to actually do the assignment then we will be happy to give comments on your code. Please post it when you have some and until then, best wishes with what ever you choose to do.
    BTW: the solution you allude to requires a field also... and in reality, you already gave the answer--just implement it. If you do not know how: well, maybe you should do one of the following:
    1-read and study the Java Tutorial
    2-pay more attention to class
    3-read your textbook for your class
    4-go to class
    5-stay awake in class
    6-pay attention in class
    7-talk to your teacher
    8-withdraw from the class
    9-change your major

  • In BADi , How to pass the values between two Method

    Hi Experts,
    We have two methods in BADis. How to pass the value  between two Methods. Can you guys explain me out with one example...
    Thanks & Regards,
    Sivakumar S

    Hi Sivakumar!
    Create a function group.
    Define global data (there is a similiar menu point to jump to the top include).
    Create one or two function modules, with which you can read and write the global data.
    In your BADI methods you can access the global data with help of your function modules. It will stay in memory through the whole transaction.
    Regards,
    Christian

  • Pass returning value of get methods to a FM

    Hi experts,
    I got a getter method, that returns a class value via RETURNING. Is it possible to call a FM and pass the returned parameter directly to an importing value of the FM?
    e.g.
    CALL FUNCTION 'MY_FM'
        EXPORTING
          test     = my_class->get_my_value( ).
    this doesn't work.
    Isn't there a way to do this besides assigning the return parameter to a temporary variable and pass this one to the FM?
    Thanks in advance.
    Regards,
    Tobi

    Hi,
       Though this is not possible syntactically, there is one workaround.
    Its not exactly what we want but just a thought.
    You can create Public static attribute and mark it as Read only.
    then you can pass the value of it directly using the classname=>attribute name.
    I know its not exactly what you want but servers most of the purpose.
    Regards,
    Sesh

  • Passing values between forms!  Help please!!!!

    I'm stuck. I don't know how to pass a value from one form to the other, and automate a task. For example, I created form1 and from that form1 I want to pass a value to form2...then I want in form2 to query the form2 so it will bring up the complete record of the new value.
    I thought if i used javascript code below it would work but I kept getting that some variable were undifined
    Form_name.Name_of_input_box.value
    that would give me the value of the inputbox. But when i tried doing this...my Form_name was undefined? How do i get the actual name of the form?(i looked that source code when the form was generated but the form name it provides is incorrect or im reading it wrong)
    Please any help or comments are greatly appreciated

    I worked out an example for you:
    Form1 is a form on scott.dept
    Form2 is a form on scott.emp
    When you enter a value for deptno and click on next, it brings up Form2 with the values.
    Follow these steps:
    1. Create a new button in Form1. Call it NEXT.
    2. Select 'Custom' for the PL/SQL button event handler and enter this code:
    declare
    l_deptno number;
    l_url varchar2(2000);
    begin
    l_deptno := p_session.get_value_as_number(p_block_name=>'DEFAULT', p_attribute_name => 'A_DEPTNO');
    l_url := '<portal_schema>.wwa_app_module.link?p_arg_names=_moduleid&p_arg_values=<module_id of form2>&p_arg_names=deptno&p_arg_values='||l_deptno||'&p_arg_names=_deptno_cond&p_arg_values='||<portal_schema>.wwv_standard_util.url_encode('=');
    <portal_schema>.wwa_app_module.set_target(l_url, 'CALL');
    end;
    Thats it!!
    Run the form, enter some value for deptno and click "next".
    You'll see the first employee in the dept 10 in Form2

  • How to pass a value to the export parameter for a method (public instance)?

    Hello,
      I am trying ABAP OO newly. How to pass a value to the export parameter for a method (public instance) called in a report? This *export parameter has a reference type of structure.
    Thanks in advance,
    Ranjini

    Hi,
    "class definition
    class lcl... definition.
      public section.
        method m1 imporitng par type ref to data.  "now you can pass any reference to the method, but this way you have to maintain this reference dynamically inside the method (you can't be sure what that reference is really "pointing" at)
    endclass.
    "in program
    data: r_lcl type ref to lcl...
    create object r_lcl.
    call method r_lcl
      exporting
         par    =  "pass any reference variable here
    Regards
    Marcin

  • Enums with common method implementation.

    Working with JDK 1.4 , i had some typesafe enums with common methods in an abstract class. Because of some issues, i want to migrate them to 'enums' provided in JDK 5.
    As enum provided in JDK 5 can neither be extended or derived from any other class, i am unable to achieve my objective.
    Is there any way out, or should i continue to live with my old code?
    Thanks,
    Prabhaker

    Well, there's always this ugly pretend-you-have-multiple-inheritance sort of construct:
    public class CommonEnumUtilities
        // the following method is the actual implementation of method foo
        public static void foo(Enum e, Object... otherParams)
    public interface CommonEnumInterface
        // the following ensures that you have the method foo
        public void foo(Object... otherParams);
    public enum SomeEnum implements CommonEnumInterface
        public void foo(Object... otherParams)
            CommonEnumUtilities.foo(this, otherParams);
    }I personally find this approach revolting, but I guess it's better than nothing.

  • Please go through the code, is it pass by value?

    Can any one explain me the diff between call by value and call by reference in Subroutines.
    ex :
    PERFORM ADD_Z1CLASS1 USING LW_MARA-MATNR
                             CHANGING IDOC_DATA[].
    FORM ADD_Z1CLASS1 USING    PV_MATNR TYPE MATNR
                     CHANGING PT_EDIDD TYPE EDIDD_TT.
    Please let me know, if the above code is call by value or call by reference...?
    Any suggestions will be appreciated!
    Regards,
    Kittu

    hi,
    using             --  Pass by reference
    changing        --  Pass by reference
    using value()   --  Pass by value
    changing value( )--  Pass by value and result
    The main difference between the pass by value and pass by reference is that " In pass by value the actual parameters are not changed while in pass by reference those are changed".
    By reference Passes a pointer to the original memory location.  Very efficient
    By value Allocates a new memory location for use within the subroutine. The memory is freed when the subroutine ends.  Prevents changes to passed variable
    By value and result Similar to pass by value, but the contents of the new memory is copied back into the original memory before returning.  Allows changes and allows a rollback .
    Go through the following eg:
    pass by ref:
    data f1 value 'A'.
    perform s1 using f1.
    write / f1.
    form s1 using p1.
         p1 = 'X'.
         endform.
    o/p is X
    using and changing Are Identical in Function
      report ztx1805.
      data: f1 value 'A',
            f2 value 'B'.
      write: / f1, f2.
      perform s1 using f1
                 changing f2.
      write: / f1, f2.
    form s1 using p1
             changing p2.
         p1 = p2 = 'X'.
         endform.
    o/p : A B
           X X
    Pass by value:
    data: f1 value 'A'.
      perform s1 using f1.
      write / f1.
      form s1 using value(p1).
          p1 = 'X'.
          write / p1.
         endform.
    o/p is X
            A
    Hope this is clear.
    so the code which you have pasted comes under pass by reference.
    Reward points if helpful.
    Thanks and regards.

Maybe you are looking for