You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@hbase.apache.org by GitBox <gi...@apache.org> on 2019/09/03 14:25:53 UTC

[GitHub] [hbase] joshelser commented on a change in pull request #476: HBASE-11062 hbtop

joshelser commented on a change in pull request #476: HBASE-11062 hbtop
URL: https://github.com/apache/hbase/pull/476#discussion_r320301846
 
 

 ##########
 File path: hbase-hbtop/src/main/java/org/apache/hadoop/hbase/hbtop/Record.java
 ##########
 @@ -0,0 +1,178 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.apache.hadoop.hbase.hbtop;
+
+import edu.umd.cs.findbugs.annotations.NonNull;
+import java.util.AbstractMap;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Set;
+import java.util.stream.Stream;
+import org.apache.hadoop.hbase.hbtop.field.Field;
+import org.apache.hadoop.hbase.hbtop.field.FieldValue;
+import org.apache.hadoop.hbase.hbtop.field.FieldValueType;
+import org.apache.yetus.audience.InterfaceAudience;
+
+import org.apache.hbase.thirdparty.com.google.common.collect.ImmutableMap;
+
+/**
+ * Represents a record of the metrics in the top screen.
+ */
+@InterfaceAudience.Private
+public final class Record implements Map<Field, FieldValue> {
+
+  private final ImmutableMap<Field, FieldValue> values;
+
+  public final static class Entry extends AbstractMap.SimpleImmutableEntry<Field, FieldValue> {
+    private Entry(Field key, FieldValue value) {
+      super(key, value);
+    }
+  }
+
+  public final static class Builder {
+    private final ImmutableMap.Builder<Field, FieldValue> builder;
+
+    private Builder() {
+      builder = ImmutableMap.builder();
+    }
+
+    public Builder put(Field key, Object value) {
+      builder.put(key, key.newValue(value));
+      return this;
+    }
+
+    public Builder put(Field key, FieldValue value) {
+      builder.put(key, value);
+      return this;
+    }
+
+    public Builder put(Entry entry) {
+      builder.put(entry);
+      return this;
+    }
+
+    public Builder putAll(Map<Field, FieldValue> map) {
+      builder.putAll(map);
+      return this;
+    }
+
+    public Record build() {
+      return new Record(builder.build());
+    }
+  }
+
+  public static Builder builder() {
+    return new Builder();
+  }
+
+  public static Entry entry(Field field, Object value) {
+    return new Entry(field, field.newValue(value));
+  }
+  public static Entry entry(Field field, FieldValue value) {
+    return new Entry(field, value);
+  }
+
+  public static Record ofEntries(Entry... entries) {
+    return ofEntries(Stream.of(entries));
+  }
+
+  public static Record ofEntries(Stream<Entry> entries) {
+    return entries.collect(Record::builder, Builder::put, (r1, r2) -> {}).build();
+  }
+
+  private Record(ImmutableMap<Field, FieldValue> values) {
+    this.values = values;
+  }
+
+  @Override
+  public int size() {
+    return values.size();
+  }
+
+  @Override
+  public boolean isEmpty() {
+    return values.isEmpty();
+  }
+
+  @Override
+  public boolean containsKey(Object key) {
+    return values.containsKey(key);
+  }
+
+  @Override
+  public boolean containsValue(Object value) {
+    return values.containsValue(value);
+  }
+
+  @Override
+  public FieldValue get(Object key) {
+    return values.get(key);
+  }
+
+  @Override
+  public FieldValue put(Field key, FieldValue value) {
+    return values.put(key, value);
 
 Review comment:
   This would always throw an exception now, right? (`values` is an `ImmutableMap`). Throw an `UnsupportedOperationException` instead (and for `put(Field, Object)`)?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services