Any Java built in function to get the Class type corresponding to primitive

I know it sounds strange but basically I have a Class and a String (I'm reading values from an XML file).
If the Class is a primitive type (boolean, byte, char, short, int, long, float, and double) I would have to convert the String into the corresponding types.
So I know how to do stuff like
Integer.parseInt("22");but for all the primitive types is there some method where I can simply get a way to do that without writing a whole bunch of if statements?

You could set up a class to parse your String. You could check to see if it contains a decimal point, if so then you check to see if it is less than float.MAX_VALUE etc same for the Integer family and you could use equals method to check if it is true or false.
one other way would be to use parseInt etc and catch exceptions if there is an error, this is a bad idea though and a dirty way to do things.
As suggested, maybe you have some idea of what data type your expecting and can limit the amount of parsing you have to do. Another way is to group all numeric values as doubles.
You could start with something like this adding other methods checking the max value of the data types.
public class StringParser
     public static void main(String[] args)
          String test = "1.0";
          System.out.println(containsDecimal(test));
          if (containsDecimal(test))
               decimalSizeFinder(test);
          else
               integerSizeFinder(test);
     static boolean containsDecimal(String input)
          for(int i=0; i<input.length(); i++)
               if (input.charAt(i) =='.')
                    return true;
          return false;
     static void integerSizeFinder(String input)
          long value = Long.parseLong(input);
          if(value <=Byte.MAX_VALUE)
               byte b = (byte)value;
          else if(value <= Short.MAX_VALUE)
               short s = (short)value;
          else if(value <=Integer.MAX_VALUE)
                int i = (int)value;
          //etc
        //Add code to assign the value to a variable someplace
     static void decimalSizeFinder(String input)
          double value = Double.parseDouble(input);
          if(value <=Float.MAX_VALUE)
               float f = (float)value;
       //Add code to assign the value to a variable someplace
}Message was edited by:
kikemelly
Message was edited by:
kikemelly

