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

com.innovenso.townplan.dsl.traits.HasRequiredKey.groovy Maven / Gradle / Ivy

There is a newer version: 2.1.0
Show newest version
package com.innovenso.townplan.dsl.traits

import jakarta.validation.constraints.NotBlank
import lombok.NonNull
import org.apache.logging.log4j.util.Strings

trait HasRequiredKey {
	private String key

	void key(@NonNull String key) {
		this.key = key
	}

	@NotBlank
	String getKey() {
		if (key != null && Strings.isNotBlank(key)) return key
		else return generateDefaultKey()
	}

	void setKey(String keyToSet) {
		this.key = keyToSet
	}

	abstract List getDefaultKeyComponents()

	private String generateDefaultKey() {
		getDefaultKeyComponents().collect {it.replaceAll("[^A-Za-z0-9]", "_").toLowerCase() }.join("_")
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy