['("/**\\\\n   * Creates Jetty\'s {@link ShutdownHandler}.\\\\n   * \\\\n   * @param environment the environment\\\\n   * @return an instance of {@link ShutdownHandler} if\\\\n   *         {@link Environment#SERVER_SHUTDOWN_TOKEN_KEY} is\\\\n   *         available; otherwise null\\\\n   */", \'\')']

b"/**\n   * Creates Jetty's {@link ShutdownHandler}.\n   * \n   * @param environment the environment\n   * @return an instance of {@link ShutdownHandler} if\n   *         {@link Environment#SERVER_SHUTDOWN_TOKEN_KEY} is\n   *         available; otherwise null\n   */"protected ShutdownHandler createShutdownHandler(Environment environment) {
    String shutdownToken = environment.getServerShutdownToken();
    if (shutdownToken == null || shutdownToken.isEmpty()) {
      return null;
    }
    return new ShutdownHandler(shutdownToken, true, false);
  }

@Test
  public void createShutdownHandlerReturnsNullWithNoToken() throws Exception {
    HandlerCollectionLoader hcl = new HandlerCollectionLoader();
    ShutdownHandler shutdownHandler = hcl.createShutdownHandler(env);
    assertThat(shutdownHandler).isNull();
  }


@Test
  public void createShutdownHandlerObserversShutdownTokenWhenPresent() throws Exception {
    HandlerCollectionLoader hcl = new HandlerCollectionLoader();
    String token = UUID.randomUUID().toString();
    defaultEnv.put(Environment.SERVER_SHUTDOWN_TOKEN_KEY, token);
    env = Environment.createEnvironment(defaultEnv);
    ShutdownHandler shutdownHandler = hcl.createShutdownHandler(env);
    assertThat(shutdownHandler).isNotNull();
    assertThat(shutdownHandler.getShutdownToken()).isEqualTo(token);
  }


['("/*\\n\\t\\t\\t\\t * we don\'t know for sure why the thread was interrupted, so we\\n\\t\\t\\t\\t * need to obey; if interrupt was not relevant, the process will\\n\\t\\t\\t\\t * restart; we need to restore the interrupt status so that the\\n\\t\\t\\t\\t * called methods know that there was an interrupt\\n\\t\\t\\t\\t */", \'\')']

@Override
	public synchronized void load(ElkAxiomProcessor axiomInserter,
			ElkAxiomProcessor axiomDeleter) throws ElkLoadingException {
		if (finished_)
			return;

		if (!started_) {
			parserThread_.start();
			started_ = true;
		}

		ArrayList<ElkAxiom> nextBatch;

		for (;;) {
			if (isInterrupted())
				break;
			try {
				nextBatch = axiomExchanger_.take();
			} catch (InterruptedException e) {
				/*
				 * we don't know for sure why the thread was interrupted, so we
				 * need to obey; if interrupt was not relevant, the process will
				 * restart; we need to restore the interrupt status so that the
				 * called methods know that there was an interrupt
				 */
				Thread.currentThread().interrupt();
				break;
			}
			if (nextBatch == POISON_BATCH_) {
				break;
			}
			for (int i = 0; i < nextBatch.size(); i++) {
				ElkAxiom axiom = nextBatch.get(i);
				axiomInserter.visit(axiom);
			}
		}
		if (exception != null) {
			throw exception;
		}
	}

@Test(expected = ElkLoadingException.class)
	public void expectedLoadingExceptionOnSyntaxError()
			throws ElkLoadingException {
		String ontology = ""//
				+ "Prefix( : = <http://example.org/> )"//
				+ "Ontology((((()("//
				+ "EquivalentClasses(:B :C)"//
				+ "SubClassOf(:A ObjectSomeValuesFrom(:R :B))"//
				+ "))";

		load(ontology);
	}


@Test(expected = ElkLoadingException.class)
	public void expectedLoadingExceptionOnLexicalError() throws Exception {
		String ontology = ""//
				+ "Prefix( : = <http://example.org/> )"//
				+ "Ontology-LEXICAL-ERROR("//
				+ "EquivalentClasses(:B :C)"//
				+ "SubClassOf(:A ObjectSomeValuesFrom(:R :B))"//
				+ ")";

		load(ontology);
	}


["('/**\\\\n\\\\t * @param prefix\\\\n\\\\t *            the prefix of configuration options to be loaded\\\\n\\\\t * @param configClass\\\\n\\\\t *            the class to be instantiated with the loaded options\\\\n\\\\t * @return the {@link BaseConfiguration} for the specified parameters\\\\n\\\\t * @throws ConfigurationException\\\\n\\\\t *             if loading fails\\\\n\\\\t */', '')", '(\'\', "// try to find elk.properties. if doesn\'t exist, use the default\\n")', "('', '// parameter values for the given class\\n')", "('', '// copy parameters from the bundle\\n')"]

b'/**\n\t * @param prefix\n\t *            the prefix of configuration options to be loaded\n\t * @param configClass\n\t *            the class to be instantiated with the loaded options\n\t * @return the {@link BaseConfiguration} for the specified parameters\n\t * @throws ConfigurationException\n\t *             if loading fails\n\t */'public BaseConfiguration getConfiguration(String prefix,
			Class<? extends BaseConfiguration> configClass)
			throws ConfigurationException {
		// try to find elk.properties. if doesn't exist, use the default
		// parameter values for the given class
		ResourceBundle bundle = null;
		BaseConfiguration config = instantiate(configClass);

		try {
			bundle = ResourceBundle.getBundle(STANDARD_RESOURCE_NAME,
					Locale.getDefault(), configClass.getClassLoader());
		} catch (MissingResourceException e) {
		}

		if (bundle == null) {
			LOGGER_.debug("Loading default configuration parameters for "
					+ configClass);
		} else {
			// copy parameters from the bundle
			copyParameters(prefix, config, bundle);
		}

		copyParameters(prefix, config, System.getProperties());

		return config;
	}

@SuppressWarnings("static-method")
	@Test
	public void getDefaultConfiguration() {
		BaseConfiguration defaultConfig = new ConfigurationFactory()
				.getConfiguration("elk", BaseConfiguration.class);

		assertEquals(3, defaultConfig.getParameterNames().size());
	}


@SuppressWarnings("static-method")
	@Test
	public void getDefaultConfigurationWithPrefix() {
		BaseConfiguration defaultConfig = new ConfigurationFactory()
				.getConfiguration("elk.reasoner", BaseConfiguration.class);

		assertEquals(2, defaultConfig.getParameterNames().size());

		defaultConfig = new ConfigurationFactory().getConfiguration(
				"elk.parser", BaseConfiguration.class);

		assertEquals(1, defaultConfig.getParameterNames().size());
	}


@Test
	public void getConfigurationFromStream() throws ConfigurationException,
			IOException {
		InputStream stream = null;

		try {
			stream = this.getClass().getClassLoader()
					.getResourceAsStream("elk.properties");

			BaseConfiguration config = new ConfigurationFactory()
					.getConfiguration(stream, "elk", BaseConfiguration.class);

			assertEquals(3, config.getParameterNames().size());
		} finally {
			IOUtils.closeQuietly(stream);
		}
	}


('', '// Add a token for end of sentence\n')

public String[] tokenize(String s) {
	InputStream modelIn = null;

	List<String> tokens = new ArrayList<String>();
	try {
	    modelIn = new FileInputStream(sentenceModelFile);
	    SentenceModel model = new SentenceModel(modelIn);

	    SentenceDetector sentenceDetector = new SentenceDetectorME(model);
	    String sentences[] = sentenceDetector.sentDetect(s);

	    for (String sentence : sentences) {
		List<String> toks =
		    Arrays.asList(tokenizeHelper(sentence));
		tokens.addAll(toks);
		// Add a token for end of sentence
		tokens.add("<SENTENCE>");
	    }
	}
	catch (IOException e) {
	    System.out.println("Error with loading Sentence model...");
	    e.printStackTrace();
	}
	finally {
	    if (modelIn != null) {
		try {
		    modelIn.close();
		}
		catch (IOException e) {
		}
	    }
	}

	return tokens.toArray(new String[tokens.size()]);
    }

@Test
    public void testTokenization() {
	String text = "This, is the first sentence. This: is    the second sentence   ";

	String[] tokenizedText = tokenizer.tokenize(text);
	System.out.println(Arrays.toString(tokenizedText));
    }


Creates a new codeFormattedEntityIdRowFiltercode instance The row key format must have an encoding of @link RowKeyEncodingFORMATTED and if there is a salt defined it must not be set to suppress key materialization If key materialization were suppressed then there would be no component fields to match against @param rowKeyFormat the row key format of the table this filter will be used on @param components the components to match on with @code nulls indicating a match on any value If fewer than the number of components defined in the row key format are supplied the rest will be filled in as @code null     Fill in null for any components defined in the row key format that have   not been passed in as components for the filter This effectively makes   a prefix filter looking at only the components defined at the beginning   of the EntityId

b'/**\n   * Creates a new FormattedEntityIdRowFilter instance. The row key\n   * format must have an encoding of {@link RowKeyEncoding#FORMATTED}, and if\n   * there is a salt defined, it must not be set to suppress key\n   * materialization.  If key materialization were suppressed, then there would\n   * be no component fields to match against.\n   *\n   * @param rowKeyFormat the row key format of the table this filter will be used on\n   * @param components the components to match on, with {@code null}s indicating\n   *     a match on any value. If fewer than the number of components defined in\n   *     the row key format are supplied, the rest will be filled in as {@code\n   *     null}.\n   */'public FormattedEntityIdRowFilter(RowKeyFormat2 rowKeyFormat, Object... components) {
    Preconditions.checkNotNull(rowKeyFormat, "RowKeyFormat must be specified");
    Preconditions.checkArgument(rowKeyFormat.getEncoding().equals(RowKeyEncoding.FORMATTED),
        "FormattedEntityIdRowFilter only works with formatted entity IDs");
    if (null != rowKeyFormat.getSalt()) {
      Preconditions.checkArgument(!rowKeyFormat.getSalt().getSuppressKeyMaterialization(),
          "FormattedEntityIdRowFilter only works with materialized keys");
    }
    Preconditions.checkNotNull(components, "At least one component must be specified");
    Preconditions.checkArgument(components.length > 0, "At least one component must be specified");
    Preconditions.checkArgument(components.length <= rowKeyFormat.getComponents().size(),
        "More components given (%s) than are in the row key format specification (%s)",
        components.length, rowKeyFormat.getComponents().size());

    mRowKeyFormat = rowKeyFormat;

    // Fill in 'null' for any components defined in the row key format that have
    // not been passed in as components for the filter.  This effectively makes
    // a prefix filter, looking at only the components defined at the beginning
    // of the EntityId.
    if (components.length < rowKeyFormat.getComponents().size()) {
      mComponents = new Object[rowKeyFormat.getComponents().size()];
      for (int i = 0; i < components.length; i++) {
        mComponents[i] = components[i];
      }
    } else {
      mComponents = components;
    }
  }

