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/** 027 * Represents a single text cell of the terminal. 028 */ 029@InterfaceAudience.Private 030public class Cell { 031 private static final char UNSET_VALUE = (char) 65535; 032 private static final char END_OF_LINE = '\0'; 033 034 private final Attributes attributes; 035 private char ch; 036 037 public Cell() { 038 attributes = new Attributes(); 039 ch = ' '; 040 } 041 042 public char getChar() { 043 return ch; 044 } 045 046 public void setChar(char ch) { 047 this.ch = ch; 048 } 049 050 public void reset() { 051 attributes.reset(); 052 ch = ' '; 053 } 054 055 public void unset() { 056 attributes.reset(); 057 ch = UNSET_VALUE; 058 } 059 060 public void endOfLine() { 061 attributes.reset(); 062 ch = END_OF_LINE; 063 } 064 065 public boolean isEndOfLine() { 066 return ch == END_OF_LINE; 067 } 068 069 public void set(Cell cell) { 070 attributes.set(cell.attributes); 071 this.ch = cell.ch; 072 } 073 074 public Attributes getAttributes() { 075 return new Attributes(attributes); 076 } 077 078 public void setAttributes(Attributes attributes) { 079 this.attributes.set(attributes); 080 } 081 082 public boolean isBold() { 083 return attributes.isBold(); 084 } 085 086 public boolean isBlink() { 087 return attributes.isBlink(); 088 } 089 090 public boolean isReverse() { 091 return attributes.isReverse(); 092 } 093 094 public boolean isUnderline() { 095 return attributes.isUnderline(); 096 } 097 098 public Color getForegroundColor() { 099 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}