Determining the number of elements defined in an enum

Hello,
I have an enum and I want to determine the number of elements (constants) defined in this enum by source code. I know I can use reflection but I just want to know if there's an easier way.
Thank you very much.

Hey JavaWisdom,
You can use the ordinal method. I made a simple example to demonstrate.
public class NumberOfEnums {
     public static enum Enumeration {
          item1, item2, item3, item4
     public void count() {
          Enumeration[] values = Enumeration.values();
          int numElems = 0;
          for (Enumeration type : values) {
               if (type.ordinal() > numElems) {
                    numElems = type.ordinal();
          // Correct 0 indexed numbering
          numElems += 1;
          System.out.println("numElems : " + numElems);
     public static void main(String args[]) {
          NumberOfEnums noe = new NumberOfEnums();
          noe.count();
}Cheers,
Cypher

Similar Messages

  • How to determine the number of pixels of a desired object within a digital photograph?

    Hi everyone. I want to determine the number of pixels in an object that is part of a digital photo. I use cameras to film chunks of ice breaking away from ice cliffs or tidewater glaciers. I want to know the size of the ice chunk that my digital photographs capture. I know the width and height of the ice cliff in metres already, so I was thinking that I could convert the equivalent of 1 pixel : ? metres - this is really what I want to do. That way every time I see a chunk of ice breaking off, I can pull up the photo, outline the chunk, calculate how many pixels fill the area of ice removed by the chunk breaking off and convert to metres area 2 - thus giving me my size order. If anyone has ideas on how to do this I would really appreciate it, thanks so much community. I was thinking that Photoshop or Fireworks could help me with this, Ricky

    Thanks gener7 and normfb.
    The Photoshop help measurement page is brilliant and I think I can use the info on that page to work out my iceberg sizes. Check out the attached photo - you are looking at an ice cliff - essentially the front of a tidewater glacier that flows in the ocean. I'm a research student and I look at the process of iceberg calving - this is the term we use to define the sudden breaking away or detachment of ice chunks from glaciers that end in the sea.
    I used the lasso tool to crop the area of ice lost as a single chunk of ice detached from the ice cliff. At the same time I had the histogram window open. The histogram showed me how many pixels were contained in the cropped area. What I need to do now is work out what 1 pixel is equivalent to in metres. Soon I will have a digital elevation model for the ice cliff that will offer centimetre to metre scale resolution of the surface topography - so that should really help. The photographs I have are taken every 30 seconds - which is brilliant for documenting how the geometry of the ice cliff adjusts in response to detaching ice pieces and also because the ice is moving. I am a research student in Canada, and at the time I took the photos we measured that the ice cliff was advancing at a rate of approximately 12 metres per day! That's pretty fast. The flow of the ice is a first order control on the rate of iceberg production - you are essentially pushing ice into the ocean where it breaks off. I'm having to learn everything Photoshop from scratch...so please bare with me because maybe some of the photoshop questions I ask are simple to most!
    I noticed the "integrated density" function on the help sheet you suggested. This function also provides the square number of pixels contained in the cropped area I select...I guess this is similar to the histogram right?
    Either way - i just need the scale conversion to go from 1 pixel : metres or cm equivalent. At that point I think I will have to manually select every single iceberg event from my time-lapse photos and do this the manual way!  I have about 800 events to manually digitise and calculate the area for...
    Thanks everyone, Ricky

  • Get the number of elements in Array

    Hi everyone,
    Could anyone give me idea on how to get the number of elements in an Array (not number of rows) ?
    I tried to find that in both property node and array functions but nothing.
    Thanks,
    -Kun

    You are going to have to provide some proof that the Array Size does not work correctly. Right click on the input to it and select 'Create Indicator'. Run the VI. Go to the front panel and select 'Edit>Make Current Values Default'. Save the VI and attach it to your post.
    You can also check the array size yourself. Right click on the index display of the array and select 'Advanced>Show Last Element'. I will bet you that number shown is equal to Array Size -1.
    p.s. The number of elements in an array is equal to the number of rows in a 1D array. If you define the number of elements as anything else, you are mistaken.
    Message Edited by Dennis Knutson on 04-21-2009 10:40 AM

  • How system is determining the Number of Foreign trade data in the Header do

    Dear consultants
    how system is determining the Number of Foreign trade data in the Header -delivery documents(LF) in the Organization Tab.
    Regards
    prakash

    Number of foreign trade data in MM and SD documents.
    Path : SPRO-MM-Purchasing-Foreign Trade/Customs-Define Number Ranges-General Import/Export Processing.(internal number range)
    I hope MM guys will maintain in the above path

  • How to determine the number of rows to be displayed in a report

    hello experts,
    Has anyone ever come across this requirement before? Before a report finishes being executed and before it displays the results, is there a way to determine the number of rows to be displayed as the result?
    Many thanks in advance.
    Regards,
    Inma

    Hello Arun,
    Thanks for your reply but do you know which method I should use for this purpose if I use the table interface?
    Thanks,
    Inma

  • How to get the number of elements in a tilelist

    I'm writing test cases for a flex application using FlexSelenium and I need to get the number of elements displayed in the tilelist.
    I know that that the tilelist is fed by an array. but i can't access that array from my test case.
    Can anyone tell me how I can get the number of elements in a tilelist on the application? which property of the tilelist can provide that number?

    try tileList.dataProvider.length;

  • How to get the number of elements in DB

    Could you tell me how to get the number of elements in DB??
    My code to get the number is below, but I think it is not efficient
    DB->cursor(DB, NULL, &cursorp, 0);
    while ((ret = cursorp->c_get(cursorp, &key, &data, DB_NEXT)) == 0)
    count++;
    --------------------------------------------------------------------------------------------------------------

    Hi,
    The most efficient way to get a count from the database is using the DB->stat API (http://docs.oracle.com/cd/E17076_02/html/api_reference/C/dbstat.html)
    The code will be something like:
            DB *dbp;
            DB_BTREE_STAT *statp;
            int ret;
            /* Print out the number of records in the database. */
            if ((ret = dbp->stat(dbp, NULL, &statp, 0)) != 0) {
                    dbp->err(dbp, ret, "DB->stat");
                    goto err1;
            printf("%s: database contains %lu records\n",
                progname, (u_long)statp->bt_ndata);
            free(statp);The code comes from the example included in the distribution at examples/c/ex_btrec.c
    If the database isn't a btree, you should update to the appropriate statistics structure and field.
    It's worth noting that retrieving the count is never a "cheap" operation. The count is not stored in the database - since doing so introduced a single point of contention that creates a bottle neck.
    Regards,
    Alex Gorrod
    Oracle Berkeley DB

  • How to determine the number of messages in a queue, that ...

    Hi,
    what's the proper way to count the number of the messages in an Advanced Queue that are currently visible to consumers?
    Currently we use:
    select count(*) from aq$queue_tab_name q where q.QUEUE = 'Q_NAME';
    The problem with that approach:
    If one consumer dequeues a lot of messages in one transaction, that change in the number of messages visible to other consumers is only made visible after the consumer issues a commit. Before the commit is issued, the above "select count(*) ..." statement (issued from a different DB-session) does not reflect the fact that one consumer consumed a lot of messages, messages that are not available to other consumers anymore (only exception: the original consumer issues a rollback sooner or later).
    So before the commit is issued:
    -the consumed messages are NOT visible to other consumers anymore (which is intended behaviour)
    -but the "select count(*) ..." statement (issued from a different DB session) does NOT reflect that fact
    So the case could arise that the queue becomes empty, while "select count(*) ..." says that e.g. 1000 messages are still in the queue.
    Is there a solution to this problem?
    PS: For our use-case we need these dequeue option :
    dbms_aq.remove;
    dbms_aq.first_message;
    dbms_aq.on_commit;
    Again, the queue itself works correctly, I just need to find a way to determine the number messages that are currently dequeable / visible to the consumers at specific point in time.
    I couldn't find a func/proc in dbms_aq for that purpose.
    Best wishes
    Peter

    The following might be of interest in better understanding the issue you are facing in a broader context:
    http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:5771117722373

  • Write two functions to find the the number of elements in a linked list?

    I am trying to Write two functions to find the the number of elements in a linked list. One method using recursion and One method using a loop...
    //The linked List class is Represented here.
    public class lp {
    public int first;
    public lp rest;
    public lp(int first1, lp rest1)
    first = first1;
    rest = rest1;
    The program i wrote so far is
    import java.util.*;
    import linklist.lp;
    public class listCount{
    //loop function
    public static void show_list(lp list)
    int counter = 0;
    while(list != null)
    list = list.rest;
    counter++;
    System.out.println ("length computed with a loop:" + counter);
    //recursive function
    public static int recursive_count(lp list)
    if (list.first == null)
    return 0;
    else
    return recursive_count(list.rest) + 1;
    //main method
    public static void main (String args[])
    lp list1 = new lp(1, new lp(2, new lp(3, null)));
    show_list(list1);
    System.out.println("length computed with a recursion:" +
    recursive_count(list1));
    at the if (list.first == null) line i get the error " incomparable types:
    int and <nulltype>" I know this is a beginners error but please
    help...What should I do?

    byte, char, short, int, long, float, double, and boolean are primitives, not objects. They have no members, you cannot call methods on them, and they cannot be set to or compared with null.

  • Function Module to determine the number of pages in a pdf file

    Hi All,
    Is there any standard function module to determine the number of pages in a pdf file?
    Thanks,
    Sai

    Hi unk2,
    There's no functionality in the Acrobat.com online services to do a character count. But, you could use ExportPDF to convert your PDF file to Word format, and then do your character count in Word.
    Please let us know if you need additional assistance.
    Best,
    Sara

  • Determine the number of lines of textfield or floating field

    Hi,
    Is there a way to determine the number of lines of text in a textfield or in a floatingfield.
    My problem is that I'm creating a form with three tables(made of subforms) underneed each other that needs to be set to hidden when the total of rows is greater than 25.
    Now it would be easy to just count the rows but these rows can exist of multiple lines of text.
    The fields of my row are floating fields so when the text is bigger than the displayable width the text continous on a new line in the same row. So I need to know when this happens because now I can show only 24 rows.
    I tried counting the characters but this doesn't work, when there are a lot of 'i,j,l' or other small characters I can place 40 characters in my textfield, but when there are a lot of 'm,w' characters I can place only 22 characters in my field.
    I also tried to use xfa.layout.h(TextField1,"cm") to determine the height of the field, but it always retuns the value -1. I get the same -1 with the y or x - position.
    Does anybody have an idea how to solve this problem?
    Thanks in advance,
    RonnyR

    oops ... i got it thanks.
    code below -----
    for(var i=0; i <= s.length-1; i++)
    sCurrentLetter = s.substring(i,i+1);
    if (s.charCodeAt(i) == 13)
    // this is a line break

  • How do I determine the number of plots on a waveform graph?

    How do I determine the number of plots that have previously been plotted on a waveform graph? I am loading dynamic data from a file. If I convert to an array and size it and there is only one plot, I get the number of data points and I don't know how to tell the difference.

    Usually by reading the graph terminal or a local of it and determining the first or second dimension (not sure which at the moment) size of the resulting 2 dimensional array. If it is a 1 dimensional array you have either only one plot or an array of clusters each representing one plot. But as these data types are determined by compile time, there shouldn't be a problem with this causing ambiguity.
    Rolf K
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How can I determine the number and resolution of the current displays/screens?

    I am developing a vision application that will require a specific window size, thus the application must run with the screen resolution at predified levels. It is also possible that the application will run on a system with multiple monitors, so I need to be able to determine the number of monitors, and the resolution of each.

    Hi
    I recommend you to work with the VI Server functions (Application class properties). See my little example.
    Regards,
    Luca
    Attachments:
    VI_Server.vi ‏22 KB

  • How can I determine the number and sizes of redologs?

    Dear all,
    How can I determine the number and sizes of redologs are sufficient to allow redo log switching while hot backup is in progress?
    Please advice,
    Amy

    Two questions here - what the OP put as the subject title and what was asked in the thread, which are different questions.
    I would interpret the question in the thread to mean "how to avoid hanging due to archiving waiting for a redo log group to become available." Alert log, wait events, and user complaints would be the source of information here.

  • How Do I Print the Number of Elements in An Array

    How do I print: "There are ____ number of elements in the array?"

    If you have a String holding a sentence, and if you split on non-empty sequences of whitespace (if the string has newlines in it, you'd probably need to pass the argument that makes \s match newlines, and for that you would probably need to use java.util.regex.Pattern -- see the docs and try some tests), when you'd get an array of Strings that were the non-whitespace parts of the original String. That makes for a reasonably good definition of the words in the sentence, although you could arguably get into some gray areas (does "isn't" count as one or two words? Does a sequence of numbers or punctuation qualify as a word?). In that case, counting the number of elements in the resulting array of String. using .length, would be a reasonable way to get the number of words in that sentence, yes.
    But rather than asking for confirmation on forums, why don't run some tests?
    import java.io.*;
    public class TestWordCount {
      public static void main(String[] argv) {
        try {
          BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
          String line;
          while((line = in.readLine()) != null) {
            int count = // your code here, to count the words
            System.out.println("I see " + count + " words.");
        } catch (IOException e) {
          e.printStackTrace();
    }Put your word-counting code in there, then run it from the command line. Type in a sentence. See how many words it thinks it found. Does it match with your expectation, or the examples given (hopefully) with your homework assignment?

Maybe you are looking for