Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » groovy script - create Hashmap as global variable(Groovy script hashmap)
groovy script - create Hashmap as global variable [message #1750930] Mon, 02 January 2017 11:50 Go to next message
fabrizio maggioni is currently offline fabrizio maggioniFriend
Messages: 3
Registered: January 2017
Junior Member
Hello Support,

I am working on this function's script:

def synchronized createUcmdbCache () {
        try {
            Map<String, Map<String,String>> localHM = new HashMap()
            String line
            // leggo dal ucmdb cache file
            FileReader fr = new FileReader(ucmdbCacheDumpFile)
			s_log.trace("Process >         >> createUcmdbCache > FileReader > OK Reader");
            BufferedReader textReader = new BufferedReader(fr)
			s_log.trace("Process >         >> createUcmdbCache > BufferedReader > OK Buffered");
            // creazione della hashmap annidata
            while((line = textReader.readLine()) != null) {
                String[] parts = line.split("~")
                // parts[0]=relatedCI
                // parts[1]=File System Type
                // parts[2]=Admin group
                if (localHM.containsKey(parts[0])) {
                    // tempHM = mappa più interna che contiene FileSystemTipe,AdminGroup
                    Map<String,String> tempHM = localHM.get(parts[0])
                    tempHM.put(parts[1], parts[2])
                    localHM.put(parts[0], tempHM)
					s_log.trace("Process >         >> createUcmdbCache > localHasMap > set TEMP e LOCAL HM");
                }
                else {
                    Map<String,String> tempHM = new HashMap()
                    tempHM.put(parts[1], parts[2])
                    // aggiunta alla hashmap più esterna di RelatedCI,(tempHM) dove tempHM=FileSystemTipe,AdminGroup
                    localHM.put(parts[0], tempHM)
					s_log.trace("Process >         >> createUcmdbCache > localHasMap > ELSE set TEMP e LOCAL HM");
                }
            }
            textReader.close()
            // set variabile globale ucmdbCache con il valore della hashmap localHM
            ucmdbCache = Collections.synchronizedMap(localHM)
			s_log.trace("Process >         >> createUcmdbCache > localHasMap > AFTER Text Reader Close:" + localHM.getValue() + tempHM.getValue() + ucmdbCache.getValue() + e.getMessage() + myFsName + relCiID);
        } catch (IOException e) {
        }
    }[/i]


where "ucmdbCacheDumpFile" is defined as public string on top of the script:

[i]public static final String ucmdbCacheDumpFile    = "F:\\HPBSM\\Temp\\ENI-HandleIncomingEventsAR-ExtUcmdbCache.dump";[/i]


in order to pass "ucmdbCache" variable as global value to another function's script in this way:
[i]String adminGrp = ucmdbCache.get(relCiID).get(myFsName)[/i]


But i got this error:

Reason: No signature of method: java.util.HashMap.getValue() is applicable for argument types: () values: []

Please do you have any suggestion about it? It seems localHM hasmap has been not set correctly.

Thanks.
Regards,
Fabrizio
Re: groovy script - create Hashmap as global variable [message #1751044 is a reply to message #1750930] Tue, 03 January 2017 21:04 Go to previous messageGo to next message
Stephan Herrmann is currently offline Stephan HerrmannFriend
Messages: 1853
Registered: July 2009
Senior Member
This forum's title is "Java Development Tools (JDT)". We're not experts for groovy.
best,
Stephan
Re: groovy script - create Hashmap as global variable [message #1751060 is a reply to message #1751044] Wed, 04 January 2017 08:58 Go to previous messageGo to next message
fabrizio maggioni is currently offline fabrizio maggioniFriend
Messages: 3
Registered: January 2017
Junior Member
Ok, to which one could i move it?

Do you think is there any knowledge about groovy on eclipse forums?

Regards,
Fabrizio
Re: groovy script - create Hashmap as global variable [message #1751067 is a reply to message #1751060] Wed, 04 January 2017 09:31 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33224
Registered: July 2009
Senior Member
It's not clear what tool you're using. What did you install to have Groovy support? Wherever you installed it from, that's where to look for a support forum.

In terms of the code you show, if that's supposed to be Java, then Map has no getValue() method. Perhaps you really want to be calling .toString() on all these map? Although toString is automatically called on any non-String argument to the + operator so maybe you just want to remove the getValue() calls.


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: groovy script - create Hashmap as global variable [message #1751120 is a reply to message #1751067] Wed, 04 January 2017 15:15 Go to previous message
fabrizio maggioni is currently offline fabrizio maggioniFriend
Messages: 3
Registered: January 2017
Junior Member
Hello,

Thanks for the answer, i have solved setting before as well my string as:
[i]String myNodeNameHint = evt.getRelatedCiHint(); [/i]


I have also renamed it from relCiID to myNodeNameHint and now in this way is working fine.

[i]String adminGrp = ucmdbCache.get(myNodeNameHint).get(myFsName);[/i]


Regards,
Fabrizio
Previous Topic:Project build breaks from recursive "target/classes" directory
Next Topic:SuppressWarnings unchecked Vs rawtypes and suppressRawWhenUnchecked
Goto Forum:
  


Current Time: Mon Oct 07 06:08:40 GMT 2024

Powered by FUDForum. Page generated in 0.04833 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top