XPath array indexing

I am trying to use the XPATH expression builder to iterate thru a array of strings and concatenate them into one single string field. I have top level element called "counter" which has a array of element "approvers" which in turn contains the string approver. I need to concatenate all the approvers in to one field. I am able to get the count by using
count(bpmn:getDataObject('counter')/approvers)
I do not know how to write the looping logic to iterate thru the array and pick out the string value for each of the index. Can some one please help me or point to any tutorials.

I think you might be able to use the oraext:create-delimited-string function for this.
Refer to the docs for usage:
http://download.oracle.com/docs/cd/E14571_01/integration.1111/e10224/bp_appx_functs.htm#BEIGJJHD
http://download.oracle.com/docs/cd/E14571_01/integration.1111/e10224/bp_xslt_mpr.htm
If that doesn't work, you could use an XSL transformation instead of XPath. There you would just use an xsl:for-each loop to iterate over the array then call concat within the loop to build your string.
Keep in mind that array indices in xpath start at 1, not 0.
Edited by: Mike Rokitka on Aug 9, 2010 8:36 AM

Similar Messages

  • Web Analysis report error : Array Index out of range :1

    while running from workspace , below error is being thrown after making few changes to the layout (e.g. moving Measures from Page to Row ) though Design for HTML setting applied.
    Array Index out of range :1
    These reports are running well in WA studio.
    Can any one advise on this please.

    Array index out of range: 1The only time you will get that error is when you are accessing an elements index that is not present in the actual indexes in that array

  • Error opening web analysis report in workspace: Array index out of range:2

    I am able to view this report in web analysis studio with no errors..Its only when I go to workspace and open report do I get following error: Array index out of range:2.
    Any suggestions?

    Have you tried checking the "Design for HTML" from the Edit toolbar to see if you get any error when saving?
    Do you have any advanced items on the report, as there are 4 types of differences between Studio and HTML:
    - font differences, Workspace (DHTML) uses the WA Server fonts whereas WA Studio client machine fonts.
    - Service Buttons are very restricted using Workspace
    - Display: Tab selection, Splitter panels, Slider selection do not render in Workspace
    - Cannot restrict WA Tools menu in Workspace at all, where you can in the Studio.
    For exact details check out the Hyperion Web Analysis Studio User’s Guide from the Doc Library:
    http://download.oracle.com/docs/cd/E10530_01/doc/nav/portal_4.htm

  • Tons of ieq/add/or instructions for array indexing in pixel shader loop (D3D 11.0, PS model 5.0)

    First of all, I have to apologize for the long code samples, but their content is not so important, I just wanted to give as much info as I can. Besides they are really simple and I tried to comment as much as possible.
    I'm working on a pixel shader doing deferred lighting of the frame (Direct3D feature level 11.0, PS
    model 5.0, IDE - Visual Studio 2013, OS - Windows 8.1 x64). I noticed some huge FPS drops when I add light sources to the scene, and the more sources I add, the bigger performance impact is. After many hours
    of trying to find the problem, experimenting and checking compiled pixel shader ASM's, I found out that at some moment after I comment / uncomment some lines (or event line) my output ASM changes dramatically. I won't put here all the code, of course, but
    here's simplified part of the point lighting in HLSL, so you could imagine the structure of the lighting algorithm:
    // Total amount of color that pixel receives from all the point light sources.
    float3 totalPointLightColor = { 0.0f, 0.0f, 0.0f };
    // Loop through the active light sources.
    [loop] for (uint i = 0; i < g_scene.pointLightCount; i++)
    // xyz - vector from light source to pixel.
    // w - the length of that vector.
    float4 fromLightToPixel;
    fromLightToPixel.xyz = worldPos - g_pointLights[i].position.xyz;
    fromLightToPixel.w = length(fromLightToPixel.xyz);
    // Check max light distance here (skip pixel if it is too far).
    if (fromLightToPixel.w > g_pointLights[i].farZ)
    continue;
    // Normalize direction vector.
    fromLightToPixel.xyz = normalize(fromLightToPixel.xyz);
    // Angle between the pixel normal and light direction.
    float lightIntensity = saturate(dot(normal, -fromLightToPixel.xyz));
    // Check that light comes not from behind of the pixel surface.
    if (lightIntensity <= 0.0f)
    continue;
    // If light casts shadows, process shadow map and get amount of light the pixel receives.
    // THIS LINE IS MENTIONED IN MY QUESTION BELOW.
    if (g_pointLights[i].shadowMapIndex >= 0)
    // Here was shadow map check, but I removed it and nothing really changed - the problem remained even with no code here.
    // Calculate the amount of light at the pixel from distance and angle and modify intensity.
    lightIntensity *= g_pointLights[i].brightness / (fromLightToPixel.w * fromLightToPixel.w);
    // Add this light's color to the total amount of light the pixel receives from point lights.
    totalPointLightColor += lightIntensity * g_pointLights[i].color.rgb;
    I compile shaders with D3DCompileFromFile() method, using the following flags:
    shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_DEBUG
    | D3DCOMPILE_SKIP_OPTIMIZATION | D3DCOMPILE_PREFER_FLOW_CONTROL;
    I tried to compile in release config with the following flags:
    shaderFlags = D3DCOMPILE_ENABLE_STRICTNESS | D3DCOMPILE_OPTIMIZATION_LEVEL3;
    But nothing seriously changes - only a couple less ASM instructions here and there, the main problem still remained. I should add that I have zero to none knowledge of ASM, and understand what's happening mostly thanks to comments Visual Studio / FXC generates
    in debug compilation mode.
    So, when I compile my whole deferred shader (including the part above), I get
    414 instructions in ASM, and performance is fine. If I uncomment only 1 line with CAPSED comment in the section above (which actually does nothing, as you can see), I get
    476 instructions, and I get huge FPS hiccups. When I check output ASM code, I can clearly see, that the line I uncommented produces no code in ASM at all, but somehow it makes many parts of compiled shader to change.
    For example, the loop above with commented line looks like the following in ASM:
    # Loop starts.
    loop
    # Loop index check and increment, as I can understand.
    uge r6.w, r5.w, cb0[1].x
    breakc_nz r6.w
    imul null, r6.w, r5.w, l(3)
    # Calculate <fromLightToPixel>.
    # cb6 - constant buffer that stores point lights.
    # Array access is done simply via [] operator.
    add r10.xyz, r3.xyzx, -cb6[r6.w + 1].xyzx
    dp3 r7.w, r10.xyzx, r10.xyzx
    sqrt r8.w, r7.w
    # Distance check.
    lt r8.w, cb6[r6.w + 1].w, r8.w
    if_nz r8.w
    iadd r8.w, r5.w, l(1)
    mov r5.w, r8.w
    continue
    endif
    # Normalization.
    rsq r8.w, r7.w
    mul r10.xyz, r8.wwww, r10.xyzx
    # Calculate <lightIntensity>.
    dp3_sat r8.w, r1.xywx, -r10.xyzx
    # Check <lightIntensity>.
    ge r9.w, l(0.000000), r8.w
    if_nz r9.w
    iadd r9.w, r5.w, l(1) // r9.w <- i
    mov r5.w, r9.w // r5.w <- i
    continue
    endif
    # Update <lightIntensity>. Note [] operator.
    div r7.w, cb6[r6.w + 0].w, r7.w
    mul r7.w, r7.w, r8.w
    # etc.
    endloop
    When I
    uncomment that 1 line, the ASM is growing heavily (by 62 instructions!), and this is how it starts to look like:
    # Loop starts.
    loop
    # Loop index check, but no <imul> instruction, why?
    uge r6.w, r5.w, cb0[1].x
    breakc_nz r6.w
    # Here comes some new code...
    # Indices are obviously related to the size of the point lights' constant buffer (16 elements).
    ieq r10.xyzw, r5.wwww, l(0, 1, 2, 3)
    ieq r11.xyzw, r5.wwww, l(4, 5, 6, 7)
    ieq r12.xyzw, r5.wwww, l(8, 9, 10, 11)
    ieq r13.xyzw, r5.wwww, l(12, 13, 14, 15)
    # And this part is also new...
    and r14.xyzw, r10.xxxx, cb6[1].xyzw
    and r15.xyzw, r10.yyyy, cb6[4].xyzw
    or r14.xyzw, r14.xyzw, r15.xyzw
    and r15.xyzw, r10.zzzz, cb6[7].xyzw
    or r14.xyzw, r14.xyzw, r15.xyzw
    # 26 more lines of such and/or pairs.
    # Calculate <fromLightToPixel> - finally! Why so much code instead of simple [] operator?
    add r14.xyz, r3.xyzx, -r14.xyzx
    dp3 r6.w, r14.xyzx, r14.xyzx
    sqrt r7.w, r6.w
    # Distance check.
    lt r7.w, r14.w, r7.w
    if_nz r7.w
    iadd r7.w, r5.w, l(1)
    mov r5.w, r7.w
    continue
    endif
    # Normalization.
    rsq r7.w, r6.w
    mul r14.xyz, r7.wwww, r14.xyzx
    # Calculate <lightIntensity>.
    dp3_sat r7.w, r1.xywx, -r14.xyzx
    # Check <lightIntensity>.
    ge r8.w, l(0.000000), r7.w
    if_nz r8.w
    iadd r8.w, r5.w, l(1)
    mov r5.w, r8.w
    continue
    endif
    # Here we go again - more code!
    and r15.xyzw, r10.xxxx, cb6[0].wxyz
    and r16.xyzw, r10.yyyy, cb6[3].wxyz
    or r15.xyzw, r15.xyzw, r16.xyzw
    and r16.xyzw, r10.zzzz, cb6[6].wxyz
    or r15.xyzw, r15.xyzw, r16.xyzw
    # 26 more lines of such and/or pairs.
    # Update <lightIntensity> - finally! Why no [] operator here, but tons of those instructions?
    div r6.w, r10.x, r6.w
    mul r6.w, r6.w, r7.w
    # etc.
    endloop
    I tried to save current array element to temp variable at the beginning of the loop, but it makes no difference - only several more instructions are added to copy the data.
    I just can't understand, why in the first case loop is translated into such small and logic code where array access is done via single
    [] operator, but in the second one it expands to such enormous bunch of instructions? And I change only 1 line of code, nothing more (and that line does nothing actually - it even has no ASM representation)! But every array access seems to
    be affected with this change.
    Can someone please explain that to me? Is there some sort of tricks with array indexing or loops in HLSL? I tried to find something about it on the Internet to no avail. Seems like I miss something very simple and obvious, but I don't get it. Sadly I
    work mostly alone by now and know nobody familiar with ASM / HLSL / Direct3D. Answering this question on another popular developer resource brought no result.
    Big thanks in advance for any tips or explanations!

    The latest version may help with this. 11.9.900.170 is now a step back.
    12.0.0.38  is here: http://get.adobe.com/flashplayer/
    or download the FULL installer here: Flash Player 12 (Mac OS X)

  • Can't store new target Array index out of range: 1 - SLD Configuration

    Hello ,
    Issue is regarding SLD configuration , We have ABAP + Java Addin on Suse Linux x86 ( 64 bit ) with Oracle 9.x .
    Java instalaltion competed succesfully , J2EE is up and runnung while configuring SLD , Data Supplier Bridge - Configure the data supplier bridge - Update SLDs
    As I set Update local SLD (sld/active) to true it gives error : Can't store new target Array index out of range: 1
    ( Error recorded in default.trace ,
    #1.5#001635052D79005D000000010000393A00041904004A592B#1153404882278#com.sap.engine.library.monitor.mapping.ccms.Trace##com.sap.engine.library.monitor.mapping.ccms.Trace######87587b2017f911dbc661001635052d79#SAPEngine_System_Thread[impl:5]_82##0#0#Error##Plain###RegisterNode</Services/Web Services/Requests Number/sap.com/com.sap.engine.heartbeat/GRMGWSTest/CurrentClient>: com.sap.mona.api.JMonException: com.sap.mona.api.JMonAPIException: Internal error in tree structure#
    #1.5#001635052D790049000000060000393A000419040226E9F1#1153404913510#com.sap.lcr.sagent.BuilderDirector#sap.com/com.sap.lcr#com.sap.lcr.sagent.BuilderDirector#J2EE_ADMIN#317####29009b1017fa11db96bd001635052d79#SAPEngine_Application_Thread[impl:3]_14##0#0#Error#1#/Applications/SLD#Plain###Can't access http store#
    #1.5#001635052D790049000000070000393A000419040226EA90#1153404913511#com.sap.lcr.sagent.BuilderDirector#sap.com/com.sap.lcr#com.sap.lcr.sagent.BuilderDirector#J2EE_ADMIN#317####29009b1017fa11db96bd001635052d79#SAPEngine_Application_Thread[impl:3]_14##0#0#Error##Plain###Thrown:
    com.sap.lcr.api.cimclient.LcrException: java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 1
    I have already through updated Component Repository – SAP Note : 669669 . 
    Regards ,
    Santosh

    Hi,
    I am having exactly the same issue. Would you please advise what the solution was?
    Thanks,
    Murad.

  • Array Index out of bound exception

    public Name[] getName() {
              Name[] retVal = new Name[0];
              retVal[0] = this.getNameInstance();
              return retVal;
         public void setName(Name[] theName) {
              theName[0]=this.getNameInstance();
         private Name myNameInstance = new Name();
         public void setNameInstance(Name theNameInstance) {
              if(isValidName(theNameInstance)){
              myNameInstance = theNameInstance;
         public Name getNameInstance() {
              return myNameInstance;
         }I am getting an array Index out of bound eception in the method setName, Can any one tell me where I am doing wrong?

    The array passed in must be empty. I suggest using the debugger for problems like these. If you don't know how to use the debugger, here's a start:
    (Assuming you have a debugger, any IDE you'd be using will)
    1. Set a breakpoint on or before your line of question. In this case, place it on the line of code in your setName() method. Set a breakpoint by either right clicking on that line and selecting "Add breakpoint," or simply click on the far left side of the editor window, right next to the line number. Either way, a little dot will appear to mark the breakpoint.
    2. Execute your code in Debug mode rather than release mode. This might mean clicking on the little bug-looking icon "Debug" rather than "Run."
    3. Your code will execute and you'll enter the debug perspective when that breakpoint is reached. There, in the variables window, you'll see your array and any information about it, particularly its size and contents.

  • An unexpected 'invalid property array index' error occured in wdbrlog

    Hi experts,
    My system is :
    SAP_BW 7.0 Path  0012
    SAP GUI Final Release Patch 24
    In my query definition, I right-click on one of the characteristics..Eg. Posting Date --> Properties --> Change 'Suppress Results Rows' option from "Never" to "Always". --> Press OK.
    Then I get this pop-up with error message:
    <u>Program Error Intercepted
    An unexpected 'invalid property array index' error occured in wdbrlog.
    1 error(s) are logged.</u>
    If I say continue, it kicks me out of BeX. I need to re-login to do the stuff.
    I find some information, but i dont know what happens.
    Did anyone get the similar error?
    Thanks,
    Marc

    <FONT FACE = "Tahoma", Font Color = "Blue">
    Hi
    <Br>
    I am afraid you may have to re-install your SAP GUI and Business Explorer.
    <Br><Br>Hope it helps.
    <Br>
    <Br>
    Cheers
    Abhijit
    <Br>* Removed
    </FONT>

  • Data Collection to Word Report array indexing

    Hi guys,
    Just need a bit of help deciding if I am measuring what i'm supposed to be. I'm trying to write the code for an automated collection of results, before i get the equipment to do it.
    Basically, I will have 3 voltages going into analog inputs and one digital input going into my DAQ.
    Two of the analog inputs need a single voltage recorded every minute for a hour. (at the minute i think my code samples one voltage every half second for 5 seconds, but i can easily change the timings of the loop) 
    Does the array indexing i'm using seperate the voltages read from each channel -  ie does the top index array (index 0) read the voltage from aI0? 
    By enabling indexing at the edge of the for loop i think i'm passing the single voltage (from each channel) read every loop iteration into the report graph, am i?
    Any help would be most appreciated
    Thanks,
    Christian
    p.s. This thread contains the whole problem i am trying to solve: http://forums.ni.com/t5/LabVIEW/Multiple-analog-inputs-performing-different-tasks/m-p/1163471#M50845...
    p.s. I realise i have posted this question in another thread already, but i did that by mistake!
    "If anyone needs me, I'll be in the Angry Dome!"
    Attachments:
    DAQ to report.vi ‏183 KB

    Hi,
    The task description is very confusing.
    - Why you use update mode Delete All? -- Why not delete uploaded data or Overwrite? -- incoming data are already discriminating by the cons unit, where is overlapping?
    - Why you need to add a new characteristic to the selection of target like company? You have a ConsUnit, an Investee unit etc. Why a new char?

  • Can I call a function using array index?

    I've defined an array which stores the function name, like this:
    var aresetButtonTop:Array = new Array(resetTop1,resetTop2,resetTop3,resetTop4,resetTop5);  
    Then I have a button named"btnresetTop" which when clicked will call one of the five functions stored in the above array(aresetButtonTop). The functions are called at run-time depending upon some conditions. I need to figure out how I can call those functions using the array index. I'm using the following code to call the function. The value of i has been already calculated.
    btnresetTop.addEventListener(MouseEvent.CLICK, aresetButtonTop[i]);
    After doing this I'm getting the following error when I click the button:
    TypeError: Error #2007: Parameter listener must be non-null.
        at flash.events::EventDispatcher/addEventListener()
        at gallerytest_fla::MainTimeline/thumbTopClick()
    Note: thumbTopClick() is a function inside which all these codes are written.
    I need to find out whether it is posible in AS3 to call a function name using the array index or not. If yes, could you pleas ehelp me out.

    Thanx Andrei1, you were right, i was out of range.The value of i will obviously expire outside the for loop. Now I have corrected my mistake by assigning the value of i to a variable index inside the for loop and then use the following code:
    btnresetTop.addEventListener(MouseEvent.CLICK, aresetButtonTop[index])
    It was a silly mistake but I was not able to figure it out for the last 2 hours. Thanks once again for your help

  • Change array index font size using VI scripting

    Hello All,
                         I have a array control in my front panel, I'm wondering is there any way to change that "array index" font size using VI scripting?
    Example:
    1. I have this array
    2. Manually I have changed the font size of the array in "Selection Font" panel as below
    3. Through VI scripting I'm able to control control font size, label font size.,.. But not the index font size. So it looks odd.
    4. I'm expecting to be modify this array as same as picture 1 through VI scripting.
    Note: It may not have any practical application, but some time it will be helpful for the programmers to make a quick drop. If anybody have any idea, please share.
    <Electro Sam>
    ELECTRO SAM
    For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
    - John 3:16

    Raven - you are right, Actually I'm looking for options to change the font size of the array index.
    Actually we have coding standard to follow. In that, all the front panel controls needs to be in Font size 14 and the size should be 25X120, so I'm trying to write a code which automatically converts the VI FP control sizes to be in standard size.
    I'm not only using one customer VI, I'm handling various customer VIs, so each one VI FP control sizes are different. So I'm developing this utility to standardize the VI's as per the guidelines we have.
    Except this array index most of the VI FP control elements I have handled, Only this array is troubling me.
    Appreciate your support guys, please share your thoughts.
    <ElectroSam>
    ELECTRO SAM
    For God so loved the world that he gave his one and only Son, that whoever believes in him shall not perish but have eternal life.
    - John 3:16

  • Array index out of range error in PCR!

    Hi All,
    I am trying to test the PCR forms in MSS in portal.
    When I click the "Edit Form" button in step 2, I am getting the following error.
    "java.lang.ArrayIndexOutOfBoundsException: Array index out of range: -1"
    I tried all the forms(Change Emp Group/SubGroup, Change Emp Sub Area,...).
    I am getting the same error.
    What could be the reason for this error?
    How do I resolve it?
    Thanks
    Sundar

    Hi Siva,
    I am getting below error code.
    It looks like what you said.
    java.lang.ArrayIndexOutOfBoundsException
         at com.sap.mw.jco.JCO$MetaData.getType(JCO.java:10210)
         at com.sap.aii.proxy.framework.core.JcoBaseTypeData.setElementValue(JcoBaseTypeData.java:828)
         at com.sap.tc.webdynpro.modelimpl.dynamicrfc.DynamicRFCModelClass.setAttributeValueAsBoolean(DynamicRFCModelClass.java:527)
         at com.sap.pcui_gp.isr.isrprocessevent.model.Isr_Get_Form_Url_Input.setI_Append_Cache_Info(Isr_Get_Form_Url_Input.java:162)
         at com.sap.pcui_gp.isr.isrprocessevent.FcISRProcessEvent.callRFCIsrGetFormUrl(FcISRProcessEvent.java:1029)
         at com.sap.pcui_gp.isr.isrprocessevent.FcISRProcessEvent.setTemplateSource(FcISRProcessEvent.java:459)
         at com.sap.pcui_gp.isr.isrprocessevent.FcISRProcessEvent.callRFCIsrProcessEvent(FcISRProcessEvent.java:798)
         at com.sap.pcui_gp.isr.isrprocessevent.FcISRProcessEvent.callIsrProcessEvent(FcISRProcessEvent.java:380)
    Thanks
    Sundar

  • Fusion Security, SearchResponse next returning array index out of bound

    I am trying to fetch all the roles under a search base and while iterating i am getting array index out of bound exception.
    SimpleSearchFilter filter=store.getSimpleSearchFilter(RoleProfile.NAME,SimpleSearchFilter.TYPE_EQUAL,null);
    String wildCardChar=filter.getWildCardChar();
    filter.setValue(wildCardChar);
    SearchParameters parameters=new SearchParameters(filter,SearchParameters.SEARCH_ROLES_ONLY) ;
    SearchResponse resp=store.searchRoles(Role.SCOPE_ANY, parameters);
    +while(resp.hasNext()){+
    Role role=(Role)resp.next();
    Can anybody kindly advise

    Hi..
    check this
    http://andrejusb.blogspot.com/2011/01/fusion-middleware-11g-security-retrieve.htmlhope this will helpful

  • Array index out of bounds

    I have in my code a method, proceed(), and in the method main, which i called.
    however, the error msg:
    java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0
    could someone please tell me what is wrong with my code?
    // in the code, 2 arrays (keeping the contents and the count are
    //declared
    public static boolean proceed(String[] data, int[] count, int count_c){
    for(int i=0; i<21; i++){
    if ((data[i] == null) || (count[i] != count[i+1])){
    return false;
    if (count_c != count[21] && data[21] == null)
    return false;
    else
    return true;
    public static void main(String[] args){
    Vector v=new Vector();
    //... do something...
    if(proceed(array, count, count_c)){
    cell.setParameters(0, "cellid", array[0])
    cell.setParameters(1, "sac", array[1]);                
         cell.setParameters(21,"tmr_cspu", array[21]);
    v.add(cell);
    count_c++;
    temp[0] = ((OneCell)v.get(0)).printParameters()[0];
    error     -->     java.lang.ArrayIndexOutOfBoundsException: Array index out of range: 0

    sorry, i hope that this is better now. thanks for your comment.
    in the code, 2 arrays (keeping the contents and the count) are declared
    temp is also an array of size 23
    i believe that the problem lies with the method proceedsince the method setParameters is correct...
    i hope that my question is now clearer. thx for the trouble taken to answer me...
    public static boolean proceed(String[] data, int[] count, int count_c){
        for(int i=0; i<21; i++){
            if ((data == null) || (count != count[i+1])){
                return false;
        if (count_c != count[21] && data[21] == null)
            return false;
        else
            return true;
    public static void main(String[] args){
        Vector v=new Vector();
        //... do something...
        if(proceed(array, count, count_c)){
            cell.setParameters(0, "cellid", array[0])
            cell.setParameters(1, "sac", array[1]);
            cell.setParameters(21,"tmr_cspu", array[21]);
            v.add(cell);
            count_c++;
        temp[0] = ((OneCell)v.get(0)).printParameters()[0];

  • 2-D array indexing

    So, I'm having trouble getting this simple 2-D array vi to work the the way I think it should. The vi is taken from a larger one that I'm writing to provide motion control signals to a 3-axis stepper motor position stage. In the vi, the data being written to the array element in the for loop is to be the sensed positon value from one of the stepper motors.
    How this vi is working is that upon exiting the for loop, only the final element in row 0 has been updated, as opposed to each element in row zero, which is what I'm after.
    What am I doing wrong?
    Solved!
    Go to Solution.
    Attachments:
    array index.jpg ‏55 KB

    Message Edited by Root Canal on 10-16-2008 10:41 AM
    Message Edited by Root Canal on 10-16-2008 10:42 AM
    global variables make robots angry
    Attachments:
    use shift registers.vi ‏7 KB
    use shift registers.PNG ‏4 KB

  • Using Enum as Array Index

    Hi Experts,
    Can you please suggest whether it 's possible to use a Enum as an array index in java? In C++, I can define a enum and use the enum as the array index. But, for some reason, I 've not been able to do so in Java. Can anyone please help me in achieving this.
    Enum Index{indexOne, index2 ....};
    Index ind;
    and I should be able to use this for any array as an index:
    String s = stringArray[ind.indexOne];
    Is this possible in java? Please suggest.
    Thanks,
    Ganapathi

    Hi - the originator of this question has probably found a good answer to this question, but in case anyone else trips on this along the way:
    The oridinal() method can be used. Then spinning through the enumerated types, feels a little more like C.
    http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Enum.html
    If it helps to see an example, here's one that follows from an exercise from the Sun tutorial dealing with representing a deck of playing cards. aCard is defined as a two dimensional array (suit, rank) with the suit and rank values defined as enums and used to represent a full deck of cards. A new Card class instance is generated and assigned to the array of cards (i.e. the deck of cards made up of instances of Cards, each named aCard).
    The part to look at is simply the use of ordinal() to reference array positions.
    private Card[][] aCard = new Card[NUM_SUITS][NUM_RANKS];
    suitLoop:
    for (Suit s: Suit.values()) {
    rankLoop:
    for (Rank r: Rank.values()) {
    aCard[s.ordinal()][r.ordinal()] = new Card(s, r);
    }

Maybe you are looking for