Stupid question on checking data types

Hi
I want to write a function that can accept a parameter which could be an int or an int array. This is what I have so far:
void translateParams(Object obj) {
Class type = obj.getClass();
if (type.isArray()){
//do something
Two questions - firstly am I going about this the right way (i.e. have the parameter be type "object" and then check to see what it is) or is there a better alternative. Secondly how can I do the javascript equivalent of isNumeric()??

If you need the same method name to accept two parameter types, just overload the method:public void someMethod(int parm){
   // some code
public void someMethod(int[] parm){
   // some code
}If you have common functionality between the two methods, one can call the other:public void someMethod(int parm){
   // some code
public void someMethod(int[] parm){
   for (int i =0;i<parm.length;i++){
      someMethod(parm);

Similar Messages

  • How to check data type of the field symbol at run time

    Hi,
    My code is as following:
          LOOP AT <fs> ASSIGNING <wa_covp_ext>.
            ASSIGN COMPONENT 86 OF STRUCTURE <wa_covp_ext> TO <f_zzname>.
            IF sy-subrc = 0.
              ASSIGN COMPONENT 158 OF STRUCTURE <wa_covp_ext> TO <f_pernr>.
              IF sy-subrc = 0.
                  SELECT SINGLE sname INTO <f_zzname> FROM pa0001
                                WHERE pernr = <f_pernr>
                                AND endda GE sy-datum
                                AND begda LE sy-datum.
             ENDIF.
          ENDIF.
        ENDLOOP.
    This query is giving dump when <f_zzname> is type P length 8 and decimals 2, because it tries to put PA0001-sname into it which is type C length 30. So I want to check the type of <f_zzname> before the select statement. If it is character 30, then I will write the select statement else not.
    How to check data type of the field symbol at run time? If it's not possible, then can somebody suggest a workaround? Thanks.

    check this ...
    write describe statement  ...
    field-symbols : <f_zzname> .
    data : sname like pa0001-sname,
           typ(10).
    assign sname to  <f_zzname>.
    describe  field <f_zzname> type typ.
    write : typ. <-- typ contains character type in this case ..
    U can check if typ is of character(C) if so .. write the select statement ...

  • Few questions - game loop, data types, speed

    Hello, I have a few questions after studying some topics in this forum regarding game creation:
    1) What's the fastest way to wait in the game loop? I've seen two approaches:
    thread.sleep(10)andsynchronized(this) { wait(10); }2) What data types shall I use? In C++ I use to prefer int over short in all cases, because 32bit hardware works faster with integers. Is this same on cell phones?
    3) Speed of applications is slow. I just wonder wheter it's my fault. I was testing application, which only cleared the buffer and outputted FPS and I got around 20 frames. It was Nokia 6300 with 240x320 display. After testing on other phones I've found out that the bigger the resolution, the slower the game is going. Is this normal?
    Thanks for replies...

    1) You're not going to notice any really speed difference between the two code snippets. Read up on 'Threads', and you'll see why one may be used in place of the other depending on the situation. In general there may be a slight performance loss, however unnoticable, when using the synchronized version, but when you are multithreading it is likely necessary.
    sleep(int) is impossible to interrupt, so it's generally a no-no in most situations. However we are talking about devices where every bit of performance helps, so as long as it works for ya, it's not a big deal.
    2) The performance difference is fairly negligable, if any. The biggest thing to consider is memory requirements, and shorts take 1/2 the data.
    Also, many phones don't support floating point data types, so you'll likely need to use ints/longs to calculate your values if you want to have any accuracy beyond whole numbers. Doing something like shifting bits or using 1000x values in your calculations can get around most of the problems when you can't use floats.
    3) The biggest performance killers are IO, memory allocation, screen drawing; pretty much in that order. So I imagine that you are re-creating a new String object every time you output your FPS value on screen right? Doing that every frame would destroy any hopes of getting high-performance.
    Just be careful, and never allocate objects when you can avoid it. anything where you concat String objects using + will cause your performance to die a horrible painful slow death. Remove anything that says 'new' from your main loop, and all String operations, and it'll likely speed things up a lot for ya.
    Does your main loop have something like this?
    g.drawString("FPS: " + currentFps, 0,0,Graphics.TOP | Graphics.LEFT);
    This is very bad because of the String operation. It'll create a new String every frame.
    If you have any more specicif questions, or you'd just like to pick the brain of a mobile game dev, stop by my messageboard:
    http://attackgames.proboards84.com
    Message was edited by:
    hooble

  • Checking data type compatibility

    Hi,
    Is there a method to check if two data types are compatible with each other? I need to perform this check without any value at hand. With a value it works if I create data references and assign them to field symbols. How do I make the same more generic with just the data type and length given.
    Any help would be greatly appreciated. Thanks.
    regards,
    nithya

    I have extracted the below info from a document that i have with me. Do provide your mail-id if you need the document. I dont mind sharing...:)
    Please check this for more understanding...
    <b>Type Checks and Type Compatibility</b>
    For historical reasons, the types of field symbols and parameters in subroutines or function modules can be defined with the STRUCTURE addition.
      If the types of field symbols are defined with FIELD-SYMBOLS <f> STRUCTURE s DEFAULT wa and they are later assigned a data object wa with ASSIGN wa TO <f> ... , in a NUP both statements are checked to see if wa is at least as long as s and wa satisfies the alignment requirements of s at runtime.
    16
    If parameter types in function modules or subroutines are defined with FORM form1 USING/CHANGING arg STRUCTURE s ... or FORM form2 TABLES itab_a STRUCTURE s ... and the parameters are passed actual parameters with PERFORM form1 USING/CHANGING wa or PERFORM form2 USING/CHANGING itab_b, the NUP also only checks if wa or the line type of itab_b is at least as long as s and wa or the line type of itab_b satisfies the alignment requirements of s. The same is true for function module parameters whose types are defined with STRUCTURE.
    The following extra rules are checked in a UP after defining the type with STRUCTURE when assigning data objects, that is for the DEFAULT addition in the FIELD-SYMBOLS statement, for ASSIGN, and when passing actual parameters.
    1. If wa or the line type of itab_b is a flat or deep structure, the length of s must be the same for the Unicode fragment views of wa or of itab_b and s.
    2. If wa is a single field, only the character-types C, N, D or T are allowed and the structure s must be purely character-type.
    Checking both these rules requires additional runtime. It is therefore recommended that, if possible, you type the parameters using TYPE, since the test for actual compatibility is much faster.
      If the type of an argument in a function module was defined with ... LIKE struc, where struc is a flat structure, the NUP only checks if the argument is a flat structure with the same length when the parameters are passed. In the UP, it also checks that the fragment views of the current and formal parameters are the same. For performance reasons, it is again recommended that you use TYPE to assign types.
      Furthermore, two structures of which one or both contain Includes, are only compatible if the alignment gaps caused by the Include are the same on all platforms. In the following example, struc1 and struc2 are not compatible because a further alignment gap occurs in the US before the INCLUDE:
    BEGIN OF struc1, BEGIN OF struc2, BEGIN OF struc3,
    a(1) TYPE X, a(1) TYPE X. b(1) TYPE X,
    b(1) TYPE X, INCUDE struc3. c(1) TYPE C,
    c(1) TYPE C, END OF struc2. END OF struc3.
    END OF struc1.
    Since the type compatibility can differ in a UP and an NUP, the type compatibility rules of the calling program are valid in an NUS for checking the parameters. This means that if an NUP calls a UP, the type compatibility is defined as in the NUP. Conversely, the Unicode check is activated if a UP calls an NUP.
    Kind Regards
    Eswar

  • Checking data type

    I know there must be an easy way to do this. Say I want to
    have a function
    to which you can pass either an integer or a point, or maybe
    a list, either
    would work. How do I determine what the data type of the data
    I've been
    given is? In other words, I'd like to be able to say:
    if data.type = #integer then <do something>
    else if data.type = #point then <do something else>
    else if data.type = #list then <do yet another thing>
    etc.

    > "ilk" is the keyword you're looking for.
    Ah, I knew it'd be something simple like that. Thanks.

  • SQL - How to check data type definition

    Is it possible to check (inside SQL statement) how particular field is defined. Is it VARCHAR2(5) or VARCHAR2(10)

    If by field you mean column, then use USER_TAB_COLUMNS, ALL_TAB_COLUMNS or DBA_TAB_COLUMNS:
    SELECT  TABLE_NAME || '.' || COLUMN_NAME || ' ' || DATA_TYPE ||
            CASE
              WHEN DATA_TYPE LIKE '%CHAR%' THEN '(' || DATA_LENGTH || ')'
              WHEN DATA_TYPE = 'NUMBER' THEN '(' || DATA_PRECISION  || ',' || DATA_SCALE || ')'
            END X
      FROM  USER_TAB_COLUMNS
      WHERE TABLE_NAME = 'EMP'
      ORDER BY COLUMN_ID
    X
    EMP.EMPNO NUMBER(4,0)
    EMP.ENAME VARCHAR2(10)
    EMP.JOB VARCHAR2(9)
    EMP.MGR NUMBER(4,0)
    EMP.HIREDATE DATE
    EMP.SAL NUMBER(7,2)
    EMP.COMM NUMBER(7,2)
    EMP.DEPTNO NUMBER(2,0)
    8 rows selected.
    SQL>   SY.

  • How to check date type is initial

    there is SQL sentence.
    DATA: BEGIN OF it OCCURS 0,
        matnr LIKE mara-matnr,
        laeda  LIKE mara-laeda,
      END OF it.
    select matnr laeda
    from mara
    where laeda <> space.
    How can I  check the  laead field is initial.
    Regards.

    Hi,
         Try this syntax
    SELECT... WHERE s IS [NOT] NULL...
    SELECT matnr laeda FROM mara INTOTABLE it_itab WHERE
    laeda IS [NOT] NULL.
    Regards
    Bala Krishna

  • I have a question about the data type static

    for any of you that read my last post for my assignment this is still the same thing but i have broke it down more, but i am getting an error and i am not for sure i understand why that is. I think i am confused on why i should, or could use a static?
    thanks again guys
    package wordstester;
    import javax.swing.JOptionPane;
    * @author christopher izatt
    public class WordsTester {
         * @param args the command line arguments
        public static void main(String[] args) {
                  // prompt the user to enter a string of their choice
          String wordChosen;
          wordChosen = JOptionPane.showInputDialog
              ("Please enter a word of your choice here");
          String middlePart;
          middlePart = Words.getMiddle(wordChosen);      <----- error nonstatic method can not be referenced in a static context
          System.out.println("At the middle of " + wordChosen + " is: "
                     + middlePart);
    package wordstester;
    * @author christopher izatt
        public class Words {
        private String wordChosen;
        public String Words(String letters) {
            wordChosen = letters;
            return wordChosen;
        public String getMiddle(String wordChosen) {
            int letters = wordChosen.length() / 2;
            int endindex = letters +1;
            return wordChosen.substring(letters, endindex);
       

    Try this.
    Imagine a blueprint from which houses are constructed. The blueprint indicates that each house will have a garage, a roof, a front door, etc. However, each house will have its own roof - be it a tar shingle roof or a cedar roof or maybe thatch - but that's another issue.
    Now, in the lower left corner of the blueprint, we find the architect's name and company logo. That logo is part of the blueprint - each house will NOT have its own discreet copy of that item. Instead, each house will share the one and only copy of that logo.
    That's what static members are. They are called "class variables" or "class methods" and are accessed through the class name instead of an object name.
    I hope that helps.

  • As to the data type of the data type of the difference between two date type of datas

    Hi,
    I have a question about the data type of the difference between two date type of datas.
    There are two date type of datas as:
    SSHIPMENTS.RECEIVEDATETIME
    SSHIPMENTS.PROMISEDATETIME
    I try to use the following SQL Script in Oracle SQL*Plus as:
    SELECT CASE
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:00:00.000' THEN 'OnTime'
    WHEN (SSHIPMENTS.RECEIVEDATETIME - SSHIPMENTS.PROMISEDATETIME) < '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    The error message of "Invalid Number" for the '000 01:30:00.000' happens.
    I don't know if the data type of the interval is wrong.
    Many Thanks,
    Cathy

    SELECT CASE
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss')) < '010000' THEN 'OnTime'
    WHEN (to_char(SSHIPMENTS.RECEIVEDATETIME,'hhmiss') - to_char(SSHIPMENTS.PROMISEDATETIME,'hh24miss'))< '000 01:30:00.000' THEN '60-89 Minutes'
    ELSE '3+ Hours'
    END
    FROM SSHIPMENTS;
    just try it out..

  • Which data type for X_Data_Type argument to PlotXY(...)

    Using Labwindows/CVI 2013.
    I'm collecting data and time stamps.
    The time is acquired by calling time( &timeTag );
    timeTag is declared as time_t;
    So now I have a big array of time_t.
    I want to use PlotXY to display the data.  The x-axis of the graph control is configured for absolute time so it will display time and date.
    My question is:
    What data type should I use for the X_Data_Type argument to the PlotXY(...) function?
    Should I convert the absolute time to double and use VAL_DOUBLE?
    Or should I use the time_t values as is and use VAL_UNSIGNED_INTEGER?  Will this still work if I build as a 64-bit application.
    Thanks,
    Kirk
    Solved!
    Go to Solution.

    You can use both: the information is basically the same but using time_t datatype you will loose the fractional part of seconds, which may or may not be a problem for you (apparently is not since you are already getting data using time () and are satisfied with that).
    Look at <cvisampledir>\userint\TimeDateUnits example for an application of time graph using doubles: you can modify the example simply using time () instead of GetCurrentDateTime () and setting the appropriate data type in PlotXY ().
    Proud to use LW/CVI from 3.1 on.
    My contributions to the Developer Zone Community
    If I have helped you, why not giving me a kudos?

  • HEELLLLP with abstract data types(ie. interfaces)

    Hello Java World,
    I have a few questions regarding abstract data types(ADT) such as interfaces, etc.
    1. Which of the following is allowed in Java ?
    interface TA extends student, Employee
    class teachAssist implements TA, Cloneable, Sortable{..}
    2. ADTs cannot be instantiated only extended/implemented(coded)??
    3. Can a interface implements/extend classe(s)?
    4. Why is a Vector not an ADT? Is it because it contains implementations for its some of its methods?
    Thanks for the help, in advance!!
    RahimS

    Hello Java World,
    I have a few questions regarding abstract data
    types(ADT) such as interfaces, etc.
    1. Which of the following is allowed in Java ?
    interface TA extends student, Employee
    {...}Allowed (if student and Employee are also Interfaces).
    class teachAssist implements TA, Cloneable,
    Sortable{..}Allowed.
    >
    2. ADTs cannot be instantiated only
    extended/implemented(coded)??True.
    3. Can a interface implements/extend classe(s)?No. An interface simply defines a skeleton...says what methods are present in classes that implement it...therefore an interface cannot 'implement' anything. It may however extend other Interfaces.
    4. Why is a Vector not an ADT? Is it because it
    contains implementations for its some of its methods?A Vector is not an ADT because it is fully implemented (it contains implementations for ALL of its methods).
    >
    >
    Thanks for the help, in advance!!
    RahimS

  • Questions on Merging Dis-similar Data Types...

    I am using Web-I version 11.5.8.834 (We do not use the Crystal Reports module, all of our reports are built with Web-I).
    I have two questions:
    Question 1: First I am attempting to create a report from two different universes and need to merge a dimension from each universe.  The two dimensions have similar data, but one is set up as a "string", and the other universe has the same data set up as a "number".  Our IT department creates and maintains the universes and I have requested that one of the dimension data type be changed to match the other, but I am told that other users have already set up reports using these dimensions and to change them at this point might cause a problem with their reports.  So my first question is: Can two separate dimensions be setup within a single universe, using the same data field, each having different data types (e.g., a field with numeric data be set up as a "string" and a second dimension be setup as a "number")?  If this works, I can make a recommendation to our IT department to do this and I will not have to resort to Question 2.  but just in case, here is Question 2:
    Question 2: I have two other dimensions that I might be able to use, but it requires creating a variable and "trimming" data off of each of the fields.  The first universe is a part number with three alpha characters followed by four numeric characters (PRT1234).  The second universe has a serial number, in which the first four characters match the last four characters of the other universe (1234-00111).  If I trim off the first three characters from the first universe using a variable (=right([Part_Number];4), and trim off the last six characters from the second universe using a variable (=left([Serial_Number],4), the variables will have matching data.  The second question is: Can variables be merged?  I've tried, but it isn't working so far.  If so, can someone give me some hints on how to do it?
    Edited by: Charles Norman on Aug 8, 2008 11:42 AM
    Edited by: Charles Norman on Aug 8, 2008 11:43 AM

    Charles,
    Can variables be merged?
    No, local variables cannot be merged.  The manipulation must be performed at the database level via Designer before the data comes across to the report.  As an aside, your IT deparatment can create "new" objects just for you, placed in the list under a separate sub-class that manipulates the data to your liking and will not upset other users who already built reports using the original columns of data.  I guess my point is that you can have multiple objects placed in your universe that derive from the same column in a given table -- user A has it per their flavor and user B has it per his flavor.
    Thanks,
    John

  • Check box with Boolean data type is not behaving properly

    Hi,
    I create a sample application with one entity driven view object with two attributes. One is of String data type [Value will be Y/N] and another (transient) attribute with Boolean data type. I planned to bind this boolean data type attribute to UI. I overridded the view row impl class and included setting of boolean attribute inside the setter of String attribute. Also in the getter of boolean attribute, added code to check the string attribute and return true/false based on that. Everything is working fine in application module tester. But when i test the same in view controller project in a page, it is not working. Always Check box component is not checked eventhough when i explicitly check it.
    [NOTE: I have given the control hint of Boolean attribute as check_box. Also i don't want selected/unselected entries in the page def file. That's why followed this approach]
    Have i missed out anything? Why this behaviour.
    Thanks in advance.
    Raguraman

    what is the value that is going in when u check it.. did u debug it.. is the viewRowimps setter and getter getting called.. and is it having the right value set and got.. and ur sure that ur using selectBooleanCheckBox..
    ur binding the checkbox to the transient value right??

  • Question about uesr-defined data types

    Can anyone help me to answer the question?
    Explain the user-defined data types in Oracle Spatial, and give examples how these data types and their associated operations are used to support
    i.     Storage
    ii.     Indexing
    iii.     Retrieval
    of spatial data.
    thanks!!

    you need to look at the oracle spatial user's guide, which gives most of that information. it is downloadable from otn...

  • How to check the data type dynamically

    hi all
    my requirement is like this  in one screen field which is of character type user is inputing data .
    now while saving to the database i have to apply one external check for this data if it is integer type or not
    as this data on the screen is refrenced to the database so i can not change the data type on the screen itself .
    i have to check it externally from PAI ....... would any one please help on this
    Thanks and regards
    Papps

    Hi
    Thanks again you are right i missed the space one ..
    but Now another problem...
    I have tried that but in that case even user can input data by mistake like this
    123 4  but this is not an integer it should also give error as this is also not a correct integer ...
    as par asi think . we have to aain check if there is any spaces in the data provided i guess or
    is there any other procedure ?

Maybe you are looking for

  • How to delete one record out the two?

    Hi all, A have an Orders table: ACCOUNT, ORDER_NO, ORDER_DATE I have a few cases where there two accounts have the same ORDER_NO. I dont think this is right in a traditional Orders/ Orderline relationship! For Example: ACCOUNT     ORDER_NO     ORDER_

  • Freight provision

    Hi Friends, We have a framework order that got an unwanted condition type FRA2 entered with a value. Goods reciept and Invoice has been done already. Looking at the accounting doc, the amount has been posted to Frieght provision G/L Account and GR/IR

  • PowerPC G5 will not soft boot

    My 2.3GHz dual core PPC G5 running 10.4.8 will not soft boot that is shut down using the restart and shutdown menu. I have to hard boot it to get it to shut down (holding down the power button on the front of the G5). I have rebooted with the shift k

  • Change of credit card number

    My credit card was stolen. I have a new number and I cannot change the number in my apple id to order items through my apple account. Suggestions please.

  • USE OF SERCH HELP EXIT

    hello i am usin serch help in callcontrol = 'DISP' in this way LOOP AT GT_IT_ITAB INTO  GW_ITAB.      LWA_SELOPT-SHLPNAME     = 'ZSDH_FOCUS_LIST'.      LWA_SELOPT-SHLPFIELD    = 'AUART'.      LWA_SELOPT-SIGN         = 'I'.      LWA_SELOPT-OPTION