import java.util.List import javax.swing.JOptionPane import groovy.lang.Closure void Zadanie1() { def maxVal, indList; (maxVal, indList) = maximum( [5, 3, 5, 5, 1, 5] ) println "Maximum: $maxVal" println "Indexes: $indList" (maxVal, indList) = maximum(['a', 'c', 'c', 'c', 'b']) println "Maximum: $maxVal" println "Indexes: $indList" } String[] maximum(array) { def arrayMax = array.max() def indexRes = array.findIndexValues { it == arrayMax } return [arrayMax, indexRes] } void Zadanie2() { def ints = getInts() println(ints.join(",")) } Integer[] getInts() { def results = [] def value; while (true) { value = JOptionPane.&showInputDialog("Podaj liczbę") if (value == null) break if (!value.isInteger()) continue; results << value } return results } void Zadanie3() { def numbers = [1,2,3,4] println(numbers.join(",")) def incrementedNumbers = apply(numbers, {it+1}) println(incrementedNumbers.join(",")) def words = ["aa", "bb", "cc", "dd"] println(words.join(",")) def multipledWords = apply(words, {it*3}) println(multipledWords.join(",")) } List apply(List l, Closure c) { List values = []; l.each { values.add(c(it)) } return values; } void Zadanie4() { println getData(Integer) { it > 0 } println getData() { it.size() > 3 } println getData() println getData(BigDecimal) } def getData(p1 = null, p2 = null) { def results = [] def value = true; while (true) { value = JOptionPane.&showInputDialog("Podaj wartość") if (value == null) break if (p1 instanceof Class) try { def v = value.asType(p1) if (p2 instanceof Closure && !p2(v)) continue } catch(e) { continue } else if (p1 instanceof Closure && !p1(value)) continue; results << value } return results } Zadanie1() Zadanie2() Zadanie3() Zadanie4()