com.pi4j.context.ContextBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pi4j-core Show documentation
Show all versions of pi4j-core Show documentation
Pi4J Java API & Runtime Library
The newest version!
package com.pi4j.context;
/*-
* #%L
* **********************************************************************
* ORGANIZATION : Pi4J
* PROJECT : Pi4J :: LIBRARY :: Java Library (CORE)
* FILENAME : ContextBuilder.java
*
* This file is part of the Pi4J project. More information about
* this project can be found here: https://pi4j.com/
* **********************************************************************
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* #L%
*/
import com.pi4j.config.Builder;
import com.pi4j.context.impl.DefaultContextBuilder;
import com.pi4j.platform.Platform;
import com.pi4j.provider.Provider;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.util.Map;
import java.util.Properties;
/**
* ContextBuilder interface.
*
* @author Robert Savage (http://www.savagehomeautomation.com)
* @version $Id: $Id
*/
public interface ContextBuilder extends Builder {
/**
* newInstance.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
static ContextBuilder newInstance(){
return DefaultContextBuilder.newInstance();
}
/**
* add.
*
* @param platform a {@link com.pi4j.platform.Platform} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder add(Platform ... platform);
/**
* add.
*
* @param provider a {@link com.pi4j.provider.Provider} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder add(Provider ... provider);
/**
* defaultPlatform.
*
* @return a {@link java.lang.String} object.
*/
String defaultPlatform();
/**
* defaultPlatform.
*
* @param platformId a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder defaultPlatform(String platformId);
/**
* autoDetectMockPlugins.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder autoDetectMockPlugins();
/**
* autoDetectPlatforms.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder autoDetectPlatforms();
/**
* noAutoDetectPlatforms.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder noAutoDetectPlatforms();
/**
* autoDetectProviders.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder autoDetectProviders();
/**
* noAutoDetectProviders.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder noAutoDetectProviders();
/**
* autoInject.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder autoInject();
/**
* noAutoInject.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder noAutoInject();
/**
* setAutoInject.
*
* @param autoInject a boolean.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder setAutoInject(boolean autoInject){
if(autoInject)
return autoInject();
else
return noAutoInject();
}
/**
* enableShutdownHook.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder enableShutdownHook();
/**
* disableShutdownHook.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder disableShutdownHook();
/**
* setShutdownHook.
*
* @param enableShutdownHook a boolean.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder setShutdownHook(boolean enableShutdownHook) {
if (enableShutdownHook)
return enableShutdownHook();
else
return disableShutdownHook();
}
/**
* toConfig.
*
* @return a {@link com.pi4j.context.ContextConfig} object.
*/
ContextConfig toConfig();
/**
* setAutoDetect.
*
* @param autoDetect a boolean.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder setAutoDetect(boolean autoDetect){
if(autoDetect)
return autoDetect();
else
return noAutoDetect();
}
/**
* autoDetect.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder autoDetect(){
// auto detect all extensibility modules in the classpath
return autoDetectPlatforms().
autoDetectProviders();
}
/**
* noAutoDetect.
*
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder noAutoDetect(){
// do not auto detect all extensibility modules in the classpath
return noAutoDetectPlatforms().
noAutoDetectProviders();
}
/**
* addPlatform.
*
* @param platform a {@link com.pi4j.platform.Platform} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addPlatform(Platform ... platform){
return add(platform);
}
/**
* addPlatform.
*
* @param provider a {@link com.pi4j.provider.Provider} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addPlatform(Provider ... provider){
return add(provider);
}
/**
* addDefaultPlatform.
*
* @param platform a {@link com.pi4j.platform.Platform} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addDefaultPlatform(Platform platform){
return this.add(platform).defaultPlatform(platform.id());
}
/**
* defaultPlatform.
*
* @param platform a {@link com.pi4j.platform.Platform} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder defaultPlatform(Platform platform){
return defaultPlatform(platform.id());
}
/**
* setDefaultPlatform.
*
* @param platformId a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder setDefaultPlatform(String platformId){
return defaultPlatform(platformId);
}
/**
* setDefaultPlatform.
*
* @param platform a {@link com.pi4j.platform.Platform} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder setDefaultPlatform(Platform platform){
return defaultPlatform(platform);
}
/**
* property.
*
* @param key a {@link java.lang.String} object.
* @param value a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder property(String key, String value);
/**
* property.
*
* @param value a {@link java.util.Map.Entry} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder property(Map.Entry ... value);
/**
* properties.
*
* @param values a {@link java.util.Map} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder properties(Map values);
/**
* properties.
*
* @param properties a {@link java.util.Map} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder properties(Map properties, String prefixFilter);
/**
* properties.
*
* @param properties a {@link java.util.Properties} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
ContextBuilder properties(Properties properties, String prefixFilter);
/**
* properties.
*
* @param stream a {@link java.io.InputStream} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code stream}.
*/
ContextBuilder properties(InputStream stream, String prefixFilter) throws IOException;
/**
* properties.
*
* @param reader a {@link java.io.Reader} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code reader}.
*/
ContextBuilder properties(Reader reader, String prefixFilter) throws IOException;
/**
* properties.
*
* @param file a {@link java.io.File} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code file}.
*/
ContextBuilder properties(File file, String prefixFilter) throws IOException;
/**
* properties.
*
* @param properties a {@link java.util.Properties} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder properties(Properties properties){
return properties(properties, null);
}
/**
* properties.
*
* @param stream a {@link java.io.InputStream} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code stream}.
*/
default ContextBuilder properties(InputStream stream) throws IOException {
return properties(stream, null);
}
/**
* properties.
*
* @param reader a {@link java.io.Reader} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code reader}.
*/
default ContextBuilder properties(Reader reader) throws IOException {
return properties(reader, null);
}
/**
* properties.
*
* @param file a {@link java.io.File} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code file}.
*/
default ContextBuilder properties(File file) throws IOException {
return properties(file, null);
}
/**
* addProperty.
*
* @param key a {@link java.lang.String} object.
* @param value a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperty(String key, String value){
return property(key, value);
}
/**
* addProperty.
*
* @param value a {@link java.util.Map.Entry} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperty(Map.Entry ... value){
return property(value);
}
/**
* addProperties.
*
* @param properties a {@link java.util.Properties} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperties(Properties properties, String prefixFilter){
return properties(properties, prefixFilter);
}
/**
* addProperties.
*
* @param properties a {@link java.util.Properties} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperties(Properties properties){
return properties(properties, null);
}
/**
* addProperties.
*
* @param properties a {@link java.util.Map} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperties(Map properties){
return properties(properties, null);
}
/**
* addProperties.
*
* @param properties a {@link java.util.Map} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder addProperties(Map properties, String prefixFilter){
return properties(properties, prefixFilter);
}
/**
* addProperties.
*
* @param stream a {@link java.io.InputStream} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code stream}.
*/
default ContextBuilder addProperties(InputStream stream) throws IOException{
return properties(stream, null);
}
/**
* addProperties.
*
* @param stream a {@link java.io.InputStream} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code stream}.
*/
default ContextBuilder addProperties(InputStream stream, String prefixFilter) throws IOException{
return properties(stream, prefixFilter);
}
/**
* addProperties.
*
* @param reader a {@link java.io.Reader} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code reader}.
*/
default ContextBuilder addProperties(Reader reader) throws IOException{
return properties(reader, null);
}
/**
* addProperties.
*
* @param reader a {@link java.io.Reader} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code reader}.
*/
default ContextBuilder addProperties(Reader reader, String prefixFilter) throws IOException{
return properties(reader, prefixFilter);
}
/**
* addProperties.
*
* @param file a {@link java.io.File} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code file}.
*/
default ContextBuilder addProperties(File file) throws IOException{
return properties(file, null);
}
/**
* addProperties.
*
* @param file a {@link java.io.File} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
* @throws java.io.IOException if an error occurs accessing {@code file}.
*/
default ContextBuilder addProperties(File file, String prefixFilter) throws IOException{
return properties(file, prefixFilter);
}
/**
* add.
*
* @param properties a {@link java.util.Properties} object.
* @param prefixFilter a {@link java.lang.String} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder add(Properties properties, String prefixFilter){
return properties(properties, prefixFilter);
}
/**
* add.
*
* @param properties a {@link java.util.Properties} object.
* @return a {@link com.pi4j.context.ContextBuilder} object.
*/
default ContextBuilder add(Properties properties){
return properties(properties, null);
}
}