Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

groovy record size

def text = "<?xml version='1.0' encoding='UTF-8'?><DocRoot xsinoNamespaceSchemaLocation='NJDataTemplate.xsd'><Entry><EMPLOYEE_ID>101014</EMPLOYEE_ID><LAST_NAME>Pendery## ;; ~?</LAST_NAME><FIRST_NAME>Claire</FIRST_NAME><COMPANY_CODE>AVI</COMPANY_CODE><SUBSIDIARY_CODE>7R3</SUBSIDIARY_CODE><SUBSIDIARY_NAME>NetJets Aviation, Inc.</SUBSIDIARY_NAME><DEPARTMENT_CODE>1305</DEPARTMENT_CODE><JOB_CODE>SV0928</JOB_CODE><LOCATION_CODE>CMHBY</LOCATION_CODE><HIRE_DATE>19960101</HIRE_DATE><PERSON_TYPE>2</PERSON_TYPE><PERSON_STATUS>1</PERSON_STATUS><VENDOR_NAME></VENDOR_NAME><TERM_DATE></TERM_DATE><MIDDLE_NAME>Test4</MIDDLE_NAME><DEPARTMENT_NAME>Aircraft Appearance Standards</DEPARTMENT_NAME><JOB_TITLE>A/Cce Stds Specialist</JOB_TITLE><MANAGER_NAME></MANAGER_NAME><MANAGER_EMAIL></MANAGER_EMAIL><LOCATION_STREET>4111 Bridgeway Ave</LOCATION_STREET><LOCATION_CITY>Columbus</LOCATION_CITY><LOCATION_STATE>OH</LOCATION_STATE><LOCATION_ZIP>43219</LOCATION_ZIP><LOCATION_COUNTRY>USA</LOCATION_COUNTRY><WORK_PHONE>990717</WORK_PHONE><WORK_MOBILE> </WORK_MOBILE><WORK_FAX> </WORK_FAX><DRUG_SCREEN>Constant</DRUG_SCREEN><BACKGROUND_CHK>Constant</BACKGROUND_CHK><Union_Code></Union_Code><SSN_LAST4>Constant</SSN_LAST4><MANAGER_ID>NO_MANAGER</MANAGER_ID></Entry><Entry><EMPLOYEE_ID>02001680</EMPLOYEE_ID><LAST_NAME>Strapp</LAST_NAME><FIRST_NAME>Gary</FIRST_NAME><COMPANY_CODE>SVC</COMPANY_CODE><SUBSIDIARY_CODE>7RC</SUBSIDIARY_CODE><SUBSIDIARY_NAME>NetJets Services, Inc. - Execs</SUBSIDIARY_NAME><DEPARTMENT_CODE>174010</DEPARTMENT_CODE><JOB_CODE>MZ0595</JOB_CODE><LOCATION_CODE>BWY1</LOCATION_CODE><HIRE_DATE>19890925</HIRE_DATE><PERSON_TYPE>2</PERSON_TYPE><PERSON_STATUS>3</PERSON_STATUS><VENDOR_NAME></VENDOR_NAME><TERM_DATE>2019-02-07T00:00:00.000</TERM_DATE><MIDDLE_NAME></MIDDLE_NAME><DEPARTMENT_NAME>Executives</DEPARTMENT_NAME><JOB_TITLE>VP, Technical Support</JOB_TITLE><MANAGER_NAME></MANAGER_NAME><MANAGER_EMAIL></MANAGER_EMAIL><LOCATION_STREET>4111 Bridgeway Ave</LOCATION_STREET><LOCATION_CITY>Columbus</LOCATION_CITY><LOCATION_STATE>OH</LOCATION_STATE><LOCATION_ZIP>43219</LOCATION_ZIP><LOCATION_COUNTRY>USA</LOCATION_COUNTRY><WORK_PHONE>614-239-5567</WORK_PHONE><WORK_MOBILE> </WORK_MOBILE><WORK_FAX> </WORK_FAX><DRUG_SCREEN>Constant</DRUG_SCREEN><BACKGROUND_CHK>Constant</BACKGROUND_CHK><Union_Code>16011</Union_Code><SSN_LAST4>Constant</SSN_LAST4><MANAGER_ID>NO_MANAGER</MANAGER_ID></Entry><Entry><EMPLOYEE_ID>241</EMPLOYEE_ID><LAST_NAME>Wookie</LAST_NAME><FIRST_NAME>Chewbacca</FIRST_NAME><COMPANY_CODE>SVC</COMPANY_CODE><SUBSIDIARY_CODE>9XG</SUBSIDIARY_CODE><SUBSIDIARY_NAME>NetJets Services, Inc.</SUBSIDIARY_NAME><DEPARTMENT_CODE>1152</DEPARTMENT_CODE><JOB_CODE>PILOTFO</JOB_CODE><LOCATION_CODE>ATL</LOCATION_CODE><HIRE_DATE>20190128</HIRE_DATE><PERSON_TYPE>2</PERSON_TYPE><PERSON_STATUS>1</PERSON_STATUS><VENDOR_NAME></VENDOR_NAME><TERM_DATE></TERM_DATE><MIDDLE_NAME></MIDDLE_NAME><DEPARTMENT_NAME>Document Distribution</DEPARTMENT_NAME><JOB_TITLE>First Officer</JOB_TITLE><MANAGER_NAME>Solo,Han</MANAGER_NAME><MANAGER_EMAIL>[email protected]</MANAGER_EMAIL><LOCATION_STREET></LOCATION_STREET><LOCATION_CITY>Atlanta</LOCATION_CITY><LOCATION_STATE>GA</LOCATION_STATE><LOCATION_ZIP></LOCATION_ZIP><LOCATION_COUNTRY>USA</LOCATION_COUNTRY><WORK_PHONE>4444444444</WORK_PHONE><WORK_MOBILE> </WORK_MOBILE><WORK_FAX> </WORK_FAX><DRUG_SCREEN>Constant</DRUG_SCREEN><BACKGROUND_CHK>Constant</BACKGROUND_CHK><Union_Code>16011</Union_Code><SSN_LAST4>Constant</SSN_LAST4><MANAGER_ID>238</MANAGER_ID></Entry></DocRoot>";

