001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *     http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.hbtop.terminal.impl;
019
020import java.util.Objects;
021import org.apache.hadoop.hbase.hbtop.terminal.Attributes;
022import org.apache.hadoop.hbase.hbtop.terminal.Color;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * Represents a single text cell of the terminal.
027 */
028@InterfaceAudience.Private
029public class Cell {
030  private static final char UNSET_VALUE = (char) 65535;
031  private static final char END_OF_LINE = '\0';
032
033  private final Attributes attributes;
034  private char ch;
035
036  public Cell() {
037    attributes = new Attributes();
038    ch = ' ';
039  }
040
041  public char getChar() {
042    return ch;
043  }
044
045  public void setChar(char ch) {
046    this.ch = ch;
047  }
048
049  public void reset() {
050    attributes.reset();
051    ch = ' ';
052  }
053
054  public void unset() {
055    attributes.reset();
056    ch = UNSET_VALUE;
057  }
058
059  public void endOfLine() {
060    attributes.reset();
061    ch = END_OF_LINE;
062  }
063
064  public boolean isEndOfLine() {
065    return ch == END_OF_LINE;
066  }
067
068  public void set(Cell cell) {
069    attributes.set(cell.attributes);
070    this.ch = cell.ch;
071  }
072
073  public Attributes getAttributes() {
074    return new Attributes(attributes);
075  }
076
077  public void setAttributes(Attributes attributes) {
078    this.attributes.set(attributes);
079  }
080
081  public boolean isBold() {
082    return attributes.isBold();
083  }
084
085  public boolean isBlink() {
086    return attributes.isBlink();
087  }
088
089  public boolean isReverse() {
090    return attributes.isReverse();
091  }
092
093  public boolean isUnderline() {
094    return attributes.isUnderline();
095  }
096
097  public Color getForegroundColor() {
098    return attributes.getForegroundColor();
099  }
100
101  public Color getBackgroundColor() {
102    return attributes.getBackgroundColor();
103  }
104
105  @Override
106  public boolean equals(Object o) {
107    if (this == o) {
108      return true;
109    }
110    if (!(o instanceof Cell)) {
111      return false;
112    }
113    Cell cell = (Cell) o;
114    return ch == cell.ch && attributes.equals(cell.attributes);
115  }
116
117  @Override
118  public int hashCode() {
119    return Objects.hash(attributes, ch);
120  }
121}