Similar Messages

  • Is there any function module getting the cpu type?

    Is there any function module getting the cpu type?

    I guess the database server...
    I would like to get the SAP system cpu type as done in transaction st06 under system information.
    Thanks.

  • I have the original AIR recently it has really slowed down. Every function usually gets the pinwheel. It is up to date and has 10g of free disk space. Any suggestions as to the cause?

    I have the original AIR recently it has really slowed down. Every function usually gets the pinwheel. It is up to date and has 10g of free disk space. Any suggestions as to the cause?

    Often a failed disk or power supply. See:
    https://encrypted.google.com/search?q=%22time+capsule%22+%22orange+light%22&as_q dr=all&newwindow=1&num=100

  • Is there any function to get the name of the days?

    Hi,
    I'm using oracle 10.2.0.1.0
    Is there any function to get the days of the week?
    like i need to get sunday,monday,tuesday.....saturday.
    I know i can use union and select the name from dual one by one.
    But just want to know whether there is any other way.
    I need to show the 7 days in a poplist in my form, thats the requirement
    Thanks

    David_Aldridge wrote:
    BluShadow wrote:
    Note: you may want to include "fm" in the format mask, otherwise the name of the day is padded with spaces:
    SQL> ed
    Wrote file afiedt.buf
    1  select replace(to_char(dt,'Day'),' ','*') as fmt1
    2        ,length(to_char(dt,'Day')) as length_fmt1
    3        ,replace(to_char(dt,'fmDay'),' ','*') as fmt2
    4        ,length(to_char(dt,'fmDay')) as length_fmt2
    5  from (select TRUNC(SYSDATE ,'DAY')+Level-1 dt
    6        from   dual
    7        connect by Level<8
    8*      )
    SQL> /
    FMT1      LENGTH_FMT1 FMT2      LENGTH_FMT2
    Monday***           9 Monday              6
    Tuesday**           9 Tuesday             7
    Wednesday           9 Wednesday           9
    Thursday*           9 Thursday            8
    Friday***           9 Friday              6
    Saturday*           9 Saturday            8
    Sunday***           9 Sunday              6
    7 rows selected.
    SQL>
    I think you should use a pl/sql function for this.
    Nah ... just joking.
    I'd be tempted to just use a union all statement to return the seven literals. People will look at it and know exactly what it does.Yeah, agreed, I was just demonstrating that the format mask of a to_char(..., 'Day') pads with spaces, which seems to have been missed in the above answers. ;)

  • Use SQL function to get the original order number using the invoice number

    Hi All,
    wondering is someone can help me with this challenge I am having?  Often I need to return the original order numbers that created the resulting invoce.  This is a relatively simple seriese of joins in a query but I am wanting to simplify it using a SQL function that can be referenced each time easily from with in the SELECT statement.  the code i currently have is:
    Use SQL function to get the original order number using the invoice number
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    RETURN @OrderList 
    END
    it is run by the following query:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number here'
    The issue is that this returns the order number for all of the lines in the invoice.  Only want to see the summary of the order numbers.  ie if 3 orders were used to make a 20 line inovice I only want to see the 3 order numbers retuned in the field.
    If this was a simple reporting SELECT query I would use SELECT DISTINCT.  But I can't do that.
    Any ideas?
    Thanks,
    Mike

    Thanks Gordon,
    I am trying to get away from the massive table access list everytime I write a query where I need to access the original order number of the invoice.  However, I have managed to solve my own problem with a GROUP BY statement!
    Others may be interested so, the code is this:
    CREATE FUNCTION dbo.fnOrdersThatMakeInvoice(@InvNum int)
    RETURNS nvarchar(200)
    AS
    BEGIN
    DECLARE @OrderList nvarchar(200)
    SET @OrderList = ''
    SELECT @OrderList = @OrderList + (cast(T6.DocNum AS nvarchar(10)) + ' ')
    FROM  OINV AS T1 INNER JOIN
          INV1 AS T2 ON T1.DocEntry = T2.DocEntry INNER JOIN
          DLN1 AS T4 ON T2.BaseEntry = T4.DocEntry AND T2.BaseLine = T4.LineNum INNER JOIN
          RDR1 AS T5 ON T4.BaseEntry = T5.DocEntry AND T4.BaseLine = T5.LineNum INNER JOIN
          ORDR AS T6 ON T5.DocEntry = T6.DocEntry
    WHERE T1.DocNum = @InvNum
    GROUP BY T6.DocNum
    RETURN @OrderList 
    END
    and to call it use this:
    Select T1.DocNum, dbo.fnOrdersThatMakeInvoice(T1.DocNum)
    From OINV T1
    Where T1.DocNum = 'your invoice number'

  • Is there a function to get the IP of this remote system

    Hello EveryBody
    Currently I have an application that runs on our network. When someone logs on to the network it checks there system and gets the pc name. I would like to also get the IP address of that system. As well I may later like to ping that computer.
    1) Is there a function to get the IP of this remote system?
    2) IS the a function to ping a remote system and receive back the response?
    Thanks a lot.
    R

    Hello EveryBody
    Currently I have an application that runs on our
    network. When someone logs on to the network it
    checks there system and gets the pc name. I would
    like to also get the IP address of that system. As
    well I may later like to ping that computer.
    1) Is there a function to get the IP of this remote system?
    2) IS the a function to ping a remote system and
    receive back the response?Is this lan only?
    Because if wan or internet then the remote computer would have to have an address that is reachable from your computer. For the internet this would mean it would have to be public. And for a wan the IP would have to be unique across the wan.

  • Ipod doesn't work on speakers but headphones are fine and speaker works with iPhone. Possible connector issue? Any thoughts on how I can get the fixed?

    ipod doesn't work on speakers but headphones are fine and speaker works with iPhone. Possible connector issue? Any thoughts on how I can get the fixed?

    Try:
    - Reset the iOS device. Nothing will be lost
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:       
    iOS: How to back up           
    - Restore to factory settings/new iOS device.

  • Is there any possibility in Ecc6.0 to get the daybook.

    is there any possibility in Ecc6.0 to get the daybook.

    hi
    Pls rund document general report , u will get the desired result
    Assign point if useful

  • Function to get the last day of the current month

    Hi friends
    Now I need to know a function to get the last day of a month. I had between my notes that function but I do not find it and I think you can give the answer faster.
    Thanks
    Joel Pérez
    DBA Oracle

    I know emoticons are a bit naff but in the absence of a UBB markup to indicate humourous intent they do serve to indicate a joke. This is useful in a purely verbal domain like these forums, especially given that many participants don't have English as their first lanaguage and so often miss the wordplay.
    Cheers, APC

  • How to get the .class file for the extended Controller .java file

    Hi,
    I did the below steps.
    1. Created New OAWorkspace
    2. Created New project
    3. Imported the page .xml file
    4. Added new .java file by extending the controller class
    5. Added code in the .java file.
    6. Ran the .xml file
    As I copied all the folders from Unix box, the page was opened.
    But My question was where can I see the .class file the extended controller. It's a .java file. How to compile and get the .class file for this .java file. If I get this .class file, I can go to the page and click the personlize page. and change the Controller name to the new path by ftp ing the new class to the cust.oracle.apps.pos.changeorder.webiui.
    Please let me know how to create the .class file.
    Thanks,
    HP

    All are Java files are stored in JDEV_INSTALL_DIR:\jdevhome\jdev\myprojects\
    In your case the path java would be
    JDEV_INSTALL_DIR:\jdevhome\jdev\ myprojects \cust\oracle\apps\pos\changeorder\webui\
    AND
    Once you compile the java file in Jdeveloper, Class files get generated @ below path
    In your case the path of class would be
    JDEV_INSTALL_DIR:\jdevhome\jdev\ myclasses \cust\oracle\apps\pos\changeorder\webui\
    Duplicate Thread-
    Thanks
    --Anil
    http://oracleanil.blogspot.com/

  • Is there any API in J2ME sdk to get the moibile device ID?

    Hi,
    I am very new to J2ME. Is there any API in J2ME sdk to get the moibile device ID (mostly the phone number)? Does MIDP 2.0 provide this or is it there in someother optional JSRs? Does it portable across all the devices?
    Regards

    Use Device provider API if they support otherwise in J2ME its not permitted due to security issue.
    Sun-shine.

  • When synchronizing my iphone4 on the computer it errors out when optimizing the photos and shuts down iTunes.  Any idea what to do to get the synch working?

    When synchronizing my iphone4 on the computer it errors out when optimizing the photos and shuts down iTunes.  Any idea what to do to get the synch working?

    OKay, here is the deal. You cannot change the location of encrypted files nor can you share them with other machines. There is no file server for iTunes so even if you export the movie index from iTunes to an external volume, each time you reboot your computer itunes has to reindex the external drive every time you want to access the files. The second you run your mobile computer without the external drive or try to access the HD movies from another device or another user on the same network, the indexing gets out of synch. The entire process is self defeating regardless. The HD movies are encapsulized by apple to stream to your devices via iCloud and NOT via Cloud. Only your TV can play 1080p. That single file you download from iTunes has mutiple versions of the same video in the capsul, one version for each type of apple device. There are no 1080p apple devices except for the Apple TV. When you buy a movie you are buying a license and not the movie. It's going to get worse with all the new copywrite laws. Already you cant share any apple devices with other itunes accounts. Your airport express just stopped streaming music to all users on the local home sharing Cloud. Only the one user for each device and soon only airplay speakers connected directly to the device. No more passthru via your TV and no more file sharing with other accounts on the same wi-fi. All the ISPs are doing the same thing. And soon everybody will be buying their phones and TV's and iPads from the cabble guy.
    Apple has done a poor job of educating the consumer as to the difference between the Cloud and iCloud. They are not the same at all.
    Message was edited by: ronfromwoodland hills

  • How to create a function to get the 16th of the current month and the 15th of the next month

    I need to create a function to get the 16th of the current month and 15th of the next month to use it in the fast formula to calculate the sick leave.
    Example:
    If an employee takes a sick leave from 16 feb 2015 to 17 feb 2015 , I want it to affect march's payroll not February.
    Please help and thanks in advance.

    Below statement gives you the result. Use the concept and write your PL/SQL function.
    select TO_DATE('16-'||TO_CHAR(SYSDATE, 'MON-RRRR')), TO_DATE('15-'||TO_CHAR(add_months(SYSDATE, 1), 'MON-RRRR')) from dual;
    Or you can use same construct directly in the fast formula by changing syntax accordingly.
    Regards,
    Peddi.

  • Getting the object type of a Table

    Hi,
    I'm trying to get metadata out of my database and am using the various features of getMetaData() etc to get most of the information I need.
    The only problem I have is that I can't get the actual types of the tables in my database.
    For example I have the Table Lecturers which is of TYPE Lecturer.
    I can get the actual name of the table back by querying the db, but I can't get the actual type of it i.e. Lecturer!
    Does anyone know of a function (or any method at all) that will do this for me in Java ?
    Hope Someone can help me,
    Best Regards,
    Finian.
    Ps I'm using Oracle 9i and the Oracle thin Jdbc driver to connect to it.

    if i dont want any thing but data on the target database.
    i am thinkink about using exclude parameter on indexes,triggers,constraints,views,functions,prodecures,packages. this is how my parameter file will look for import.....
    DIRECTORY=IMP_USAC_DIR
    DUMPFILE=slcu.dmp
    SCHEMAS=slc
    EXCLUDE=ref_constraint
    EXCLUDE=index
    EXCLUDE=view
    EXCLUDE=function
    EXLUDE=trigger
    EXCLUDE=procedure
    EXCLUDE=package
    EXCLUDE=sequence
    LOGFILE=slcutest.log
    Let me know if this will work
    Thanks
    Message was edited by:
    mtaji wa maskini

  • How to get the class file of jar file

    hello all,
    is there any way to get the class file of jar file,as we have when we compile a java file we get class file
    same do we have any option to get the class file of jar file

    A jar file is a zip archive, so you can uznip it or extract the contents with the command "jar" - if it is what you need.

