twitter4jads.conf.ConfigurationBuilder Maven / Gradle / Ivy
package twitter4jads.conf;
/**
* A builder that can be used to construct a twitter4jads configuration with desired settings. This
* builder has sensible defaults such that {@code new ConfigurationBuilder().build()} would create a
* usable configuration. This configuration builder is useful for clients that wish to configure
* twitter4jads in unit tests or from command line flags for example.
*
*
*/
public final class ConfigurationBuilder {
private ConfigurationBase configurationBean = new PropertyConfiguration();
public ConfigurationBuilder setOAuthConsumerKey(String oAuthConsumerKey) {
checkNotBuilt();
configurationBean.setOAuthConsumerKey(oAuthConsumerKey);
return this;
}
public ConfigurationBuilder setOAuthConsumerSecret(String oAuthConsumerSecret) {
checkNotBuilt();
configurationBean.setOAuthConsumerSecret(oAuthConsumerSecret);
return this;
}
public ConfigurationBuilder setOAuthAccessToken(String oAuthAccessToken) {
checkNotBuilt();
configurationBean.setOAuthAccessToken(oAuthAccessToken);
return this;
}
public ConfigurationBuilder setOAuthAccessTokenSecret(String oAuthAccessTokenSecret) {
checkNotBuilt();
configurationBean.setOAuthAccessTokenSecret(oAuthAccessTokenSecret);
return this;
}
public Configuration build() {
checkNotBuilt();
configurationBean.cacheInstance();
try {
return configurationBean;
} finally {
configurationBean = null;
}
}
private void checkNotBuilt() {
if (configurationBean == null) {
throw new IllegalStateException("Cannot use this builder any longer, build() has already been called");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy