text:
package org.apache.gora.hbase.store;

import static org.apache.gora.hbase.util.HBaseByteInterface.fromBytes;
import static org.apache.gora.hbase.util.HBaseByteInterface.toBytes;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NavigableMap;
import java.util.Properties;
import java.util.Set;

import org.apache.avro.Schema;
import org.apache.avro.Schema.Field;
import org.apache.avro.Schema.Type;
import org.apache.avro.util.Utf8;
import org.apache.gora.hbase.query.HBaseGetResult;
import org.apache.gora.hbase.query.HBaseQuery;
import org.apache.gora.hbase.query.HBaseScannerResult;
import org.apache.gora.hbase.store.HBaseMapping.HBaseMappingBuilder;
import org.apache.gora.hbase.util.HBaseByteInterface;
import org.apache.gora.hbase.util.HBaseFilterUtil;
import org.apache.gora.persistency.impl.DirtyListWrapper;
import org.apache.gora.persistency.impl.DirtyMapWrapper;
import org.apache.gora.persistency.impl.PersistentBase;
import org.apache.gora.query.PartitionQuery;
import org.apache.gora.query.Query;
import org.apache.gora.query.impl.PartitionQueryImpl;
import org.apache.gora.store.DataStoreFactory;
import org.apache.gora.store.impl.DataStoreBase;
import org.apache.hadoop.conf.Configurable;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.HConstants;
import org.apache.hadoop.hbase.HTableDescriptor;
import org.apache.hadoop.hbase.client.Admin;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.Delete;
import org.apache.hadoop.hbase.client.Get;
import org.apache.hadoop.hbase.client.Put;
import org.apache.hadoop.hbase.client.Result;
import org.apache.hadoop.hbase.client.ResultScanner;
import org.apache.hadoop.hbase.client.Scan;
import org.apache.hadoop.hbase.util.Bytes;
import org.apache.hadoop.hbase.util.Pair;
import org.jdom.Document;
import org.jdom.Element;
import org.jdom.input.SAXBuilder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * DataStore for HBase. Thread safe.
 *
 */
