Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

参考 这种设置值 #545

Open
venusdrogon opened this issue Apr 18, 2023 · 0 comments
Open

参考 这种设置值 #545

venusdrogon opened this issue Apr 18, 2023 · 0 comments

Comments

@venusdrogon
Copy link
Collaborator

venusdrogon commented Apr 18, 2023

/**

  • 设置默认值

*/
public class ValueUtils{

/**
 * 如果judgeValue的值为null且value不为null则调用set.accept方法
 *
 * @param judgeValue
 *            待判断的值
 * @param set
 *            设置器
 * @param value
 *            给与设置器的值
 */
public static <T> void setValueIfNull(Supplier<T> judgeValue,Consumer<T> set,T value){
    if (judgeValue.get() == null && value != null){
        set.accept(value);
    }
}

public static <T> void setValueIfNotNull(Supplier<T> newValue,Consumer<T> consumer){
    if (newValue.get() != null){
        consumer.accept(newValue.get());
    }
}

}

// 默认主站专辑
ValueUtils.setValueIfNull(albumQueryDTO::getAlbumScope, albumQueryDTO::setAlbumScope, "111111");

@venusdrogon venusdrogon added this to the 3.5.0 milestone May 3, 2023
@venusdrogon venusdrogon removed this from the 3.5.0 milestone Jun 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant