All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.codearte.accurest.dsl.internal.Headers.groovy Maven / Gradle / Ivy

package io.codearte.accurest.dsl.internal

import groovy.transform.EqualsAndHashCode
import groovy.transform.ToString
import groovy.transform.TypeChecked

@EqualsAndHashCode(includeFields = true)
@ToString(includePackage = false, includeFields = true, ignoreNulls = true, includeNames = true)
@TypeChecked
class Headers {

	Set
entries = [] void header(Map singleHeader) { Map.Entry first = singleHeader.entrySet().first() entries << new Header(first?.key, first?.value) } void header(String headerKey, Object headerValue) { entries << new Header(headerKey, headerValue) } void collect(Closure closure) { entries?.each { header -> closure(header) } } Map asStubSideMap() { def acc = [:].withDefault { [] as Collection } return entries.inject(acc as Map) { Map map, Header header -> map[header.name] = header.clientValue return map } as Map } boolean equals(o) { if (this.is(o)) return true if (getClass() != o.class) return false Headers headers = (Headers) o if (entries != headers.entries) return false return true } int hashCode() { return entries.hashCode() } }