public class HBaseStore<K, T extends PersistentBase> extends DataStoreBase<K, T>
implements Configurable {

  public static final Logger LOG = LoggerFactory.getLogger(HBaseStore.class);

  public static final String PARSE_MAPPING_FILE_KEY = "gora.hbase.mapping.file";

  public static final String DEFAULT_MAPPING_FILE = "gora-hbase-mapping.xml";

  private static final String SCANNER_CACHING_PROPERTIES_KEY = "scanner.caching" ;
  private static final int SCANNER_CACHING_PROPERTIES_DEFAULT = 0 ;

  private volatile Admin admin;

  private volatile HBaseTableConnection table;

  private final boolean autoCreateSchema = true;

  private volatile HBaseMapping mapping;

  private HBaseFilterUtil<K, T> filterUtil;

  private int scannerCaching = SCANNER_CACHING_PROPERTIES_DEFAULT ;

  /**
   * Default constructor
   */
  public HBaseStore() {//Empty Constrctor
  }

  /**
   * Initialize the data store by reading the credentials, setting the client's properties up and
   * reading the mapping file. Initialize is called when then the call to
   * {@link org.apache.gora.store.DataStoreFactory#createDataStore} is made.
   *
   * @param keyClass
   * @param persistentClass
   * @param properties
   */
  @Override
  public void initialize(Class<K> keyClass, Class<T> persistentClass,
      Properties properties) {
    try {
      super.initialize(keyClass, persistentClass, properties);

      this.conf = HBaseConfiguration.create(getConf());
      admin = ConnectionFactory.createConnection(getConf()).getAdmin();
      mapping = readMapping(getConf().get(PARSE_MAPPING_FILE_KEY, DEFAULT_MAPPING_FILE));
      filterUtil = new HBaseFilterUtil<>(this.conf);
    } catch (FileNotFoundException ex) {
      LOG.error("{}  is not found, please check the file.", DEFAULT_MAPPING_FILE);
      throw new RuntimeException(ex);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    // Set scanner caching option
    try {
      this.setScannerCaching(
          Integer.valueOf(DataStoreFactory.findProperty(this.properties, this,
              SCANNER_CACHING_PROPERTIES_KEY,
              String.valueOf(SCANNER_CACHING_PROPERTIES_DEFAULT)))) ;
    }catch(Exception e){
      LOG.error("Can not load {} from gora.properties. Setting to default value: {}.", SCANNER_CACHING_PROPERTIES_KEY, SCANNER_CACHING_PROPERTIES_DEFAULT);
      this.setScannerCaching(SCANNER_CACHING_PROPERTIES_DEFAULT) ; // Default value if something is wrong
    }

    if(autoCreateSchema) {
      createSchema();
    }
    try{
      boolean autoflush = this.conf.getBoolean("hbase.client.autoflush.default", false);
      table = new HBaseTableConnection(getConf(), getSchemaName(), autoflush);
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
    }
    closeHBaseAdmin();
  }

  @Override
  public String getSchemaName() {
    //return the name of this table
    return mapping.getTableName();
  }

  public HBaseMapping getMapping() {
    return mapping;
  }

  @Override
  public void createSchema() {
    try{
      if(schemaExists()) {
        return;
      }
      HTableDescriptor tableDesc = mapping.getTable();

      admin.createTable(tableDesc);
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
    }
    closeHBaseAdmin();
  }

  @Override
  public void deleteSchema() {
    try{
      if(!schemaExists()) {
        return;
      }
      admin.disableTable(mapping.getTable().getTableName());
      admin.deleteTable(mapping.getTable().getTableName());
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
    }
    closeHBaseAdmin();
  }

  @Override
  public boolean schemaExists() {
    try{
      return admin.tableExists(mapping.getTable().getTableName());
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
      return false;
    }
  }

  @Override
  public T get(K key, String[] fields) {
    try{
      fields = getFieldsToQuery(fields);
      Get get = new Get(toBytes(key));
      addFields(get, fields);
      Result result = table.get(get);
      return newInstance(result, fields);
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
      return null;
    }
  }

  /**
   * {@inheritDoc} Serializes the Persistent data and saves in HBase. Topmost
   * fields of the record are persisted in "raw" format (not avro serialized).
   * This behavior happens in maps and arrays too.
   *
   * ["null","type"] type (a.k.a. optional field) is persisted like as if it is
   * ["type"], but the column get deleted if value==null (so value read after
   * will be null).
   *
   * @param persistent
   *          Record to be persisted in HBase
   */
  @Override
  public void put(K key, T persistent) {
    try {
      Schema schema = persistent.getSchema();
      byte[] keyRaw = toBytes(key);
      Put put = new Put(keyRaw);
      Delete delete = new Delete(keyRaw);
      List<Field> fields = schema.getFields();
      for (int i = 0; i < fields.size(); i++) {
        if (!persistent.isDirty(i)) {
          continue;
        }
        Field field = fields.get(i);
        Object o = persistent.get(i);
        HBaseColumn hcol = mapping.getColumn(field.name());
        if (hcol == null) {
          throw new RuntimeException("HBase mapping for field ["
              + persistent.getClass().getName() + "#" + field.name()
              + "] not found. Wrong gora-hbase-mapping.xml?");
        }
        addPutsAndDeletes(put, delete, o, field.schema().getType(),
            field.schema(), hcol, hcol.getQualifier());
      }

      if (delete.size() > 0) {
        table.delete(delete);
//        table.delete(delete);
//        table.delete(delete); // HBase sometimes does not delete arbitrarily
      }
      if (put.size() > 0) {
        table.put(put);
      }
    } catch (IOException ex2) {
      LOG.error(ex2.getMessage(), ex2);
    }
  }

  private void addPutsAndDeletes(Put put, Delete delete, Object o, Type type,
      Schema schema, HBaseColumn hcol, byte[] qualifier) throws IOException {
    switch (type) {
    case UNION:
      if (isNullable(schema) && o == null) {
        if (qualifier == null) {
//          delete.deleteFamily(hcol.getFamily());
          delete.addFamily(hcol.getFamily());
        } else {
//          delete.deleteColumn(hcol.getFamily(), qualifier);
          delete.addColumn(hcol.getFamily(), qualifier);
        }
      } else {
//        int index = GenericData.get().resolveUnion(schema, o);
        int index = getResolvedUnionIndex(schema);
        if (index > 1) {  //if more than 2 type in union, serialize directly for now
          byte[] serializedBytes = toBytes(o, schema);
          put.addColumn(hcol.getFamily(), qualifier, serializedBytes);
        } else {
          Schema resolvedSchema = schema.getTypes().get(index);
          addPutsAndDeletes(put, delete, o, resolvedSchema.getType(),
              resolvedSchema, hcol, qualifier);
        }
      }
      break;
    case MAP:
      // if it's a map that has been modified, then the content should be replaced by the new one
      // This is because we don't know if the content has changed or not.
      if (qualifier == null) {
        //delete.deleteFamily(hcol.getFamily());
        delete.addFamily(hcol.getFamily());
      } else {
        //delete.deleteColumn(hcol.getFamily(), qualifier);
        delete.addColumn(hcol.getFamily(), qualifier);
      }
      @SuppressWarnings({ "rawtypes", "unchecked" })
      Set<Entry> set = ((Map) o).entrySet();
      for (@SuppressWarnings("rawtypes") Entry entry : set) {
        byte[] qual = toBytes(entry.getKey());
        addPutsAndDeletes(put, delete, entry.getValue(), schema.getValueType()
            .getType(), schema.getValueType(), hcol, qual);
      }
      break;
    case ARRAY:
      List<?> array = (List<?>) o;
      int j = 0;
      for (Object item : array) {
        addPutsAndDeletes(put, delete, item, schema.getElementType().getType(),
            schema.getElementType(), hcol, Bytes.toBytes(j++));
      }
      break;
    default:
      byte[] serializedBytes = toBytes(o, schema);
      put.addColumn(hcol.getFamily(), qualifier, serializedBytes);
      break;
    }
  }

  private boolean isNullable(Schema unionSchema) {
    for (Schema innerSchema : unionSchema.getTypes()) {
      if (innerSchema.getType().equals(Schema.Type.NULL)) {
        return true;
      }
    }
    return false;
  }

  public void delete(T obj) {
    throw new RuntimeException("Not implemented yet");
  }

  /**
   * Deletes the object with the given key.
   * @return always true
   */
  @Override
  public boolean delete(K key) {
    try{
      table.delete(new Delete(toBytes(key)));
      //HBase does not return success information and executing a get for
      //success is a bit costly
      return true;
    } catch(IOException ex2){
      LOG.error(ex2.getMessage(), ex2);
      return false;
    }
  }

  @Override
  public long deleteByQuery(Query<K, T> query) {
    try {
      String[] fields = getFieldsToQuery(query.getFields());
      //find whether all fields are queried, which means that complete
      //rows will be deleted
      boolean isAllFields = Arrays.equals(fields, getFields());

      org.apache.gora.query.Result<K, T> result = null;
      result = query.execute();
      ArrayList<Delete> deletes = new ArrayList<>();
      while(result.next()) {
        Delete delete = new Delete(toBytes(result.getKey()));
        deletes.add(delete);
        if(!isAllFields) {
          addFields(delete, query);
        }
      }
      table.delete(deletes);
      return deletes.size();
    } catch (Exception ex) {
      LOG.error(ex.getMessage(), ex);
      return -1;
    }
  }

  @Override
  public void flush() {
    try{
      table.flushCommits();
    }catch(IOException ex){
      LOG.error(ex.getMessage(), ex);
    }
  }

  @Override
  public Query<K, T> newQuery() {
    return new HBaseQuery<>(this);
  }

  @Override
  public List<PartitionQuery<K, T>> getPartitions(Query<K, T> query)
      throws IOException {

    if (table == null) {
      throw new IOException("No table was provided.");
    }

    // taken from o.a.h.hbase.mapreduce.TableInputFormatBase
    Pair<byte[][], byte[][]> keys = table.getStartEndKeys();
    if (keys == null || keys.getFirst() == null ||
        keys.getFirst().length == 0) {
      throw new IOException("Expecting at least one region.");
    }

    List<PartitionQuery<K,T>> partitions = new ArrayList<>(keys.getFirst().length);
    for (int i = 0; i < keys.getFirst().length; i++) {
      String regionLocation = table.getRegionLocation(keys.getFirst()[i]).getHostname();
      byte[] startRow = query.getStartKey() != null ? toBytes(query.getStartKey())
          : HConstants.EMPTY_START_ROW;
      byte[] stopRow = query.getEndKey() != null ? toBytes(query.getEndKey())
          : HConstants.EMPTY_END_ROW;

      // determine if the given start an stop key fall into the region
      if ((startRow.length == 0 || keys.getSecond()[i].length == 0 ||
          Bytes.compareTo(startRow, keys.getSecond()[i]) < 0) &&
          (stopRow.length == 0 ||
              Bytes.compareTo(stopRow, keys.getFirst()[i]) > 0)) {

        byte[] splitStart = startRow.length == 0 ||
            Bytes.compareTo(keys.getFirst()[i], startRow) >= 0 ?
            keys.getFirst()[i] : startRow;

        byte[] splitStop = (stopRow.length == 0 ||
            Bytes.compareTo(keys.getSecond()[i], stopRow) <= 0) &&
            keys.getSecond()[i].length > 0 ? keys.getSecond()[i] : stopRow;

        K startKey = Arrays.equals(HConstants.EMPTY_START_ROW, splitStart) ?
            null : HBaseByteInterface.fromBytes(keyClass, splitStart);
        K endKey = Arrays.equals(HConstants.EMPTY_END_ROW, splitStop) ?
            null : HBaseByteInterface.fromBytes(keyClass, splitStop);

        PartitionQueryImpl<K, T> partition = new PartitionQueryImpl<>(
            query, startKey, endKey, regionLocation);
        partition.setConf(getConf());

        partitions.add(partition);
      }
    }
    return partitions;
  }

  @Override
  public org.apache.gora.query.Result<K, T> execute(Query<K, T> query){
    try{
      //check if query.fields is null
      query.setFields(getFieldsToQuery(query.getFields()));

      if(query.getStartKey() != null && query.getStartKey().equals(
          query.getEndKey())) {
        Get get = new Get(toBytes(query.getStartKey()));
        addFields(get, query.getFields());
        addTimeRange(get, query);
        Result result = table.get(get);
        return new HBaseGetResult<>(this, query, result);
      } else {
        ResultScanner scanner = createScanner(query);

        org.apache.gora.query.Result<K,T> result
            = new HBaseScannerResult<>(this, query, scanner);

        return result;
      }
    }catch(IOException ex){
      LOG.error(ex.getMessage(), ex);
      return null;
    }
  }

  public ResultScanner createScanner(Query<K, T> query) throws IOException {
    final Scan scan = new Scan();

    scan.setCaching(this.getScannerCaching()) ;

    if (query.getStartKey() != null) {
      scan.setStartRow(toBytes(query.getStartKey()));
    }
    if (query.getEndKey() != null) {
      scan.setStopRow(toBytes(query.getEndKey()));
    }
    addFields(scan, query);
    if (query.getFilter() != null) {
      boolean succeeded = filterUtil.setFilter(scan, query.getFilter(), this);
      if (succeeded) {
        // don't need local filter
        query.setLocalFilterEnabled(false);
      }
    }

    return table.getScanner(scan);
  }

  private void addFields(Get get, String[] fieldNames) {
    for (String f : fieldNames) {
      HBaseColumn col = mapping.getColumn(f);
      if (col == null) {
        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
            "Wrong gora-hbase-mapping.xml?");
      }
      Schema fieldSchema = fieldMap.get(f).schema();
      addFamilyOrColumn(get, col, fieldSchema);
    }
  }

  private void addFamilyOrColumn(Get get, HBaseColumn col, Schema fieldSchema) {
    switch (fieldSchema.getType()) {
    case UNION:
      int index = getResolvedUnionIndex(fieldSchema);
      Schema resolvedSchema = fieldSchema.getTypes().get(index);
      addFamilyOrColumn(get, col, resolvedSchema);
      break;
    case MAP:
    case ARRAY:
      get.addFamily(col.family);
      break;
    default:
      get.addColumn(col.family, col.qualifier);
      break;
    }
  }

  private void addFields(Scan scan, Query<K, T> query) throws IOException {
    String[] fields = query.getFields();
    for (String f : fields) {
      HBaseColumn col = mapping.getColumn(f);
      if (col == null) {
        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
            "Wrong gora-hbase-mapping.xml?");
      }
      Schema fieldSchema = fieldMap.get(f).schema();
      addFamilyOrColumn(scan, col, fieldSchema);
    }
  }

  private void addFamilyOrColumn(Scan scan, HBaseColumn col, Schema fieldSchema) {
    switch (fieldSchema.getType()) {
    case UNION:
      int index = getResolvedUnionIndex(fieldSchema);
      Schema resolvedSchema = fieldSchema.getTypes().get(index);
      addFamilyOrColumn(scan, col, resolvedSchema);
      break;
    case MAP:
    case ARRAY:
      scan.addFamily(col.family);
      break;
    default:
      scan.addColumn(col.family, col.qualifier);
      break;
    }
  }

  // TODO: HBase Get, Scan, Delete should extend some common interface with
  // addFamily, etc
  private void addFields(Delete delete, Query<K, T> query)    throws IOException {
    String[] fields = query.getFields();
    for (String f : fields) {
      HBaseColumn col = mapping.getColumn(f);
      if (col == null) {
        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
            "Wrong gora-hbase-mapping.xml?");
      }
      Schema fieldSchema = fieldMap.get(f).schema();
      addFamilyOrColumn(delete, col, fieldSchema);
    }
  }

  private void addFamilyOrColumn(Delete delete, HBaseColumn col,
      Schema fieldSchema) {
    switch (fieldSchema.getType()) {
    case UNION:
      int index = getResolvedUnionIndex(fieldSchema);
      Schema resolvedSchema = fieldSchema.getTypes().get(index);
      addFamilyOrColumn(delete, col, resolvedSchema);
      break;
    case MAP:
    case ARRAY:
      delete.addFamily(col.family);
      break;
    default:
      delete.addColumn(col.family, col.qualifier);
      break;
    }
  }

  private void addTimeRange(Get get, Query<K, T> query) throws IOException {
    if(query.getStartTime() > 0 || query.getEndTime() > 0) {
      if(query.getStartTime() == query.getEndTime()) {
        get.setTimeStamp(query.getStartTime());
      } else {
        long startTime = query.getStartTime() > 0 ? query.getStartTime() : 0;
        long endTime = query.getEndTime() > 0 ? query.getEndTime() : Long.MAX_VALUE;
        get.setTimeRange(startTime, endTime);
      }
    }
  }

  /**
   * Creates a new Persistent instance with the values in 'result' for the fields listed.
   * @param result result form a HTable#get()
   * @param fields List of fields queried, or null for all
   * @return A new instance with default values for not listed fields
   *         null if 'result' is null.
   * @throws IOException
   */
  public T newInstance(Result result, String[] fields)
  throws IOException {
    if(result == null || result.isEmpty())
      return null;

    T persistent = newPersistent();
    for (String f : fields) {
      HBaseColumn col = mapping.getColumn(f);
      if (col == null) {
        throw new  RuntimeException("HBase mapping for field ["+ f +"] not found. " +
            "Wrong gora-hbase-mapping.xml?");
      }
      Field field = fieldMap.get(f);
      Schema fieldSchema = field.schema();
      setField(result,persistent, col, field, fieldSchema);
    }
    persistent.clearDirty();
    return persistent;
  }

  private void setField(Result result, T persistent, HBaseColumn col,
      Field field, Schema fieldSchema) throws IOException {
    switch (fieldSchema.getType()) {
    case UNION:
      int index = getResolvedUnionIndex(fieldSchema);
      if (index > 1) { //if more than 2 type in union, deserialize directly for now
        byte[] val = result.getValue(col.getFamily(), col.getQualifier());
        if (val == null) {
          return;
        }
        setField(persistent, field, val);
      } else {
        Schema resolvedSchema = fieldSchema.getTypes().get(index);
        setField(result, persistent, col, field, resolvedSchema);
      }
      break;
    case MAP:
      NavigableMap<byte[], byte[]> qualMap = result.getNoVersionMap().get(
          col.getFamily());
      if (qualMap == null) {
        return;
      }
      Schema valueSchema = fieldSchema.getValueType();
      Map<Utf8, Object> map = new HashMap<>();
      for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
        map.put(new Utf8(Bytes.toString(e.getKey())),
            fromBytes(valueSchema, e.getValue()));
      }
      setField(persistent, field, map);
      break;
    case ARRAY:
      qualMap = result.getFamilyMap(col.getFamily());
      if (qualMap == null) {
        return;
      }
      valueSchema = fieldSchema.getElementType();
      ArrayList<Object> arrayList = new ArrayList<>();
      DirtyListWrapper<Object> dirtyListWrapper = new DirtyListWrapper<>(arrayList);
      for (Entry<byte[], byte[]> e : qualMap.entrySet()) {
        dirtyListWrapper.add(fromBytes(valueSchema, e.getValue()));
      }
      setField(persistent, field, arrayList);
      break;
    default:
      byte[] val = result.getValue(col.getFamily(), col.getQualifier());
      if (val == null) {
        return;
      }
      setField(persistent, field, val);
      break;
    }
  }

  //TODO temporary solution, has to be changed after implementation of saving the index of union type
  private int getResolvedUnionIndex(Schema unionScema) {
    if (unionScema.getTypes().size() == 2) {

      // schema [type0, type1]
      Type type0 = unionScema.getTypes().get(0).getType();
      Type type1 = unionScema.getTypes().get(1).getType();

      // Check if types are different and there's a "null", like ["null","type"]
      // or ["type","null"]
      if (!type0.equals(type1)
          && (type0.equals(Schema.Type.NULL) || type1.equals(Schema.Type.NULL))) {

        if (type0.equals(Schema.Type.NULL))
          return 1;
        else
          return 0;
      }
    }
    return 2;
  }

  @SuppressWarnings({ "unchecked", "rawtypes" })
  private void setField(T persistent, Field field, Map map) {
    persistent.put(field.pos(), new DirtyMapWrapper(map));
  }

  private void setField(T persistent, Field field, byte[] val)
  throws IOException {
    persistent.put(field.pos(), fromBytes(field.schema(), val));
  }

  @SuppressWarnings({ "rawtypes", "unchecked" })
  private void setField(T persistent, Field field, List list) {
    persistent.put(field.pos(), new DirtyListWrapper(list));
  }

  @SuppressWarnings("unchecked")
  private HBaseMapping readMapping(String filename) throws IOException {

    HBaseMappingBuilder mappingBuilder = new HBaseMappingBuilder();

    try {
      SAXBuilder builder = new SAXBuilder();
      Document doc = builder.build(getClass().getClassLoader()
          .getResourceAsStream(filename));
      Element root = doc.getRootElement();

      List<Element> tableElements = root.getChildren("table");
      for(Element tableElement : tableElements) {
        String tableName = tableElement.getAttributeValue("name");

        List<Element> fieldElements = tableElement.getChildren("family");
        for(Element fieldElement : fieldElements) {
          String familyName  = fieldElement.getAttributeValue("name");
          String compression = fieldElement.getAttributeValue("compression");
          String blockCache  = fieldElement.getAttributeValue("blockCache");
          String blockSize   = fieldElement.getAttributeValue("blockSize");
          String bloomFilter = fieldElement.getAttributeValue("bloomFilter");
          String maxVersions = fieldElement.getAttributeValue("maxVersions");
          String timeToLive  = fieldElement.getAttributeValue("timeToLive");
          String inMemory    = fieldElement.getAttributeValue("inMemory");

          mappingBuilder.addFamilyProps(tableName, familyName, compression,
              blockCache, blockSize, bloomFilter, maxVersions, timeToLive,
              inMemory);
        }
      }

      List<Element> classElements = root.getChildren("class");
      for(Element classElement: classElements) {
        if(classElement.getAttributeValue("keyClass").equals(
            keyClass.getCanonicalName())
            && classElement.getAttributeValue("name").equals(
                persistentClass.getCanonicalName())) {
          LOG.debug("Keyclass and nameclass match.");

          String tableNameFromMapping = classElement.getAttributeValue("table");
          String tableName = getSchemaName(tableNameFromMapping, persistentClass);

          //tableNameFromMapping could be null here
          if (!tableName.equals(tableNameFromMapping)) {
          //TODO this might not be the desired behavior as the user might have actually made a mistake.
            LOG.warn("Mismatching schema's names. Mappingfile schema: '{}'. PersistentClass schema's name: '{}'. Assuming they are the same.", tableNameFromMapping, tableName);
            if (tableNameFromMapping != null) {
              mappingBuilder.renameTable(tableNameFromMapping, tableName);
            }
          }
          mappingBuilder.setTableName(tableName);

          List<Element> fields = classElement.getChildren("field");
          for(Element field:fields) {
            String fieldName =  field.getAttributeValue("name");
            String family =  field.getAttributeValue("family");
            String qualifier = field.getAttributeValue("qualifier");
            mappingBuilder.addField(fieldName, family, qualifier);
            mappingBuilder.addColumnFamily(tableName, family);
          }
          //we found a matching key and value class definition,
          //do not continue on other class definitions
          break;
        } else {
          LOG.error("KeyClass in gora-hbase-mapping is not the same as the one in the databean.");
        }
      }
    } catch (MalformedURLException ex) {
      LOG.error("Error while trying to read the mapping file {}. "
              + "Expected to be in the classpath "
              + "(ClassLoader#getResource(java.lang.String)).",
              filename) ;
      LOG.error("Actual classpath = {}", Arrays.asList(
          ((URLClassLoader) getClass().getClassLoader()).getURLs()));
      throw ex ;
    } catch(IOException ex) {
      LOG.error(ex.getMessage(), ex);
      throw ex;
    } catch(Exception ex) {
      LOG.error(ex.getMessage(), ex);
      throw new IOException(ex);
    }

    return mappingBuilder.build();
  }

  @Override
  public void close() {
    try{
      table.close();
    }catch(IOException ex){
      LOG.error(ex.getMessage(), ex);
    }
  }

  @Override
  public Configuration getConf() {
    return conf;
  }

  @Override
  public void setConf(Configuration conf) {
    this.conf = conf;
  }

  /**
   * Gets the Scanner Caching optimization value
   * @return The value used internally in {@link Scan#setCaching(int)}
   */
  public int getScannerCaching() {
    return this.scannerCaching ;
  }

  /**
   * Sets the value for Scanner Caching optimization
   *
   * @see Scan#setCaching(int)
   *
   * @param numRows the number of rows for caching {@literal >=} 0
   * @return <<Fluent interface>>
   */
  public HBaseStore<K, T> setScannerCaching(int numRows) {
    if (numRows < 0) {
      LOG.warn("Invalid Scanner Caching optimization value. Cannot set to: {}.", numRows) ;
      return this ;
    }
    this.scannerCaching = numRows ;
    return this ;
  }

  private void closeHBaseAdmin(){
    try {
      admin.close();
    } catch (IOException ioe) {
      LOG.error("An error occured whilst closing HBase Admin", ioe);
    }
  }
}