@Test
  public void testFormattedEntityIdRowFilter() throws Exception {
    FormattedEntityIdRowFilter filter = createFilter(mRowKeyFormat, 100, null, "value");
    runTest(mRowKeyFormat, filter, mFactory, INCLUDE, 100, 2000L, "value");
    runTest(mRowKeyFormat, filter, mFactory, EXCLUDE, 100, null, null);
    runTest(mRowKeyFormat, filter, mFactory, EXCLUDE, 0, null, null);
  }


["('/** {@inheritDoc} */', '')", "('', '// In the case that we have enough information to generate a prefix, we will\\n')", '(\'\', "// construct a PrefixFilter that is AND\'ed with the RowFilter.  This way,\\n")', "('', '// when the scan passes the end of the prefix, it can end the filtering\\n')", "('', '// process quickly.\\n')", "('', '// Define a regular expression that effectively creates a mask for the row\\n')", "('', '// key based on the key format and the components passed in.  Prefix hashes\\n')", "('', '// are skipped over, and null components match any value.\\n')", "('', '// ISO-8859-1 is used so that numerals map to valid characters\\n')", "('', '// see http://stackoverflow.com/a/1387184\\n')", "('', '// Use the embedded flag (?s) to turn on single-line mode; this makes the\\n')", '(\'\', "// \'.\' match on line terminators.  The RegexStringComparator uses the DOTALL\\n")', "('', '// flag during construction, but it does not use that flag upon\\n')", "('', '// deserialization.  This bug has been fixed in HBASE-5667, part of the 0.95\\n')", "('', '// release.\\n')", "('', '// ^ matches the beginning of the string\\n')", "('', '// If all of the components included in the hash have been specified,\\n')", "('', '// then match on the value of the hash\\n')", "('', '// Write the hashed bytes to the prefix buffer\\n')", '(\'\', "// match any character exactly \'hash size\' number of times\\n")', "('', '// Only add to the prefix buffer until we hit a null component.  We do this\\n')", "('', '// here, because the prefix is going to expect to have 0x00 component\\n')", "('', '// terminators, which we put in during this loop but not in the loop above.\\n')", "('', '// null integers can be excluded entirely if there are just nulls at\\n')", "('', '// the end of the EntityId, otherwise, match the correct number of\\n')", "('', '// bytes\\n')", "('', '// match each byte in the integer using a regex hex sequence\\n')", "('', '// null longs can be excluded entirely if there are just nulls at\\n')", "('', '// the end of the EntityId, otherwise, match the correct number of\\n')", "('', '// bytes\\n')", "('', '// match each byte in the long using a regex hex sequence\\n')", "('', '// match any non-zero character at least once, followed by a zero\\n')", "('', '// delimiter, or match nothing at all in case the component was at\\n')", "('', '// the end of the EntityId and skipped entirely\\n')", "('', '// FormattedEntityId converts a string component to UTF-8 bytes to\\n')", "('', '// create the HBase key.  RegexStringComparator will convert the\\n')", "('', '// value it sees (ie, the HBase key) to a string using ISO-8859-1.\\n')", "('', '// Therefore, we need to write ISO-8859-1 characters to our regex so\\n')", "('', '// that the comparison happens correctly.\\n')", "('', '// $ matches the end of the string\\n')"]

b'/** {@inheritDoc} */'@Override
  public Filter toHBaseFilter(Context context) throws IOException {
    // In the case that we have enough information to generate a prefix, we will
    // construct a PrefixFilter that is AND'ed with the RowFilter.  This way,
    // when the scan passes the end of the prefix, it can end the filtering
    // process quickly.
    boolean addPrefixFilter = false;
    ByteArrayOutputStream prefixBytes = new ByteArrayOutputStream();

    // Define a regular expression that effectively creates a mask for the row
    // key based on the key format and the components passed in.  Prefix hashes
    // are skipped over, and null components match any value.
    // ISO-8859-1 is used so that numerals map to valid characters
    // see http://stackoverflow.com/a/1387184

    // Use the embedded flag (?s) to turn on single-line mode; this makes the
    // '.' match on line terminators.  The RegexStringComparator uses the DOTALL
    // flag during construction, but it does not use that flag upon
    // deserialization.  This bug has been fixed in HBASE-5667, part of the 0.95
    // release.
    StringBuilder regex = new StringBuilder("(?s)^"); // ^ matches the beginning of the string
    if (null != mRowKeyFormat.getSalt()) {
      if (mRowKeyFormat.getSalt().getHashSize() > 0) {
        // If all of the components included in the hash have been specified,
        // then match on the value of the hash
        Object[] prefixComponents =
            getNonNullPrefixComponents(mComponents, mRowKeyFormat.getRangeScanStartIndex());
        if (prefixComponents.length == mRowKeyFormat.getRangeScanStartIndex()) {
          ByteArrayOutputStream tohash = new ByteArrayOutputStream();
          for (Object component : prefixComponents) {
            byte[] componentBytes = toBytes(component);
            tohash.write(componentBytes, 0, componentBytes.length);
          }
          byte[] hashed = Arrays.copyOfRange(Hasher.hash(tohash.toByteArray()), 0,
              mRowKeyFormat.getSalt().getHashSize());
          for (byte hashedByte : hashed) {
            regex.append(String.format("\\x%02x", hashedByte & 0xFF));
          }

          addPrefixFilter = true;
          // Write the hashed bytes to the prefix buffer
          prefixBytes.write(hashed, 0, hashed.length);
        } else {
          // match any character exactly 'hash size' number of times
          regex.append(".{").append(mRowKeyFormat.getSalt().getHashSize()).append("}");
        }
      }
    }
    // Only add to the prefix buffer until we hit a null component.  We do this
    // here, because the prefix is going to expect to have 0x00 component
    // terminators, which we put in during this loop but not in the loop above.
    boolean hitNullComponent = false;
    for (int i = 0; i < mComponents.length; i++) {
      final Object component = mComponents[i];
      switch (mRowKeyFormat.getComponents().get(i).getType()) {
        case INTEGER:
          if (null == component) {
            // null integers can be excluded entirely if there are just nulls at
            // the end of the EntityId, otherwise, match the correct number of
            // bytes
            regex.append("(.{").append(Bytes.SIZEOF_INT).append("})?");
            hitNullComponent = true;
          } else {
            byte[] tempBytes = toBytes((Integer) component);
            // match each byte in the integer using a regex hex sequence
            for (byte tempByte : tempBytes) {
              regex.append(String.format("\\x%02x", tempByte & 0xFF));
            }
            if (!hitNullComponent) {
              prefixBytes.write(tempBytes, 0, tempBytes.length);
            }
          }
          break;
        case LONG:
          if (null == component) {
            // null longs can be excluded entirely if there are just nulls at
            // the end of the EntityId, otherwise, match the correct number of
            // bytes
            regex.append("(.{").append(Bytes.SIZEOF_LONG).append("})?");
            hitNullComponent = true;
          } else {
            byte[] tempBytes = toBytes((Long) component);
            // match each byte in the long using a regex hex sequence
            for (byte tempByte : tempBytes) {
              regex.append(String.format("\\x%02x", tempByte & 0xFF));
            }
            if (!hitNullComponent) {
              prefixBytes.write(tempBytes, 0, tempBytes.length);
            }
          }
          break;
        case STRING:
          if (null == component) {
            // match any non-zero character at least once, followed by a zero
            // delimiter, or match nothing at all in case the component was at
            // the end of the EntityId and skipped entirely
            regex.append("([^\\x00]+\\x00)?");
            hitNullComponent = true;
          } else {
            // FormattedEntityId converts a string component to UTF-8 bytes to
            // create the HBase key.  RegexStringComparator will convert the
            // value it sees (ie, the HBase key) to a string using ISO-8859-1.
            // Therefore, we need to write ISO-8859-1 characters to our regex so
            // that the comparison happens correctly.
            byte[] utfBytes = toBytes((String) component);
            String isoString = new String(utfBytes, Charsets.ISO_8859_1);
            regex.append(isoString).append("\\x00");
            if (!hitNullComponent) {
              prefixBytes.write(utfBytes, 0, utfBytes.length);
              prefixBytes.write((byte) 0);
            }
          }
          break;
        default:
          throw new IllegalStateException("Unknown component type: "
              + mRowKeyFormat.getComponents().get(i).getType());
      }
    }
    regex.append("$"); // $ matches the end of the string

    final RowFilter regexRowFilter =
        SchemaPlatformBridge.get().createRowFilterFromRegex(CompareOp.EQUAL, regex.toString());
    if (addPrefixFilter) {
      return new FilterList(new PrefixFilter(prefixBytes.toByteArray()), regexRowFilter);
    }
    return regexRowFilter;
  }

@Test
  public void testLatinNewlineCharacterInclusion() throws Exception {
    RowKeyFormat2 rowKeyFormat = createRowKeyFormat(1, INTEGER, LONG);
    EntityIdFactory factory = EntityIdFactory.getFactory(rowKeyFormat);

    // Create and serialize a filter.
    FormattedEntityIdRowFilter filter = createFilter(rowKeyFormat, 10);
    byte[] serializedFilter = filter.toHBaseFilter(null).toByteArray();

    // Deserialize the filter.
    Filter deserializedFilter = FilterList.parseFrom(serializedFilter);

    // Filter an entity with the deserialized filter.
    EntityId entityId = factory.getEntityId(10, 10L);
    byte[] hbaseKey = entityId.getHBaseRowKey();
    boolean filtered = deserializedFilter.filterRowKey(hbaseKey, 0, hbaseKey.length);
    assertEquals(INCLUDE, filtered);
  }


['(\'/**\\\\n   * Gets a builder configured with default Kiji URI fields.\\\\n   *\\\\n   * More precisely, the following defaults are initialized:\\\\n   *
\\\\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\\\\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n   *       (<tt>"default"</tt>).
\\\\n   *
The table name and column names are explicitly left unset.
\\\\n   *
\\\\n   *\\\\n   * @return A builder configured with this Kiji URI.\\\\n   */\', \'\')']

b'/**\n   * Gets a builder configured with default Kiji URI fields.\n   *\n   * More precisely, the following defaults are initialized:\n   *
\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n   *       (<tt>"default"</tt>).
\n   *
The table name and column names are explicitly left unset.
\n   *
\n   *\n   * @return A builder configured with this Kiji URI.\n   */'public static HBaseKijiURIBuilder newBuilder() {
    return new HBaseKijiURIBuilder();
  }

@Test
  public void testSingleHost() {
    final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost:1234/instance/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost", uri.getZookeeperQuorum().get(0));
    assertEquals(1234, uri.getZookeeperClientPort());
    assertEquals("instance", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


('/**\\n   * Creates and returns a new KijiTableLayout instance as specified by an Avro TableLayoutDesc\\n   * description record.\\n   *\\n   * @param layout The Avro TableLayoutDesc descriptor record that describes the actual layout.\\n   * of the table.\\n   * @return A new table layout.\\n   * @throws InvalidLayoutException If the descriptor is invalid.\\n   */', '')

b'/**\n   * Creates and returns a new KijiTableLayout instance as specified by an Avro TableLayoutDesc\n   * description record.\n   *\n   * @param layout The Avro TableLayoutDesc descriptor record that describes the actual layout.\n   * of the table.\n   * @return A new table layout.\n   * @throws InvalidLayoutException If the descriptor is invalid.\n   */'public static KijiTableLayout newLayout(TableLayoutDesc layout) throws InvalidLayoutException {
    return new KijiTableLayout(layout, null);
  }

@Test
  public void badHashSizeRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(badHashSizeRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals("Valid hash sizes are between 1 and 16", ile.getMessage());
    }
  }


@Test
  public void repeatedNamesRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(repeatedNamesRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals("Component name already used.", ile.getMessage());
    }
  }


