// Path: src/util/src/main/java/org/lilycms/util/ArgumentValidator.java
// public class ArgumentValidator {
//     public static void notNull(Object object, String argName) {
//         if (object == null)
//             throw new IllegalArgumentException("Null argument: " + argName);
//     }
// }


import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Bytes;
import org.lilycms.util.ArgumentValidator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
/*
 * Copyright 2010 Outerthought bvba
 *
 * Licensed 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.lilycms.hbaseindex;



/**
 * Allows to query an index, and add entries to it or remove entries from it.
 *
 * <p>An Index instance can be obtained from {@link IndexManager#getIndex}.
 *
 * <p>The Index class <b>is not thread safe</b> for writes, because the underlying
 * HBase HTable is not thread safe for writes.
 *
 */
public class Index {
  private HTable htable;
  private IndexDefinition definition;

  protected static final byte[] DATA_FAMILY = Bytes.toBytes("data");
  private static final byte[] DUMMY_QUALIFIER = Bytes.toBytes("dummy");
  private static final byte[] DUMMY_VALUE = Bytes.toBytes("dummy");

  /** Number of bytes overhead per field. */
  private static final int FIELD_FLAGS_SIZE = 1;

  private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

  protected Index(HTable htable, IndexDefinition definition) {
    this.htable = htable;
    this.definition = definition;
  }

  /**
   * Adds an entry to this index. See {@link IndexEntry} for more information.
   *
   * @param entry the values to be part of the index key, should correspond to the fields
   *              defined in the {@link IndexDefinition}
   * @param identifier the identifier of the indexed object, typically the key of a row in
   *                   another HBase table
   */
  public void addEntry(IndexEntry entry, byte[] identifier) throws IOException {
// Path: src/util/src/main/java/org/lilycms/util/ArgumentValidator.java
// public class ArgumentValidator {
//     public static void notNull(Object object, String argName) {
//         if (object == null)
//             throw new IllegalArgumentException("Null argument: " + argName);
//     }
// }


// Path: src/hbaseindex/src/main/java/org/lilycms/hbaseindex/Index.java
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.filter.*;
import org.apache.hadoop.hbase.filter.CompareFilter.CompareOp;
import org.apache.hadoop.hbase.util.Bytes;
import org.lilycms.util.ArgumentValidator;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/*
 * Copyright 2010 Outerthought bvba
 *
 * Licensed 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.lilycms.hbaseindex;



/**
 * Allows to query an index, and add entries to it or remove entries from it.
 *
 * <p>An Index instance can be obtained from {@link IndexManager#getIndex}.
 *
 * <p>The Index class <b>is not thread safe</b> for writes, because the underlying
 * HBase HTable is not thread safe for writes.
 *
 */
public class Index {
  private HTable htable;
  private IndexDefinition definition;

  protected static final byte[] DATA_FAMILY = Bytes.toBytes("data");
  private static final byte[] DUMMY_QUALIFIER = Bytes.toBytes("dummy");
  private static final byte[] DUMMY_VALUE = Bytes.toBytes("dummy");

  /** Number of bytes overhead per field. */
  private static final int FIELD_FLAGS_SIZE = 1;

  private static final byte[] EMPTY_BYTE_ARRAY = new byte[0];

  protected Index(HTable htable, IndexDefinition definition) {
    this.htable = htable;
    this.definition = definition;
  }

  /**
   * Adds an entry to this index. See {@link IndexEntry} for more information.
   *
   * @param entry the values to be part of the index key, should correspond to the fields
   *              defined in the {@link IndexDefinition}
   * @param identifier the identifier of the indexed object, typically the key of a row in
   *                   another HBase table
   */
  public void addEntry(IndexEntry entry, byte[] identifier) throws IOException {
    ArgumentValidator.notNull(entry, "entry");