Monday 15 February 2010

java - Matching Keys in a HashMap -


  • HashMapOne will generate:

    I try to do after (in psuedocode) The result was a DICOM file (the key was for manipulating purposes for matching purposes).

  • Generate a second HashMapTwo that will be read from a text document.
  • Compare the keys to both HashMaps if matching matches the value of HashMapOne in a new HashMapThree.

I'm stuck with HashMapThree to add the value of the matching key. It always populates a redundant value even after declaring a public stable variable. Can anyone tell me why this could happen? Below are the code snippets given below:

  Public class viewDocumentTags {Hashmap < String, string & gt; DicomFile = New Hashmap & lt; String, string & gt; (); HashMap & LT; String, string & gt; DikomTaglist = New Hashmop & lt; String, string & gt; (); HashMap & LT; String, string & gt; Results = New Hashmop & lt; String, string & gt; (); Iterator & LT; Org.dcm4che2.data.DicomElement & gt; Iter = null; DCOM object is working; Public stable DicomElement element; Give the diochem element element two; Public stable string result; File digamlist = new file ("C: \\ user \\ ryan \\ dicomTagList.txt"); Public Zero reads DICOMObject (string path) throws IOException {DicomInputStream din = null; Days = new dynamic inputstream (new file (path)); Try {work = din.readDicomObject (); IARR = Working While (iter.hasNext ()) {element = iter.next (); Result = element.toString (); String s = element.toString () Substring (0, Math.man (element.toString (). Length (), 11)); DicomFile.put (String.valueOf (s.toString ()), element.vr (). ToString ()); } System.out.println ("stored tag, VR code, and descriptions from DICOM file ...."); } Hold (IOException e) {e.printStackTrace (); Return; } Finally {try {din.close ()}} Hold (ignoring IOException) {}} readFromTextFile (); } Public Zero read FremTextFile () throws IOException {try {string dicomData = "DICOM"; String line = null; Buffarder bReader = new buffed reader (new flamerdider (decomlist)); While ((line = bredder. Readline ())! = Null {dicomTagList.put (line.toString (), dicomData);} System.out.println ("Reading tag from text file ...."); bReader. Close ();} Hold (FileNotFoundException e) {System.err.print (e);} Hold (IOException i) {System.err.print (i);} Compare DICOMSets ();} Public Zero compareDICOMSets () throws For IOException {enter  string> entry: dicomFile.entrySet ()} {if (dicomTagList.containsKey (entry.getKey ())) Result.put (entry.getKey (), dicomFile Get (element.toString ()); Println (dicomFile.get (element.toString ());} Sorted set & lt; string & gt; keys = new TreeSet & lt; string & g (String key: keys) {string value = result. Gate (key); println (key);}}}  

This line of code looks very wrong

  result. Enter (entry .getKey (), dicomFile .get (element.toString ()));  

The main / value pairs from HashMapOne are trying to copy, so this is not correct.

The value for each key will be nulled for the result, because you are calling the on method on the interface on the decompile. find requires a key as a lookup value, and you enter

  element.toString ()  

Where the element is the last element that has been read from your file.

I think

  should be using Result.put (entry.getKey (), entry.getValue ()););  

No comments:

Post a Comment