@Test
  public void tooHighRangeScanIndexRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(tooHighRangeScanIndexRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals(
          "Invalid range scan index. Range scans are supported starting with the second component.",
          ile.getMessage());
    }
  }


@Test
  public void zeroNullableIndexRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(zeroNullableIndexRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals(
          "Invalid index for nullable component. The second component onwards can be set to null.",
          ile.getMessage());
    }
  }


@Test
  public void tooHighNullableScanIndexRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(tooHighNullableIndexRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals(
          "Invalid index for nullable component. The second component onwards can be set to null.",
          ile.getMessage());
    }
  }


@Test
  public void emptyCompNameRKF() throws InvalidLayoutException {
    final TableLayoutDesc desc = TableLayoutDesc.newBuilder()
        .setName("table_name")
        .setKeysFormat(emptyCompNameRowKeyFormat())
        .setVersion(TABLE_LAYOUT_VERSION)
        .build();
    try {
      final KijiTableLayout ktl = KijiTableLayout.newLayout(desc);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals("Names should begin with a letter followed by a combination of letters, numbers "
          + "and underscores.", ile.getMessage());
    }
  }


('/**\\n   * Build a new table layout descriptor.\\n   *\\n   * @return a built table layout descriptor.\\n   */', '')

b'/**\n   * Build a new table layout descriptor.\n   *\n   * @return a built table layout descriptor.\n   */'public TableLayoutDesc build() {
    return mDescBuilder.build();
  }

@Test
  public void testTableLayoutSafeMutation() throws IOException {
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(TEST_LAYOUT);
    final TableLayoutDesc tld = layout.getDesc();
    final TableLayoutBuilder tlb = new TableLayoutBuilder(tld, getKiji());
    tld.setName("blastoise");
    final TableLayoutDesc tldBuilt = tlb.build();
    assertFalse(tld.getName().equals(tldBuilt.getName()));
  }


('/**\\n   * Register a reader schema to a column.\\n   *\\n   * @param columnName at which to register the schema.\\n   * @param schema to register.\\n   * @throws IOException If the parameters are invalid.\\n   * @return this.\\n   */', '')

b'/**\n   * Register a reader schema to a column.\n   *\n   * @param columnName at which to register the schema.\n   * @param schema to register.\n   * @throws IOException If the parameters are invalid.\n   * @return this.\n   */'public TableLayoutBuilder withReader(
      final KijiColumnName columnName,
      final Schema schema)
      throws IOException {
    return withSchema(columnName, schema, SchemaRegistrationType.READER);
  }

@Test
  public void testSchemaRegistrationAtBadColumns() throws IOException {
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(TEST_LAYOUT);
    final TableLayoutBuilder tlb = new TableLayoutBuilder(layout.getDesc(), getKiji());
    final Schema.Parser p = new Schema.Parser();
    Schema stringSchema = p.parse("\"string\"");

    // Unqualified group family
    try {
      tlb.withReader(KijiColumnName.create("profile"), stringSchema);
      fail("An exception should have been thrown.");
    } catch (NoSuchColumnException nsce) {
      assertEquals("Table 'table_name' has no column 'profile'.", nsce.getMessage());
    }

    // Fully qualified map family
    try {
      tlb.withReader(KijiColumnName.create("heroism:mordor"), stringSchema);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals("A fully qualified map-type column name was provided.", ile.getMessage());
    }

    // Nonexistent column
    try {
      tlb.withReader(KijiColumnName.create("info:name"), stringSchema);
      fail("An exception should have been thrown.");
    } catch (NoSuchColumnException nsce) {
      assertEquals("Table 'table_name' has no column 'info:name'.", nsce.getMessage());
    }

    // FINAL column
    try {
      tlb.withReader(KijiColumnName.create("clans"), stringSchema);
      fail("An exception should have been thrown.");
    } catch (InvalidLayoutException ile) {
      assertEquals("Final or non-AVRO column schema cannot be modified.", ile.getMessage());
    }
  }


('/**\\n   * Adds the jars from a directory into the distributed cache of a job.\\n   *\\n   * @param job The job to configure.\\n   * @param jarDirectory A path to a directory of jar files.\\n   * @throws IOException If there is a problem reading from the file system.\\n   */', '')

b'/**\n   * Adds the jars from a directory into the distributed cache of a job.\n   *\n   * @param job The job to configure.\n   * @param jarDirectory A path to a directory of jar files.\n   * @throws IOException If there is a problem reading from the file system.\n   */'public static void addJarsToDistributedCache(Job job, String jarDirectory) throws IOException {
    addJarsToDistributedCache(job, new File(jarDirectory));
  }

