Package de.mnl.osgi.lf4osgi.core
Class DefaultLoggerGroup<T>
- java.lang.Object
-
- de.mnl.osgi.lf4osgi.core.DefaultLoggerGroup<T>
-
- Type Parameters:
T
- the type of the loggers in the group
- All Implemented Interfaces:
LoggerGroup
public class DefaultLoggerGroup<T> extends Object implements LoggerGroup
A simple cache for loggers used by a bundle.
-
-
Constructor Summary
Constructors Constructor Description DefaultLoggerGroup(Bundle bundle, BiFunction<LoggerGroup,String,T> loggerSupplier)
Instantiates a new bundle group.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
computeIfAbsent(String name)
Gets the logger with the specified name.If it is not already in this group, create it using the default supplier.T
computeIfAbsent(String name, BiFunction<LoggerGroup,String,T> supplier)
Gets the logger with the specified name.Bundle
getBundle()
Returns the bundle that this group is associated with.boolean
hasLogger(String name)
Checks if the logger with the provided name already exists.Optional<T>
logger(String name)
Gets the logger if it exists.void
putIfAbsent(String name, T logger)
Put the logger in the group if it isn't already known.
-
-
-
Constructor Detail
-
DefaultLoggerGroup
public DefaultLoggerGroup(Bundle bundle, BiFunction<LoggerGroup,String,T> loggerSupplier)
Instantiates a new bundle group.- Parameters:
bundle
- the bundleloggerSupplier
- the default logger supplier used bycomputeIfAbsent(String)
-
-
Method Detail
-
getBundle
public final Bundle getBundle()
Returns the bundle that this group is associated with.- Specified by:
getBundle
in interfaceLoggerGroup
- Returns:
- the bundle
-
hasLogger
public boolean hasLogger(String name)
Checks if the logger with the provided name already exists.- Parameters:
name
- the name- Returns:
- true, if successful
-
logger
public Optional<T> logger(String name)
Gets the logger if it exists.- Parameters:
name
- the name- Returns:
- the logger
-
computeIfAbsent
public T computeIfAbsent(String name, BiFunction<LoggerGroup,String,T> supplier)
Gets the logger with the specified name. If it is not already in this group, create it using the provided supplier.- Parameters:
name
- the namesupplier
- the supplier- Returns:
- the logger
-
computeIfAbsent
public T computeIfAbsent(String name)
Gets the logger with the specified name.If it is not already in this group, create it using the default supplier.- Parameters:
name
- the name- Returns:
- the logger
-
putIfAbsent
public void putIfAbsent(String name, T logger)
Put the logger in the group if it isn't already known.- Parameters:
name
- the namelogger
- the logger
-
-