Vector with a twist

Hello all,
The problem i am having is trying to get the index number for my
setElementAt.
This is what is happening...
A person will enter an employee number (i.e 100)
and name
What i need to get is the actual number "1" as a int
Once i get that then i will do it like this...
employee.setElementAt(employee, here is where that "1" goes in)
and if they enter 200...
employee.setElementAt(employee, here is where the "2" goes in)
remember, the index has to be a number.
I know some of you may be asking "hastable or list array"
Well, i cant use those, sorry.

You could this code to get the index:
int getIndex(int value)
int divideBy = 10;
int newValue = 0;
int processValue = value;
while(true)
  if(processValue < 10)
   //if the value is less than 10, u get ur index without any processing
   return Math.abs(processValue); //taking care of -ve vals
  else
   newValue = (int) processValue / divideBy;
   if(newValue < 10)
    //got the index.
    return Math.abs(newValue);
   else
    //process further
    newValue = processValue;
    continue;
return Math.abs(value);
}Very crude implementation, without any performance implications etc.
But i guess, should work. U could improve on it further.
-Manish.

Similar Messages

  • How to create Vector with reference to Collection

    hello experts,
    can someone let me know how to create vector with reference to Collection interface.
    Collection is an interface. and we cant create an instance of it. i'm not clear of what to pass in that constructor.
    Vector v = new Vector (Collection c);
    what are the possible objects of 'c'
    post some example code please.
    thanks

    Ever heard of reading the javadocs?
    "Collection is an interface. and we cant create an instance of it." - you don't understand interfaces, then.
    // I certainly can create a Collection - here's one
    Collection c = new ArrayList();
    // Now I'll add some Strings to my Collection.
    c.add("foo");
    c.add("bar");
    c.add("baz");
    // Now I'll make a Vector out of it.
    Vector v = new Vector(c);%

  • Can i save a vector with gradient mesh as isolated .PNG?

    Hi,
    Can i save a vector with gradient mesh as isolated .PNG?
    It has some effects, so if i'm taking it out from the blue background it becomes darker.
    Any advice? I need it isolated png for using it in an iOS app.
    Many thanks

    I am using Illustrator CS6, on Mac.
    I can't copy and paste the "cloud" into a new document to save it, because it looses the effect of those filters (since the background is no longer behind it).
    Sorry if im not explaining it right, i'm a beginner in illustrator.  Can i group both the "cloud" and the blue background, to get just one shape: the realistic white cloud?
    P.S: i can make a link with the .esp file of the clouds, if it helps.

  • Replacing vectors with better collection

    Hi,
    My Netbeans IDE is giving me a hint that vectors (which I am using to build custom table models from AbstractTableModel) are obsolete.
    What should I replace vectors with, or what collection should I use to build custom table models, any example will be appreciated.
    Thanks

    jverd wrote:
    Use ArrayList instead of Vector.
    However, interaction with legacy GUI APIs is one commons place where you have to use Vector. I'm not sure if AbstractTableModel falls into that category, but you can find out easily enough.Unlike DefaultTableModel, AbstractTableModel makes no assumptions about how the data must be stored. That is why it is useful. It can be used to adapt other data structures to TableModel without the need to copy the data.

  • Element-by-element multiplication of a vector with matrix rows

    I want to element-by-element multiply a Vector with the rows of a Matrix ,in the most efficient way. Anybody knows if there is a sub vi for this in LW7.0 ?
    (The Inputs are a Matrix; and a Vector with the same size as Matrix's # of columns ; the output is a Matrix with the same dimension as input Matrix. Every row of the output Matrix is the product of element-by-element multiplication of input vector with the correspondind input Matrix's row )
    Thanks

    (Yes, the 2D linear evaluation is basically the same as the 1D evaluation except for the dimension if the array. NI could merge them into one and make the array input polymorphic with respect to size. )
    I "think" you want a plain multiply (not a polynomial evaluation). You can do it (A) one row at a time or (B) one column at a time, but A might possibly be slightly more efficient. Do all three (including the one in the next message) and race them with your real data! Message Edited by altenbach on 03-14-2005 07:47 AM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    MatrixTimesVector.gif ‏5 KB

  • Why do images/vectors with effects get rasterised when clipped in Illustrator

    Why do images/vectors with effects get rasterised when clipped in Illustrator@

    Which version
    which system?
    What exactly did you do?
    What exactly happened?
    What exactly is wrong with that?
    Can you show a screenshot?

  • Enum thru vector with many diff types of obj?

    lets say i have vector 'food' which contains a bunch of objects of different classes, like 'bread' and 'cheese', if i wanted to enumerate through them, how would i go about doing that? i know how to enumerate through a vector with the knowledge that all the objects in it are of the same class, like Food currentFood = (Food)enum.nextElement() , but i dont see how to make variable type dynamic

    If you have a vector where all the elements are Food, then you can safely cast each element to Food and call Food methods on each element.
    If one of the elements is a Bread, and Bread has a method that isn't present in Food, then you can't call that method without first checking to see if the element is a Bread and casting it. But ideally you should be designing such that this isn't an issue.
    For example, Bread may have a bake() method, and ChocolateMilk may have a mix() method. But rather than using instanceof on each Food to see if it's a Bread or a ChocolateMilk, and then calling either bake() or mix(), it's better to have a method prepare() in the Food class. Then you just call prepare() on each object. It may be that Bake.prepare() does nothing more than invoke bake(), but the point is that the caller doesn't need to know that.
    That may not be the best example.

  • Converting Vector with Floats to float[] typecast error?

    Java Developers,
    I am able to convert my String vector to a
    String[] but just can't get the Vector with Floats to be converted to a float[] array. I have looked into google and java.sun.com Forums but still cant seem to find the answer. I would really appreciate your help!
    This is how I am making the conversion from Vector(String) to String[]:
    legendLabelsArray = new String[columnHeads.size()];
    int k=0;
    Iterator e = columnHeads.iterator();
    while(e.hasNext()){
    System.out.println("inside the enumerator");
    legendLabelsArray[k] = e.next().toString();
    System.out.println("Array elements at " + k + " are " + legendLabelsArray[k]);
    System.out.println(k++);
    How can I make something similar to work with a Vector with Floats to float[] instead of Strings?
    Thanks,
    Musaddiq
    [email protected]

    Something like this ...
    float[] floatArray = new float[vectorOfFloats.size()];
    int k=0;
    Iterator e = vectorOfFloats.iterator();
    while(e.hasNext()){
    floatArray[k] = ((Float) e.next()).floatValue();
    k++;

  • Vector with bytes to byte[ ]

    I have a Vector with bytes as it elements:
    Vector _buffer = new Vector();
    byte a = 120;
    byte b = 67;
    byte c = 98;
    _buffer.addElement(a);
    _buffer.addElement(b);
    _buffer.addElement(c);And I want to read it our into a byte[ ], so it is more easy to, for example, make a string of it. So I want to do this:
    byte[] b = (byte[]) _buffer.toArray(new byte[0]);But this isn't working, probably because byte is a primitive, and the function Vector: public <T> T[] toArray(T[] a) works on classes (I am not sure about this...?)
    The following is working:
    Vector _buffer = new Vector();
    Byte a = new Byte(120);
    Byte b = new Byte(67);
    Byte c = new Byte(98);
    _buffer.addElement(a);
    _buffer.addElement(b);
    _buffer.addElement(c);
    Byte[] b = (Byte[]) _buffer.toArray(new Byte[0]);But this isn't what I want, because even now I can't make a byte[] out of the Byte[]. Is there an easy way (loops off course, but maybe a more elegant way) to bridge this gap between primitives and classes?
    Thanks in Advance

    Geert wrote:
    I don't see how to work with the ByteArrayInputStream...? The socket only returns me an InputStream, so how to convert it to an ByteArrayInputStream?I said ByteArrayOutputStream, not ByteArrayInputStream.
    You're reading from the stream and adding the bytes to a Vector<Byte>, right? Instead of storing them in a Vector<Byte>, write them to the ByteArrayOutputStream instead. Then you can call toByteArray() to get a byte[].
    EDIT: I should've limited my quote in reply #5 to this part:
    I need to have a dynamical created array. Because the order of the List is important I thought I would need to use a Vector object.

  • Photos missing from iPhoto/TM backup but with a twist.....

    So, there is a challenging twist associated with this case of missing photos and I hope an expert can provide some advice. Note: This is not related to upgrading from iPhoto '09 to '11 thank goodness!
    Here is the story in condensed form, with additional details below:
    MBP stolen but backed up with TM
    Used TM on the replacement MBP to browse backup of iPhoto backup of stolen MBP
    Restored iPhoto library to new MBP
    Open iPhoto on new MBP and browse library
    Everything looks OK except *FIVE* Events which show in the Event viewer as blank grey squares. However, the Events have the correct titles and show the correct number of pictures in brackets in the title. In addition, using the trackpad to scroll over the Event there are no thumbnails visible. If I click on the Event all the photos are greyed out but they do have the correct titles and keywords below the grey boxes. If I click on an individual photo I get a black exclamation mark in a grey circle. Interestingly the LAST IMPORT folder in iPhoto DOES show the thumbnails for ALL the missing pictures, all arrange with the correct Event titles. Of course, clicking on any individual picture gives me the same exclamation mark detailed above.
    After reading these support forums I have tried the following:
    1) Viewed package contents ---> the blank Events DO NOT show up as folders in the Finder window
    2) Used COMMAND & OPTION to launch iPhoto and checked the following boxes in the REBUILD DIALOG BOX: rebuild small thumbnails/rebuild all of the photos' thumbnails/recover orphaned photos/examine and repair permissions ---> Issue persists
    3) Download iPhoto Manager and tried EXTRACTING all the photos from the library --> Photos from missing events still not showing up. Not really surprising given that the VIEW PKG. CONTENTS in #1 above didn't show them either.
    4) Used iPhoto Manager to REBUILD LIBRARY --> still doesn't show them
    5) Used TM to browse the backup directly --> missing photos have blank placeholders only.
    It appears for what ever reason the photos have been deleted from the backup. I say "deleted", as opposed to "not backup up", because iPhoto has the remnants of the photos (i.e, Events, thumbnails, titles, keyword, etc.). Any suggestions on how to possibly recover these missing pictures. How about the thumbnail versions at least, even in their their low resolution form. Although, I admit I don't know how/where thumbnails are dealt with in iPhoto as they don't seem to show up in the Library package contents.
    Additional info:
    OSX 10.7.5, iPhoto '09 is version 8.1.2, and iPhoto library is 75GB, 139 Events, 28,000 pics
    The day before the MBP was stolen I downloaded a number of photos and did some editing. That night plugged the MBP in and noticed that the Time Machine did a number of backups through the night, although the iPhoto library seems untouched but can't be sure. The following morning, the computer was used for a few hours and thus had plenty of time to complete any backups necessary.
    The *FIVE* Events that are affected seem to be the most recent ones, worked on the night before the MBP was stolen.

    I cannot say for certian but it is highly likley that YES, when the person finished editing they just closed the lid of the computer and didn't actually quit iPhoto. So would this explain why there are fragmenst of them in the backup (i.e. Events, keywords, thumbnails, etc.) but not the actual image files? Any way I can at least save the extremely low res thumbnail versions?
    I'm also going to try Data Rescue on the camera memory card to try and recover them that way.
    Thanks.

  • Would like to Downgrade OS, with a twist.

    Hi,
    Thanks for reading !
    The thing is i play games and recently ive come up against a brick-wall in that i cant play World of Warcraft, ok so its not gonna ruin my life but ...
    Anyway what happens is ( after either 10.4.9 / 10.4.10 ) login to game and maybe 5 mins after I will be disconnected from the game server. Not only that and this is the crunch, net connectivity is lost completely. No safari, skype, ventrilo ..nothing. On attempt to reconnect, `the other side is not responding`. Ive tried by direct ethernet and using a wireless router with no luck.
    As to how im writing this email, a restart of computer magically fixes it. The weird thing is that my IP address keeps changing, why that is i cannot say. Hence why i throw myself down upon the mercy of those who may understand it better than i do.
    The solution? Reverting to a previous version of the OS seems a good bet. I know it can be done using the Mac install cds. This brings me to the twist, the optical drive that came with my mac was great for a while but now is unable to read either cds or dvds ( and yes ive tried every brand under the sun ). Guess i got one of the bad ones there then. To avoid me just moaning >
    1) Can a downgrade be done without the boot cds?
    2) Would it just be better to get the drive fixed? ( im loathed to do this as i use it a great deal for work and it would be a big loss)
    I have an an external HD if that helps Im guessing that a reformat is in the offing but sob sob...
    Anyone any ideas about what the trouble is in any case??
    kind regards
    M.
    MacBook Pro 15"   Mac OS X (10.4.10)   2Ghz CoreDuo, 2Gb RAM

    I would concentrate on the changing the IP address rather than reinstall the OS! Can yo ugive anymore details on that? It is obviously where your issue lies. How is your network setup? Even if you have a very short DHCP lease, the router should try and redistribute the same IP address to you, so an every changing address is a problem.

  • How to cast vector to vector with out using loop. and how to override "operator =" of vector for this kind of condition.

    Hi All How to TypeCast in vector<>...  typedef  struct ...  to class... 
    //how to cast the vector to vector cast with out using loop
    // is there any way?
    //================ This is Type Definition for the class of ClsMytype=====================
    typedef struct tagClsMytype
    CString m_Name;
    int m_Index;
    double m_Value;
    } xClsMytype;
    //================ End of Type Definition for the class of ClsMytype=====================
    class ClsMytype : public CObject
    public:
    ClsMytype(); // Constructor
    virtual ~ClsMytype(); // Distructor
    ClsMytype(const ClsMytype &e);//Copy Constructor
    // =========================================
    DECLARE_SERIAL(ClsMytype)
    virtual void Serialize(CArchive& ar); /// Serialize
    ClsMytype& operator=( const ClsMytype &e); //= operator for class
    xClsMytype GetType(); // return the typedef struct of an object
    ClsMytype& operator=( const xClsMytype &e);// = operator to use typedef struct
    ClsMytype* operator->() { return this;};
    operator ClsMytype*() { return this; };
    //public veriable decleare
    public:
    CString m_Name;
    int m_Index;
    double m_Value;
    typedef struct tagClsMyTypeCollection
    vector <xClsMytype> m_t_Col;
    } xClsMyTypeCollection;
    class ClsMyTypeCollection : public CObject
    public:
    ClsMyTypeCollection(); // Constructor
    virtual ~ClsMyTypeCollection(); // Distructor
    ClsMyTypeCollection(const ClsMyTypeCollection &e);//Copy Constructor
    DECLARE_SERIAL(ClsMyTypeCollection)
    virtual void Serialize(CArchive& ar);
    xClsMyTypeCollection GetType();
    ClsMyTypeCollection& operator=( const xClsMyTypeCollection &e);
    ClsMyTypeCollection& operator=( const ClsMyTypeCollection &e); //= operator for class
    void Init(); // init all object
    CString ToString(); // to convert value to string for the display or message proposed
    ClsMyTypeCollection* operator->() { return this;}; // operator pointer to ->
    operator ClsMyTypeCollection*() {return this;};
    public:
    vector <ClsMytype> m_t_Col;
    //private veriable decleare
    private:
    //===================================================
    ClsMytype& ClsMytype::operator=( const xClsMytype &e )
    this->m_Name= e.m_Name;
    this->m_Index= e.m_Index;
    this->m_Value= e.m_Value;
    return (*this);
    //==========================Problem for the vector to vector cast
    ClsMyTypeCollection& ClsMyTypeCollection::operator=( const xClsMyTypeCollection &e )
    this->m_t_Col= (vector<ClsMytype>)e.m_t_Col; // how to cast
    return (*this);
    Thanks in Advance

    Hi Smirt
    You could do:
    ClsMyTypeCollection* operator->() {
    returnthis;};
    // operator pointer to ->
    operatorClsMyTypeCollection*()
    {returnthis;};
    public:
    vector<ClsMytype>
    m_t_Col;//??
    The last line with "vector<xClsMytype>
    m_t_Col;". It compiles but I doubt that is what you want.
    Regards
    Chong

  • Initializing Vectors with objects.

    Hi all,
    I am investigating a problem and have narrowed down to a section of code where the Vector.get() method returns an empty string instead of null when the key queried doesn�t exist. I know I can alter the code to check for null or empty string but I wanted to find out why?
    I am not sure if initializing a Vector variable with an existing object is the cause� Here is a line from the code:
    Vector result = oracleWrapper.getCodeList (regionCode); //This call returns a vector.In test I ran this code a million times but couldn�t recreate it� but in production, after a few days (since the server bounce (JRun 4x)) of normal behaviour, it just starts returning empty string instead of null for keys that don�t exist in the Vector! Restarting the server is the solution for now!
    What I want to find out:
    1. Is initializing Vectors like in the snippet above fine?
    2. Are there any known issues similar to this scenario?
    3. Is call to a constructor explicitly required to guarantee its integrity?
    Thanks a mill,
    Jay

    True and I have already removed the Vector from my list of suspects because this problem only happens after a few days of normal functioning and the vector still contains an incomplete string when the error starts. I am on the look for statements that may be resulting in memory leaks and temporarily have a Properties object in my list of suspects along with a few StringBuffers.
    The code has a statement Properties props = null; and then after a few lines a value from a Vector object is put into it!
    props= (Properties) result.elementAt(idx);I have load tested it but cant get it to break!
    I have spent way too long on this and may be rewriting it would have been quicker! But can�t :(
    I am soo stuck.

  • Illustrator saving vectors with different attributes than assigned prior to saving

    I am having a problem whenever I save a document in Illustrator.
    Near the edges of the page, I am placing a few rectangular vectors filled in only with black.
    When I save the image as a .pdf, two of these get changed.
    One on top, and one on bottom, at the exact same x placement.
    Prior to saving, they are all completely identical with the same attributes.
    I even deleted the old ones, replaced them with new ones, which I copied from other marks that were not messing up, and saved the .ai file as a .pdf again, but to no avail.
    Please help as I have no idea what to do to fix this.
    I have tried unchecking save as an illustrator editable file, save with layers, etc.
    Any advice would be greatly appreciated.

    BeeHiver wrote:
    Well, I believe that it is simply the way that adobe was displaying it, because if I zoom in on the .pdf file, the added thickness disappears.
    The same thing happens when I have the letter I in text, not sure why this happens, but I no longer think it is an issue.
    That letter 'l' looking thicker is a known issue with a PDF file... as you've noticed, it clears up when you zoom in and also, it doesn't print like that...

  • Initializing Vector with ResultSet(too Slow!)

    Hi
    I'm createing a JTable with two Vectors. Im am initializing the Vectors in a while loop, but it is way to slow with large ResultSets.
    Does anyone know how I can speed this process up?
    Thanks!

    Heres the full method Ive removed some of hte code in the for loop. But that makes no difference to the speed
    private Vector getData(int columns[]) throws Exception
         rows = new Vector(queue.count);
         while (res.next())
                 Vector newRow = new Vector(columns.length);
              for (int i = 0; i < columns.length; i++)
                 newRow.addElement(res.getString(columns));     
    rows.addElement(newRow);
    return rows;

Maybe you are looking for

  • While I can access my email webpage after upgrading to Firefox 5 I cannot access my email inbox

    We have no problem accessing other web pages such as google or ebay and it is strange that we can get onto our email site but just not get into our inbox for new emails. There are no details given about the inbox contents either - it says 'undefined

  • Apache Axis Soap Envelope soap:Header

    <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"> <soap:Header> <DataHeader xmlns="http://m

  • Hiding the web start security popup

    Dear friends, a simple question: if I sign my WS app with a comercial ceriticate from Verysign, it will eliminate that popup alerting the user about security tips ? i.e., I don�t want the system ask the user about the certificate.. the same behaviour

  • Understanding the object model yh

    Dear all, I'm building a simple PDF export script. Before exporting the script will search the flattenerpreset collection for a specific preset - if found use, else alert and exit. For this purpose I've located the class FlattenerPresets and the meth

  • Modifying standard  ALV report

    Hi while modifying one of the standard alv reports, I had to include one more field.. for that I have made changes to the feild cat and i_tab structure. but the final report is not displaying that additional column Can any one help me... The report i