@Test
  public void testJarsDeDupe() throws IOException {
    // Jar list should de-dupe to {"myjar_a, "myjar_b", "myjar_0", "myjar_1"}
    Set<String> dedupedJarNames = new HashSet<String>(4);
    dedupedJarNames.add("myjar_a.jar");
    dedupedJarNames.add("myjar_b.jar");
    dedupedJarNames.add("myjar_0.jar");
    dedupedJarNames.add("myjar_1.jar");

    Job job = new Job();

    List<String> someJars = new ArrayList<String>();
    // Some unique jar names.
    someJars.add("/somepath/myjar_a.jar");
    someJars.add("/another/path/myjar_b.jar");
    someJars.add("/myjar_0.jar");

    // Duplicate jars.
    someJars.add("/another/path/myjar_b.jar");
    someJars.add("/yet/another/path/myjar_b.jar");

    job.getConfiguration().set(CONF_TMPJARS, StringUtils.join(someJars, ","));

    // Now add some duplicate jars from mTempDir.
    assertEquals(0, mTempDir.getRoot().list().length);
    createTestJars("myjar_0.jar", "myjar_1.jar");
    assertEquals(2, mTempDir.getRoot().list().length);
    DistributedCacheJars.addJarsToDistributedCache(job, mTempDir.getRoot());

    // Confirm each jar appears in de-dupe list exactly once.
    String listedJars = job.getConfiguration().get(CONF_TMPJARS);
    String[] jars = listedJars.split(",");
    for (String jar : jars) {
      // Check that path terminates in an expected jar.
      Path p = new Path(jar);
      assertTrue(dedupedJarNames.contains(p.getName()));
      dedupedJarNames.remove(p.getName());
    }
    assertEquals(0, dedupedJarNames.size());
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public void close() throws IOException {
    mVersionPager.close();
  }

@Test
  public void testQualifiersIterator() throws IOException {
    final EntityId eid = mTable.getEntityId("me");

    final KijiDataRequest dataRequest = KijiDataRequest.builder()
        .addColumns(ColumnsDef.create()
            .withMaxVersions(HConstants.ALL_VERSIONS).withPageSize(1).addFamily("jobs"))
        .build();

    final KijiRowData row = mReader.get(eid, dataRequest);
    final ColumnVersionIterator<String> it =
        new ColumnVersionIterator<String>(row, "jobs", "j2", 3);
    try {
      long counter = 5;
      for (Entry<Long, String> entry : it) {
        assertEquals(counter, (long) entry.getKey());
        counter -= 1;
      }
    } finally {
      it.close();
    }
  }


@Test
  public void testSingleHostGroupColumn() {
    final KijiURI uri =
        KijiURI.newBuilder("kiji-hbase://zkhost:1234/instance/table/family:qualifier").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost", uri.getZookeeperQuorum().get(0));
    assertEquals(1234, uri.getZookeeperClientPort());
    assertEquals("instance", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("family:qualifier", uri.getColumns().get(0).getName());
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public boolean equals(Object object) {
    if (object instanceof KijiCell) {
      final KijiCell<?> that = (KijiCell<?>) object;
      return this.mColumn.equals(that.mColumn)
          && (this.mTimestamp == that.mTimestamp)
          && this.mDecodedCell.equals(that.mDecodedCell);
    } else {
      return false;
    }
  }

@Test
  public void testEquals() {
    final KijiCell<Integer> cell1 =
        KijiCell.create(KijiColumnName.create("family", "qualifier"), 1234L,
            new DecodedCell<Integer>(Schema.create(Schema.Type.INT), 31415));

    final KijiCell<Integer> cell2 =
        KijiCell.create(KijiColumnName.create("family", "qualifier"), 1234L,
            new DecodedCell<Integer>(Schema.create(Schema.Type.INT), 31415));

    Assert.assertTrue(cell1.equals(cell2));
    Assert.assertTrue(cell2.equals(cell1));

    Assert.assertEquals(cell1.hashCode(), cell2.hashCode());
  }


('/**\\n   * Create a new KijiColumnName from a family and qualifier.\\n   *\\n   * @param family Family of the Kiji column for which to create a name.\\n   * @param qualifier Qualifier of the Kiji column for which to create a name.\\n   * @return a new KijiColumnName from the given family and qualifier.\\n   */', '')

b'/**\n   * Create a new KijiColumnName from a family and qualifier.\n   *\n   * @param family Family of the Kiji column for which to create a name.\n   * @param qualifier Qualifier of the Kiji column for which to create a name.\n   * @return a new KijiColumnName from the given family and qualifier.\n   */'public static KijiColumnName create(
      final String family,
      final String qualifier
  ) {
    return new KijiColumnName(family, qualifier);
  }

@Test
  public void testNull() {
    try {
      KijiColumnName.create(null);
      fail("An exception should have been thrown.");
    } catch (IllegalArgumentException iae) {
      assertEquals("Column name may not be null. At least specify family", iae.getMessage());
    }
  }


@Test
  public void testNullFamily() {
    try {
      KijiColumnName.create(null, "qualifier");
      fail("An exception should have been thrown.");
    } catch (IllegalArgumentException iae) {
      assertEquals("Family name may not be null.", iae.getMessage());
    }
  }


@Test
  public void testInvalidFamilyName() {
    try {
      KijiColumnName.create("1:qualifier");
      fail("An exception should have been thrown.");
    } catch (KijiInvalidNameException kine) {
      assertEquals("Invalid family name: 1 Name must match pattern: [a-zA-Z_][a-zA-Z0-9_]*",
          kine.getMessage());
    }
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public boolean equals(Object otherObj) {
    if (otherObj == this) {
      return true;
    } else if (null == otherObj) {
      return false;
    } else if (!otherObj.getClass().equals(getClass())) {
      return false;
    }
    final KijiColumnName other = (KijiColumnName) otherObj;
    return other.getFamily().equals(mFamily) && Objects.equal(other.getQualifier(), mQualifier);
  }

@Test
  public void testEquals() {
    KijiColumnName columnA = KijiColumnName.create("family", "qualifier1");
    KijiColumnName columnC = KijiColumnName.create("family", null);
    KijiColumnName columnD = KijiColumnName.create("family", "qualifier2");
    assertTrue(columnA.equals(columnA)); // reflexive
    assertFalse(columnA.equals(columnC) || columnC.equals(columnA));
    assertFalse(columnA.equals(columnD) || columnD.equals(columnA));
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public int hashCode() {
    return new HashCodeBuilder().append(mFamily).append(mQualifier).toHashCode();
  }

@Test
  public void testHashCode() {
    KijiColumnName columnA = KijiColumnName.create("family", "qualifier");
    KijiColumnName columnB = KijiColumnName.create("family:qualifier");
    assertEquals(columnA.hashCode(), columnB.hashCode());
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public int compareTo(KijiColumnName otherObj) {
    final int comparison = this.mFamily.compareTo(otherObj.mFamily);
    if (0 == comparison) {
      return (this.isFullyQualified() ? mQualifier : "")
          .compareTo(otherObj.isFullyQualified() ? otherObj.getQualifier() : "");
    } else {
      return comparison;
    }
  }

@Test
  public void testCompareTo() {
    KijiColumnName columnA = KijiColumnName.create("family");
    KijiColumnName columnB = KijiColumnName.create("familyTwo");
    KijiColumnName columnC = KijiColumnName.create("family:qualifier");
    assertTrue(0 == columnA.compareTo(columnA));
    assertTrue(0 > columnA.compareTo(columnB) && 0 < columnB.compareTo(columnA));
    assertTrue(0 > columnA.compareTo(columnC) && 0 < columnC.compareTo(columnA));
    assertTrue(0 < columnB.compareTo(columnC) && 0 > columnC.compareTo(columnB));
  }


('/**\\n   * Creates a new {@link KijiDataRequestBuilder}. Use this to configure a KijiDataRequest,\\n   * then create one with the {@link KijiDataRequestBuilder#build()} method.\\n   *\\n   * @return a new KijiDataRequestBuilder.\\n   */', '')

b'/**\n   * Creates a new {@link KijiDataRequestBuilder}. Use this to configure a KijiDataRequest,\n   * then create one with the {@link KijiDataRequestBuilder#build()} method.\n   *\n   * @return a new KijiDataRequestBuilder.\n   */'public static KijiDataRequestBuilder builder() {
    return new KijiDataRequestBuilder();
  }

@Test
  public void testDataRequestEquals() {
    KijiDataRequestBuilder builder0 = KijiDataRequest.builder()
        .withTimeRange(3L, 4L);
    builder0.newColumnsDef().withMaxVersions(2).addFamily("foo");
    builder0.newColumnsDef().withMaxVersions(5).add("bar", "baz");
    KijiDataRequest request0 = builder0.build();

    KijiDataRequestBuilder builder1 = KijiDataRequest.builder()
        .withTimeRange(3L, 4L);
    builder1.newColumnsDef().withMaxVersions(2).addFamily("foo");
    builder1.newColumnsDef().withMaxVersions(5).add("bar", "baz");
    KijiDataRequest request1 = builder1.build();

    KijiDataRequestBuilder builder2 = KijiDataRequest.builder()
        .withTimeRange(3L, 4L);
    builder2.newColumnsDef().withMaxVersions(2).addFamily("foo");
    builder2.newColumnsDef().withMaxVersions(5).add("car", "bot");
    KijiDataRequest request2 = builder2.build();

    KijiDataRequestBuilder builder3 = KijiDataRequest.builder()
        .withTimeRange(3L, 4L);
    builder3.newColumnsDef().withMaxVersions(2).addFamily("foo");
    builder3.newColumnsDef().withMaxVersions(3).add("car", "bot");
    KijiDataRequest request3 = builder3.build();

    assertEquals(request0, request1);
    assertThat(new Object(), is(not((Object) request0)));
    assertThat(request0, is(not(request2)));
    assertThat(request2, is(not(request3)));
  }


Creates a new data request representing the union of this data request and the data request specified as an argument pThis method merges data requests using the widestpossible treatment of parameters This may result in cells being included in the result set that were not specified by either data set For example if request A includes ttinfofoott from time range 400 700 and request B includes ttinfobartt from time range 500 900 then AmergeB will yield a data request for both columns with time range 400 900p pMore precisely merges are handled in the following wayp ul liThe output time interval encompasses both data requests time intervalsli liAll columns associated with both data requests will be includedli liWhen maxVersions differs for the same column in both requests the greater value is chosenli liWhen pageSize differs for the same column in both requests the lesser value is chosenli liIf either request contains KijiColumnFilter definitions attached to a column this is considered an error and a RuntimeException is thrown Data requests with filters cannot be mergedli liIf one data request includes an entire column family ttfoott and the other data request includes a column within that family ttfoobartt the entire family will be requested and properties such as max versions etc for the familywide request will be merged with the column to ensure the request is as wide as possibleli ul @param other another data request to include as a part of this one @return A new KijiDataRequest instance including the union of this data request and the argument request     maptype families requested   First include any requests for column families   And while were at it check for filters We dont know how to merge these   Loop through any requests on our end that have the same family   Include requests for column families on our side that arent present on theirs   And while were at it check for filters We dont know how to merge these   Loop through requests on their end that have the same family   Now include individual columns from their side If we have corresponding definitions   for the same columns merge them If the column is already covered by a request   for a family ignore the individual column its already been merged   We dont have a request for otherColumn so add it   Now grab any columns that were present in our data request but missed entirely   in the other sides data request   Column in our list but not the other sides list

b"/**\n   * Creates a new data request representing the union of this data request and the\n   * data request specified as an argument.\n   *\n   *
This method merges data requests using the widest-possible treatment of\n   * parameters. This may result in cells being included in the result set that\n   * were not specified by either data set. For example, if request A includes <tt>info:foo</tt>\n   * from time range [400, 700), and request B includes <tt>info:bar</tt> from time range\n   * [500, 900), then A.merge(B) will yield a data request for both columns, with time\n   * range [400, 900).
\n   *\n   *
More precisely, merges are handled in the following way:
\n   *
\n   *
The output time interval encompasses both data requests' time intervals.
\n   *
All columns associated with both data requests will be included.
\n   *
When maxVersions differs for the same column in both requests, the greater\n   *       value is chosen.
\n   *
When pageSize differs for the same column in both requests, the lesser value\n   *       is chosen.
\n   *
If either request contains KijiColumnFilter definitions attached to a column,\n   *      this is considered an error, and a RuntimeException is thrown. Data requests with\n   *      filters cannot be merged.
\n   *
If one data request includes an entire column family (<tt>foo:*</tt>) and\n   *       the other data request includes a column within that family (<tt>foo:bar</tt>),\n   *       the entire family will be requested, and properties such as max versions, etc.\n   *       for the family-wide request will be merged with the column to ensure the request\n   *       is as wide as possible.
\n   *
\n   *\n   * @param other another data request to include as a part of this one.\n   * @return A new KijiDataRequest instance, including the union of this data request\n   *     and the argument request.\n   */"public KijiDataRequest merge(KijiDataRequest other) {
    if (null == other) {
      throw new IllegalArgumentException("Input data request cannot be null.");
    }

    List<Column> outCols = new ArrayList<Column>();
    Set<String> families = new HashSet<String>(); // map-type families requested.

    // First, include any requests for column families.
    for (Column otherCol : other.getColumns()) {
      if (otherCol.getFilter() != null) {
        // And while we're at it, check for filters. We don't know how to merge these.
        throw new IllegalStateException("Invalid merge request: "
            + otherCol.getName() + " has a filter.");
      }

      if (otherCol.getQualifier() == null) {
        Column outFamily = otherCol;
        // Loop through any requests on our end that have the same family.
        for (Column myCol : getColumns()) {
          if (myCol.getFamily().equals(otherCol.getFamily())) {
            outFamily = mergeColumn(myCol.getFamily(), null, myCol, outFamily);
          }
        }

        outCols.add(outFamily);
        families.add(outFamily.getFamily());
      }
    }

    // Include requests for column families on our side that aren't present on their's.
    for (Column myCol : getColumns()) {
      if (myCol.getFilter() != null) {
        // And while we're at it, check for filters. We don't know how to merge these.
        throw new IllegalStateException("Invalid merge request: "
            + myCol.getName() + " has a filter.");
      }

      if (myCol.getQualifier() == null && !families.contains(myCol.getFamily())) {
        Column outFamily = myCol;
        // Loop through requests on their end that have the same family.
        for (Column otherCol : other.getColumns()) {
          if (otherCol.getFamily().equals(myCol.getFamily())) {
            outFamily = mergeColumn(myCol.getFamily(), null, outFamily, otherCol);
          }
        }

        outCols.add(outFamily);
        families.add(outFamily.getFamily());
      }
    }

    // Now include individual columns from their side. If we have corresponding definitions
    // for the same columns, merge them. If the column is already covered by a request
    // for a family, ignore the individual column (it's already been merged).
    for (Column otherCol : other.getColumns()) {
      if (otherCol.getQualifier() != null && !families.contains(otherCol.getFamily())) {
        Column myCol = getColumn(otherCol.getFamily(), otherCol.getQualifier());
        if (null == myCol) {
          // We don't have a request for otherColumn, so add it.
          outCols.add(otherCol);
        } else {
          outCols.add(mergeColumn(myCol.getFamily(), myCol.getQualifier(), myCol, otherCol));
        }
      }
    }

    // Now grab any columns that were present in our data request, but missed entirely
    // in the other side's data request.
    for (Column myCol : getColumns()) {
      if (myCol.getQualifier() != null && !families.contains(myCol.getFamily())) {
        Column otherCol = other.getColumn(myCol.getFamily(), myCol.getQualifier());
        if (null == otherCol) {
          // Column in our list but not the other side's list.
          outCols.add(myCol);
        }
      }
    }

    long outMinTs = Math.min(getMinTimestamp(), other.getMinTimestamp());
    long outMaxTs = Math.max(getMaxTimestamp(), other.getMaxTimestamp());

    return new KijiDataRequest(outCols, outMinTs, outMaxTs);
  }

@Test
  public void testMerge() {
    KijiDataRequestBuilder builder1 = KijiDataRequest.builder().withTimeRange(3, 4);
    builder1.newColumnsDef().withMaxVersions(2).add("foo", "bar");
    KijiDataRequest first = builder1.build();

    KijiDataRequestBuilder builder2 = KijiDataRequest.builder().withTimeRange(2, 4);
    builder2.newColumnsDef().add("baz", "bot");
    builder2.newColumnsDef().withMaxVersions(6).add("foo", "bar");
    KijiDataRequest second = builder2.build();

    KijiDataRequest merged = first.merge(second);
    assertTrue("merge() cannot mutate the object in place", first != merged);

    KijiDataRequest.Column fooBarColumnRequest = merged.getColumn("foo", "bar");
    assertNotNull("Missing column foo:bar from merged request", fooBarColumnRequest);
    assertEquals("Max versions was not increased", 6, fooBarColumnRequest.getMaxVersions());
    assertEquals("Time range was not extended", 2L, merged.getMinTimestamp());
    assertEquals(4L, merged.getMaxTimestamp());

    KijiDataRequest.Column bazBotColumnRequest = merged.getColumn("baz", "bot");
    assertNotNull("Missing column from merged-in request", bazBotColumnRequest);

    KijiDataRequest symmetricMerged = second.merge(first);
    assertEquals("Merge must be symmetric", merged, symmetricMerged);
  }


@Test
  public void testInvalidColumnSpec() {
    // The user really wants 'builder.columns().add("family", "qualifier")'.
    // This will throw an exception.
    try {
      KijiDataRequest.builder().newColumnsDef().addFamily("family:qualifier");
      fail("An exception should have been thrown.");
    } catch (KijiInvalidNameException kine) {
      assertEquals(
          "Invalid family name: family:qualifier Name must match pattern: [a-zA-Z_][a-zA-Z0-9_]*",
          kine.getMessage());
    }
  }


@Test
  public void testSingleHostDefaultInstance() {
    final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost:1234/default/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost", uri.getZookeeperQuorum().get(0));
    assertEquals(1, uri.getZookeeperQuorum().size());
    assertEquals(1234, uri.getZookeeperClientPort());
    assertEquals("default", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


Construct a new KijiDataRequest based on the configuration specified in this builder and its associated column builders pAfter calling build you may not use the builder anymorep @return a new KijiDataRequest object containing the column requests associated with this KijiDataRequestBuilder     Entire families for which a definition has been recorded   Fullyqualified columns for which a definition has been recorded   Families of fullyqualified columns for which definitions have been recorded   Iterate over the ColumnsDefs in the order they were added mColumnsDef is a LinkedHashSet

b'/**\n   * Construct a new KijiDataRequest based on the configuration specified in this builder\n   * and its associated column builders.\n   *\n   *
After calling build(), you may not use the builder anymore.
\n   *\n   * @return a new KijiDataRequest object containing the column requests associated\n   *     with this KijiDataRequestBuilder.\n   */'public KijiDataRequest build() {
    checkNotBuilt();
    mIsBuilt = true;

    // Entire families for which a definition has been recorded:
    final Set<String> families = Sets.newHashSet();

    // Fully-qualified columns for which a definition has been recorded:
    final Set<KijiColumnName> columns = Sets.newHashSet();

    // Families of fully-qualified columns for which definitions have been recorded:
    final Set<String> familiesOfColumns = Sets.newHashSet();

    final List<KijiDataRequest.Column> requestedColumns = Lists.newArrayList();
    // Iterate over the ColumnsDefs in the order they were added (mColumnsDef is a LinkedHashSet).
    for (ColumnsDef columnsDef : mColumnsDefs) {
      for (KijiDataRequest.Column column : columnsDef.buildColumns()) {
        if (column.getQualifier() == null) {
          final boolean isNotDuplicate = families.add(column.getFamily());
          Preconditions.checkState(isNotDuplicate,
              "Duplicate definition for family '%s'.", column.getFamily());

          Preconditions.checkState(!familiesOfColumns.contains(column.getFamily()),
              "KijiDataRequest may not simultaneously contain definitions for family '%s' "
              + "and definitions for fully qualified columns in family '%s'.",
              column.getFamily(), column.getFamily());

        } else {
          final boolean isNotDuplicate = columns.add(column.getColumnName());
          Preconditions.checkState(isNotDuplicate, "Duplicate definition for column '%s'.", column);

          Preconditions.checkState(!families.contains(column.getFamily()),
              "KijiDataRequest may not simultaneously contain definitions for family '%s' "
              + "and definitions for fully qualified columns '%s'.",
              column.getFamily(), column.getColumnName());
          familiesOfColumns.add(column.getFamily());
        }
        requestedColumns.add(column);
      }
    }
    return new KijiDataRequest(requestedColumns, mMinTimestamp, mMaxTimestamp);
  }

@Test
  public void testBuild() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    builder.newColumnsDef().add("info", "foo");
    KijiDataRequest request = builder.build();

    // We should be able to use KijiDataRequest's create() method to similar effect.
    KijiDataRequest request2 = KijiDataRequest.create("info", "foo");
    assertEquals("Constructions methods make different requests", request, request2);
    assertTrue("Builder doesn't build a new object", request != request2);

    assertNotNull("Missing info:foo!", request.getColumn("info", "foo"));
    assertNull("Got spurious info:missing", request.getColumn("info", "missing"));
    assertNull("Got spurious info: family", request.getColumn("info", null));
  }


('/**\\n   * Return a builder for columns associated with this KijiDataRequestBuilder.\\n   *\\n   *
Creates an object that allows you to specify a set of related columns attached\\n   * to the same KijiDataRequest that all share the same retrieval properties, like\\n   * the number of max versions.
\\n   *\\n   * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\\n   *     data request builder.\\n   */', '')

b'/**\n   * Return a builder for columns associated with this KijiDataRequestBuilder.\n   *\n   *
Creates an object that allows you to specify a set of related columns attached\n   * to the same KijiDataRequest that all share the same retrieval properties, like\n   * the number of max versions.
\n   *\n   * @return a new KijiDataRequestBuilder.ColumnsDef builder object associated with this\n   *     data request builder.\n   */'public ColumnsDef newColumnsDef() {
    checkNotBuilt();
    final ColumnsDef c = new ColumnsDef();
    mColumnsDefs.add(c);
    return c;
  }

@Test
  public void testNoRedundantColumn() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().add("info", "foo").add("info", "foo");
      fail("Should have thrown exception for redundant add");
    } catch (IllegalArgumentException ise) {
      assertEquals("Duplicate request for column 'info:foo'.", ise.getMessage());
    }
  }


@Test
  public void testNoNegativeMaxVer() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().withMaxVersions(-5).addFamily("info");
      fail("An exception should have been thrown.");
    } catch (IllegalArgumentException iae) {
      assertEquals("Maximum number of versions must be strictly positive, but got: -5",
          iae.getMessage());
    }
  }


@Test
  public void testNoNegativePageSize() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().withPageSize(-5).addFamily("info");
      fail("An exception should have been thrown.");
    } catch (IllegalArgumentException iae) {
      assertEquals("Page size must be 0 (disabled) or positive, but got: null",
          iae.getMessage());
    }
  }


