NSNumber or primitives?

Hi,
I'm new to objective-c programming from a PHP / Ruby background. I'm just trying to get a handle on best practices for my development.
I have a method which does a fair bit of floating point calculations then returns an NSNumber object. When i'm doing my calculations i've just used float/double primitives then created an NSNumber object at the end to return. Is this the correct/cocoa way? Or should i be using NSNumbers from end to end?
Second question is: is there an convert to radians from degrees method anywhere? I'm just doing it myself at the moment.
Thanks.
Nick.

The only reason to use an NSNumber is if you need a persistent object that knows how to archive itself.

Similar Messages

  • Primitive APAB editor in start/end routines in transformations

    When editing or viewing ABAP code in BI transformations, for example in a start routine, the editor that opens is very primitive compared to the normal SE38 editor. Some of the limitations include:
    The editor window doesn't cover the whole screen with seemingly no way to increase its size.
    The syntax check doesn't show on which line syntax errors are located.
    There is no option to perform a extended program check.
    There is no way to insert break-points (other than with the ABAP keyword of course)
    These limitations are present regardless of whether i choose the new front-end editor, the old front-end editor or the back-end editor. We're running SAP Netweaver 2004s.
    It is of course possible to create a program in SE38 and copy-paste your start routine code to see the code using the "real" editor, but this is very tiresome and time consuming. Is there a way to make this editor look and behave like the normal editor? I have looked through the setting options an searched SDN without finding a way.

    Hi,
    This is just the settings you need to change to open the start,end, and characteristics routine using the old editor you are comfortable with. No need to go to se38 and check copy the program.
    Go to se38->Utilities->settings->abap editor->editor tab->select the old abap editor.
    To specifically put break point in transformations (start routine..end routine..)..goto transformation (RSA1) and then display the transformation.
    Then goto extra (menu)->generated program. search for start_routine (method now) and put break point in the desired place.
    Then from the DTP enable all 4 break points..in tranformation (this will come when u cange it to debug mode simulation). And u can debug the transformation.
    The new editor is a good handy one. But take some time to get acquented to it. After you may start liking it :).
    Cheers,
    -J

  • Runtime conversion of a string value to a primitive data type in java

    can anyone of you give me an idea to convert a string value to a primitive data type during run time...i have the value and the type to which it has to be converted as String values...do you have any idea ,...pls share

    String recvalvalue = inputval;
                    String recvartype = inputtype;
                   if (recvartype.equals("int")){
                   value0 = Integer.parseInt(recvalvalue);
             else
             if (recvartype.equals("double")){
                    value1  = Double.parseDouble(recvalvalue);
             else
             if(recvartype.equals("float")){
              value2 = Float.parseFloat(recvalvalue);
             else
             if(recvartype.equals("Boolean")){
              value3 = Boolean.parseBoolean(recvalvalue);
             else
             if(recvartype.equals("char")){
               value4 = (char)recvalvalue.charAt(0);
            else
            if(recvartype.equals("String")){
              value5 = recvalvalue;
             else
             if(recvartype.equals("byte")){
               value6 = Byte.parseByte(recvalvalue);
                  //listA.add(6, value6);
                  //     listA.g = value6;
             else
              if(recvartype.equals("long")){
               value7 = Long.parseLong(recvalvalue);
             else
              if(recvartype.equals("short")){
              value8 = Short.parseShort(recvalvalue);
             } yes i can do this but the resultant value has to be assigned to a variable of a specific type which is here recvartype .....it has to be done dynamically automatically..if we know what type of data is that we can convert and assign to the type but we donot know when we run the program as the program will be supllied by someone and has to be executed

  • No compiler error when assigning null to a primitive with ? :

    In 5.0, the statement
    int a = true ? null : 0;
    does not produce a compiler error. In 1.4 it produced an error stating "Incompatible conditional operand types int and null". I understand that auto-boxing complicates the compiler's job here, but isn't it still possible for the compiler to error on this statement?

    That's perfectly legit in 1.5 because of autoboxing.
    The compiler looks at the expression
    true?null:0and needs to determine the type produced by it. 0 can be autoboxed to an Integer and null is a valid Integer value, so that expression produces an Integer.
    Then, it tries to auto-unbox the Integer to assign it to the primitive int. And the same thing happens as always happens when you try to auto-unbox null: you get a NullPointerException. :)

  • Creation of new primitive data types

    Is it possible to create primitive data types? Or perhaps there's another solution...
    I have a need to work with signed integers represented by more than 128 bits, and would prefer to define such variables as primitive types and be able to use them as such. I have no problem creating "toString()" and friends for convert binary to decimal.
    Thanks in advance.
    Randolf Richardson - [email protected]
    Inter-Corporate Computer & Network Services, Inc.
    Vancouver, British Columbia, Canada
    http://www.8x.ca/

    What about using "BigIntegers"?
    http://java.sun.com/j2se/1.4.2/docs/api/java/math/BigInteger.html

  • Reference to primitive types?

    I want to write a GUI that is able to set parameters to classes without knowing the exact nature of parameters. The parameter types are restricted to int and String. Something like this:
    ...in GUI class:
    ClassToConfigure c = getFromSomewhere();
    for (int i=0; i<c.getPropertyCount(); i++) {
      addToGUI(c.getDescription(), c.getType(), c.getKeyName())
    then later after the value is set in the GUI:
    c.setProperty(keyName, newValue);the setProperty method would have implementations for each type of newValue, and the GUI would have editing capabilities for each type too.
    My problem is that I do not know how to implement this in the ClassToConfigure (CTC). My thoughts were: CTC enumerates all field it wants to be configurable in its constructor, something like:
    addProperty(actual_field, "int", "Some description", "UniqueName");the CTC class would have a list of all properties with the "references" to the actual field to be able to update them.
    but then I don't know how to update the fields when CTC.setProperty() is called. Is there a way to keep a reference to a field, even if the field has a primitive type? Another way to do it would be using function pointers, passing the getter and setter to CTC.addProperty, but this isn't possible in java.
    Is there any straightforward way of implementing such behavior in java without tricky use of reflection?
    Thanks in advance,
    -Lev
    P.S. I hope I made my point understandable, if not please let me know and I'll try to rephrase my concern.

    I did not understand what you meant. But you can have the OO equivalents to function pointers, and that is method references. (But that is part of the the java.lang.reflect package)
    Kaj

  • Need suggestion for variable size array of primitive type.

    Hi all,
    I am working on a problem in which I need to keep an array of primitive (type int) sorted. Also I insert new elements while keeping it sorted, and at times I merge two similar arrays with unique elements.
    I would welcome suggestions on the implementation aspects as to which type/class to use. My primary consideration is performance. Here are my observations:
    1. type int
    Efficient operation, but arrays are fixed size so it makes clumsy code and overhead when the array is expanded or merged with another.
    Methods in class Arrays can be used, incl. binary search and sort.
    2. Vector, ArrayList, List, LinkedList
    Accept objects only. I can use Integer instead of int, but it will involve overhead, and I'll need to write my own sort and search routines (already done).
    For now, I choose option 2 using Vectors. Is there a better choice, or are there other options, given the conditions and consideration enumerated at the beginning?
    Appreciate any input or comments.

    mathmate wrote:
    I have not had the occasion to use them in parallel to recognize the difference. It pays to talk to people!A small benchmark is easily constructed:
    import bak.pcj.list.IntArrayList;
    import java.util.Random;
    import java.util.ArrayList;
    public class CollectionTest {
        static void testObjectsList(ArrayList<Integer> list, int n, long seed) {
            long start = System.currentTimeMillis();
            Random rand = new Random(seed);
            for(int i = 0; i < n; i++)
                list.add(new Integer(rand.nextInt()));
            for(int i = 0; i < n/2; i++)
                list.remove(rand.nextInt(list.size()));
            long end = System.currentTimeMillis();
            System.out.println("objectsList -> "+(end-start)+" ms.");
        static void testPrimitiveList(IntArrayList list, int n, long seed) {
            long start = System.currentTimeMillis();
            Random rand = new Random(seed);
            for(int i = 0; i < n; i++)
                list.add(rand.nextInt());
            for(int i = 0; i < n/2; i++)
                list.remove(rand.nextInt(list.size()));
            long end = System.currentTimeMillis();
            System.out.println("primitiveList -> "+(end-start)+" ms.");
        public static void main(String[] args) {
            long seed = System.currentTimeMillis();
            int numTests = 100000;
            testObjectsList(new ArrayList<Integer>(), numTests, seed);
            testPrimitiveList(new IntArrayList(), numTests, seed);
    }In the test above, Java's ArrayList is about 5 times faster. But when commenting out the remove(...) methods, the primitive 3rd party IntArrayList is about 4 to 5 times faster.
    Give it a spin.
    Again: just try to do it with the standard classes: if performance lacks, look at something else.

  • Trouble with primitive arrays and casting, lesson 521

    hi everyone!
    there is a problem i discovered right now - after years with java where was no necessity to do this.....
    and i'm shure this must have been the topic already, but i couldn't find any helpful resource :-/
    right here we go:
    1. an array is a (special) kind of object.
    2. there are "primitive" arrays and such containing references to objects. of course - and i imagine why - they are treated differently by the VM.
    3. then both are - somehow - subclasses of Object. whereas primitive types are not really, primitive-arrays are. this is hidden to the programmer....
    4. any array can be "pointed" at via local Object variable, like this:
    Object xyz = new int[6];
    5. arrays of Objects (with different dimensions) can be casted, like this:
      Object pointer = null;
      Object[]   o  = new SomeClass[42] ;
      Object[][] oo = new OtherClass[23] [2] ;
      Object[][][] ooo = new OtherClass[23] [2] [9] ;
      o = oo = ooo;     // this is save to do,
                                   //because "n-dimensional" object-arrays
                                  // are just arrays of  other arrays, down to simple array
    pointer = o;         // ok, we are referencing o via Object "pointer"6. but, you cannot do this with primitive types:
      int[]  i1 = new int [99] ;
      int[][] i2 = new int [1] [3] ;
      i1 = i2                  // terror: impossible. this is awful, if you ask me.
                                   // ok, one could talk about "special cases" and
                                   // "the way the VM works", but this is not of interest to me as
                                   // a programmer. i'm not happy with that array-mess!
      pointer = i2;       // now this is completely legal. i2, i1 etc is an object!7. after the preparation, let's get into my main trouble (you have the answer, i know!) :
    suppose i have a class, with methods that should process ANY kind of object given. and - i don't know which. i only get it at runtime from an unknown source.
    let's say: public void BlackBox( Object x );
    inside, i know that there might be regular objects or arrays, and for this case i have some special hidden method, just for arrays... now try to find it out:
    public void BlackBox( Object x )
      if ( x == null)
           return;
       Class c = x.getClass();
       if ( c.isArray() )
              // call the array method if it's an array.........
              BlackBoxes(     (Object [] )  x );         // wait: this is a cast! and it WILL throw an exception, eventually!
              return;
       else
               DoSpecialStuffWith( x );
    }ok ? now, to process any kind of array, the special method you cannot reach from outside:
    private void BlackBoxes( Object[] xs )
       if ( xs != null )
            for ( Object x : xs )
                 BlackBox( x );
    // this will end up in some kind of recursion with more than one array-dimension, or when an Object[] has any other array as element!this approach is perfectly save when processing any (real) Object, array or "multi-dimensional" arrays of Objects.
    but, you cannot use this with primitive type arrays.
    using generics wouldn't help, because internally it is all downcasted to Object.
    BlackBox( new Integer(3) ) ---- does work, using a wrapper class
    BlackBox( new Integer[3] ) ----- yep!
    BlackBox( 3 ) ---- even this!
    BlackBox( new int[42] ) ---- bang! ClassCastException, Object[] != int[]
    i'm stuck. i see no way to do this smoothly. i could write thousands of methods for each primitive array - BlackBox( int[] is ) etc. - but this wouldn't help. because i can't cast an int[][] to int[], i would also have to write countless methods for each dimension. and guess, how much there are?
    suppose, i ultimately wrote thousands of possible primitive-type methods. it would be easy to undergo any of it, writing this:
    BlackBox( (Object) new int[9] [9] );
    the method-signature would again only fit to my first method, so the whole work is useless. i CAN cast an int[] to Object, but there seems no convenient way to get the real array out of Object - in a generic way.
    i wonder, how do you write a serialisation-engine? and NO, i can't rely on "right usage" of my classes, i must assume the worst case...
    any help appreciated!

    thanks, brigand!
    your code looks weird to me g and i think there's at least one false assumption: .length of a multidimensional array returns only the number of "top-level" subarrays. that means, every length of every subarray may vary. ;)
    well i guess i figured it out, in some way:
    an int is no Object;
    int[ ] is an Object
    the ComponentType of int [ ] is int
    so, the ComponentType of an Object int[ ] is no Object, thus it cannot be casted to Object.
    but the ComponentType of int [ ] [ ] IS Object, because it is int [ ] !
    so every method which expects Object[], will work fine with int[ ] [ ] !!
    now, you only need special treatment for 1-dimensional primitive arrays:
    i wrote some code, which prints me everything of everything:
        //this method generates tabs for indentation
        static String Pre( int depth)
             StringBuilder pre = new StringBuilder();
             for ( int i = 0; i < depth; i++)
                  pre.append( "\t" );
             return pre.toString();
        //top-level acces for any Object
        static void Print( Object t)
             Print ( t, 0);
        //the same, but with indentation depth
        static void Print( Object t, int depth)
            if ( t != null )
                 //be shure it is treated exactly as the class it represents, not any downcast
                 t = t.getClass().cast( t );
                if ( t.getClass().isArray() )
                     //special treatment for int[]
                     if ( t instanceof int[])
                          Print( (int[]) t, depth);
                     // everything else can be Object[] !
                     else
                          Print( (Object[]) t, depth );
                     return;
                else
                    System.out.println( Pre(depth) + " [ single object:] " + t.toString() );
            else
                System.out.println( Pre(depth) + "[null!]");
        // now top-level print for any array of Objects
        static void Print( Object [] o)
             Print( o, 0 );
        // the same with indentation
        static void Print( Object [] o, int depth)
            System.out.println( Pre(depth) + "array object " + o.toString() );
            for ( Object so : o )
                    Print( so, depth + 1 );
        //the last 2 methods are only for int[] !
        static void Print( int[] is)
             Print( is, 0 );
        static void Print( int[] is, int depth)
            System.out.println( Pre(depth) + "primitive array object " + is.toString() );
            // use the same one-Object method as every other Object!
            for ( int i : is)
                 Print ( i, depth + 1 );
            System.out.println( "-----------------------------" );
        }now, calling it with
    Print ( (int) 4 );
    Print ( new int[] {1,2,3} );
    Print( new int[][] {{1,2,3}, {4,5,6}} );
    Print( new int[][][] {{{1,2,3}, {4,5,6}} , {{7,8,9}, {10,11,12}}, {{13,14,15}, {16,17,18}} } );
    Print( (Object) (new int[][][][] {{{{99}}}} ) );
    produces this fine array-tree:
    [ single object:] 4
    primitive array object [I@9cab16
          [ single object:] 1
          [ single object:] 2
          [ single object:] 3
    array object [[I@1a46e30
         primitive array object [I@3e25a5
               [ single object:] 1
               [ single object:] 2
               [ single object:] 3
         primitive array object [I@19821f
               [ single object:] 4
               [ single object:] 5
               [ single object:] 6
    array object [[[I@addbf1
         array object [[I@42e816
              primitive array object [I@9304b1
                    [ single object:] 1
                    [ single object:] 2
                    [ single object:] 3
              primitive array object [I@190d11
                    [ single object:] 4
                    [ single object:] 5
                    [ single object:] 6
         array object [[I@a90653
              primitive array object [I@de6ced
                    [ single object:] 7
                    [ single object:] 8
                    [ single object:] 9
              primitive array object [I@c17164
                    [ single object:] 10
                    [ single object:] 11
                    [ single object:] 12
         array object [[I@1fb8ee3
              primitive array object [I@61de33
                    [ single object:] 13
                    [ single object:] 14
                    [ single object:] 15
              primitive array object [I@14318bb
                    [ single object:] 16
                    [ single object:] 17
                    [ single object:] 18
    array object [[[[I@ca0b6
         array object [[[I@10b30a7
              array object [[I@1a758cb
                   primitive array object [I@1b67f74
                         [ single object:] 99
    -----------------------------and i'll have to write 8 methods or so for every primitive[ ] type !
    sounds like a manageable effort... ;-)

  • Array Of Primitive Type (kodo3.4)

    Hello,
    I want to map an array of primitive type (double[] or double[][] or...) to
    a blob, so I specified the mapping this way:
    <extension vendor-name="kodo" key="jdbc-field-map-name" value="blob">
    <extension vendor-name="kodo" key="column" value="DATA"/>
    </extension>
    As I use MySQL and not to have an exception, I have added:
    kodo.jdbc.DBDictionary: DriverDeserializesBlobs=false
    But when I tried to refresh using kodo.jdbc.meta.MappingTool, I get:
    [refresh] Exception in thread "main" kodo.util.FatalInternalException:
    Cannot map "fr.ifp.reservoir.model.business.geostat.Lithotype.facies".
    Check the class and make sure you are using only supported types.
    [refresh] at
    kodo.jdbc.meta.DynamicMappingProvider.createFieldMapping(DynamicMappingProvider.java:336)
    [refresh] at
    kodo.jdbc.meta.DynamicMappingProvider.getFieldMapping(DynamicMappingProvider.java:118)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getFieldMapping(MappingRepository.java:470)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:993)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:973)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getMappings(AbstractClassMapping.java:939)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.getDeclaredFieldMappings(AbstractClassMapping.java:659)
    [refresh] at
    kodo.jdbc.meta.AbstractClassMapping.resolve(AbstractClassMapping.java:801)
    [refresh] at
    kodo.jdbc.meta.BaseClassMapping.resolve(BaseClassMapping.java:341)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.resolve(MappingRepository.java:431)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:349)
    [refresh] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:177)
    [refresh] at kodo.jdbc.meta.MappingTool.refresh(MappingTool.java:591)
    [refresh] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:941)
    [refresh] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:879)
    [refresh] at kodo.jdbc.meta.MappingTool.main(MappingTool.java:802)
    Thanks for your help.
    nicolas

    Hi,
    No more succes with persistence-modifier="persistent"...
    My class:
    public class ArrayWrapper {
    private String name;
    private double[] array;
    public ArrayWrapper(String name, double[] array) {
    this.name = name;
    this.array = array;
    public double[] getValues() {
    return array;
    public String getName() {
    return name;
    My metadata file:
    <jdo>
    <package name="model">
    <class name="ArrayWrapper">
    <field name="array" persistence-modifier="persistent">
    <extension vendor-name="kodo" key="jdbc-field-map-name" value="blob">
    <extension vendor-name="kodo" key="column" value="DATA"/>
    </extension>
    </field>
    </class>
    </package>
    </jdo>
    My StackTrace:
    refresh-mapping:
    [java] Exception in thread "main" kodo.util.FatalInternalException:
    Cannot map "model.ArrayWrapper.array". Check the class and make sure you
    are using only supported types.
    [java] at
    kodo.jdbc.meta.DynamicMappingProvider.createFieldMapping(DynamicMappingProvider.java:336)
    [java] at
    kodo.jdbc.meta.DynamicMappingProvider.getFieldMapping(DynamicMappingProvider.java:118)
    [java] at
    kodo.jdbc.meta.MappingRepository.getFieldMapping(MappingRepository.java:470)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:993)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getFieldMapping(AbstractClassMapping.java:973)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getMappings(AbstractClassMapping.java:939)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.getDeclaredFieldMappings(AbstractClassMapping.java:659)
    [java] at
    kodo.jdbc.meta.AbstractClassMapping.resolve(AbstractClassMapping.java:801)
    [java] at
    kodo.jdbc.meta.BaseClassMapping.resolve(BaseClassMapping.java:341)
    [java] at
    kodo.jdbc.meta.MappingRepository.resolve(MappingRepository.java:431)
    [java] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:349)
    [java] at
    kodo.jdbc.meta.MappingRepository.getMapping(MappingRepository.java:177)
    [java] at kodo.jdbc.meta.MappingTool.refresh(MappingTool.java:591)
    [java] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:941)
    [java] at kodo.jdbc.meta.MappingTool.run(MappingTool.java:879)
    [java] at kodo.jdbc.meta.MappingTool.main(MappingTool.java:802)

  • Primitives and garbage collector

    Hi everyone,
    Do primitives get garbage collected?
    Is it recommended to set all references to null in a classes finalize method?
    Thanks

    Do primitives get garbage collected?No.
    Is it recommended to set all references to null in
    in a classes finalize method?No, there is no point in doing that.

  • Has anyone tried to extend Spatial with a 3D primitive?

    Has anyone tried to extend Spatial with a 3D primitive that for example can model buildings and tunnels? I am trying to add the polyhedron primitive next to the existing point, line, polygon model. I just want to hear some tips or ideas...

    The plan is to make a new GType and new stored functions that recognize this GType.
    A polyhedron could be of type 3008,3D and 8=polyhedron(=new). The elem_info
    and ordinates contain multiple planes. Self-created stored functions would be
    able to recognize this GType, e.g. area3D should give the sum of the areas of all the
    faces of the polyhedron and should also work on Gtype=3003 and give the real area
    of a 3D polygon instead of the projection.I wouldn't suggest this methodology if you are considering using any spatial indexing or
    functions with your data.
    There is a mechanism Oracle Spatial has for defining custom datatypes. It should only
    be used with custom apps, i.e. it won't be usable in the context of applications that know
    about Oracle Spatial data types.
    The mechanism allows you to define you own element using an element type of 0, and using
    the interpretation to define what you are looking at. You would also include an a supported
    element type that approximates your geometry, and that element is the one that is indexed,
    and the gtype entered is associated with that geometry. Your private functions could access
    the 3d geometry when required. For instance, you want to have a 3d cube. It might look like this:
    sdo_gtype=3002
    sdo_elem_info=(1,2,1, 7,0,1, 22,0,2 etc.
    sdo_ordinates=(0,0,0,2,2,2, 0,0,0,2,0,0,2,2,0,0,2,0,0,0,0, 2,0,0,2,0,2,2,2,2,2,2,0,2,0,0, etc
    the 1,2,1 in the elem info array corresponds to a 3d line string that when indexed with a minimum bounding
    volume encloses the 3d cube. The 0,0,0 and 2,2,2 in the ordinate array stored as the line string when indexed
    include the bounds of the cube. Next in the elem info array are 7,0,1. The 7 means offst 7 in the ordinate array
    and in this example is fixed. Next the 0 tells Oracle Spatial to ignore this element. The interpretation of 1 you define,
    the number could be anything. Since it is my example, I'll say the 1 means this is the definition of the first face in the
    x,y plane (i.e. the front face of the cube which faces me). I've set the ordinate array with the coordinates of that face.
    Next in elem info comes 22,0,2 which is starting at offset 22 there is another element that Oracle spatial should ignore
    (element type 0), and next comes 2, which might mean this is the second face definition, that I've defined as the right
    hand side y,z plane.
    etc.
    The meaning of the interpretation value is only limited by your imagination.
    Note while you can index three dimensions if you want, the only spatial functionality that supports 3d is a spatial
    index and a filter query, and some lrs functions. You will not be able to run any operator except for SDO_FILTER if you
    have a 3d index, and all spatial functions will only work on 2d.
    Do not define your own gtype and expect to use spatial. it will not work.

  • Reading/writing doubles in primitive format

    I created an array of doubles using random.nextDouble(). Then wrote the array to a file using a primitive format. When trying read the data and put it back into an array, it gives me a java.io.EOFException. Here's the code I used to write and read the data, not the entire program, just the code used for it. Any help is much appretiated; I've been working on this for hours.
              try {
                   DataOutputStream output = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("dblPrim.data")));
                   start = System.currentTimeMillis();
                   for(count=0; count<arraysize; count++){
                        output.writeDouble(anarray[count]);
                        ++count;
                   end = System.currentTimeMillis();
                   time = end - start;
                   displayTime(time, 1);
                   output.close();
                   average = 0;
                   total = 0;
                   start = 0;
                   time = 0;
                   end = 0;
                   double[] anarray2 = new double[arraysize];
                   DataInputStream input = new DataInputStream(new BufferedInputStream(new FileInputStream("dblPrim.data")));
                   start = System.currentTimeMillis();
                   for (count = 0; count<arraysize; count++){
                        System.out.println("" + input.readDouble());
                        anarray2[count] = input.readDouble();
                        total = total + anarray[count];
                   end = System.currentTimeMillis();
                   time = end - start;
                   average = total / anarray.length;
                   displayAverage(average, 2);
                   displayTime(time, 2);
                   input.close();

    take a look at your second 'for' loop:
    for (count = 0; count<arraysize; count++){
    System.out.println("" + input.readDouble());
    anarray2[count] = input.readDouble();
    total = total + anarray[count];
    }you are calling readDouble() TWICE for each iteration, so you will run out of doubles to read too quickly!!

  • JAX-RPC and non-primitive data types

    Hello all!
    I am using JWSDP v1.3 and i have a problem using non-primitive data types as return types for my operations.
    Consider the helloservice example of the JWSDP1.3 tutorial. Now suppose that instead of having the simple operation sayHello() that returns a String, we execute a query on a database, get some ResultSetMetaData and we want these Metadata to be the return type of our operation. I.e. have the operation
    public ResultSetMetaData sayHello()
    instead of the
    public String sayHello()
    of the tutorial.
    When trying to build the service i get the following error which is normal, because ResultSetMetaData is not a supported JAX-RPC type.
    run-wscompile: [echo] Running wscompile: [echo] C:\jwsdp\apache-ant\../jaxrpc/bin/wscompile.bat -define -d build - nd build -classpath build config-interface.xml -model build/model. gz [exec] error: invalid type for JAX-RPC structure: java.sql.ResultSetMetaData [exec] Result: 1
    Is there any way to define an operation like this? Can i specify somehow ResultSetMetaData as a supported-type?
    I hope someone can give me some advice on it, because i have lost one evening trying to figure it out myself :)
    Regards,
    Kostas

    Courtesy links to crossposts so people don't waste their time answering a question which has already been answered
    http://forum.java.sun.com/thread.jsp?thread=482875&forum=59&message=2253704
    http://forum.java.sun.com/thread.jsp?thread=482873&forum=331&message=2253699

  • 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

  • What is a primitive data type?

    ?

    See 4.1 The Kinds of Types and Values and 4.2 Primitive Types and Values in the JLS, and then post again if you have questions.

Maybe you are looking for