text:
package com.avairebot.ai.dialogflow.intents;

import ai.api.model.AIResponse;
import com.avairebot.AvaIre;
import com.avairebot.commands.CommandContainer;
import com.avairebot.commands.CommandHandler;
import com.avairebot.commands.CommandMessage;
import com.avairebot.commands.utility.RankCommand;
import com.avairebot.contracts.ai.Intent;
import com.avairebot.database.transformers.GuildTransformer;
import com.avairebot.factories.MessageFactory;

@SuppressWarnings("unused")
public class RequestLevel extends Intent {

    public RequestLevel(AvaIre avaire) {
        super(avaire);
    }

    @Override
    public String getAction() {
        return "request.level";
    }

    @Override
    @SuppressWarnings("ConstantConditions")
    public void onIntent(CommandMessage context, AIResponse response) {
        GuildTransformer guildTransformer = context.getGuildTransformer();
        if (guildTransformer == null || !guildTransformer.isLevels()) {
            MessageFactory.makeWarning(context.getMessage(),
                "This server doesn't have the `Levels & Experience` feature enabled so I can't tell you what level you are :("
            ).queue();
            return;
        }

        CommandContainer container = CommandHandler.getCommand(RankCommand.class);
        container.getCommand().onCommand(
            new CommandMessage(container, context.getDatabaseEventHolder(), context.getMessage()), new String[]{"---skip-mentions"}
        );
    }
}

redpajama_set_name: RedPajamaGithub


text:
//
// This file was generated by the JavaTM Architecture for XML Binding(JAXB) Reference Implementation, v2.2.7
// See http://java.sun.com/xml/jaxb
// Any modifications to this file will be lost upon recompilation of the source schema.
// Generated on: 2013.12.03 at 11:33:45 AM PST
//

package org.ndexbio.xbel.model;

import java.util.ArrayList;
import java.util.List;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlSchemaType;
import javax.xml.bind.annotation.XmlType;
import javax.xml.datatype.XMLGregorianCalendar;

/**
 *
 *                     The citation annotation type to capture the knowledge source details.
 *
 *
 *
Java class for anonymous complex type.
 *
 *
The following schema fragment specifies the expected content contained within this class.
 *
 *

 * <complexType>
 *   <complexContent>
 *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *       <sequence>
 *         <element name="reference" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         <element name="name" type="{http://www.w3.org/2001/XMLSchema}string"/>
 *         <element name="comment" type="{http://www.w3.org/2001/XMLSchema}string" minOccurs="0"/>
 *         <element name="date" type="{http://www.w3.org/2001/XMLSchema}date" minOccurs="0"/>
 *         <element name="authorGroup" minOccurs="0">
 *           <complexType>
 *             <complexContent>
 *               <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
 *                 <sequence>
 *                   <element name="author" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
 *                 </sequence>
 *               </restriction>
 *             </complexContent>
 *           </complexType>
 *         </element>
 *       </sequence>
 *       <attribute name="type" use="required" type="{http://belframework.org/schema/1.0/xbel}citationType" />
 *     </restriction>
 *   </complexContent>
 * </complexType>
 *

 *
 *
 */
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "reference",
    "name",
    "comment",
    "date",
    "authorGroup"
})
@XmlRootElement(name = "citation")
public class Citation {

    @XmlElement(required = true)
    protected String reference;
    @XmlElement(required = true)
    protected String name;
    protected String comment;
    @XmlSchemaType(name = "date")
    protected XMLGregorianCalendar date;
    protected Citation.AuthorGroup authorGroup;
    @XmlAttribute(name = "type", namespace = "http://belframework.org/schema/1.0/xbel", required = true)
    protected CitationType type;

    /**
     * Gets the value of the reference property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getReference() {
        return reference;
    }

    /**
     * Sets the value of the reference property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setReference(String value) {
        this.reference = value;
    }

    /**
     * Gets the value of the name property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getName() {
        return name;
    }

    /**
     * Sets the value of the name property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setName(String value) {
        this.name = value;
    }

    /**
     * Gets the value of the comment property.
     *
     * @return
     *     possible object is
     *     {@link String }
     *
     */
    public String getComment() {
        return comment;
    }

    /**
     * Sets the value of the comment property.
     *
     * @param value
     *     allowed object is
     *     {@link String }
     *
     */
    public void setComment(String value) {
        this.comment = value;
    }

    /**
     * Gets the value of the date property.
     *
     * @return
     *     possible object is
     *     {@link XMLGregorianCalendar }
     *
     */
    public XMLGregorianCalendar getDate() {
        return date;
    }

    /**
     * Sets the value of the date property.
     *
     * @param value
     *     allowed object is
     *     {@link XMLGregorianCalendar }
     *
     */
    public void setDate(XMLGregorianCalendar value) {
        this.date = value;
    }

    /**
     * Gets the value of the authorGroup property.
     *
     * @return
     *     possible object is
     *     {@link Citation.AuthorGroup }
     *
     */
    public Citation.AuthorGroup getAuthorGroup() {
        return authorGroup;
    }

    /**
     * Sets the value of the authorGroup property.
     *
     * @param value
     *     allowed object is
     *     {@link Citation.AuthorGroup }
     *
     */
    public void setAuthorGroup(Citation.AuthorGroup value) {
        this.authorGroup = value;
    }

    /**
     * Gets the value of the type property.
     *
     * @return
     *     possible object is
     *     {@link CitationType }
     *
     */
    public CitationType getType() {
        return type;
    }

    /**
     * Sets the value of the type property.
     *
     * @param value
     *     allowed object is
     *     {@link CitationType }
     *
     */
    public void setType(CitationType value) {
        this.type = value;
    }

    /**
     *
     *                                 The author type for a citation.
     *
     *
     *
Java class for anonymous complex type.
     *
     *
The following schema fragment specifies the expected content contained within this class.
     *
     *

     * <complexType>
     *   <complexContent>
     *     <restriction base="{http://www.w3.org/2001/XMLSchema}anyType">
     *       <sequence>
     *         <element name="author" type="{http://www.w3.org/2001/XMLSchema}string" maxOccurs="unbounded"/>
     *       </sequence>
     *     </restriction>
     *   </complexContent>
     * </complexType>
     *

     *
     *
     */
    @XmlAccessorType(XmlAccessType.FIELD)
    @XmlType(name = "", propOrder = {
        "author"
    })
    public static class AuthorGroup {

        @XmlElement(required = true)
        protected List<String> author;

        /**
         * Gets the value of the author property.
         *
         *

         * This accessor method returns a reference to the live list,
         * not a snapshot. Therefore any modification you make to the
         * returned list will be present inside the JAXB object.
         * This is why there is not a set method for the author property.
         *
         *

         * For example, to add a new item, do as follows:
         *

         *    getAuthor().add(newItem);
         *

         *
         *
         *

         * Objects of the following type(s) are allowed in the list
         * {@link String }
         *
         *
         */
        public List<String> getAuthor() {
            if (author == null) {
                author = new ArrayList<>();
            }
            return this.author;
        }

    }

}


text:
{-
   Arch.hs: Architecture-specific information needed for stub generation.

  Part of Flounder: a message passing IDL for Barrelfish

  Copyright (c) 2007-2010, ETH Zurich.
  All rights reserved.

  This file is distributed under the terms in the attached LICENSE file.
  If you do not find this file, copies can be found by writing to:
  ETH Zurich D-INFK, Universit\"atstr. 6, CH-8092 Zurich. Attn: Systems Group.
-}

module Arch (Arch (..), parse_arch) where

import Syntax

-- everything the generic LMP backend needs to know about the architecture
data Arch = Arch {
    archname :: String, -- name of the architecture

    -- architecture-specific sizes
    wordsize :: Int,    -- size of words, in bits
    ptrsize  :: Int,    -- size of pointers, in bits
    sizesize :: Int,    -- size of size_t, in bits
    enum_type :: TypeBuiltin, -- type of an enumeration

    -- details of the barrelfish LMP channel implementation for this arch
    lmp_words :: Int,   -- payload of an LMP message, in number of words
    lrpc_words :: Int   -- payload of LRPC, in number of words
}