@Test
  public void testNoZeroMaxVersions() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().withMaxVersions(0).addFamily("info");
      fail("An exception should have been thrown.");
    } catch (IllegalArgumentException iae) {
      assertEquals("Maximum number of versions must be strictly positive, but got: 0",
          iae.getMessage());
    }
  }


('/**\\n   * Construct a new KijiDataRequest based on the configuration specified in this builder\\n   * and its associated column builders.\\n   *\\n   *
After calling build(), you may not use the builder anymore.
\\n   *\\n   * @return a new KijiDataRequest object containing the column requests associated\\n   *     with this KijiDataRequestBuilder.\\n   */', '')

('', '// Entire families for which a definition has been recorded:\n')

('', '// Fully-qualified columns for which a definition has been recorded:\n')

('', '// Families of fully-qualified columns for which definitions have been recorded:\n')

('', '// Iterate over the ColumnsDefs in the order they were added (mColumnsDef is a LinkedHashSet).\n')

@Test
  public void testEmptyOk() {
    assertNotNull(KijiDataRequest.builder().build());
  }


@Test
  public void testNoSettingMaxVerTwice() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().withMaxVersions(2).withMaxVersions(3).addFamily("info");
      fail("An exception should have been thrown.");
    } catch (IllegalStateException ise) {
      assertEquals("Cannot set max versions to 3, max versions already set to 2.",
          ise.getMessage());
    }
  }


@Test
  public void testNoSettingPageSizeTwice() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().withPageSize(2).withPageSize(3).addFamily("info");
      fail("An exception should have been thrown.");
    } catch (IllegalStateException ise) {
      assertEquals("Cannot set page size to 3, page size already set to 2.",
          ise.getMessage());
    }
  }


('/**\\n   * Sets the time range of cells to return: [minTimestamp,\\n   * maxTimestamp).\\n   *\\n   * @param minTimestamp Request cells with a timestamp at least minTimestamp.\\n   * @param maxTimestamp Request cells with a timestamp less than maxTimestamp.\\n   * @return This data request builder instance.\\n   */', '')

b'/**\n   * Sets the time range of cells to return: [minTimestamp,\n   * maxTimestamp).\n   *\n   * @param minTimestamp Request cells with a timestamp at least minTimestamp.\n   * @param maxTimestamp Request cells with a timestamp less than maxTimestamp.\n   * @return This data request builder instance.\n   */'public KijiDataRequestBuilder withTimeRange(long minTimestamp, long maxTimestamp) {
    checkNotBuilt();
    Preconditions.checkArgument(minTimestamp >= 0,
        "minTimestamp must be positive or zero, but got: %d", minTimestamp);
    Preconditions.checkArgument(maxTimestamp > minTimestamp,
        "Invalid time range [%d--%d]", minTimestamp, maxTimestamp);
    Preconditions.checkState(!mIsTimeRangeSet,
        "Cannot set time range more than once.");

    mIsTimeRangeSet = true;
    mMinTimestamp = minTimestamp;
    mMaxTimestamp = maxTimestamp;
    return this;
  }

@Test
  public void testNoSettingTimeRangeTwice() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.withTimeRange(2, 3).withTimeRange(6, 9);
      fail("An exception should have been thrown.");
    } catch (IllegalStateException ise) {
      assertEquals("Cannot set time range more than once.", ise.getMessage());
    }
  }


@Test
  public void testNoPropertiesAfterAdd() {
    KijiDataRequestBuilder builder = KijiDataRequest.builder();
    try {
      builder.newColumnsDef().add("info", "foo").withMaxVersions(5);
      fail("An exception should have been thrown.");
    } catch (IllegalStateException ise) {
      assertEquals(
          "Properties of the columns builder cannot be changed once columns are assigned to it.",
          ise.getMessage());
    }
  }


@Test
  public void testSingleHostDefaultPort() {
    final KijiURI uri = KijiURI.newBuilder("kiji-hbase://zkhost/instance/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals(1, uri.getZookeeperQuorum().size());
    assertEquals("zkhost", uri.getZookeeperQuorum().get(0));
    assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort());
    assertEquals("instance", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


Validates a data request against this validators table layout @param dataRequest The KijiDataRequest to validate @throws KijiDataRequestException If the data request is invalid

b"/**\n   * Validates a data request against this validator's table layout.\n   *\n   * @param dataRequest The KijiDataRequest to validate.\n   * @throws KijiDataRequestException If the data request is invalid.\n   */"public void validate(KijiDataRequest dataRequest) {
    for (KijiDataRequest.Column column : dataRequest.getColumns()) {
      final String qualifier = column.getQualifier();
      final KijiTableLayout.LocalityGroupLayout.FamilyLayout fLayout =
          mTableLayout.getFamilyMap().get(column.getFamily());

      if (null == fLayout) {
        throw new KijiDataRequestException(String.format("Table '%s' has no family named '%s'.",
            mTableLayout.getName(), column.getFamily()));
      }

      if (fLayout.isGroupType() && (null != column.getQualifier())) {
        if (!fLayout.getColumnMap().containsKey(qualifier)) {
          throw new KijiDataRequestException(String.format("Table '%s' has no column '%s'.",
              mTableLayout.getName(), column.getName()));
        }
      }
    }
  }

@Test
  public void testValidate() throws InvalidLayoutException {
    KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3);
    builder.newColumnsDef().withMaxVersions(1).add("info", "name");
    KijiDataRequest request = builder.build();

    mValidator.validate(request);
  }


['("/**\\\\n   * Validates a data request against this validator\'s table layout.\\\\n   *\\\\n   * @param dataRequest The KijiDataRequest to validate.\\\\n   * @throws KijiDataRequestException If the data request is invalid.\\\\n   */", \'\')']

@Test
  public void testValidateNoSuchFamily() throws InvalidLayoutException {
    KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3);
    builder.newColumnsDef().withMaxVersions(1).add("blahblah", "name");
    KijiDataRequest request = builder.build();

    try {
      mValidator.validate(request);
    } catch (KijiDataRequestException kdre) {
      assertEquals("Table 'user' has no family named 'blahblah'.", kdre.getMessage());
    }
  }