def list = new XmlSlurper().parseText(text);

list.each { rootTag ->
  println "root name: ${rootTag.name()}"
  println "size ${rootTag.children().size()}"
  rootTag.children().each { record ->
  println "record - ${record.name()}"
    record.children().each { childTag ->
        println "  ${childTag.name()}: ${childTag.text()}"
    }
    
  }
}

// println("abc");

// // list.each { thing -> println(thing.children())}

// list.each { thing ->
//   println "thing index: ${thing.@indexNum}"
//   thing.children().each { tag ->
//     println "  ${tag.name()}: ${tag.text()}"
//   }
// }

if-else

/* Hello World in Groovy */
// println("Hello world")

def appConfig = [
    int: [ 
      LogLevel: "INFO",
      ThirdPartyIntegrationURL: "https://internal-third-party-integration-elb-1263876329.ap-south-1.elb.amazonaws.com/third-party-integration/v1/",
      BaseEntitlementURL: "https://internal-entitlement-partnerspecific-72155629.ap-south-1.elb.amazonaws.com/entitlement/v1/mgmt/",
      Cassandra: [cmsservice: "common", migration: "false", keyspace: "remote_access_db"]
    ]
]

def cassandra = appConfig.int.Cassandra
// println(cassandra)

if(cassandra != null) {
    println("cassandra-True")
}else {
    println("cassandra-Flase")
}

Groovy add()

class Example {
   static void main(String[] args) {
      def testCaseTag = "@a or @b"
     
    def tag = "'(" + testCaseTag + ")'"
      
      testCaseTag = './gradlew -Dcucumber.options="--tags '+tag+'" test --refresh-dependencies'
     
      println(testCaseTag)
   } 
}

Groovy replaceAll()

class Example { 
   static void main(String[] args) { 
      String a = "@a or @b"; 
      println(a.replaceAll("or",",")); 
      a=a.replaceAll("or",",")
      println(a.replaceAll("\\s","")); 
      
      
      String b = "@a and @b and @c";
       println(b.replaceAll("and","--tags ")); 

   } 
}

Parsing Text

import groovy.json.JsonSlurper 

class Example {
   static void main(String[] args) {
      def jsonSlurper = new JsonSlurper()
      
      def object = jsonSlurper.parseText('{ "name": "John", "ID" : "1"}') 
	  def str = object.replace("John", "****");
      
      println(str);
	  
      println(object.name);
      println(object.ID);
      
    
   } 
}

tak?

println($/link=echo -n -e "$$line" | cut -f3 -d";" | sed -e 's/[/]/\\\\\\//g'/$)

Groovy split()

class Example {
   static void main(String[] args) {
      String a = "Origin/User/Test-Builds/";
      String[] str;
      str = a.split('/');
      
      for( String values : str )
      println(values);
      println(str[str.length-1])
   } 
}

Execute Groovy Online

/* Hello World in Groovy */
def file = new file(sh "echo test1 > test")

1111

 String agentStatus = "Active"
 status = agentStatus ?: "Inactive"
void checkHello()
{
   
System.out.println(status);
}

checkHello();

test

import java.lang.management.*

def os = ManagementFactory.operatingSystemMXBean 
println """OPERATING SYSTEM: 
\tOS architecture = $os.arch 
\tOS name = $os.name 
\tOS version = $os.version 
\tOS processors = $os.availableProcessors 
""" 
 
def rt = ManagementFactory.runtimeMXBean 
println """RUNTIME: 
   \tRuntime name = $rt.name 
   \tRuntime spec name = $rt.specName 
   \tRuntime vendor = $rt.specVendor 
   \tRuntime spec version = $rt.specVersion 
   \tRuntime management spec version = $rt.managementSpecVersion 
   """ 

def mem = ManagementFactory.memoryMXBean 
def heapUsage = mem.heapMemoryUsage 
def nonHeapUsage = mem.nonHeapMemoryUsage 

println """MEMORY: 
   HEAP STORAGE: 
      \tMemory committed = $heapUsage.committed 
      \tMemory init = $heapUsage.init 
      \tMemory max = $heapUsage.max 
      \tMemory used = $heapUsage.used NON-HEAP STORAGE: 
      \tNon-heap memory committed = $nonHeapUsage.committed 
      \tNon-heap memory init = $nonHeapUsage.init 
      \tNon-heap memory max = $nonHeapUsage.max 
      \tNon-heap memory used = $nonHeapUsage.used 
   """
  
println "GARBAGE COLLECTION:" 
ManagementFactory.garbageCollectorMXBeans.each { gc ->
   println "\tname = $gc.name"
   println "\t\tcollection count = $gc.collectionCount"
   println "\t\tcollection time = $gc.collectionTime"
   String[] mpoolNames =   gc.memoryPoolNames
	
   mpoolNames.each { 
      mpoolName -> println "\t\tmpool name = $mpoolName"
   } 
}

1 2 3 4 5 6 7 ... 27 Next
Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.