Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Register Tags Active Topics RSS Search Mark Forums Read SiteMap

Tags: , , , , , ,

Sponsored Links



Converting a map.get (key) to int

Software Development


Reply
 
Thread Tools Search this Thread
  #1  
Old 11-02-2010
Member
 
Join Date: Dec 2009
Posts: 296
Converting a map.get (key) to int

Hello,
I'm on an application from a server logs produces statistics on this one. However I encounter some difficulties and I'd like your help . Let me explain:
I put the logs in a 2D array (online information). Subsequently, I created a map with key as the name of a database and I value is the connection time on the latter in milliseconds.
Code:
Map m = new TreeMap ();
      for (int i = 0; i <x; i + +)
        (
        Object o = m.get (Logsession [i] [3]);
        if (o == null)
          m.put (Logsession [i] [3], new Integer (Integer.parseInt (Logsession [i] [1 ])));
        else
          (
            (
          Integer cnt = (Integer) o;
          m.put (Logsession [i] [3], new Integer (cnt.intValue () + Integer.parseInt (Logsession [i] [1 ])));
          ))
        )

      List ky = new ArrayList (m.kySet ());
        Iterator it = ky.it ();
        while (it.hasNext ())
          (
          Object ky = Iterator.next ();
          nb = Integer.parseInt ((String) m.get (ky)) / (1000 * 60 * 60);
          modulo =Integer.parseInt ((String) m.get (ky))% (1000 * 60 * 60);
          nbMin = mod / (60 * 1000);
          modulo = modulo% (60 * 1000);
          nbSec = modulo/1000;
          label = new JLabel ( "Time of connection to the Database" + ky + ":" + nb + "hours," nbMin + + "minutes and" + nbSec + "seconds");
          )
Reply With Quote
  #2  
Old 11-02-2010
Member
 
Join Date: Nov 2009
Posts: 347
Re: Converting a map.get (key) to int

Hello,
Your map is of type Map <String,Integer>, if I remember correctly, the key to a map is unique so if you have several times the same key in a. Put on your map, risk of crush the values as and. You have in your map values of type Integer then when you go to a map.get (key) you will have the value type Integer, you do not need the caste to convert String to Integer with Integer.parseInt.
Reply With Quote
  #3  
Old 11-02-2010
Member
 
Join Date: Nov 2009
Posts: 344
Re: Converting a map.get (key) to int

Hello,
Just have a look at the following code this can help you.
Code:
for (int j = 0 j <map.size () j + +) (
nb = map.get (j)/ (1000 * 60 * 60);
mod =map.get (j)% (1000 * 60 * 60);
nbn = mod / (60 * 1000);
modu = modulo% (60 * 1000);
nbSe = modulo/1000;
lb = new JLabel ( "Time of connection to the Database" + key + ":" + nbHour + "hours," nbMin + + "minutes and" + nbSec + "seconds");
)
I have modified it, just see if it work for you.
Reply With Quote
  #4  
Old 11-02-2010
Member
 
Join Date: Dec 2009
Posts: 296
Re: Converting a map.get (key) to int

Hello,
Yes, actually what I wanted to do was to convert the value to int, not one is designated as the object by the map when it is actually of type Integer (I myself loses). By dint of tinkering I found something that works:
Code:
nb = ((Integer)(map.get(key))).intValue()/(1000*60*60);
mod =((Integer)(map.get(key))).intValue()%(1000*60*60);
If you have an alternative for this then please let me know. Thanks in advance.
Reply With Quote
  #5  
Old 11-02-2010
Member
 
Join Date: Nov 2009
Posts: 359
Re: Converting a map.get (key) to int

Hello,
You have try the following code
Code:
     Iterator it = map.keySet().iterator();
     while (it.hasNext()){
          Object key = it.next();
          nb = map.get(key)/(1000*60*60);
          mod = map.get(key )%(1000*60*60);
          nbM = modulo /(60*1000);
          modu = modulo%(60*1000);
          nbSe = modulo /1000;
          lb =new JLabel("Time of connection to the Database" + Key
                    + " : "+ + nbHour"Hours" + + NbMin "Minutes" + NbSec
                    + "Seconds");
     }
Reply With Quote
  #6  
Old 11-02-2010
Member
 
Join Date: Nov 2009
Posts: 583
Re: Converting a map.get (key) to int

Hello,
If you are using Java 1.4 then the following code should work with you.
Code:
     Iterator itr = map.kySet().iterator();
     while (itr.hasNext()){
          Object ky = itr.next();
          int milSec = ((Integer) map.get(ky)).intValue();
          nb = milSec /(1000*60*60);
          mod = milSec%(1000*60*60);
          nbM = modulo /(60*1000);
          modu = modulo%(60*1000);
          nbSe = modulo /1000;
          lb =new JLabel("Time of connection to the Database" + Key
                    + " : "+ + nbHour"Hours" + + NbMin "Minutes" + NbSec
                    + "Seconds");
     }
Reply With Quote
Reply

  TechArena Community > Software > Software Development


Thread Tools Search this Thread
Search this Thread:

Advanced Search


Similar Threads for: "Converting a map.get (key) to int"
Thread Thread Starter Forum Replies Last Post
Converting exe to msi John mitchell Windows Software 4 04-11-2011 01:57 AM
Converting MKV to M4V Defender14 Windows Software 6 03-06-2010 12:30 PM
Converting H.264 to DVD Quinton Windows Software 5 04-05-2010 11:09 AM
Converting mpg to mov Avigdor Windows Software 2 27-08-2009 04:25 PM
Converting ASP to PHP? Irene Software Development 4 18-09-2008 02:08 PM


All times are GMT +5.5. The time now is 03:43 AM.