@Test
  public void testValidateNoSuchColumn() throws InvalidLayoutException {
    KijiDataRequestBuilder builder = KijiDataRequest.builder().withTimeRange(2, 3);
    builder.newColumnsDef().withMaxVersions(1)
        .add("info", "name")
        .add("info", "blahblah");
    KijiDataRequest request = builder.build();

    try {
      mValidator.validate(request);
    } catch (KijiDataRequestException kdre) {
      assertEquals("Table 'user' has no column 'info:blahblah'.", kdre.getMessage());
    }
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public boolean equals(Object obj) {
    if (obj == null) {
      return false;
    }
    if (!getClass().equals(obj.getClass())) {
      return false;
    }
    final KijiRowKeyComponents krkc = (KijiRowKeyComponents)obj;

    return Arrays.deepEquals(mComponents, krkc.mComponents);
  }

@Test
  public void testEquals() throws Exception {
    KijiRowKeyComponents krkc1 = KijiRowKeyComponents.fromComponents(
        "jennyanydots",
        1,
        null,
        null);
    KijiRowKeyComponents krkc2 = KijiRowKeyComponents.fromComponents(
        "jennyanydots",
        1,
        null,
        null);
    KijiRowKeyComponents krkc3 = KijiRowKeyComponents.fromComponents(
        "jennyanydots",
        1,
        null);
    assertFalse(krkc1 == krkc2);
    assertEquals(krkc1, krkc2);
    assertFalse(krkc1.equals(krkc3));

    // byte[] use a different code path.
    byte[] bytes1 = new byte[]{47};
    byte[] bytes2 = new byte[]{47};
    assertFalse(bytes1.equals(bytes2));
    KijiRowKeyComponents krkc4 = KijiRowKeyComponents.fromComponents(bytes1);
    KijiRowKeyComponents krkc5 = KijiRowKeyComponents.fromComponents(bytes2);
    assertEquals(krkc4, krkc5);
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public int hashCode() {
    return Arrays.deepHashCode(mComponents);
  }

@Test
  public void testHashCode() throws Exception {
    byte[] bytes1 = new byte[]{47};
    byte[] bytes2 = new byte[]{47};
    assertFalse(bytes1.equals(bytes2));
    KijiRowKeyComponents krkc1 = KijiRowKeyComponents.fromComponents(bytes1);
    KijiRowKeyComponents krkc2 = KijiRowKeyComponents.fromComponents(bytes2);
    assertEquals(krkc1.hashCode(), krkc2.hashCode());
  }


["('/**\\\\n   * Creates a KijiRowKeyComponents from components.\\\\n   *\\\\n   * @param components the components of the row key.\\\\n   * @return a KijiRowKeyComponents\\\\n   */', '')", "('', '// Some of these checks will be redundant when the KijiRowKeyComponents is converted\\n')", "('', '// into an EntityId, but putting them here helps the user see them at the time of creation.\\n')", "('', '// We need to make a deep copy of the byte[] to ensure that a later mutation to the original\\n')", '(\'\', "// byte[] doesn\'t confuse hash codes, etc.\\n")', "('', '// Pass in a copy rather than the actual array, just in case the user called us with an\\n')", "('', '// Object[], which would make components mutable.\\n')"]

b'/**\n   * Creates a KijiRowKeyComponents from components.\n   *\n   * @param components the components of the row key.\n   * @return a KijiRowKeyComponents\n   */'public static KijiRowKeyComponents fromComponents(Object... components) {
    Preconditions.checkNotNull(components);
    Preconditions.checkArgument(components.length > 0);
    Preconditions.checkNotNull(components[0], "First component cannot be null.");

    // Some of these checks will be redundant when the KijiRowKeyComponents is converted
    // into an EntityId, but putting them here helps the user see them at the time of creation.
    if (components[0] instanceof byte[]) {
      Preconditions.checkArgument(components.length == 1, "byte[] only valid as sole component.");
      // We need to make a deep copy of the byte[] to ensure that a later mutation to the original
      // byte[] doesn't confuse hash codes, etc.
      byte[] original = (byte[])components[0];
      return new KijiRowKeyComponents(new Object[]{Arrays.copyOf(original, original.length)});
    } else {
      boolean seenNull = false;
      for (int i = 0; i < components.length; i++) {
        if (seenNull) {
          Preconditions.checkArgument(
              components[i] == null,
              "Kiji Row Keys cannot contain have a non-null component after a null component");
        } else {
          Object part = components[i];
          if (part == null) {
            seenNull = true;
          } else {
            Preconditions.checkArgument(
                (part instanceof String) || (part instanceof Integer) || (part instanceof Long),
                "Components must be of type String, Integer, or Long.");
          }
        }
      }
    }

    // Pass in a copy rather than the actual array, just in case the user called us with an
    // Object[], which would make components mutable.
    return new KijiRowKeyComponents(Arrays.copyOf(components, components.length));
  }

@Test
  public void testFormattedCompare() {
    List<KijiRowKeyComponents> sorted = ImmutableList.of(
        KijiRowKeyComponents.fromComponents("a", null, null),
        KijiRowKeyComponents.fromComponents("a", 123, 456L),
        KijiRowKeyComponents.fromComponents("a", 456, null));

    List<KijiRowKeyComponents> shuffled = Lists.newArrayList(sorted);
    Collections.shuffle(shuffled);
    Collections.sort(shuffled);

    Assert.assertEquals(sorted, shuffled);
  }


@Test
  public void testRawCompare() {
    final List<KijiRowKeyComponents> sorted = ImmutableList.of(
        KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x00, 0x00}}),
        KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x00, 0x01}}),
        KijiRowKeyComponents.fromComponents(new Object[] {new byte[] {0x01, 0x00}}));

    List<KijiRowKeyComponents> shuffled = Lists.newArrayList(sorted);
    Collections.shuffle(shuffled);
    Collections.sort(shuffled);

    Assert.assertEquals(sorted, shuffled);
  }


Resolution in number of bytes when generating evenly spaced HBase row keys @return the number of bytes required by an md5 hash

b'/**\n   * Resolution (in number of bytes) when generating evenly spaced HBase row keys.\n   *\n   * @return the number of bytes required by an md5 hash.\n   */'@Deprecated
  public int getRowKeyResolution() {
    return 16;
  }

@Test
  public void testGetRowKeyResolution() throws IOException {
    assertEquals(2, KijiRowKeySplitter
        .getRowKeyResolution(KijiTableLayouts.getLayout(KijiTableLayouts.FORMATTED_RKF)));
    assertEquals(16, KijiRowKeySplitter
        .getRowKeyResolution(KijiTableLayouts.getLayout(KijiTableLayouts.FULL_FEATURED)));
  }


['(\'/**\\\\n   * Gets a builder configured with default Kiji URI fields for an HBase cluster.\\\\n   *\\\\n   * More precisely, the following defaults are initialized:\\\\n   *
\\\\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\\\\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n   *       (<tt>"default"</tt>).
\\\\n   *
The table name and column names are explicitly left unset.
\\\\n   *
\\\\n   *\\\\n   * @return A builder configured with defaults for an HBase cluster.\\\\n   */\', \'\')']

b'/**\n   * Gets a builder configured with default Kiji URI fields for an HBase cluster.\n   *\n   * More precisely, the following defaults are initialized:\n   *
\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n   *       (<tt>"default"</tt>).
\n   *
The table name and column names are explicitly left unset.
\n   *
\n   *\n   * @return A builder configured with defaults for an HBase cluster.\n   */'public static KijiURIBuilder newBuilder() {
    return new HBaseKijiURIBuilder();
  }

@Test
  public void testIllegalScheme() {
    try {
      KijiURI.newBuilder("kiji-foo:///");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertTrue(kurie.getMessage().contains("No parser available for"));
    }
  }


@Test
  public void testNoAuthority() {
    try {
      KijiURI.newBuilder("kiji:///");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertEquals("Invalid Kiji URI: 'kiji:///' : ZooKeeper ensemble missing.",
          kurie.getMessage());
    }
  }


['(\'/**\\\\n   * Gets a builder configured with default Kiji URI fields.\\\\n   *\\\\n   * More precisely, the following defaults are initialized:\\\\n   *
\\\\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\\\\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\\\\n   *       (<tt>"default"</tt>).
\\\\n   *
The table name and column names are explicitly left unset.
\\\\n   *
\\\\n   *\\\\n   * @return A builder configured with this Kiji URI.\\\\n   */\', \'\')']

b'/**\n   * Gets a builder configured with default Kiji URI fields.\n   *\n   * More precisely, the following defaults are initialized:\n   *
\n   *
The Zookeeper quorum and client port is taken from the Hadoop <tt>Configuration</tt>
\n   *
The Kiji instance name is set to <tt>KConstants.DEFAULT_INSTANCE_NAME</tt>\n   *       (<tt>"default"</tt>).
\n   *
The table name and column names are explicitly left unset.
\n   *
\n   *\n   * @return A builder configured with this Kiji URI.\n   */'public static HBaseKijiURIBuilder newBuilder() {
    return new HBaseKijiURIBuilder();
  }

