Created
June 18, 2016 18:00
-
-
Save RicardoRFaria/8812e478a4fd3a3d8f5ba82a3b4a5cc0 to your computer and use it in GitHub Desktop.
SetUtil
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.function.Consumer; | |
import java.util.function.Supplier; | |
import org.apache.commons.lang3.StringUtils; | |
/** | |
* Classe responsavel por fornecer metodos utilitarios para transferencia do | |
* valor de um objeto para outro | |
* | |
* @author Ricardo Faria | |
* | |
*/ | |
public final class SetUtil { | |
private SetUtil() { | |
// Classe utilitaria... | |
} | |
/** | |
* Obtém o valor do método get e caso ele nao seja nulo transfere para o método set de destino | |
* | |
* @param getMethod o método get da origem | |
* @param setMethod o método set do destino | |
* @return {@code true} caso seja transferido o valor, {@code false} caso contrário. | |
*/ | |
public static <T> boolean seNaoForNuloSet(Supplier<T> getMethod, Consumer<T> setMethod) { | |
if (getMethod.get() != null) { | |
setMethod.accept(getMethod.get()); | |
return true; | |
} | |
return false; | |
} | |
/** | |
* Obtém a string do método get e caso ela nao seja nem nula e nem vazia transfere para o | |
* método set de destino. | |
* | |
* @param getMethod o método get da origem | |
* @param setMethod o método set do destino | |
* @return {@code true} caso seja transferido o valor, {@code false} caso contrário. | |
*/ | |
public static boolean seStringNaoForNulaSet(Supplier<String> getMethod, Consumer<String> setMethod) { | |
if (StringUtils.isNotEmpty(getMethod.get())) { | |
setMethod.accept(getMethod.get()); | |
return true; | |
} | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment