/*
* All content copyright Terracotta, Inc., unless otherwise indicated.
*
* 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.
*/
package org.terracotta.statistics;
import org.terracotta.statistics.observer.OperationObserver;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
public final class StatisticBuilder {
Instantiates a new statistic builder.
/**
* Instantiates a new statistic builder.
*/
private StatisticBuilder() {
}
Operation.
Params: - type – the type
Type parameters: - <T> – the generic type
Returns: the operation statistic builder
/**
* Operation.
*
* @param <T> the generic type
* @param type the type
* @return the operation statistic builder
*/
public static <T extends Enum<T>> OperationStatisticBuilder<T> operation(Class<T> type) {
return new OperationStatisticBuilder<>(type);
}
The Class OperationStatisticBuilder.
Type parameters: - <T> – the generic type
/**
* The Class OperationStatisticBuilder.
*
* @param <T> the generic type
*/
public static class OperationStatisticBuilder<T extends Enum<T>> extends
AbstractStatisticBuilder<OperationStatisticBuilder<T>> {
The type.
/**
* The type.
*/
private final Class<T> type;
Instantiates a new operation statistic builder.
Params: - type – the type
/**
* Instantiates a new operation statistic builder.
*
* @param type the type
*/
public OperationStatisticBuilder(Class<T> type) {
this.type = type;
}
Builds the.
Returns: the operation observer
/**
* Builds the.
*
* @return the operation observer
*/
public OperationObserver<T> build() {
if (context == null || name == null) {
throw new IllegalStateException();
} else {
return StatisticsManager.createOperationStatistic(context, name, tags, properties, type);
}
}
}
The Class AbstractStatisticBuilder.
Type parameters: - <T> – the generic type
/**
* The Class AbstractStatisticBuilder.
*
* @param <T> the generic type
*/
static class AbstractStatisticBuilder<T extends AbstractStatisticBuilder<T>> {
The tags.
/**
* The tags.
*/
protected final Set<String> tags = new HashSet<>();
The properties.
/**
* The properties.
*/
protected final Map<String, Object> properties = new HashMap<>();
The context.
/**
* The context.
*/
protected Object context;
The name.
/**
* The name.
*/
protected String name;
Of.
Params: - of – the of
Returns: the builder
/**
* Of.
*
* @param of the of
* @return the builder
*/
@SuppressWarnings("unchecked")
public T of(Object of) {
if (context == null) {
context = of;
return (T) this;
} else {
throw new IllegalStateException("Context already defined");
}
}
Named.
Params: - name – the name
Returns: the builder
/**
* Named.
*
* @param name the name
* @return the builder
*/
@SuppressWarnings("unchecked")
public T named(String name) {
if (this.name == null) {
this.name = name;
return (T) this;
} else {
throw new IllegalStateException("Name already defined");
}
}
Tag.
Params: - tags – the tags
Returns: the builder
/**
* Tag.
*
* @param tags the tags
* @return the builder
*/
@SuppressWarnings("unchecked")
public T tag(String... tags) {
Collections.addAll(this.tags, tags);
return (T) this;
}
Tag.
Params: - key – the property key
- value – the property value
Returns: the builder
/**
* Tag.
*
* @param key the property key
* @param value the property value
* @return the builder
*/
@SuppressWarnings("unchecked")
public T property(String key, Object value) {
this.properties.put(key, value);
return (T) this;
}
}
}