Quantcast
Channel: User learning... - Stack Overflow
Viewing all articles
Browse latest Browse all 38

Using add or push to add items to an array in groovy

$
0
0

I am getting the following error while push/add items to an array in groovy.

$groovy main.groovyCaught: groovy.lang.MissingMethodException: No signature of method: [LProgressNotes;.push() is applicable for argument types: (ProgressNotes) values: [ProgressNotes@d35dea7]Possible solutions: sum(), plus(java.util.Collection), plus([Ljava.lang.Object;), plus(java.lang.Object), use([Ljava.lang.Object;), plus(java.lang.Iterable)groovy.lang.MissingMethodException: No signature of method: [LProgressNotes;.push() is applicable for argument types: (ProgressNotes) values: [ProgressNotes@d35dea7]Possible solutions: sum(), plus(java.util.Collection), plus([Ljava.lang.Object;), plus(java.lang.Object), use([Ljava.lang.Object;), plus(java.lang.Iterable) at main$_buildOutNotes_closure2.doCall(main.groovy:82) at main.buildOutNotes(main.groovy:75) at main$buildOutNotes.callCurrent(Unknown Source) at main.run(main.groovy:64)

Here is the function:

def buildOutNotes(incomingNotes, systemNotes) {    ProgressNotes[] outNotes = systemNotes;    //iterate incoming chares    incomingNotes.each { incoming ->         //split the note further         def iNote = splitIncoming(incoming);        //check that the incoming note is in the system note        def foundNotes = systemNotes.findAll { it.ProgressNote == iNote.ProgressNote }        if(!foundNotes){            //add the incoming note to the outNote             outNotes.push(iNote);        }    }    return outNotes;} 

Here are the articles that show push and add use

https://mrhaki.blogspot.com/2015/01/groovy-goodness-pop-and-push-items-in.html

def list = ['Groovy', 'is', 'great!']list.push('rocks!')

http://docs.groovy-lang.org/next/html/documentation/working-with-collections.html

def list = [5, 6, 7, 8]emptyList.add(5)

I am building the example code on https://www.tutorialspoint.com/execute_groovy_online.php.

You can view the example herehttp://tpcg.io/NGw4szCv

Here is the full code as well:

//package com.javacodegeeks.groovy.date;//import static java.util.Calendar.*;//import groovy.json.*;//import java.util.Properties;//import java.util.List;//progress notes object class ProgressNotes {    def ActionDate    String ActionBy    String Status    String ProgressNote    ProgressNotes(inActionDate, inActionBy, inStatus, inNote){        this.ActionDate = inActionDate        this.ActionBy = inActionBy        this.Status = inStatus        this.ProgressNote  = inNote    }}//delimiterString delimiter = "@@";//out notesProgressNotes[] outNotes;//date patternsdef dateInSystemPattern = "yyyy-MM-dd HH:mm:ss";def dateIncomingPattern = "MM/dd/yyyy hh:mm ";/************** SAMPLE DATA START ****************///incoming  note stringString incomingNote  = "2019-12-15T01:29:44 User1: December 13 went to pickup the toilet at the wholesaler "+"then went to site then remove and replace the toilet then  found out that there is a "+"fruit inside the toilet then clean up the site and silicone around the toilet then "+"throw the old toilet at dumpster."+ delimiter +"2019-12-13T10:43:05 User2: applied 3 bottles of urinal treatment.  let sit for an "+"hour. augered out  urinal main. draining excellent.  tried augering toilet. object stuck in "+"toilet. will not come out. Don will replace."+ delimiter +"2019-12-13T09:18:51 user3: PO 508758 - unclog Washroom "+"Details: "+"Unclog toilet bowl and urinal in. Room 116.";//in system notesProgressNotes[] systemNotes = [    ["2012-01-26T14:52:50", "User1", "DISPATCHED", "reassign to Space Planning to confirm space availability"],    ["2012-02-01T12:23:05", "User2", "DISPATCHED", "spoke to requestor and she has a few relocations and POD requirements."],    ["2012-02-01T12:23:45", "User3", "DISPATCHED", "Contacted Customer for clarification spreadsheet is forthcoming for this request."],    ["2012-02-03T18:45:00", "User1", "DISPATCHED", "Extending date to allow for clean-up of backlog."]];/************** SPLIT incomingNote ****************/def incomingNotes = [];if (incomingNote != ""){    incomingNotes = incomingNote.split(delimiter);}/************** PICK NOTES ****************/if (!incomingNotes){    //No incoming notes push the system notes out    outNotes = systemNotes;}else{    //check and build the outnotes    outNotes = buildOutNotes(incomingNotes, systemNotes);}println("OUTNOTES Length: "+ outNotes.length)println("");/************** HELPER METHODS ****************/def buildOutNotes(incomingNotes, systemNotes) {    ProgressNotes[] outNotes = systemNotes;    //iterate incoming chares    incomingNotes.each { incoming ->         //split the note further         def iNote = splitIncoming(incoming);        //check that the incoming note is in the system note        def foundNotes = systemNotes.findAll { it.ProgressNote == iNote.ProgressNote }        if(!foundNotes){            //add the incoming note to the outNote             outNotes.push(iNote);        }    }    return outNotes;}def splitIncoming(incoming){    //date time characters    int dateTimeChars = 20;    def dateAndTimePart = incoming.substring(0,dateTimeChars).trim();    String remainingNote = incoming.substring(dateTimeChars);    String userPart = "";    String notePart = "";    def remainingNotes = remainingNote.split(":");    if(remainingNotes){        userPart = remainingNotes.getAt(0);        notePart = incoming.substring(dateTimeChars+userPart.length()+1).trim();    }    //build the object     def outNote = new ProgressNotes(dateAndTimePart, userPart, "", notePart);    return outNote;}

Viewing all articles
Browse latest Browse all 38

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>