x86_64 = Arch {
    archname = "x86_64",
    wordsize = 64,
    ptrsize = 64,
    sizesize = 64,
    enum_type = Int32,
    lmp_words = 10,
    lrpc_words = 4
}

x86_32 = Arch {
    archname = "x86_32",
    wordsize = 32,
    ptrsize = 32,
    sizesize = 32,
    enum_type = Int32,
    lmp_words = 4,
    lrpc_words = 0
}

arm = Arch {
    archname = "arm",
    wordsize = 32,
    ptrsize = 32,
    sizesize = 32,
    enum_type = Int32,
    lmp_words = 4,
    lrpc_words = 0
}

-- settings for the xeon phi. TODO: Verify.
k1om = Arch {
    archname = "k1om",
    wordsize = 64,
    ptrsize = 64,
    sizesize = 64,
    enum_type = Int32,
    lmp_words = 10,
    lrpc_words = 4
}

all_archs = [x86_64, x86_32, arm, k1om]

-- for option parsing: find the matching arch info
parse_arch :: String -> Maybe Arch
parse_arch n = case [a | a <- all_archs, archname a == n] of
        [a] -> Just a
        _ -> Nothing


text:
<?php
// Layout and Design
function tromax_customize_register_layouts($wp_customize) {
    $wp_customize->add_panel('tromax_design_panel', array(
        'priority' => 40,
        'capability' => 'edit_theme_options',
        'theme_supports' => '',
        'title' => __('Design & Layout', 'tromax'),
    ));

    $wp_customize->add_section(
        'tromax_design_options',
        array(
            'title' => __('Blog Layout', 'tromax'),
            'priority' => 0,
            'panel' => 'tromax_design_panel'
        )
    );

    $wp_customize->add_setting(
        'tromax_blog_layout',
        array('sanitize_callback' => 'tromax_sanitize_blog_layout')
    );

    function tromax_sanitize_blog_layout($input)
    {
        if (in_array($input, array('grid', 'tromax', 'photograph')))
            return $input;
        else
            return '';
    }

    $wp_customize->add_control(
        'tromax_blog_layout', array(
            'label' => __('Select Layout', 'tromax'),
            'settings' => 'tromax_blog_layout',
            'section' => 'tromax_design_options',
            'type' => 'select',
            'choices' => array(
                'grid' => __('Standard Blog Layout', 'tromax'),
                'tromax' => __('Tromax Theme Layout', 'tromax'),
                'photograph' => __('Photograph Layout', 'tromax'),
            )
        )
    );

    $wp_customize->add_section(
        'tromax_sidebar_options',
        array(
            'title' => __('Sidebar Layout', 'tromax'),
            'priority' => 0,
            'panel' => 'tromax_design_panel'
        )
    );

    $wp_customize->add_setting(
        'tromax_disable_sidebar',
        array('sanitize_callback' => 'tromax_sanitize_checkbox')
    );

    $wp_customize->add_control(
        'tromax_disable_sidebar', array(
            'settings' => 'tromax_disable_sidebar',
            'label' => __('Disable Sidebar Everywhere.', 'tromax'),
            'section' => 'tromax_sidebar_options',
            'type' => 'checkbox',
            'default' => false
        )
    );

    $wp_customize->add_setting(
        'tromax_disable_sidebar_home',
        array('sanitize_callback' => 'tromax_sanitize_checkbox')
    );

    $wp_customize->add_control(
        'tromax_disable_sidebar_home', array(
            'settings' => 'tromax_disable_sidebar_home',
            'label' => __('Disable Sidebar on Home/Blog.', 'tromax'),
            'section' => 'tromax_sidebar_options',
            'type' => 'checkbox',
            'active_callback' => 'tromax_show_sidebar_options',
            'default' => false
        )
    );

    $wp_customize->add_setting(
        'tromax_disable_sidebar_front',
        array('sanitize_callback' => 'tromax_sanitize_checkbox')
    );

    $wp_customize->add_control(
        'tromax_disable_sidebar_front', array(
            'settings' => 'tromax_disable_sidebar_front',
            'label' => __('Disable Sidebar on Front Page.', 'tromax'),
            'section' => 'tromax_sidebar_options',
            'type' => 'checkbox',
            'active_callback' => 'tromax_show_sidebar_options',
            'default' => false
        )
    );

    $wp_customize->add_setting(
        'tromax_sidebar_width',
        array(
            'default' => 4,
            'sanitize_callback' => 'tromax_sanitize_positive_number')
    );

    $wp_customize->add_control(
        'tromax_sidebar_width', array(
            'settings' => 'tromax_sidebar_width',
            'label' => __('Sidebar Width', 'tromax'),
            'description' => __('Min: 25%, Default: 33%, Max: 40%', 'tromax'),
            'section' => 'tromax_sidebar_options',
            'type' => 'range',
            'active_callback' => 'tromax_show_sidebar_options',
            'input_attrs' => array(
                'min' => 3,
                'max' => 5,
                'step' => 1,
                'class' => 'sidebar-width-range',
                'style' => 'color: #0a0',
            ),
        )
    );

    /* Active Callback Function */
    function tromax_show_sidebar_options($control)
    {

        $option = $control->manager->get_setting('tromax_disable_sidebar');
        return $option->value() == false;

    }

    function tromax_sanitize_text($input)
    {
        return wp_kses_post(force_balance_tags($input));
    }

    $wp_customize->add_section(
        'tromax_custom_footer',
        array(
            'title' => __('Custom Footer Text', 'tromax'),
            'description' => __('Enter your Own Copyright Text.', 'tromax'),
            'priority' => 11,
            'panel' => 'tromax_design_panel'
        )
    );

    $wp_customize->add_setting(
        'tromax_footer_text',
        array(
            'default' => '',
            'sanitize_callback' => 'sanitize_text_field'
        )
    );

    $wp_customize->add_control(
        'tromax_footer_text',
        array(
            'section' => 'tromax_custom_footer',
            'settings' => 'tromax_footer_text',
            'type' => 'text'
        )
    );
}
add_action('customize_register', 'tromax_customize_register_layouts');


text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.nopy.html.attributes.aria;

import com.nopy.html.util.UtilString;

/**
 *
 * @author RODRIGO
 */
public class AriaFlowto {

    private String ariaFlowto;

    public String getAriaFlowto() {
        return ariaFlowto;
    }

    public void setAriaFlowto(Object onpagehide) {
        this.ariaFlowto = ariaFlowto + "";
    }

    @Override
    public String toString() {
        return ((new UtilString()).isEmpty(this.ariaFlowto) ? "" : " aria-flowto='" + this.ariaFlowto + "'");
    }
}


text:
.class public Lcom/android/gallery3d/util/ReverseGeocoder$SetLatLong;
.super Ljava/lang/Object;
.source "ReverseGeocoder.java"

# annotations
.annotation system Ldalvik/annotation/EnclosingClass;
    value = Lcom/android/gallery3d/util/ReverseGeocoder;
.end annotation

.annotation system Ldalvik/annotation/InnerClass;
    accessFlags = 0x9
    name = "SetLatLong"
.end annotation

# instance fields
.field public mMaxLatLatitude:D

.field public mMaxLatLongitude:D

.field public mMaxLonLatitude:D

.field public mMaxLonLongitude:D

.field public mMinLatLatitude:D

.field public mMinLatLongitude:D

.field public mMinLonLatitude:D

.field public mMinLonLongitude:D

# direct methods
.method public constructor <init>()V
    .locals 2

    .prologue
    .line 57
    invoke-direct {p0}, Ljava/lang/Object;-><init>()V

    .line 59
    const-wide v0, 0x4056800000000000L

    iput-wide v0, p0, Lcom/android/gallery3d/util/ReverseGeocoder$SetLatLong;->mMinLatLatitude:D

    .line 62
    const-wide v0, -0x3fa9800000000000L

    iput-wide v0, p0, Lcom/android/gallery3d/util/ReverseGeocoder$SetLatLong;->mMaxLatLatitude:D

    .line 66
    const-wide v0, 0x4066800000000000L

    iput-wide v0, p0, Lcom/android/gallery3d/util/ReverseGeocoder$SetLatLong;->mMinLonLongitude:D

    .line 69
    const-wide v0, -0x3f99800000000000L

    iput-wide v0, p0, Lcom/android/gallery3d/util/ReverseGeocoder$SetLatLong;->mMaxLonLongitude:D

    return-void
.end method


text:
# -*- coding: utf-8 -*-
"""
Flask assets bundles and filters
"""

import os

from flask_assets import Bundle, Environment

from lib.jinja_to_js_filter import JinjaToJs
from lib.sass_filter import LibSass

def static(*path):
    return os.path.join(os.path.dirname(__file__), 'static', *path)

jinja_to_js = JinjaToJs()

libsass_output = LibSass(include_paths=[
    static('sass'),
    static('govuk_frontend_toolkit/stylesheets'),
    static('govuk_elements/public/sass/elements')])

env = Environment()

env.register('css_govuk_elements', Bundle(
    'sass/govuk_elements.scss',
    filters=(libsass_output,),
    output='stylesheets/govuk_elements.css',
    depends=[
        '/static/govuk_elements/public/sass/**/*.scss',
        '/static/govuk_frontend_toolkit/stylesheets/**/*.scss']))

env.register('css_main', Bundle(
    'sass/main.scss',
    filters=(libsass_output,),
    output='stylesheets/main.css',
    depends=[
        '/static/sass/main/**/*.scss',
        '/static/govuk_frontend_toolkit/stylesheets/**/*.scss']))

env.register('css_notes', Bundle(
    'sass/notes.scss',
    filters=(libsass_output,),
    output='stylesheets/notes.css',
    depends=[
        '/static/sass/notes/**/*.scss',
        '/static/govuk_frontend_toolkit/stylesheets/**/*.scss']))

env.register('note_template', Bundle(
    'notes/note.html',
    filters=(jinja_to_js,),
    output='javascript/templates/notes/note.js'))

env.register('js_notes', Bundle(
    'js/vendor/jinja-to-js-runtime.js',
    'js/notesapp.js',
    filters=('rjsmin',),
    output='javascript/notes.js'))


text:
package org.mifos.reports.struts.action;

import junit.framework.Assert;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMessage;
import org.mifos.framework.MifosMockStrutsTestCase;
import org.mifos.framework.TestUtils;
import org.mifos.framework.util.helpers.Constants;
import org.mifos.security.util.ActivityContext;
import org.mifos.security.util.SecurityConstants;
import org.mifos.security.util.UserContext;

public class ReportsActionStrutsTest extends MifosMockStrutsTestCase {
    public ReportsActionStrutsTest() throws Exception {
        super();
    }

    private UserContext userContext;

    @Override
    protected void setStrutsConfig() {
        super.setStrutsConfig();
        setConfigFile("/WEB-INF/struts-config.xml,/WEB-INF/reports-struts-config.xml");
    }

    @Override
    protected void setUp() throws Exception {
        super.setUp();
        userContext = TestUtils.makeUser();
        request.getSession().setAttribute(Constants.USERCONTEXT, userContext);
        addRequestParameter("recordLoanOfficerId", "1");
        addRequestParameter("recordOfficeId", "1");
        ActivityContext ac = new ActivityContext((short) 0, userContext.getBranchId().shortValue(), userContext.getId()
                .shortValue());
        request.getSession(false).setAttribute("ActivityContext", ac);
    }

    @Override
    protected void tearDown() throws Exception {
        super.tearDown();
    }