Maybe you are looking for

  • Visual basic code problem

    Hello! I want to use visual basic to build a htm which can control labview throght datasocket, i set the switch as " Swithc until release " in visual basic, the code is Private Sub CWButton1_Click() CWDataSocket1.Data = CWButton1.Value End Sub but th

  • SAP Netweaver MDM 7.1 Installation with MS SQL Database

    Hello Experts, I have installed MDM  7.1 System on IBM AIX and connected to Oracle database. I have observed whenever we create Repositories MDM Created Table Spaces/ Data files under the one Oracle_SID that is how it should be . Now we had to instal

  • ABAP code Help for Customer Exit variable

    Hello All, Can anyone provide ABAP code for a customer exit variable please? Requirement: 0CALYEAR(InfoObject) - ZCALCYR (Variable) <b>Calender year with default value actual year</b>. Proiperties of variable: single value,mandatory,ready for input,c

  • Location to location STO customization

    Hi,   I found many threads for the customization,  of STO inetcompnay and intra compnay,  but i want to set up STO for onluy location to location in the same plant, can you provide any stpes for this. regards, zafar Moderator message: Locked. Reason:

  • Strange behavior with getCommonCharacterFormat and links

    I am working on a texteditor using TLF and Flash CS5. The problem I have is that when I use getCommonCharacterFormat on a single point selection the behavior is different if I have a link-tag adjacent to the selection compared to not having it. Think