@Test
  public void testMultipleHosts() {
    final KijiURI uri =
        KijiURI.newBuilder("kiji-hbase://(zkhost1,zkhost2):1234/instance/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost1", uri.getZookeeperQuorum().get(0));
    assertEquals("zkhost2", uri.getZookeeperQuorum().get(1));
    assertEquals(1234, uri.getZookeeperClientPort());
    assertEquals("instance", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


@Test
  public void testMultipleHostsNoParen() {
    try {
      KijiURI.newBuilder("kiji://zkhost1,zkhost2:1234/instance/table/col");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertEquals("Invalid Kiji URI: 'kiji://zkhost1,zkhost2:1234/instance/table/col' : Multiple "
          + "ZooKeeper hosts must be parenthesized.", kurie.getMessage());
    }
  }


@Test
  public void testMultipleHostsMultiplePorts() {
    try {
      KijiURI.newBuilder("kiji://zkhost1:1234,zkhost2:2345/instance/table/col");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertEquals("Invalid Kiji URI: 'kiji://zkhost1:1234,zkhost2:2345/instance/table/col' : "
          + "Invalid ZooKeeper ensemble cluster identifier.",
          kurie.getMessage());
    }
  }


@Test
  public void testExtraPath() {
    try {
      KijiURI.newBuilder("kiji://(zkhost1,zkhost2):1234/instance/table/col/extra");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertEquals("Invalid Kiji URI: 'kiji://(zkhost1,zkhost2):1234/instance/table/col/extra' : "
          + "Too many path segments.",
          kurie.getMessage());
    }
  }


@inheritDoc

b'/** {@inheritDoc} */'@Override
  public String toString() {
    return toString(false);
  }

@Test
  public void testToString() {
    String uri = "kiji://(zkhost1,zkhost2):1234/instance/table/col/";
    assertEquals(uri, KijiURI.newBuilder(uri).build().toString());
    uri = "kiji://zkhost1:1234/instance/table/col/";
    assertEquals(uri, KijiURI.newBuilder(uri).build().toString());
    uri = "kiji://zkhost:1234/instance/table/col1,col2/";
    assertEquals(uri, KijiURI.newBuilder(uri).build().toString());
    uri = "kiji://zkhost:1234/.unset/table/col/";
    assertEquals(uri, KijiURI.newBuilder(uri).build().toString());
  }


@Test
  public void testKijiURIBuilderFromInstance() {
    final KijiURI uri = KijiURI.newBuilder("kiji://zkhost:1234/.unset/table").build();
    KijiURI built = KijiURI.newBuilder(uri).build();
    assertEquals(uri, built);
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public void close() throws IOException {
    mQualifierPager.close();
  }

@Test
  public void testQualifiersIterator() throws IOException {
    final EntityId eid = mTable.getEntityId("me");

    final KijiDataRequest dataRequest = KijiDataRequest.builder()
        .addColumns(ColumnsDef.create()
            .withMaxVersions(HConstants.ALL_VERSIONS).withPageSize(1).addFamily("jobs"))
        .build();

    final KijiRowData row = mReader.get(eid, dataRequest);
    final MapFamilyQualifierIterator it = new MapFamilyQualifierIterator(row, "jobs", 3);
    try {
      final List<String> qualifiers = Lists.newArrayList((Iterator<String>) it);
      Assert.assertEquals(Lists.newArrayList("j0", "j1", "j2", "j3", "j4"), qualifiers);
    } finally {
      it.close();
    }
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public void close() throws IOException {
    mQualifierIterator.close();
    if (mVersionIterator != null) {
      mVersionIterator.close();
    }
  }

@Test
  public void testQualifiersIterator() throws IOException {
    final EntityId eid = mTable.getEntityId("me");

    final KijiDataRequest dataRequest = KijiDataRequest.builder()
        .addColumns(ColumnsDef.create()
            .withMaxVersions(HConstants.ALL_VERSIONS).withPageSize(1).addFamily("jobs"))
        .build();

    final KijiRowData row = mReader.get(eid, dataRequest);
    final MapFamilyVersionIterator<Utf8> it =
        new MapFamilyVersionIterator<Utf8>(row, "jobs", 3, 2);
    try {
      int ncells = 0;
      int ijob = 0;
      int timestamp = 5;
      for (Entry<Utf8> entry : it) {
        assertEquals(String.format("j%d", ijob), entry.getQualifier());
        assertEquals(timestamp, entry.getTimestamp());
        assertEquals(String.format("j%d-t%d", ijob, timestamp), entry.getValue().toString());
        timestamp -= 1;
        if (timestamp == 0) {
          timestamp = 5;
          ijob += 1;
        }
        ncells += 1;
      }
      assertEquals(NJOBS * NTIMESTAMPS, ncells);
    } finally {
      it.close();
    }
  }


Creates a raw entity ID @param rowKey KijiHBase row key both row keys are identical

b'/**\n   * Creates a raw entity ID.\n   *\n   * @param rowKey Kiji/HBase row key (both row keys are identical).\n   */'private RawEntityId(byte[] rowKey) {
    mBytes = Preconditions.checkNotNull(rowKey);
  }

@Test
  public void testRawEntityId() {
    final byte[] bytes = new byte[] {0x11, 0x22};
    final RawEntityId eid = RawEntityId.getEntityId(bytes);
    assertArrayEquals(bytes, (byte[])eid.getComponentByIndex(0));
    assertArrayEquals(bytes, eid.getHBaseRowKey());
    assertEquals(1, eid.getComponents().size());
    assertEquals(bytes, eid.getComponents().get(0));
  }


Loads the dictionary from a file @param filename The path to a file of words one per line @return The list of words from the file @throws IOException If there is an error reading the words from the file

b'/**\n   * Loads the dictionary from a file.\n   *\n   * @param filename The path to a file of words, one per line.\n   * @return The list of words from the file.\n   * @throws IOException If there is an error reading the words from the file.\n   */'public List<String> load(String filename) throws IOException {
    FileInputStream fileStream = new FileInputStream(filename);
    try {
      return load(fileStream);
    } finally {
      fileStream.close();
    }
  }

@Test
  public void testLoad() throws IOException {
    DictionaryLoader loader = new DictionaryLoader();
    List<String> dictionary = loader.load(getClass().getClassLoader().getResourceAsStream(
            "org/kiji/schema/tools/synth/dictionary.txt"));
    assertEquals(3, dictionary.size());
    assertEquals("apple", dictionary.get(0));
    assertEquals("banana", dictionary.get(1));
    assertEquals("carrot", dictionary.get(2));
  }


@Test
  public void testMultipleHostsDefaultPort() {
    final KijiURI uri =
        KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2/instance/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost1", uri.getZookeeperQuorum().get(0));
    assertEquals("zkhost2", uri.getZookeeperQuorum().get(1));
    assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort());
    assertEquals("instance", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


Construct an email address string @param username The part before the @ symbol @param domain The part after the @ symbol @return An email address ltusernamegt@ltdomaingt

b"/**\n   * Construct an email address string.\n   *\n   * @param username The part before the '@' symbol.\n   * @param domain The part after the '@' symbol.\n   * @return An email address (<username>@<domain>).\n   */"public static String formatEmail(String username, String domain) {
    return username + "@" + domain;
  }

@Test
  public void testFormatEmail() {
    assertEquals("a@b.com", EmailSynthesizer.formatEmail("a", "b.com"));
  }


('', '// Pick n words from the dictionary.\n')

@Override
  public String synthesize() {
    // Pick n words from the dictionary.
    List<String> grams = new ArrayList<String>(mN);
    for (int i = 0; i < mN; i++) {
      grams.add(mWordSynthesizer.synthesize());
    }
    return StringUtils.join(grams, " ");
  }

@Test
  public void testWordSynth() {
    WordSynthesizer wordSynthesizer = createStrictMock(WordSynthesizer.class);
    expect(wordSynthesizer.synthesize()).andReturn("a");
    expect(wordSynthesizer.synthesize()).andReturn("b");
    expect(wordSynthesizer.synthesize()).andReturn("c");
    expect(wordSynthesizer.synthesize()).andReturn("d");

    replay(wordSynthesizer);
    NGramSynthesizer synth = new NGramSynthesizer(wordSynthesizer, 2);
    assertEquals("a b", synth.synthesize());
    assertEquals("c d", synth.synthesize());
    verify(wordSynthesizer);
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public String getName() {
    return "create-table";
  }

@Test
  public void testCreateHashedTableWithNumRegions() throws Exception {
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST);
    final File layoutFile = getTempLayoutFile(layout);
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    assertEquals(BaseTool.SUCCESS, runTool(new CreateTableTool(),
      "--table=" + tableURI,
      "--layout=" + layoutFile,
      "--num-regions=" + 2,
      "--debug"
    ));
    assertEquals(2, mToolOutputLines.length);
    assertTrue(mToolOutputLines[0].startsWith("Parsing table layout: "));
    assertTrue(mToolOutputLines[1].startsWith("Creating Kiji table"));
  }


('/** {@inheritDoc} */', '')

@Test
  public void testCreateUnhashedTableWithSplitKeys() throws Exception {
    final KijiTableLayout layout =
        KijiTableLayout.newLayout(KijiTableLayouts.getFooUnhashedTestLayout());
    final File layoutFile = getTempLayoutFile(layout);
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    final String splitKeyFile =
        getClass().getClassLoader().getResource(REGION_SPLIT_KEY_FILE).getPath();

    assertEquals(BaseTool.SUCCESS, runTool(new CreateTableTool(),
      "--table=" + tableURI,
      "--layout=" + layoutFile,
      "--split-key-file=file://" + splitKeyFile,
      "--debug"
    ));
    assertEquals(2, mToolOutputLines.length);
    assertTrue(mToolOutputLines[0].startsWith("Parsing table layout: "));
    assertTrue(mToolOutputLines[1].startsWith("Creating Kiji table"));

  }


('/** {@inheritDoc} */', '')

@Test
  public void testCreateHashedTableWithSplitKeys() throws Exception {
    final KijiTableLayout layout =
        KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST_LEGACY);
    final File layoutFile = getTempLayoutFile(layout);
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    final String splitKeyFile =
        getClass().getClassLoader().getResource(REGION_SPLIT_KEY_FILE).getPath();

    try {
      runTool(new CreateTableTool(),
        "--table=" + tableURI,
        "--layout=" + layoutFile,
        "--split-key-file=file://" + splitKeyFile
      );
      fail("Should throw IllegalArgumentException");
    } catch (IllegalArgumentException iae) {
      assertTrue(iae.getMessage().startsWith(
          "Row key hashing is enabled for the table. Use --num-regions=N instead."));
    }
  }


('/** {@inheritDoc} */', '')

@Test
  public void testCreateUnhashedTableWithNumRegions() throws Exception {
    final KijiTableLayout layout =
        KijiTableLayout.newLayout(KijiTableLayouts.getFooUnhashedTestLayout());
    final File layoutFile = getTempLayoutFile(layout);
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    try {
      runTool(new CreateTableTool(),
        "--table=" + tableURI,
        "--layout=" + layoutFile,
        "--num-regions=4"
      );
      fail("Should throw InvalidLayoutException");
    } catch (IllegalArgumentException iae) {
      assertTrue(iae.getMessage().startsWith(
          "May not use numRegions > 1 if row key hashing is disabled in the layout"));
    }
  }


('/** {@inheritDoc} */', '')

@Test
  public void testCreateTableWithInvalidSchemaClassInLayout() throws Exception {
    final TableLayoutDesc layout = KijiTableLayouts.getLayout(KijiTableLayouts.INVALID_SCHEMA);
    final File layoutFile = getTempLayoutFile(layout);
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    try {
      runTool(new CreateTableTool(),
        "--table=" + tableURI,
        "--layout=" + layoutFile
      );
      fail("Should throw InvalidLayoutException");
    } catch (InvalidLayoutException ile) {
      assertTrue(ile.getMessage(), ile.getMessage().startsWith(
          "Invalid cell specification with Avro class type has invalid class name: '\"string\"'."));
    }
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public String getName() {
    return "get";
  }

@Test
  public void testGetFromTable() throws Exception {
    final Kiji kiji = getKiji();
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE);
    kiji.createTable(layout.getName(), layout);

    new InstanceBuilder(kiji)
        .withTable(layout.getName(), layout)
            .withRow("hashed")
                .withFamily("family").withQualifier("column").withValue(314L, "value")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(),
          "--entity-id=hashed"));
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
  }


('/** {@inheritDoc} */', '')

@Test
  public void testGetFromTableMore() throws Exception {
    final Kiji kiji = getKiji();
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST);
    final long timestamp = 10L;
    new InstanceBuilder(kiji)
        .withTable(layout.getName(), layout)
            .withRow("gwu@usermail.example.com")
                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "gwu@usermail.example.com")
                    .withQualifier("name").withValue(timestamp, "Garrett Wu")
            .withRow("aaron@usermail.example.com")
                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "aaron@usermail.example.com")
                    .withQualifier("name").withValue(timestamp, "Aaron Kimball")
            .withRow("christophe@usermail.example.com")
                .withFamily("info")
                    .withQualifier("email")
                        .withValue(timestamp, "christophe@usermail.example.com")
                    .withQualifier("name").withValue(timestamp, "Christophe Bisciglia")
            .withRow("kiyan@usermail.example.com")
                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "kiyan@usermail.example.com")
                    .withQualifier("name").withValue(timestamp, "Kiyan Ahmadizadeh")
            .withRow("john.doe@gmail.com")
                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "john.doe@gmail.com")
                    .withQualifier("name").withValue(timestamp, "John Doe")
            .withRow("jane.doe@gmail.com")
                .withFamily("info")
                    .withQualifier("email").withValue(timestamp, "jane.doe@gmail.com")
                    .withQualifier("name").withValue(timestamp, "Jane Doe")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(),
          "--entity-id=[\"jane.doe@gmail.com\"]"));
      assertEquals(5, mToolOutputLines.length);
      EntityId eid = EntityIdFactory.getFactory(layout).getEntityId("gwu@usermail.example.com");
      String hbaseRowKey = Hex.encodeHexString(eid.getHBaseRowKey());
      assertEquals(BaseTool.SUCCESS, runTool(new GetTool(),
          table.getURI() + "info:name",
              "--entity-id=hbase=hex:" + hbaseRowKey
          ));
      assertEquals(3, mToolOutputLines.length);
      // TODO: Validate GetTool output
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
  }