    public void testVerifyForwardOfNonExistentReportThrowsSecurityError() {
        addRequestParameter("viewPath", "report_designer");
        setRequestPathInfo("/reportsAction.do");
        addRequestParameter("method", "getReportPage");
        actionPerform();
        ActionErrors errors = (ActionErrors) request.getAttribute(Globals.ERROR_KEY);
        ActionMessage retrievedMessage = (ActionMessage) (errors).get(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED)
                .next();
        ActionMessage expectedErrorMessage = new ActionMessage(SecurityConstants.KEY_ACTIVITY_NOT_ALLOWED);
       Assert.assertEquals(expectedErrorMessage.toString(), retrievedMessage.toString());
    }

    public void testSkipConvertFormObjectToBusinessObjectReturnsTrueForAnyMethod() throws Exception {
       Assert.assertTrue(new ReportsAction().skipActionFormToBusinessObjectConversion(null));
    }
}


text:
require_relative 'require'

FILENAME = 'text.txt'

class Controller

	def self.run(filename)
		@message = Message.create_new_message(filename)
		encrypt
		decrypt
	end

	def self.encrypt(shift = make_rand_shift)
		@message.char_array = Shifter.shift_char_array(@message.char_array, shift)
		@message.save_text
		View.clear_screen
		@message.display
	end

	def self.decrypt
		shifts = Solver.finding_shifts(@message)
		encrypt(shifts)
	end

	def self.make_rand_shift
		length = rand(1..MAX_REPEAT_LENGTH)
		shift = []
		length.times {|i| shift << rand(1..26)}
		puts "shift #{shift}"
		return shift
	end

end

Controller.run(FILENAME)
# my_controller.display_message


text:
import pytest

import pyannote.core
from pyannote.core import Annotation
from pyannote.core import Segment
from pyannote.core import Timeline
from pyannote.metrics.identification import IdentificationErrorRate
from pyannote.metrics.identification import IdentificationPrecision
from pyannote.metrics.identification import IdentificationRecall

import numpy.testing as npt

@pytest.fixture
def reference():
    reference = Annotation()
    reference[Segment(0, 10)] = 'A'
    reference[Segment(12, 20)] = 'B'
    reference[Segment(24, 27)] = 'A'
    reference[Segment(30, 40)] = 'C'
    return reference

@pytest.fixture
def hypothesis():
    hypothesis = Annotation()
    hypothesis[Segment(2, 13)] = 'A'
    hypothesis[Segment(13, 14)] = 'D'
    hypothesis[Segment(14, 20)] = 'B'
    hypothesis[Segment(22, 38)] = 'C'
    hypothesis[Segment(38, 40)] = 'D'
    return hypothesis

def test_error_rate(reference, hypothesis):
    identificationErrorRate = IdentificationErrorRate()
    error_rate = identificationErrorRate(reference, hypothesis)
    npt.assert_almost_equal(error_rate, 0.5161290322580645, decimal=7)

def test_detailed(reference, hypothesis):
    identificationErrorRate = IdentificationErrorRate()
    details = identificationErrorRate(reference, hypothesis, detailed=True)

    confusion = details['confusion']
    npt.assert_almost_equal(confusion, 7.0, decimal=7)

    correct = details['correct']
    npt.assert_almost_equal(correct, 22.0, decimal=7)

    rate = details['identification error rate']
    npt.assert_almost_equal(rate, 0.5161290322580645, decimal=7)

    false_alarm = details['false alarm']
    npt.assert_almost_equal(false_alarm, 7.0, decimal=7)

    missed_detection = details['missed detection']
    npt.assert_almost_equal(missed_detection, 2.0, decimal=7)

    total = details['total']
    npt.assert_almost_equal(total, 31.0, decimal=7)

def test_precision(reference, hypothesis):
    identificationPrecisions = IdentificationPrecision()
    precision = identificationPrecisions(reference, hypothesis)
    npt.assert_almost_equal(precision, 0.611, decimal=3)

def test_recall(reference, hypothesis):
    identificationRecall = IdentificationRecall()
    recall = identificationRecall(reference, hypothesis)
    npt.assert_almost_equal(recall, 0.710, decimal=3)


text:
module PETFINDER
  OPH_PAGE = "https://www.petfinder.com/pet-search?shelter_id=VA600"
end


text:
require 'spec_helper'

RSpec.describe LiveEditor::CLI::Main do
  describe 'new' do
    context 'with underscored TITLE' do
      include_context 'outside of theme root', false

      it "echoes new theme's TITLE" do
        output = capture(:stdout) { subject.new('my_theme') }
        expect(output).to match /Creating a new Live Editor theme titled "My Theme".../
      end

      it 'creates a `my_theme` folder with the correct contents' do
        output = capture(:stdout) { subject.new('my_theme') }

        # Check that correct files were generated.
        expect(File).to exist temp_folder + "/my_theme/assets/css/site.css"
        expect(File).to exist temp_folder + "/my_theme/assets/fonts/.keep"
        expect(File).to exist temp_folder + "/my_theme/assets/images/.keep"
        expect(File).to exist temp_folder + "/my_theme/assets/js/init.js"
        expect(File).to exist temp_folder + "/my_theme/assets/js/site.js"
        expect(File).to exist temp_folder + "/my_theme/content_templates/.keep"
        expect(File).to exist temp_folder + "/my_theme/partials/.keep"
        expect(File).to exist temp_folder + "/my_theme/layouts/layouts.json"
        expect(File).to exist temp_folder + "/my_theme/layouts/site_layout.liquid"
        expect(File).to exist temp_folder + "/my_theme/navigation/global_navigation.liquid"
        expect(File).to exist temp_folder + "/my_theme/navigation/navigation.json"
        expect(File).to exist temp_folder + "/my_theme/.gitignore"
        expect(File).to exist temp_folder + "/my_theme/config.json.sample"
        expect(File).to exist temp_folder + "/my_theme/README.md"
        expect(File).to exist temp_folder + "/my_theme/theme.json"

        # Check that template files were generated and parsed correctly.
        expect(IO.read(temp_folder + "/my_theme/README.md")).to match /^# My Theme/
        expect(IO.read(temp_folder + "/my_theme/theme.json")).to match /"title": "My Theme"/

        # Clean up generated my_theme directory.
        FileUtils.rm_rf(File.dirname(File.realpath(__FILE__)).sub('commands', 'my_theme'))
      end
    end # with underscored TITLE

    context 'with titleized TITLE' do
      include_context 'outside of theme root', false

      it "echoes new theme's name when titleized" do
        output = capture(:stdout) { subject.new('My Theme') }
        expect(output).to match /Creating a new Live Editor theme titled "My Theme".../
      end

      it 'creates a `my_theme` folder with the correct contents' do
        output = capture(:stdout) { subject.new('My Theme') }

        # Check that correct files were generated.
        expect(File).to exist temp_folder + "/my_theme/assets/css/site.css"
        expect(File).to exist temp_folder + "/my_theme/assets/fonts/.keep"
        expect(File).to exist temp_folder + "/my_theme/assets/images/.keep"
        expect(File).to exist temp_folder + "/my_theme/assets/js/init.js"
        expect(File).to exist temp_folder + "/my_theme/assets/js/site.js"
        expect(File).to exist temp_folder + "/my_theme/content_templates/.keep"
        expect(File).to exist temp_folder + "/my_theme/partials/.keep"
        expect(File).to exist temp_folder + "/my_theme/layouts/layouts.json"
        expect(File).to exist temp_folder + "/my_theme/layouts/site_layout.liquid"
        expect(File).to exist temp_folder + "/my_theme/navigation/global_navigation.liquid"
        expect(File).to exist temp_folder + "/my_theme/navigation/navigation.json"
        expect(File).to exist temp_folder + "/my_theme/.gitignore"
        expect(File).to exist temp_folder + "/my_theme/config.json.sample"
        expect(File).to exist temp_folder + "/my_theme/README.md"
        expect(File).to exist temp_folder + "/my_theme/theme.json"

        # Check that template files were generated and parsed correctly.
        expect(IO.read(temp_folder + "/my_theme/README.md")).to match /^# My Theme/
        expect(IO.read(temp_folder + "/my_theme/theme.json")).to match /"title": "My Theme"/
      end
    end # with titleized TITLE

    context 'within existing theme', fakefs: true do
      include_context 'basic theme'
      include_context 'within theme root'

      it 'displays an error and does not generate a new theme' do
        output = capture(:stdout) { subject.new('My Theme') }
        expect(output).to match /ERROR: Cannot create a new theme within the folder of another theme./
        expect(File).to_not exist "#{theme_root}/my_theme/assets/css/site.css"
      end
    end
  end
end


text:
<?php

namespace Brickoo\Component\Annotation\Definition;

use Brickoo\Component\Common\Assert;

/**
 * AnnotationParameterDefinition
 *
 * Implements an annotation parameter definition.
 * @author Celestino Diaz <celestino.diaz@gmx.de>
 */
class AnnotationParameterDefinition {

    /** @var string */
    private $name;

    /** @var string */
    private $type;

    /** @var boolean */
    private $required;

    /**
     * Class constructor.
     * @param string $name
     * @param string $type
     * @param boolean $required
     * @throws \InvalidArgumentException
     */
    public function __construct($name, $type, $required = true) {
        Assert::isString($name);
        Assert::isString($type);
        Assert::isBoolean($required);
        $this->name = $name;
        $this->type = $type;
        $this->required = $required;
    }

    /**
     * Returns the parameter name.
     * @return string the parameter name
     */
    public function getName() {
        return $this->name;
    }

    /**
     * Returns the parameter type.
     * @return string the parameter type
     */
    public function getType() {
        return $this->type;
    }

    /**
     * Checks if the parameter is required.
     * @return boolean check result
     */
    public function isRequired() {
        return $this->required;
    }

}


text:
package algo.lecture.stack;

/**
 * Created on 15/10/11.
 * Author: ylgrgyq
 */
public interface Processor {
    public boolean process(Character symbol, Context ctx);
}


text:
<?xml version="1.0" encoding="utf-8"?>
<menu
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">

    <item
        android:id="@+id/menu_master_detail_toggle_master"
        android:orderInCategory="0"
        app:showAsAction="ifRoom"
        android:title="@string/menu_master_detail_toggle_default" />

</menu>


text:
namespace Microsoft.Azure.Management.Network.Fluent.Models
{
    using Newtonsoft.Json;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// List of ApplicationGatewayBackendHealthPool resources.
    /// </summary>
    public partial class ApplicationGatewayBackendHealthInner
    {
        /// <summary>
        /// Initializes a new instance of the
        /// ApplicationGatewayBackendHealthInner class.
        /// </summary>
        public ApplicationGatewayBackendHealthInner()
        {
            CustomInit();
        }

        /// <summary>
        /// Initializes a new instance of the
        /// ApplicationGatewayBackendHealthInner class.
        /// </summary>
        public ApplicationGatewayBackendHealthInner(IList<ApplicationGatewayBackendHealthPool> backendAddressPools = default(IList<ApplicationGatewayBackendHealthPool>))
        {
            BackendAddressPools = backendAddressPools;
            CustomInit();
        }

        /// <summary>
        /// An initialization method that performs custom operations like setting defaults
        /// </summary>
        partial void CustomInit();

        /// <summary>
        /// </summary>
        [JsonProperty(PropertyName = "backendAddressPools")]
        public IList<ApplicationGatewayBackendHealthPool> BackendAddressPools { get; set; }

    }
}


text:
#ifndef QATOMIC_UNIX_H
#define QATOMIC_UNIX_H

#include <QtCore/qgenericatomic.h>

QT_BEGIN_NAMESPACE

#if 0
// silence syncqt warnings
QT_END_NAMESPACE
#pragma qt_sync_skip_header_check
#pragma qt_sync_stop_processing
#endif

