Forcing a vector to become an array.

I have a method I want to call that returns a vector of generic object instances. I want it to return an arraylist of instances of my specific class.
neighbors = netGrid.getVonNeumannNeighbors(x, y, false);//vector my VN neighbors. Where neighbors is a class vector. I'd like neighbors to be a local arraylist. Is there a way to do this? I've tried casting neighbors as an array, but since getVonNeumannNeighbors returns a vector, this obviously didn't work, as I've found out.

Perhaps I should have included the whole method so you can see the problem.
     public void creatingEdges() {
          neighbors = netGrid.getVonNeumannNeighbors(x, y, false);//vector my VN neighbors.
          ArrayList <Node> temporary = new ArrayList <Node>();
          for ( int i = 0; i < neighbors.size(); i++ ){//for every neighbor node stored in neighbors
               Object o = neighbors.get(i);//get an object out of the vector.
               System.out.println("Object #" + i  + " is a " + o.getClass().getName());//check that it's a node..
               if (o instanceof Node) {//if it is
                    temporary.add((Node) o); //add it to the temporary array list
               for (int j = 0; j <temporary.size(); j++) {//for all the neighbors in temporary
                    Node neighborNode = new Node();// cast it as a Node 
                    System.out.println("the neighbor node's ID is " + neighborNode.getID());
                    if (neighborNode.getEdgesFrom(this) == null){//if the neighbor node doesn't have an edge FROM this node
                         Edge anEdge = new Edge(); //make a new edge.
                         anEdge.setFrom(this);//send a new edge from this node
                         anEdge.setTo(neighborNode);//connect that edge to the neighbor.
                         this.addOutEdge(anEdge);//tell this node it's got a new out edge.
                         neighborNode.addInEdge(anEdge);//tell the neighbor node it's got a new in edge.
     }While the method is still a work in progress, I'd like to use an array list instead of a vector, since then I can get rid of half the crap in this method. Here's the API for the problem method: http://repast.sourceforge.net/api/uchicago/src/sim/space/Object2DGrid.html
Can it be cast as an array?

Similar Messages

  • Converting a Vector to a Typed Array Problems

    Ok so consider the code below for the error I get right here. Why doesn't it allow me to cast back?
    ava.lang.ClassCastException: [Ljava.lang.Object;
            at woobobs.Status.getStatusNodes(Status.java:78)
    public class Status {
        private Vector<StatusNode> status;
        private String accountName;
        /** Creates a new instance of Status */
        public Status(String accountName) {
            this.accountName = accountName;
            status = new Vector<StatusNode>();
            this.status.add(new StatusNode(accountName, 1, "Account Created - Not Running"));
        public void setStatus(int code, String status) {
            this.status.add(new StatusNode(accountName, code, status));
        public void setStatus(String status) {
            this.status.add(new StatusNode(accountName, 1, status));
        public String getLastStatus(boolean code, boolean date, boolean account) {
            String returnString = "";
            if(code) {
                returnString = "{" + Integer.toString(this.status.lastElement().getCode()) + "}";
            if(date) {
                returnString = returnString + "[" + this.status.lastElement().getTime().toString() + "]";
            if(account) {
                returnString = returnString + this.accountName + ": ";
            return returnString + this.status.lastElement().getMessage();
        public String getLastStatus() {
            return this.getLastStatus(false, false, false);
        public int getLastColor() {
            return this.status.lastElement().getCode();
        public String[] getAllStatus(boolean code, boolean date, boolean account) {
            String[] sStatus = new String[this.status.size()];
            for(int i=0;i<this.status.size();i++) {
                if(code) {
                    sStatus[i] = "{" + Integer.toString(this.status.get(i).getCode()) + "}";
                if(date) {
                    sStatus[i] = sStatus[i] + "[" + this.status.get(i).getTime().toString() + "]";
                if(account) {
                    sStatus[i] = sStatus[i] + this.accountName + ": ";
                sStatus[i] = sStatus[i] + this.status.get(i).getMessage();
            return sStatus;
        public StatusNode[] getStatusNodes() {
            return (StatusNode[])this.status.toArray();
        public int getStatusNodeCount() {
            return this.status.size();
        public class StatusNode implements Comparable {
            private String message;
            private int code;
            private Date time;
            private String accountName;
            public StatusNode(String accountName, int code, String message) {
                time = new Date();
                this.code = code;
                this.message = message;
                this.accountName = accountName;
            public String getMessage() {
                return message;
            public int getCode() {
                return code;
            public Date getTime() {
                return time;
            public String getAccountName() {
                return accountName;
            public int compareTo(Object o) {
                StatusNode compare = (StatusNode)o;
                if(compare.getTime().after(this.time)) {
                    return 1;
                } else if(compare.getTime().before(this.time)) {
                    return -1;
                } else {
                    return 0;
    }

    The code that I've posted belongs to a simple function whose aim is to fill an array with
    all the prime numbers the are less than a given value.
    The function must return an array of int (int[]).Since I don't know how many primes I will find, I need a growable array, so I decided to use Vector.If there is a better way, please tell me.
    Here is the function prototype:
    /**returns all prime numbers that are less than max_value*/
    public int[] getPrimeNumbers(int max_value){
    //function's body
    }thank you in advance

  • Vectors : Converting to double[ ] array

    Hello,
    I have a vector which I know consists of double values only. I am trying to create an array of double from this vector but am having some difficulty.
    Firstly if I try this :
    double[] high = (double[])datavector.high.toArray(new double[0]);JBuilder reports :
    'Cannot find method toArray(double[])'
    But if I try this :
    Double[] high = (Double[])datavector.high.toArray(new Double[0]);It works.
    So from this I assume 'Double' is not equal to 'double'
    The trouble is I require 'double[ ]' and NOT 'Double [ ]'.
    Casting Double as (double) does not work... so how do I get double[] from my original vector ?
    Many thanks
    Kerry

    double[] d = new double[v.size()];
              int i = 0;
              for(Iterator<Double> it = v.iterator(); it.hasNext();)
                   d[i++] = (double)it.next();
              just declare the double array to be the size of the vector, then loop thru and populate the array one at a time
    ~Tim

  • Vector image becomes pixelated and distorts text

    This is an issue that is driving me nuts!  I have a vector image created in Illustrator that I am placing in InDesign with an opacity setting.  When I print it to a PDF the text (and anything created in InDesign) that is over the image and the image itself become pixelated.  In InDesign in displays perfectly but something is happening in the conversion to PDF that is screwing up the file.  It displays and prints pixelated.  Any help would be GREATLY appreciated!
    Thanks so much!

    Hey Nik-
    I think I fixed it but fill me in.  The text is on a seperate layer above the image. I am printing to a PDF, is exporting better?  I just changed the transparency flattener to High resolution when i printed to a PDF it is now displaying and printing properly in Acrobat.
    Is that the best way to do this to ensure when I take it to a printer it will come out clean?
    Thanks!

  • Illustrator vector object becomes less black in Photoshop

    I drew an object, all black, in Illustrator, then placed it into Photoshop, the vector become less saturated than it was in Illustrator. Can anyone help me solve this problem?

    Sulaco wrote:
    You might also want to check "Edit/Preferences/Appearance of Black" in Illustrator. To deepen the black when printing (CMYK) you mix other colours into it, creating something called Rich Black. The mix could be something like C=50,M=50,Y=50,K=100, this will produce a blacker black than C=0,M=0,Y=0,K=100 (called 100K Black) when printing, it's desirable in certain situations.
    Now "Appearance of Black" controls how black is displayed/printed/exported in Illustrator and I think that the default setting is "Display All Blacks As Rich Black" which means than if you use 100K Black in Illustrator and then transfer it to PS it might look less black in PS, depending on your settings.
    It's one of those things that, even if new to CMYK, 100K black would look so wrong, you'd have to look into it and find out what the heck was going on
    Sulaco, useful tip about pasting into Photoshop.

  • Illustrator vector shapes become jagged in flash

    does anyone know why when importing vector shapes from
    illustrator into flash the shapes become very jagged when the swf
    file is published?
    thanks

    Hi R-Designer,
    The jagged edges are caused by the import process in Flash.
    When it
    encounters complex fills or lines it can't directly handle,
    it converts them
    to bitmaps. Illustrator will also sometimes do this when
    exporting for
    Flash. Unfortunately, the only way to deal with this is to
    reduce the
    complexity of your image (especially fills or fancy lines) or
    exporting the
    whole thing as a high-res bitmap.
    Regards,
    Patrick Bay
    BAY NEW MEDIA
    "R-Designer" <[email protected]> wrote in message
    news:foacbt$4fg$[email protected]..
    > I'm having the same problem. I've taken an AI and tried
    to import as an
    > AI, PDF
    > and 'save for web' gif and the outer curve is jagged.
    The inner curves
    > look
    > great. I've noticed none of the questions regarding this
    type of problem
    > have
    > been answered... Any ideas?
    >

  • How to Use a Boolean Vector To Index an Array

    Say I have an array A = [1 2 3 4 5 6 7 8 9 10].
    I also have a boolean array B = [1 1 0 0 0 0 0 0 0 1].
    I want to use the boolean array B to pick out elements in A, creating a new array C = [1 2 10]. In MATLAB, I would just type C = A(B).
    I'm scratching my head trying to figure out how to do this. One solution would be to run through a for loop, querying B(i), and deleting A(i) if B(i) = 1. But this would change the size of A, so that the second time I did this, my index would be wrong.
    Anyone know a clean way of doing this?
    BONUS: If I have a 2D AA, with multiple columns, it would be nice to use B to pick out multiple columns of AA (in MATLAB, this would be CC = AA(:,B).
    Solved!
    Go to Solution.

    This can be done with auto-indexing with conditional tunnels.  The same approach could easily be applied to a 2D array, as well:

  • Rastorized Vector Art Becomes Translucent

    Sometimes I get vector art that appears to be completely normal, and opaque: screenshot 1
    Then I try to convert the file into a rastor image for presentation purposes and this happens:
    If you can see in the first picture, the vector art is all opaque, but in the second image, it has been rasterized, and appears to be set to a "Multiply" transparency. You may also note in Screenshot 1 that the Transparency Tab on the right specifies the vector art as normal. However, if I were to take each piece individually and rasterize it, it would look normal, as such: screenshot 3
    Whether I am saving for web & devices, exporting as a jpeg, or using Object>Rastorize (all together), this problem comes up. However, it only happens on rare occasions, and only in CMYK document color mode. I have rastorized hundreds of such images without any such problem. The graphics in the screenshot were copied directly from a file I was working with, and I was not the original creator of this art, so I don't know the process that occured to create it in the first place. However, the attribute is transferable with the eyedrop tool.
    Anybody have an explanation??

    Thank you, that was the problem. When I select the individual objects, the overprint shows up in the attributes window. Now I'm wondering how does one turn off/on overprint? I found I could dump the attribute, but then I lose my color (and that may be problematic in the future). Is there a better way to turn off the overprint?

  • How to force BDC to accept individual selection array entries in a pulldown

    I'm calling the HUMO transaction from an ALV program passing the handling unit single values (RSCSEL-SLOW(01, 02, 03...09)).  When you execute the transaction, at the initial selection screen, the Handling Unit box appears empty.  However, if you click to open the box for the single values, ranges, excluded single values, excluded ranges, you see the values in the single values.  At that point, you must click on the slider bar to get them accepted.  You can then execute the HUMO transaction so that it will use the single values.  If you don't step in and click on the boxes, the transaction will not see them.
    Is there something that can be passed that will force the transaction to recognize those values without having to click on them?
    thx
    Mike DeGuire

    Naresh,
    Thx for the tip.  When the code runs, it populates the field beautifully, but when you press the execute button, it returns without executing the transaction.  I've put your code in a test program:
    report z_test_print_barc.
    tables vekp.
    select-options r_hnum for vekp-exidv.
    SAP DEveloper NEtwork tip
       ranges: r_hnum for vekp-exidv.
       loop at h_lenum.
         r_hnum-sign   = 'I'.
         r_hnum-option = 'EQ'.
         r_hnum-low    = h_lenum-lenum.
         append r_hnum.
       endloop.
        submit rhu_help with selexidv in r_hnum
        via selection-screen
        and return
        exporting list to memory.
    I populate the select-options r_hnum with some data from the clipboard and when the submit is executed, it populates the screen, but  will not execute the transaction.
    Ideas?
    thx,
    Mike

  • Why does my vector drawing become pixelated once uploaded to the Creative Cloud?

    I'm drawing in Adobe Ideas on my iPad. I assume the only way to save it is to upload it to the Creative Cloud. When I go to view it in the cloud, it looks pixelated. Even when I download it, it is still pixelated. Why is this happening?

    You need to ask in the appropriate TOUCH APP forum
    If you will start at the Forums Index https://forums.adobe.com/welcome
    You will be able to select a forum for the specific Adobe product(s) you use
    Click the "down arrow" symbol on the right (where it says All communities) to open the drop down list and scroll

  • Arrrgghgh!! "Force Quitting" Aperture has become routine

    I am processing 2-3 jobs of 100-300 images(most JPG) daily and am finding I need to slow up when doing things like pasting(stamping) image settings otherwise I get the SBOD(spinning beach ball of death).
    My steps:
    1. Cull entire project
    2. Rotate each keeper in project (STAMPING a crop would be most helpful here!)
    3. Crop and color/exposure correct via stamp(CMD-SHIFT-V)
    I find if I stamp too quickly after the crop the SBOD tournament begins...
    BTW a setting of setting the crop aspect to match the aspect of the image would be a time saver as well...

    I would just go ahead and delete the  vaults in Finder with Aperture CLOSED. Then start Aperture and remove the vaults in Aperture.
    When a disk that is being used gets full it is hard to predict what behavior you will see and it might be different each time it happens.  So it is possible that the symptoms you had might have been caused by running out of disk space, really no way to say for certain. What you can say is that running out of or low of disk space is a condition you really want to avoid.
    The vault like the library is really a folder containing lots of folders and files so deleting it is not as simple a task as deleting a single file. However when I go to remove a vault in Aperture I get the following dialog
    Which shows both Remove and Remove and Delete options. If I select just Remove the vault is removed from Aperture but remains on the disk. Did you not see the same thing?
    Anyway given all you've been through you're doing pretty good. You have your library intact and a backup of it. I'd just go ahead and delete the vaults make sure you have enough room on the disk and then create new vaults. You should be good to go after that,
    good luck
    regards

  • Problem in converting vector to array of strings

    hi
    i am having a vector which in turn contains hashtable as elements
    Vector v=new Vector()
    Hashtable ht=new Hashtable();
    v.add(ht.add("key1",value1))
    v.add(ht.add("key2",value2))
    v.add(ht.add("key3",value3))
    v.add(ht.add("key4",value4))now i am trying to conver this vector in to a array of string like
    String[] str=(String[])v.toArray(new String[v.size()]);but i am getting java.lang.ArrayStoreExceptioncan anybody help me plz
    Thanks

    Hi,
    The api for public Object[] toArray(Object[] a) says
    Returns an array containing all of the elements in this Vector in the correct order; the runtime type of the returned array is that of the specified array.
    ArrayStoreException will be thrown if the runtime type of a is not a supertype of the runtime type of every element in this Vector.
    The runtime type of the elements of the vector is Hashtable.
    Because String is not a supertype of Hashtable the ArrayStoreException is thrown.

  • Converting vector to string array

    How can I convert values in a vector into a string array?
    Vector formsVector = new Vector();
    while (rs.next())
    {formsVector.add(rs.getString("forms"));}
    String forms[] = (String[])formsVector.toArray();
    I tried the above line but it did not work. Any input please?
    Thanks

    .... What is the difference between the two as
    according to online help, both are same.
    String forms[] = (String [])formsVector.toArray();
    String forms[] = (String [])formsVector.toArray( new
    String[0] );The difference lies in the type of the object returned from toArray. The first form you list, formsVector.toArray(), always returns an Object[]. In your example, you'll get a ClassCastException at runtime when you cast to String[].
    The second form will try to use the array you pass in. If it's not big enough, it'll create a new one of the same type as that array. This is what's happening when passing a zero-length array into toArray.
    My personal preference is to save an extra instantiation and build the array to the proper size to begin with:String forms[] = (String [])formsVector.toArray( new String[formsVector.size()] );

  • Vector Array out of range error

    Hiya, I've run into a strange Vector out of range error when trying to splice a Vector array. The idea is to cut off the Vector array after a certain point....
    var vec:Vector.<int> = new Vector.<int>();
    vec.push(1);
    vec.push(2);
    vec.push(3);
    vec.push(4);
    vec.push(5);
    vec.splice(3,vec.length); // output RangeError: Error #1125: The index 5 is out of range 5.
    The strange thing is that it works perfectly, if I change the Vector to a regular array like:
    var vec:Vector.<int> = new Vector.<int>();    to    var vec:Array.<int> = new Array();
    Any ideas what am i doing wrong ?
    Thanks, Martin

    I don't know why it don't throw error in Array, but seccond parameter in splice method is deletecount, so you try to delete all elements start from 3 (from element 3 to element 8, but you don't have 8 elements).
    vec.splice(3,vec.length - 3);

  • Sorting Arrays in a Vector by a String field in the array

    Hi
    i have a Vector where i put Arrays in. These Arrays are all of the same type. The first field is kind of an indetifier, the type is String. That's the key field i'd like to sort the vector elements in an alphabetical order.
    I know there is that Collator methode to sort Vectors. That's no problem for me to do if i just have Strings in the Vector. But with this contruct of Arrays that need do be sortet for one fiel of the array, i have no idea whether this might be done with that Collator methode too.
    So, before i start written some kind of bubble sort methode (that sure would solve the problem, but probably not very smart and fast...) I'd like to ask you, whether you have an idea how to solve that problem with Collator or even with some other methode?
    thanks for your help!

    Comparable and Arrays.sort. Read the APIs, or look at the two or three examples I've done so far today in this forum. Or search the forum for +Comparable Arrays sort
    Answer provided by Friends of the Water Cooler. Please inform forum admin via the
    'Discuss the JDC Web Site' forum that off-topic threads should be supported.

Maybe you are looking for

  • How to enable full autocomplete description with own JAR ?

    Hi there, To put my problem simply: I've created a JAR file and wish to utilize it within another Java project. Therefor I've imported the JAR file in my project path (I've done this in Eclipse and IntelliJ) and in both IDEs the JAR file works just f

  • Itunes 6.0.2 crashes along with the dock

    After I upgraded to itunes 6.0.2 and OS 10.4.4 my itunes crashes whenever my mouse rolls over the "my ratings" tab after "right-clicking" on a song or accessing my ratings through the menu bar at the top. itunes will immediately hang and eventually c

  • SMTP Mail on a Solaris Platform

    What is the best way to get email into and out of Forte on the Solaris Platform. The mail will contain a MIME partition. We would like the incoming mail to create a Forte Event that passes a copy of the file sent via the MIME partition. The file shou

  • Flash 8  My Fading Text Doesn't Work

    I am quite a novice flash user so this maybe a really basic question. I have created a flash file where I have text fading in and then fading out. I created my text, coverted to symbol and then set the alpha to 0%, then in a later key frame set it to

  • Law-enforcement-rpn.linabirsa.tk

    Hello everybody, from 2 days my browers (firefox, safari and crhome) are the redirect to law-enforcement-rpn.linabirsa.tk . i think it's a malaware but, how i can fix it? How i can remove this malaware? please help matteo