View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.hbtop.terminal.impl;
19  
20  import java.util.Objects;
21  
22  import org.apache.hadoop.hbase.classification.InterfaceAudience;
23  import org.apache.hadoop.hbase.hbtop.terminal.Attributes;
24  import org.apache.hadoop.hbase.hbtop.terminal.Color;
25  
26  /**
27   * Represents a single text cell of the terminal.
28   */
29  @InterfaceAudience.Private
30  public class Cell {
31    private static final char UNSET_VALUE = (char) 65535;
32    private static final char END_OF_LINE = '\0';
33  
34    private final Attributes attributes;
35    private char ch;
36  
37    public Cell() {
38      attributes = new Attributes();
39      ch = ' ';
40    }
41  
42    public char getChar() {
43      return ch;
44    }
45  
46    public void setChar(char ch) {
47      this.ch = ch;
48    }
49  
50    public void reset() {
51      attributes.reset();
52      ch = ' ';
53    }
54  
55    public void unset() {
56      attributes.reset();
57      ch = UNSET_VALUE;
58    }
59  
60    public void endOfLine() {
61      attributes.reset();
62      ch = END_OF_LINE;
63    }
64  
65    public boolean isEndOfLine() {
66      return ch == END_OF_LINE;
67    }
68  
69    public void set(Cell cell) {
70      attributes.set(cell.attributes);
71      this.ch = cell.ch;
72    }
73  
74    public Attributes getAttributes() {
75      return new Attributes(attributes);
76    }
77  
78    public void setAttributes(Attributes attributes) {
79      this.attributes.set(attributes);
80    }
81  
82    public boolean isBold() {
83      return attributes.isBold();
84    }
85  
86    public boolean isBlink() {
87      return attributes.isBlink();
88    }
89  
90    public boolean isReverse() {
91      return attributes.isReverse();
92    }
93  
94    public boolean isUnderline() {
95      return attributes.isUnderline();
96    }
97  
98    public Color getForegroundColor() {
99      return attributes.getForegroundColor();
100   }
101 
102   public Color getBackgroundColor() {
103     return attributes.getBackgroundColor();
104   }
105 
106   @Override
107   public boolean equals(Object o) {
108     if (this == o) {
109       return true;
110     }
111     if (!(o instanceof Cell)) {
112       return false;
113     }
114     Cell cell = (Cell) o;
115     return ch == cell.ch && attributes.equals(cell.attributes);
116   }
117 
118   @Override
119   public int hashCode() {
120     return Objects.hash(attributes, ch);
121   }
122 }