public final class StoreUtils {
private final static Function<Identifiable<Object>, Object> EXTRACT_IDENTIFIER = new Function<Identifiable<Object>, Object>() {
-
@Override
public Object apply(final Identifiable<Object> input) {
return input.getIdentifier();
return new InitialDataChangeEvent(path, data.getData());
}
+ /*
+ * Suppressing warnings here allows us to fool the compiler enough
+ * such that we can reuse a single function for all applicable types
+ * and present it in a type-safe manner to our users.
+ */
+ @SuppressWarnings({ "unchecked", "rawtypes" })
+ public static <V> Function<Identifiable<V>, V> identifierExtractor() {
+ return (Function) EXTRACT_IDENTIFIER;
+ }
+
private static final class InitialDataChangeEvent implements
AsyncDataChangeEvent<InstanceIdentifier, NormalizedNode<?, ?>> {
public NormalizedNode<?, ?> getUpdatedSubtree() {
return data;
}
-
- }
-
- @SuppressWarnings({ "unchecked", "rawtypes" })
- public static <V> Function<Identifiable<V>,V> identifierExtractor() {
- return (Function) EXTRACT_IDENTIFIER;
}
public static <V> Set<V> toIdentifierSet(final Iterable<? extends Identifiable<V>> children) {
- return FluentIterable.from(children).transform(StoreUtils.<V>identifierExtractor()).toSet();
+ return FluentIterable.from(children).transform(StoreUtils.<V> identifierExtractor()).toSet();
}
public static String toStringTree(final StoreMetadataNode metaNode) {
StringBuilder builder = new StringBuilder();
- toStringTree(builder, metaNode,0);
+ toStringTree(builder, metaNode, 0);
return builder.toString();
-
}
- private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode,final int offset) {
+ private static void toStringTree(final StringBuilder builder, final StoreMetadataNode metaNode, final int offset) {
String prefix = Strings.repeat(" ", offset);
builder.append(prefix).append(toStringTree(metaNode.getIdentifier()));
NormalizedNode<?, ?> dataNode = metaNode.getData();
- if(dataNode instanceof NormalizedNodeContainer<?,?,?>) {
- builder.append(" {").append("\n");
- for(StoreMetadataNode child : metaNode.getChildren()) {
- toStringTree(builder, child, offset+4);
+ if (dataNode instanceof NormalizedNodeContainer<?, ?, ?>) {
+ builder.append(" {\n");
+ for (StoreMetadataNode child : metaNode.getChildren()) {
+ toStringTree(builder, child, offset + 4);
}
- builder.append(prefix).append("}");
+ builder.append(prefix).append('}');
} else {
- builder.append(" ").append(dataNode.getValue());
+ builder.append(' ').append(dataNode.getValue());
}
- builder.append("\n");
+ builder.append('\n');
}
private static String toStringTree(final PathArgument identifier) {
- if( identifier instanceof NodeIdentifierWithPredicates) {
+ if (identifier instanceof NodeIdentifierWithPredicates) {
StringBuilder builder = new StringBuilder();
builder.append(identifier.getNodeType().getLocalName());
builder.append(((NodeIdentifierWithPredicates) identifier).getKeyValues().values());