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;
019
020import java.util.Iterator;
021import java.util.Optional;
022
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * An extended version of cell that gives more power to CPs
027 */
028@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.COPROC)
029public interface RawCell extends Cell {
030  static final int MAX_TAGS_LENGTH = (2 * Short.MAX_VALUE) + 1;
031
032  /**
033   * Allows cloning the tags in the cell to a new byte[]
034   * @return the byte[] having the tags
035   */
036  default byte[] cloneTags() {
037    return PrivateCellUtil.cloneTags(this);
038  }
039
040  /**
041   * Creates a list of tags in the current cell
042   * @return a list of tags
043   */
044  default Iterator<Tag> getTags() {
045    return PrivateCellUtil.tagsIterator(this);
046  }
047
048  /**
049   * Returns the specific tag of the given type
050   * @param type the type of the tag
051   * @return the specific tag if available or null
052   */
053  default Optional<Tag> getTag(byte type) {
054    return PrivateCellUtil.getTag(this, type);
055  }
056
057  /**
058   * Check the length of tags. If it is invalid, throw IllegalArgumentException
059   * @param tagsLength the given length of tags
060   * @throws IllegalArgumentException if tagslength is invalid
061   */
062  public static void checkForTagsLength(int tagsLength) {
063    if (tagsLength > MAX_TAGS_LENGTH) {
064      throw new IllegalArgumentException("tagslength " + tagsLength + " > " + MAX_TAGS_LENGTH);
065    }
066  }
067}