#define Q_ATOMIC_INT_REFERENCE_COUNTING_IS_NOT_NATIVE
#define Q_ATOMIC_INT_TEST_AND_SET_IS_NOT_NATIVE
#define Q_ATOMIC_INT_FETCH_AND_STORE_IS_NOT_NATIVE
#define Q_ATOMIC_INT_FETCH_AND_ADD_IS_NOT_NATIVE

#define Q_ATOMIC_INT32_IS_SUPPORTED
#define Q_ATOMIC_INT32_REFERENCE_COUNTING_IS_NOT_NATIVE
#define Q_ATOMIC_INT32_TEST_AND_SET_IS_NOT_NATIVE
#define Q_ATOMIC_INT32_FETCH_AND_STORE_IS_NOT_NATIVE
#define Q_ATOMIC_INT32_FETCH_AND_ADD_IS_NOT_NATIVE

#define Q_ATOMIC_INT64_IS_SUPPORTED
#define Q_ATOMIC_INT64_REFERENCE_COUNTING_IS_NOT_NATIVE
#define Q_ATOMIC_INT64_TEST_AND_SET_IS_NOT_NATIVE
#define Q_ATOMIC_INT64_FETCH_AND_STORE_IS_NOT_NATIVE
#define Q_ATOMIC_INT64_FETCH_AND_ADD_IS_NOT_NATIVE

#define Q_ATOMIC_POINTER_TEST_AND_SET_IS_NOT_NATIVE
#define Q_ATOMIC_POINTER_FETCH_AND_STORE_IS_NOT_NATIVE
#define Q_ATOMIC_POINTER_FETCH_AND_ADD_IS_NOT_NATIVE

// No definition, needs specialization
template <typename T> struct QAtomicOps;

// 32-bit version
template <>
struct QAtomicOps<int> : QGenericAtomicOps<QAtomicOps<int> >
{
    typedef int Type;

    static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
    static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
    Q_CORE_EXPORT static bool testAndSetRelaxed(int &_q_value, int expectedValue, int newValue) Q_DECL_NOTHROW;
};

// 64-bit version
template <>
struct QAtomicOps<long long> : QGenericAtomicOps<QAtomicOps<long long> >
{
    typedef long long Type;

    static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
    static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
    Q_CORE_EXPORT static bool testAndSetRelaxed(Type &_q_value, Type expectedValue, Type newValue) Q_DECL_NOTHROW;
};

// pointer version
template <>
struct QAtomicOps<void *> : QGenericAtomicOps<QAtomicOps<void *> >
{
    typedef void *Type;

    static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
    static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
    Q_CORE_EXPORT static bool testAndSetRelaxed(void *&_q_value, void *expectedValue, void *newValue) Q_DECL_NOTHROW;
};

template <typename T>
struct QAtomicOps<T *> : QGenericAtomicOps<QAtomicOps<T *> >
{
    typedef T *Type;

    // helper to strip cv qualifiers
    static inline void *nocv(const T *p) { return const_cast<void *>(static_cast<const volatile void *>(p)); }

    static inline Q_DECL_CONSTEXPR bool isTestAndSetNative() Q_DECL_NOTHROW { return false; }
    static inline Q_DECL_CONSTEXPR bool isTestAndSetWaitFree() Q_DECL_NOTHROW { return false; }
    static inline bool testAndSetRelaxed(T *&_q_value, T *expectedValue, T *newValue) Q_DECL_NOTHROW
    {
        // forward to the void* specialization
        void *voidp = nocv(_q_value);
        bool returnValue = QAtomicOps<void *>::testAndSetRelaxed(voidp, nocv(expectedValue), nocv(newValue));
        _q_value = reinterpret_cast<T *>(voidp);
        return returnValue;
    }
};

// 32- and 64-bit unsigned versions
template <> struct QAtomicOps<unsigned> : QAtomicOps<int>
{
    typedef unsigned Type;
    Q_CORE_EXPORT static bool testAndSetRelaxed(Type &_q_value, Type expectedValue, Type newValue) Q_DECL_NOTHROW
    {
        return QAtomicOps<int>::testAndSetRelaxed(reinterpret_cast<int &>(_q_value), int(expectedValue), int(newValue));
    }
};
template <> struct QAtomicOps<unsigned long long> : QAtomicOps<long long>
{
    typedef unsigned long longType;
    Q_CORE_EXPORT static bool testAndSetRelaxed(Type &_q_value, Type expectedValue, Type newValue) Q_DECL_NOTHROW
    {
        return QAtomicOps<long long>::testAndSetRelaxed(reinterpret_cast<long long &>(_q_value), int(expectedValue), int(newValue));
    }
};

QT_END_NAMESPACE
#endif // QATOMIC_UNIX_H


text:
package hex.segments;

import water.Iced;

class SegmentModelsStats extends Iced<SegmentModelsStats> {
  int _succeeded;
  int _failed;

  void reduce(SegmentModelsStats other) {
    _succeeded += other._succeeded;
    _failed += other._failed;
  }

  @Override
  public String toString() {
    return "succeeded=" + _succeeded + ", failed=" + _failed;
  }

}


text:
namespace gpopt
{
using namespace gpos;

//---------------------------------------------------------------------------
//	@class:
//		CXformExpandNAryJoinDPv2
//
//	@doc:
//		Expand n-ary join into series of binary joins using dynamic
//		programming
//
//---------------------------------------------------------------------------
class CXformExpandNAryJoinDPv2 : public CXformExploration
{
private:
public:
	CXformExpandNAryJoinDPv2(const CXformExpandNAryJoinDPv2 &) = delete;

	// ctor
	explicit CXformExpandNAryJoinDPv2(CMemoryPool *mp);

	// dtor
	~CXformExpandNAryJoinDPv2() override = default;

	// ident accessors
	EXformId
	Exfid() const override
	{
		return ExfExpandNAryJoinDPv2;
	}

	// return a string for xform name
	const CHAR *
	SzId() const override
	{
		return "CXformExpandNAryJoinDPv2";
	}

	// compute xform promise for a given expression handle
	EXformPromise Exfp(CExpressionHandle &exprhdl) const override;

	// do stats need to be computed before applying xform?
	BOOL
	FNeedsStats() const override
	{
		return true;
	}

	// actual transform
	void Transform(CXformContext *pxfctxt, CXformResult *pxfres,
				   CExpression *pexpr) const override;

};	// class CXformExpandNAryJoinDPv2

}  // namespace gpopt

#endif	// !GPOPT_CXformExpandNAryJoinDPv2_H

// EOF


text:
import unittest
import os
from sqltxt.table import Table
from sqltxt.query import Query, condition_applies, stage_columns, stage_conditions
from sqltxt.column import Column, ColumnName, AmbiguousColumnNameError
from sqltxt.expression import Expression, AndList, OrList
import subprocess

