Skip to content

Commit

Permalink
Move Existing Articles to core-groovy-collections Module
Browse files Browse the repository at this point in the history
  • Loading branch information
catalin-burcea committed Oct 22, 2019
1 parent 621d462 commit 2468c93
Show file tree
Hide file tree
Showing 10 changed files with 102 additions and 242 deletions.
4 changes: 3 additions & 1 deletion core-groovy-collections/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,6 @@ This module contains articles about Groovy core collections
## Relevant articles:

- [Maps in Groovy](https://www.baeldung.com/groovy-maps)

- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package com.baeldung.lists
package com.baeldung.find

import com.baeldung.Person
import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class ListUnitTest {
class ListFindUnitTest {

private final personList = [
new Person("Regina", "Fitzpatrick", 25),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,96 +1,18 @@
package com.baeldung.map
package com.baeldung.find

import com.baeldung.Person
import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class MapUnitTest {
class MapFindUnitTest {

private final personMap = [
Regina : new Person("Regina", "Fitzpatrick", 25),
Abagail: new Person("Abagail", "Ballard", 26),
Lucian : new Person("Lucian", "Walter", 30)
]

@Test
void whenUsingEach_thenMapIsIterated() {
def map = [
'FF0000' : 'Red',
'00FF00' : 'Lime',
'0000FF' : 'Blue',
'FFFF00' : 'Yellow'
]

map.each { println "Hex Code: $it.key = Color Name: $it.value" }
}

@Test
void whenUsingEachWithEntry_thenMapIsIterated() {
def map = [
'E6E6FA' : 'Lavender',
'D8BFD8' : 'Thistle',
'DDA0DD' : 'Plum',
]

map.each { entry -> println "Hex Code: $entry.key = Color Name: $entry.value" }
}

@Test
void whenUsingEachWithKeyAndValue_thenMapIsIterated() {
def map = [
'000000' : 'Black',
'FFFFFF' : 'White',
'808080' : 'Gray'
]

map.each { key, val ->
println "Hex Code: $key = Color Name $val"
}
}

@Test
void whenUsingEachWithIndexAndEntry_thenMapIsIterated() {
def map = [
'800080' : 'Purple',
'4B0082' : 'Indigo',
'6A5ACD' : 'Slate Blue'
]

map.eachWithIndex { entry, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenUsingEachWithIndexAndKeyAndValue_thenMapIsIterated() {
def map = [
'FFA07A' : 'Light Salmon',
'FF7F50' : 'Coral',
'FF6347' : 'Tomato',
'FF4500' : 'Orange Red'
]

map.eachWithIndex { key, val, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $key = Color Name: $val"
}
}

@Test
void whenUsingForLoop_thenMapIsIterated() {
def map = [
'2E8B57' : 'Seagreen',
'228B22' : 'Forest Green',
'008000' : 'Green'
]

for (entry in map) {
println "Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenMapContainsKeyElement_thenCheckReturnsTrue() {
def map = [a: 'd', b: 'e', c: 'f']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung
package com.baeldung.find

class Person {
private String firstname
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.baeldung.set
package com.baeldung.find

import org.junit.Test

import static org.junit.Assert.assertTrue

class SetUnitTest {
class SetFindUnitTest {

@Test
void whenSetContainsElement_thenCheckReturnsTrue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.baeldung.iteratemap

import com.baeldung.find.Person
import org.junit.Test

import static org.junit.Assert.*

class IterateMapUnitTest {

@Test
void whenUsingEach_thenMapIsIterated() {
def map = [
'FF0000' : 'Red',
'00FF00' : 'Lime',
'0000FF' : 'Blue',
'FFFF00' : 'Yellow'
]

map.each { println "Hex Code: $it.key = Color Name: $it.value" }
}

@Test
void whenUsingEachWithEntry_thenMapIsIterated() {
def map = [
'E6E6FA' : 'Lavender',
'D8BFD8' : 'Thistle',
'DDA0DD' : 'Plum',
]

map.each { entry -> println "Hex Code: $entry.key = Color Name: $entry.value" }
}

@Test
void whenUsingEachWithKeyAndValue_thenMapIsIterated() {
def map = [
'000000' : 'Black',
'FFFFFF' : 'White',
'808080' : 'Gray'
]

map.each { key, val ->
println "Hex Code: $key = Color Name $val"
}
}

@Test
void whenUsingEachWithIndexAndEntry_thenMapIsIterated() {
def map = [
'800080' : 'Purple',
'4B0082' : 'Indigo',
'6A5ACD' : 'Slate Blue'
]

map.eachWithIndex { entry, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $entry.key = Color Name: $entry.value"
}
}

@Test
void whenUsingEachWithIndexAndKeyAndValue_thenMapIsIterated() {
def map = [
'FFA07A' : 'Light Salmon',
'FF7F50' : 'Coral',
'FF6347' : 'Tomato',
'FF4500' : 'Orange Red'
]

map.eachWithIndex { key, val, index ->
def indent = ((index == 0 || index % 2 == 0) ? " " : "")
println "$indent Hex Code: $key = Color Name: $val"
}
}

@Test
void whenUsingForLoop_thenMapIsIterated() {
def map = [
'2E8B57' : 'Seagreen',
'228B22' : 'Forest Green',
'008000' : 'Green'
]

for (entry in map) {
println "Hex Code: $entry.key = Color Name: $entry.value"
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.baeldung.groovy.lists
package com.baeldung.lists

import static groovy.test.GroovyAssert.*
import org.junit.Test

class ListTest{
class ListUnitTest {

@Test
void testCreateList() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.baeldung.map;
package com.baeldung.maps;

import static groovy.test.GroovyAssert.*
import org.junit.Test
Expand Down
3 changes: 0 additions & 3 deletions core-groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,8 @@ This module contains articles about core Groovy concepts
- [Working with JSON in Groovy](https://www.baeldung.com/groovy-json)
- [Reading a File in Groovy](https://www.baeldung.com/groovy-file-read)
- [Types of Strings in Groovy](https://www.baeldung.com/groovy-strings)
- [A Quick Guide to Iterating a Map in Groovy](https://www.baeldung.com/groovy-map-iterating)
- [An Introduction to Traits in Groovy](https://www.baeldung.com/groovy-traits)
- [Closures in Groovy](https://www.baeldung.com/groovy-closures)
- [Finding Elements in Collections in Groovy](https://www.baeldung.com/groovy-collections-find-elements)
- [Lists in Groovy](https://www.baeldung.com/groovy-lists)
- [Converting a String to a Date in Groovy](https://www.baeldung.com/groovy-string-to-date)
- [Guide to I/O in Groovy](https://www.baeldung.com/groovy-io)
- [[More -->]](/core-groovy-2)
Loading

0 comments on commit 2468c93

Please sign in to comment.