@Test
  public void testMultipleHostsDefaultPortDefaultInstance() {
    final KijiURI uri =
        KijiURI.newBuilder("kiji-hbase://zkhost1,zkhost2/default/table/col").build();
    assertEquals("kiji-hbase", uri.getScheme());
    assertEquals("zkhost1", uri.getZookeeperQuorum().get(0));
    assertEquals("zkhost2", uri.getZookeeperQuorum().get(1));
    assertEquals(KijiURI.DEFAULT_ZOOKEEPER_CLIENT_PORT, uri.getZookeeperClientPort());
    assertEquals("default", uri.getInstance());
    assertEquals("table", uri.getTable());
    assertEquals("col", uri.getColumns().get(0).getName());
  }


('/** {@inheritDoc} */', '')

@Test
  public void testGetFormattedRKF() throws Exception {
    final Kiji kiji = getKiji();
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.FORMATTED_RKF);
    new InstanceBuilder(kiji)
        .withTable(layout.getName(), layout)
            .withRow("NYC", "Technology", "widget", 1, 2)
                .withFamily("family").withQualifier("column")
                    .withValue("Candaules")
            .withRow("NYC", "Technology", "widget", 1, 20)
                .withFamily("family").withQualifier("column")
                    .withValue("Croesus")
            .withRow("NYC", "Technology", "thingie", 2)
                .withFamily("family").withQualifier("column")
                    .withValue("Gyges")
            .withRow("DC", "Technology", "stuff", 123)
                .withFamily("family").withQualifier("column")
                    .withValue("Glaucon")
            .withRow("DC", "Technology", "stuff", 124, 1)
                .withFamily("family").withQualifier("column")
                    .withValue("Lydia")
        .build();

    final KijiTable table = kiji.openTable(layout.getName());
    try {
      assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(),
          "--entity-id=['NYC','Technology','widget',1,2]"
          ));
      assertEquals(3, mToolOutputLines.length);
      assertEquals(BaseTool.SUCCESS, runTool(new GetTool(), table.getURI().toString(),
          "--entity-id=['NYC','Technology','thingie',2,null]"
          ));
      assertEquals(3, mToolOutputLines.length);
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
  }


['("/**\\\\n   * Return the tool specified by the \'toolName\' argument.\\\\n   * (package-protected for use by the HelpTool, and for testing.)\\\\n   *\\\\n   * @param toolName the name of the tool to instantiate.\\\\n   * @return the KijiTool that provides for that name, or null if none does.\\\\n   */", \'\')', "('', '// Iterate over available tools, searching for the one with\\n')", "('', '// the same name as the supplied tool name argument.\\n')"]

b"/**\n   * Return the tool specified by the 'toolName' argument.\n   * (package-protected for use by the HelpTool, and for testing.)\n   *\n   * @param toolName the name of the tool to instantiate.\n   * @return the KijiTool that provides for that name, or null if none does.\n   */"KijiTool getToolForName(String toolName) {
    KijiTool tool = null;

    // Iterate over available tools, searching for the one with
    // the same name as the supplied tool name argument.
    for (KijiTool candidate : Lookups.get(KijiTool.class)) {
      if (toolName.equals(candidate.getName())) {
        tool = candidate;
        break;
      }
    }

    return tool;
  }

@Test
  public void testGetToolName() {
    KijiTool tool = new KijiToolLauncher().getToolForName("ls");
    assertNotNull("Got a null tool back, should have gotten a real one.", tool);
    assertEquals("Tool does not advertise it responds to 'ls'.", "ls", tool.getName());
    assertTrue("Didn't get the LsTool we expected!", tool instanceof LsTool);
  }


@Test
  public void testGetMissingTool() {
    KijiTool tool = new KijiToolLauncher().getToolForName("this-tool/can't1`exist");
    assertNull(tool);
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public String getName() {
    return "layout";
  }

@Test
  public void testChangeRowKeyHashing() throws Exception {
    final KijiTableLayout layout =
            KijiTableLayouts.getTableLayout(KijiTableLayouts.FOO_TEST_LEGACY);
    getKiji().createTable(layout.getDesc());

    final File newLayoutFile = getTempLayoutFile(KijiTableLayouts.getFooChangeHashingTestLayout());
    final KijiURI tableURI =
        KijiURI.newBuilder(getKiji().getURI()).withTableName(layout.getName()).build();

    try {
      runTool(new LayoutTool(),
        "--table=" + tableURI,
        "--do=set",
        "--layout=" + newLayoutFile
        );
      fail("Should throw InvalidLayoutException");
    } catch (InvalidLayoutException ile) {
      assertTrue(ile.getMessage().startsWith(
          "Invalid layout update from reference row keys format"));
    }
  }


Parses a table name for a kiji instance name @param kijiTableName The table name to parse @return instance name or null if none found

b'/**\n   * Parses a table name for a kiji instance name.\n   *\n   * @param kijiTableName The table name to parse\n   * @return instance name (or null if none found)\n   */'protected static String parseInstanceName(String kijiTableName) {
    final String[] parts = StringUtils.split(kijiTableName, '\u0000', '.');
    if (parts.length < 3 || !KijiURI.KIJI_SCHEME.equals(parts[0])) {
      return null;
    }
    return parts[1];
  }

@Test
  public void testParseInstanceName() {
    assertEquals("default", LsTool.parseInstanceName("kiji.default.meta"));
    assertEquals("default", LsTool.parseInstanceName("kiji.default.schema_hash"));
    assertEquals("default", LsTool.parseInstanceName("kiji.default.schema_id"));
    assertEquals("default", LsTool.parseInstanceName("kiji.default.system"));
    assertEquals("default", LsTool.parseInstanceName("kiji.default.table.job_history"));
  }


('/**\\n   * Parses a table name for a kiji instance name.\\n   *\\n   * @param kijiTableName The table name to parse\\n   * @return instance name (or null if none found)\\n   */', '')

@Test
  public void testParseNonKijiTable() {
    String tableName = "hbase_table";
    assertEquals(null, LsTool.parseInstanceName(tableName));
  }


@Test
  public void testParseMalformedKijiTableName() {
    assertEquals(null, LsTool.parseInstanceName("kiji.default"));
    assertEquals(null, LsTool.parseInstanceName("kiji."));
    assertEquals(null, LsTool.parseInstanceName("kiji"));
  }


Lists all kiji instances @param hbaseURI URI of the HBase instance to list the content of @return A program exit code zero on success @throws IOException If there is an error

b'/**\n   * Lists all kiji instances.\n   *\n   * @param hbaseURI URI of the HBase instance to list the content of.\n   * @return A program exit code (zero on success).\n   * @throws IOException If there is an error.\n   */'private int listInstances(KijiURI hbaseURI) throws IOException {
    for (String instanceName : getInstanceNames(hbaseURI)) {
      getPrintStream().println(KijiURI.newBuilder(hbaseURI).withInstanceName(instanceName).build());
    }
    return SUCCESS;
  }

@Test
  public void testListInstances() throws Exception {
    final Kiji kiji = getKiji();
    final KijiURI hbaseURI = KijiURI.newBuilder(kiji.getURI()).withInstanceName(null).build();

    final LsTool ls = new LsTool();
    assertEquals(BaseTool.SUCCESS, runTool(ls, hbaseURI.toString()));
    final Set<String> instances = Sets.newHashSet(mToolOutputLines);
    assertTrue(instances.contains(kiji.getURI().toString()));
  }


Lists all the tables in a kiji instance @param kiji Kiji instance to list the tables of @return A program exit code zero on success @throws IOException If there is an error

b'/**\n   * Lists all the tables in a kiji instance.\n   *\n   * @param kiji Kiji instance to list the tables of.\n   * @return A program exit code (zero on success).\n   * @throws IOException If there is an error.\n   */'private int listTables(Kiji kiji) throws IOException {
    for (String name : kiji.getTableNames()) {
      getPrintStream().println(kiji.getURI() + name);
    }
    return SUCCESS;
  }

@Test
  public void testListTables() throws Exception {
    final Kiji kiji = getKiji();

    assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString()));
    assertEquals(1, mToolOutputLines.length);

    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE);
    kiji.createTable(layout.getDesc());

    assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), kiji.getURI().toString()));
    assertEquals(1, mToolOutputLines.length);
    assertEquals(kiji.getURI() + layout.getName(), mToolOutputLines[0]);
  }


('/** {@inheritDoc} */', '')

b'/** {@inheritDoc} */'@Override
  public String getName() {
    return "ls";
  }

@Test
  public void testTableColumns() throws Exception {
    final Kiji kiji = getKiji();
    final KijiTableLayout layout = KijiTableLayouts.getTableLayout(KijiTableLayouts.SIMPLE);
    kiji.createTable(layout.getDesc());
    final KijiTable table = kiji.openTable(layout.getName());
    try {
      // Table is empty:
      assertEquals(BaseTool.SUCCESS, runTool(new LsTool(), table.getURI().toString()));
      assertEquals(1, mToolOutputLines.length);
      assertTrue(mToolOutputLines[0].contains("family:column"));
    } finally {
      ResourceUtils.releaseOrLog(table);
    }
  }


@Test
  public void testIllegalScheme() {
    try {
      KijiURI.newBuilder("kiji-foo:///");
      fail("An exception should have been thrown.");
    } catch (KijiURIException kurie) {
      assertTrue(kurie.getMessage().contains("No parser available for"));
    }
  }