class QueryTest(unittest.TestCase):

    def setUp(self):

        # TODO: replace this hack to make sure test files are found with fixtures
        if 'tests/data' not in os.getcwd():
            os.chdir(os.path.join(os.getcwd(), 'tests/data'))

        table_header = ["col_a", "col_b"]
        table_contents = """1,1\n2,3\n3,2"""

        self.table_a = Table.from_cmd(
            name = 'table_a',
            cmd = 'echo -e "{0}"'.format(table_contents),
            columns = table_header
        )

        table_header = ["col_a", "col_z"]
        table_contents = """1,w\n2,x\n2,y\n5,z"""

        self.table_b = Table.from_cmd(
            name = 'table_b',
            cmd = 'echo -e "{0}"'.format(table_contents),
            columns = table_header
        )

    def test_condition_applies(self):

        condition = AndList([
            Expression('table_a.col_a', '==', 'table_b.col_z'),
            Expression('table_a.col_b', '==', 'table_b.col_a')
        ])
        self.assertTrue(condition_applies(condition, self.table_a, self.table_b))

        condition = OrList([
            Expression('table_a.col_a', '==', 'table_b.col_z'),
            Expression('table_a.col_b', '==', 'table_b.col_a')
        ])
        self.assertTrue(condition_applies(condition, self.table_a, self.table_b))

        condition = OrList([
            Expression('table_a.col_a', '==', 'table_b.col_z'),
            Expression('table_a.col_b', '==', 'table_b.col_a')
        ])
        self.assertFalse(condition_applies(condition, self.table_a))

        condition = AndList([
            Expression('table_a.col_a', '==', 'table_b.col_z'),
            Expression('table_c.col_b', '==', 'table_b.col_a')
        ])
        self.assertFalse(condition_applies(condition, self.table_a, self.table_b))

        condition = OrList([
            Expression('table_a.col_a', '==', 'table_b.col_j'),
            Expression('table_a.col_b', '==', 'table_b.col_a')
        ])
        self.assertFalse(condition_applies(condition, self.table_a, self.table_b))

        condition = AndList([
            Expression('table_a.col_a', '==', '1'),
            Expression('table_a.col_b', '==', 'table_b.col_a')
        ])
        self.assertTrue(condition_applies(condition, self.table_a, self.table_b))

        with self.assertRaises(AmbiguousColumnNameError):
            condition = AndList([
                Expression('table_a.col_a', '==', '1'),
                Expression('table_a.col_b', '==', 'col_a')
            ])
            condition_applies(condition, self.table_a, self.table_b)

    def test_stage_columns(self):

        column_names = [
            ColumnName('table_a.col_a'),
            ColumnName('table_b.col_a'),
            ColumnName('col_z'),
            ColumnName('col_b'),
        ]
        expected_stages = [
            [ColumnName('table_a.col_a'), ColumnName('col_b'), ],
            [ColumnName('table_b.col_a'), ColumnName('col_z'), ]
        ]
        actual_stages = stage_columns([self.table_a, self.table_b], column_names)
        self.assertEqual(expected_stages, actual_stages)

        with self.assertRaises(AmbiguousColumnNameError):
            column_names = [ColumnName('col_a'), ]
            actual_stages = stage_columns([self.table_a, self.table_b], column_names)

    def test_stage_conditions(self):

        conditions = [
            Expression('table_a.col_a', '==', 'table_b.col_z'),
            Expression('table_a.col_a', '==', 'table_a.col_b'),
            OrList([
                Expression('table_a.col_a', '==', 'table_b.col_z'),
                Expression('table_a.col_a', '==', 'table_a.col_b')
            ]),
        ]

        expected_condition_order = [
            [Expression('table_a.col_a', '==', 'table_a.col_b')],
            [
                Expression('table_a.col_a', '==', 'table_b.col_z'),
                OrList([
                    Expression('table_a.col_a', '==', 'table_b.col_z'),
                    Expression('table_a.col_a', '==', 'table_a.col_b')
                ])
            ],
        ]
        actual_condition_order = stage_conditions([self.table_a, self.table_b], conditions)
        self.assertEqual(expected_condition_order, actual_condition_order)

    def test_select(self):

        query = Query(
            [{'path': 'table_a.txt', 'alias': 'table_a.txt'}],
            columns=['col_b']
        )
        table_actual = query.execute()

        table_expected = Table.from_cmd(
            name = 'expected',
            cmd = 'echo -e "1\n3\n2"',
            columns = ["col_b"]
            )

        table_expected_out = subprocess.check_output(['/bin/bash', '-c', table_expected.get_cmd_str(output_column_names=True)])
        table_actual_out = subprocess.check_output(['/bin/bash', '-c', table_actual.get_cmd_str(output_column_names=True)])
        self.assertEqual(table_actual_out, table_expected_out)

    def test_where(self):

        query = Query(
            [{'path': 'table_a.txt', 'alias': 'table_a.txt'}],
            conditions=[['col_b', '<', '3'], 'or', ['col_b', '<', '3']],
            columns=['col_a']
        )
        table_actual = query.execute()

        table_expected = Table.from_cmd(
          'expected',
          cmd = 'echo -e "1\n3"',
          columns = ['col_a']
          )

        table_expected_out = subprocess.check_output(['/bin/bash', '-c', table_expected.get_cmd_str(output_column_names=True)])
        table_actual_out = subprocess.check_output(['/bin/bash', '-c', table_actual.get_cmd_str(output_column_names=True)])
        self.assertEqual(table_actual_out, table_expected_out)

    def test_join_columns(self):

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'table_b.txt'}
            ],
            conditions=[ ['table_a.txt.col_a', '==', 'table_b.txt.col_a'], ],
            columns=['table_a.txt.col_a', 'col_b', 'col_z']
        )
        t = query.execute()
        header_actual = t.columns
        header_expected = ['col_a', 'col_b', 'col_z']

        self.assertEqual([str(col) for col in header_actual], header_expected)

    def test_join_two_tables(self):

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'table_b.txt'}
            ],
            conditions=[ ['table_a.txt.col_a', '==', 'table_b.txt.col_a'], ],
            columns=['table_a.txt.col_a', 'col_b', 'col_z']
        )

        table_actual = query.execute()
        table_expected = Table.from_cmd(
          name = 'table_a',
          cmd = 'echo -e "1,1,w\n2,3,x\n2,3,y"',
          columns = ['col_a','col_b','col_z']
          )

        table_expected_out = subprocess.check_output(['/bin/bash', '-c', table_expected.get_cmd_str(output_column_names=True)])
        table_actual_out = subprocess.check_output(['/bin/bash', '-c', table_actual.get_cmd_str(output_column_names=True)])

        self.assertEqual(table_actual_out, table_expected_out)

    def test_join_two_tables_with_sort(self):

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'table_b.txt'}
            ],
            conditions=[ ['table_a.txt.col_b', '==', 'table_b.txt.col_a'], ],
            columns=['col_b', 'table_b.txt.col_a', 'col_z']
        )
        table_actual = query.execute()
        cmd_actual = table_actual.get_cmd_str(output_column_names=True)
        cmd_expected = \
          'echo "col_b,col_a,col_z"; ' + \
          "join -t, -1 2 -2 1 <(tail -n+2 table_a.txt | sort -t, -k 2,2) <(tail -n+2 table_b.txt | sort -t, -k 1,1) | awk -F\',\' \'OFS=\",\" { print $1,$1,$3 }\'"
        assert cmd_actual == cmd_expected

        table_actual_out = subprocess.check_output(['/bin/bash', '-c', cmd_actual])
        table_expected_out = subprocess.check_output(['/bin/bash', '-c', cmd_expected])

        self.assertEqual(table_actual_out, table_expected_out)

    def test_join_two_tables_with_multiple_join_conditions(self):

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_d.txt', 'alias': 'table_d.txt'}
            ],
            conditions=[
                ['table_a.txt.col_a', '==', 'table_d.txt.col_a'], 'and',
                ['table_a.txt.col_b', '==', 'table_d.txt.col_b'],
            ],
            columns=['table_a.txt.col_b', 'table_a.txt.col_a', 'col_x']
        )
        table_actual = query.execute()
        cmd_actual = table_actual.get_cmd_str(output_column_names=True)
        cmd_expected = \
          'echo "col_b,col_a,col_x"; ' + \
          "join -t, -1 1 -2 1 <(tail -n+2 table_d.txt | sort -t, -k 1,1) <(tail -n+2 table_a.txt | sort -t, -k 1,1) | awk -F\',\' \'OFS=\",\" { if ($4 == $2) { print $1,$2,$3,$4 } }\' | awk -F\',\' \'OFS=\",\" { print $4,$1,$3 }\'"
        assert cmd_actual == cmd_expected

        table_actual_out = subprocess.check_output(['/bin/bash', '-c', cmd_actual])
        table_expected_out = subprocess.check_output(['/bin/bash', '-c', cmd_expected])

        self.assertEqual(table_actual_out, table_expected_out)

    def test_join_three_tables(self):
        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'table_b.txt'},
                {'path': 'table_d.txt', 'alias': 'table_d.txt'}
            ],
            conditions=[
                ['table_a.txt.col_a', '==', 'table_d.txt.col_a'], 'and',
                ['table_a.txt.col_a', '==', 'table_b.txt.col_a'],
            ],
            columns=['col_z', 'table_a.txt.col_a', 'col_x']
        )
        table_actual = query.execute()
        cmd_actual = table_actual.get_cmd_str(output_column_names=True)
        cmd_expected = \
          'echo "col_z,col_a,col_x"; ' + \
          'join -t, -1 1 -2 1 ' + \
              '<(join -t, -1 1 -2 1 ' + \
                  '<(tail -n+2 table_d.txt | sort -t, -k 1,1) ' + \
                  '<(tail -n+2 table_a.txt | sort -t, -k 1,1) | sort -t, -k 1,1) ' + \
              '<(tail -n+2 table_b.txt | sort -t, -k 1,1) ' + \
          '| awk -F\',\' \'OFS="," { print $5,$1,$3 }\''
        assert cmd_actual == cmd_expected

        table_actual_out = subprocess.check_output(['/bin/bash', '-c', cmd_actual])
        table_expected_out = subprocess.check_output(['/bin/bash', '-c', cmd_expected])

        self.assertEqual(table_actual_out, table_expected_out)

    def test_wildcard_selects_all_columns(self):

        query = Query(
            [{'path': 'table_a.txt', 'alias': 'table_a.txt'}],
            columns=['*']
        )
        table_actual = query.execute()

        table_expected = Table.from_cmd(
            name = 'expected',
            cmd = 'echo -e "1,1\n2,3\n3,2"',
            columns = ["col_a", "col_b"]
            )

        table_expected_out = subprocess.check_output(['/bin/bash', '-c', table_expected.get_cmd_str(output_column_names=True)])
        table_actual_out = subprocess.check_output(['/bin/bash', '-c', table_actual.get_cmd_str(output_column_names=True)])
        self.assertEqual(table_actual_out, table_expected_out)

    def test_qualified_wildcard_selects_all_table_columns_for_table_qualifier(self):

        query = Query(
            [{'path': 'table_a.txt', 'alias': 'table_a.txt'}],
            columns=['table_a.txt.*']
        )
        table_actual = query.execute()

        table_expected = Table.from_cmd(
            name = 'expected',
            cmd = 'echo -e "1,1\n2,3\n3,2"',
            columns = ["col_a", "col_b"]
            )

        table_expected_out = subprocess.check_output(['/bin/bash', '-c', table_expected.get_cmd_str(output_column_names=True)])
        table_actual_out = subprocess.check_output(['/bin/bash', '-c', table_actual.get_cmd_str(output_column_names=True)])
        self.assertEqual(table_actual_out, table_expected_out)

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'table_b.txt'}
            ],
            conditions=[ ['table_a.txt.col_a', '==', 'table_b.txt.col_a'], ],
            columns=['table_a.txt.*']
        )
        t = query.execute()
        header_actual = t.columns
        header_expected = ['col_a', 'col_b']

        self.assertEqual([str(col) for col in header_actual], header_expected)

        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'tb'}
            ],
            conditions=[ ['table_a.txt.col_a', '==', 'table_b.txt.col_a'], ],
            columns=['tb.*']
        )
        t = query.execute()
        header_actual = t.columns
        header_expected = ['col_a', 'col_z']

        self.assertEqual([str(col) for col in header_actual], header_expected)

    def test_multiple_wildcards_result_in_duplicate_columns(self):
        query = Query(
            [
                {'path': 'table_a.txt', 'alias': 'table_a.txt'},
                {'path': 'table_b.txt', 'alias': 'tb'}
            ],
            conditions=[ ['table_a.txt.col_a', '==', 'tb.col_a'], ],
            columns=['table_a.txt.col_a', 'tb.*', '*']
        )
        t = query.execute()
        header_actual = t.columns
        header_expected = ['col_a', 'col_a', 'col_z', 'col_a', 'col_b', 'col_a', 'col_z', ]

        self.assertEqual([str(col) for col in header_actual], header_expected)


text:
#pragma once

#include <string>
#include <unordered_map>

#include "envoy/common/exception.h"

#include "fmt/format.h"
#include "fmt/ostream.h"

namespace Envoy {
namespace Registry {

/**
 * General registry for implementation factories. The registry is templated by the Base class that a
 * set of factories conforms to.
 *
 * Classes are found by name, so a single name cannot be registered twice for the same Base class.
 * Factories are registered by reference and this reference is expected to be valid through the life
 * of the program. Factories cannot be deregistered.
 * Factories should generally be registered by statically instantiating the RegisterFactory class.
 *
 * Note: This class is not thread safe, so registration should only occur in a single threaded
 * environment, which is guaranteed by the static instantiation mentioned above.
 *
 * Exaple lookup: BaseFactoryType *factory =
 * FactoryRegistry<BaseFactoryType>::getFactory("example_factory_name");
 */
template <class Base> class FactoryRegistry {
public:
  static void registerFactory(Base& factory) {
    auto result = factories().emplace(std::make_pair(factory.name(), &factory));
    if (!result.second) {
      throw EnvoyException(fmt::format("Double registration for name: '{}'", factory.name()));
    }
  }

  /**
   * Gets a factory by name.  If the name isn't found in the registry, returns nullptr.
   */
  static Base* getFactory(const std::string& name) {
    auto it = factories().find(name);
    if (it == factories().end()) {
      return nullptr;
    }
    return it->second;
  }

private:
  /**
   * Gets the current map of factory implementations.
   */
  static std::unordered_map<std::string, Base*>& factories() {
    static std::unordered_map<std::string, Base*>* factories =
        new std::unordered_map<std::string, Base*>;
    return *factories;
  }
};

/**
 * Factory registration template. Enables users to register a particular implementation factory with
 * the FactoryRegistry by instantiating this templated class with the specific factory class and the
 * general Base class to which that factory conforms.
 *
 * Because factories are generally registered once and live for the length of the program, the
 * standard use of this class is static instantiation within a linked implementation's translation
 * unit. For an example of a typical use case, @see NamedNetworkFilterConfigFactory.
 *
 * Example registration: static Registry::RegisterFactory<SpecificFactory, BaseFactory> registered_;
 */
template <class T, class Base> class RegisterFactory {
public:
  /**
   * Contructor that registers an instance of the factory with the FactoryRegistry.
   */
  RegisterFactory() {
    static T* instance = new T;
    FactoryRegistry<Base>::registerFactory(*instance);
  }
};

} // namespace Registry
} // namespace Envoy


text:
@interface Session : NSObject

@property (nonatomic, strong) User* user;
@property (nonatomic, assign) BOOL muted;

- (void) loadData;
- (void) saveData;

@end


text:
package com.redis.service.cacheable;

import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;

import org.springframework.cache.Cache;
import org.springframework.cache.support.SimpleValueWrapper;
import org.springframework.util.StringUtils;

import com.redis.persistence.cache.BaseValueCache;

public class RedisCache implements Cache{

    @Resource(name = "baseRedisCache")
    private BaseValueCache<String, Object> baseCache;

    public BaseValueCache<String, Object> getBaseCache() {
        return baseCache;
    }

    public void setBaseCache(BaseValueCache<String, Object> baseCache) {
        this.baseCache = baseCache;
    }

    /**
     * 缓存名称
     */
	private String name;

	/**
     * 超时时间
     */
    private Long timeout = 1000L;

	public void setName(String name) {
        this.name = name;
    }

	@Override
	public String getName() {
		return this.name;
	}

	public long getTimeout() {
        return timeout;
    }

    public void setTimeout(long timeout) {
        this.timeout = timeout;
    }

    @Override
	public Object getNativeCache() {
		return this.baseCache;
	}

	@Override
	public ValueWrapper get(Object key) {
	    Object object = this.baseCache.get(key.toString());
	    return (object != null ? new SimpleValueWrapper(object) : null);
	}

	@SuppressWarnings("unchecked")
    @Override
	public <T> T get(Object key, Class<T> type) {
	    if (StringUtils.isEmpty(key) || null == type) {
            return null;
        } else {
            Object object = this.baseCache.get(key.toString());
            if (type.isInstance(object) && null != object) {
                return (T) object;
            } else {
                return null;
            }
        }
	}

	@Override
	public void put(Object key, Object value) {System.err.println("put");
        this.baseCache.set(key.toString(), value, timeout, TimeUnit.SECONDS);
	}

	@Override
	public ValueWrapper putIfAbsent(Object key, Object value) {
		// TODO Auto-generated method stub
		return null;
	}

	@Override
	public void evict(Object key) {
		this.baseCache.del(key.toString());
	}

	@Override
	public void clear() {
		this.baseCache.flushDb();
	}

}


text:
{% extends "base.html" %}

{% block content %}

Edit workout for {{workout.athlete_name()}}

<form action="" method="post" name="workout">
  {{form.hidden_tag()}}

    Distance ( mi )

      {{ form.distance(class_="col-sm-10 form-control") }}

    Speed ( mi/min )

      {{ form.speed(class_="col-sm-10 form-control") }}

    Date

      {{ form.date(class_="col-sm-10 form-control") }}

    Note

      {{ form.note(class_="col-sm-10 form-control") }}

      <button type="submit" class="btn btn-default">Update</button>

</form>

{% endblock %}


text:
class PerconaServer < Formula
  desc "Drop-in MySQL replacement"
  homepage "https://www.percona.com"
  url "https://www.percona.com/downloads/Percona-Server-8.0/Percona-Server-8.0.19-10/source/tarball/percona-server-8.0.19-10.tar.gz"
  sha256 "b819d81b9cdef497dd5fd1044ddb033d222b986cf610cb5d4bb1fa5010dba580"

  bottle do
    sha256 "c6ad05c52e82f419f65a46bd627c784fec43dfb8545e68fb4939995fb5fefed2" => :catalina
    sha256 "cae8782ea16aa5fdfebe4ccac3189d2e7fbdc0d6290c0b8fda6ab46792f956eb" => :mojave
    sha256 "30719045c2ee376f8cf269e12fcd307f7d0313338b59b6e1c24861207177b287" => :high_sierra
  end

  pour_bottle? do
    reason "The bottle needs a var/mysql datadir (yours is var/percona)."
    satisfy { datadir == var/"mysql" }
  end

  depends_on "cmake" => :build

  # https://github.com/Homebrew/homebrew-core/issues/1475
  # Needs at least Clang 3.3, which shipped alongside Lion.
  # Note: MySQL themselves don't support anything below Sierra.
  depends_on :macos => :yosemite
  depends_on "openssl@1.1"

  conflicts_with "mariadb", "mysql",
    :because => "percona, mariadb, and mysql install the same binaries."
  conflicts_with "protobuf",
    :because => "both install libprotobuf(-lite) libraries."

  # https://bugs.mysql.com/bug.php?id=86711
  # https://github.com/Homebrew/homebrew-core/pull/20538
  fails_with :clang do
    build 800
    cause "Wrong inlining with Clang 8.0, see MySQL Bug #86711"
  end

  resource "boost" do
    url "https://dl.bintray.com/boostorg/release/1.70.0/source/boost_1_70_0.tar.bz2"
    sha256 "430ae8354789de4fd19ee52f3b1f739e1fba576f0aded0897c3c2bc00fb38778"
  end

  # Where the database files should be located. Existing installs have them
  # under var/percona, but going forward they will be under var/mysql to be
  # shared with the mysql and mariadb formulae.
  def datadir
    @datadir ||= (var/"percona").directory? ? var/"percona" : var/"mysql"
  end

  def install
    # -DINSTALL_* are relative to `CMAKE_INSTALL_PREFIX` (`prefix`)
    args = %W[
      -DFORCE_INSOURCE_BUILD=1
      -DCOMPILATION_COMMENT=Homebrew
      -DDEFAULT_CHARSET=utf8mb4
      -DDEFAULT_COLLATION=utf8mb4_0900_ai_ci
      -DINSTALL_DOCDIR=share/doc/#{name}
      -DINSTALL_INCLUDEDIR=include/mysql
      -DINSTALL_INFODIR=share/info
      -DINSTALL_MANDIR=share/man
      -DINSTALL_MYSQLSHAREDIR=share/mysql
      -DINSTALL_PLUGINDIR=lib/percona-server/plugin
      -DMYSQL_DATADIR=#{datadir}
      -DSYSCONFDIR=#{etc}
      -DWITH_SSL=yes
      -DWITH_UNIT_TESTS=OFF
      -DWITH_EMBEDDED_SERVER=ON
      -DENABLED_LOCAL_INFILE=1
      -DWITH_INNODB_MEMCACHED=ON
      -DWITH_EDITLINE=system
    ]

    # MySQL >5.7.x mandates Boost as a requirement to build & has a strict
    # version check in place to ensure it only builds against expected release.
    # This is problematic when Boost releases don't align with MySQL releases.
    (buildpath/"boost").install resource("boost")
    args << "-DWITH_BOOST=#{buildpath}/boost"

    # Percona MyRocks does not compile on macOS
    # https://bugs.launchpad.net/percona-server/+bug/1741639
    args.concat %w[-DWITHOUT_ROCKSDB=1]

    # TokuDB does not compile on macOS
    # https://bugs.launchpad.net/percona-server/+bug/1531446
    args.concat %w[-DWITHOUT_TOKUDB=1]

    system "cmake", ".", *std_cmake_args, *args
    system "make"
    system "make", "install"

    (prefix/"mysql-test").cd do
      system "./mysql-test-run.pl", "status", "--vardir=#{Dir.mktmpdir}"
    end

    # Remove the tests directory
    rm_rf prefix/"mysql-test"

    # Don't create databases inside of the prefix!
    # See: https://github.com/Homebrew/homebrew/issues/4975
    rm_rf prefix/"data"

    # Fix up the control script and link into bin.
    inreplace "#{prefix}/support-files/mysql.server",
              /^(PATH=".*)(")/,
              "\\1:#{HOMEBREW_PREFIX}/bin\\2"
    bin.install_symlink prefix/"support-files/mysql.server"

    # Install my.cnf that binds to 127.0.0.1 by default
    (buildpath/"my.cnf").write <<~EOS
      # Default Homebrew MySQL server config
      [mysqld]
      # Only allow connections from localhost
      bind-address = 127.0.0.1
    EOS
    etc.install "my.cnf"
  end

  def post_install
    # Make sure the datadir exists
    datadir.mkpath
    unless (datadir/"mysql/user.frm").exist?
      ENV["TMPDIR"] = nil
      system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
        "--basedir=#{prefix}", "--datadir=#{datadir}", "--tmpdir=/tmp"
    end
  end

  def caveats
    s = <<~EOS
      We've installed your MySQL database without a root password. To secure it run:
          mysql_secure_installation
      MySQL is configured to only allow connections from localhost by default
      To connect run:
          mysql -uroot
    EOS
    if (my_cnf = ["/etc/my.cnf", "/etc/mysql/my.cnf"].find { |x| File.exist? x })
      s += <<~EOS
        A "#{my_cnf}" from another install may interfere with a Homebrew-built
        server starting up correctly.
      EOS
    end
    s
  end

  plist_options :manual => "mysql.server start"

  def plist
    <<~EOS
      <?xml version="1.0" encoding="UTF-8"?>
      <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
      <plist version="1.0">
      <dict>
        <key>KeepAlive</key>
        <true/>
        <key>Label</key>
        <string>#{plist_name}</string>
        <key>ProgramArguments</key>
        <array>
          <string>#{opt_bin}/mysqld_safe</string>
          <string>--datadir=#{datadir}</string>
        </array>
        <key>RunAtLoad</key>
        <true/>
        <key>WorkingDirectory</key>
        <string>#{datadir}</string>
      </dict>
      </plist>
    EOS
  end

  test do
    # Expects datadir to be a completely clean dir, which testpath isn't.
    dir = Dir.mktmpdir
    system bin/"mysqld", "--initialize-insecure", "--user=#{ENV["USER"]}",
    "--basedir=#{prefix}", "--datadir=#{dir}", "--tmpdir=#{dir}"

    pid = fork do
      exec bin/"mysqld", "--bind-address=127.0.0.1", "--datadir=#{dir}"
    end
    sleep 2

    output = shell_output("curl 127.0.0.1:3306")
    output.force_encoding("ASCII-8BIT") if output.respond_to?(:force_encoding)
    assert_match version.to_s, output
  ensure
    Process.kill(9, pid)
    Process.wait(pid)
  end
end


text:
<?php

namespace udecBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use udecBundle\Entity\Estudiante;
use udecBundle\Form\EstudianteType;

class EstudiantesController extends Controller
{
    public function indexAction()
    {
        $repository = $this->getDoctrine()->getRepository("udecBundle:Estudiante");
        $estudiantes=$repository->findAll();

        $estudiante = new Estudiante();

        $form = $this->createForm(new EstudianteType(),$estudiante);

        return $this->render('udecBundle:estudiantes:index.html.twig', array('estudiantes' => $estudiantes, 'form' => $form->createView()));
    }

    public function EstudianteAction($codigo)
    {
        $repository = $this->getDoctrine()->getRepository("udecBundle:Estudiante");
        $estudiante=$repository->find($codigo);
        return $this->render('udecBundle:estudiantes:estudiante.html.twig',array('estudiante' => $estudiante));
    }

    public function NuevoAction()
    {
        $estudiante = new Estudiante();
        $form = $this->createFormBuilder($estudiante)
            ->add('Codigo', 'number')
            ->add('Cedula', 'number')
            ->add('Nombre', 'text')
            ->add('Apellido', 'text')
            ->add('telefonos','collection',array('type' => 'number','by_reference' => '?','allow_add'=>'true','options'  => array(
        'required'  => false,
        'attr'      => array('class' => 'form-control')
    )))
            ->add('crear', 'submit')
            ->getForm();

        return $this->render('udecBundle:estudiantes:nuevo.html.twig', array('form' => $form->createView()));
    }

    public function GuardarAction()
    {
        $form = $this->createForm(new EstudianteType());

        $form->bind($this->getRequest());
        if ($form->isValid()) {
        // guardar la tarea en la base de datos
            //Insertar a BD
            $estudiante = new Estudiante();

            $estudiante = $form->getData();

            $em=$this->getDoctrine()->getManager();
            $em->persist($estudiante);
            $em->flush();

            return $this->redirect($this->generateUrl('udec_estudiantes'));
        }else{
            return $this->render('udecBundle:estudiantes:index.html.twig', array('form' => $form->createView()));
        }
    }
}


text:
This repository contains information about the minimal metadata for imaging mass spectrometry (imaging MS) as developed in the METASPACE project. In particular, the metadata is required to provide during the [upload of the imaging MS data to METASPACE](http://upload.metaspace2020.eu/).

* [JSON schema for the minimal metadata](min metadata schema.json)

The work on aligning this metadata with metadata required by the [EBI MetaboLights repository](www.ebi.ac.uk/metabolights/) is in progress.

## Funding

This project is funded from the [European Horizon2020](https://ec.europa.eu/programmes/horizon2020/)
project [METASPACE](http://project.metaspace2020.eu/) (no. 634402),
[NIH NIDDK project KPMP](http://kpmp.org/)
and internal funds of the [European Molecular Biology Laboratory](https://www.embl.org/).

## License

This project is licensed under the [Apache 2.0 license](LICENSE).


text:
module Currentize
  def self.format(number, currency = "$")
    arr = number.to_s.split("").reverse
    currentized = ""
    arr.each_with_index do |n, idx|
      if idx % 3 == 0 && idx > 0
        currentized << ","
        currentized << n
      else
        currentized << n
      end
    end
    currency + currentized.reverse
  end
end