text:
package water.fvec;

import jsr166y.CountedCompleter;
import water.*;
import water.nbhm.NonBlockingHashMapLong;
import water.util.Log;
import water.util.Utils;

import java.util.Arrays;
import java.util.UUID;

import static water.util.Utils.seq;

/**
 * A single distributed vector column.
 *

 * A distributed vector has a count of elements, an element-to-chunk mapping, a
 * Java type (mostly determines rounding on store and display), and functions
 * to directly load elements without further indirections.  The data is
 * compressed, or backed by disk or both.  *Writing* to elements may throw if the
 * backing data is read-only (file backed).
 *

 *

 *  Vec Key format is: Key. VEC - byte, 0 - byte,   0    - int, normal Key bytes.
 * DVec Key format is: Key.DVEC - byte, 0 - byte, chunk# - int, normal Key bytes.
 *

 *
 * The main API is at, set, and isNA:

 *

 *   double  at  ( long row );  // Returns the value expressed as a double.  NaN if missing.
 *   long    at8 ( long row );  // Returns the value expressed as a long.  Throws if missing.
 *   boolean isNA( long row );  // True if the value is missing.
 *   set( long row, double d ); // Stores a double; NaN will be treated as missing.
 *   set( long row, long l );   // Stores a long; throws if l exceeds what fits in a double and any floats are ever set.
 *   setNA( long row );         // Sets the value as missing.
 *

 *
 * Note this dangerous scenario: loading a missing value as a double, and
 * setting it as a long:

 *   set(row,(long)at(row)); // Danger!
 *

 * The cast from a Double.NaN to a long produces a zero!  This code will
 * replace a missing value with a zero.
 *
 * @author Cliff Click
 */
public class Vec extends Iced {
  /** Log-2 of Chunk size. */
  public static final int LOG_CHK = ValueArray.LOG_CHK; // Same as VA to help conversions
  /** Chunk size.  Bigger increases batch sizes, lowers overhead costs, lower
   * increases fine-grained parallelism. */
  static final int CHUNK_SZ = 1 << LOG_CHK;

  /** Key mapping a Value which holds this Vec.  */
  final public Key _key;        // Top-level key
  /** Element-start per chunk.  Always zero for chunk 0.  One more entry than
   *  chunks, so the last entry is the total number of rows.  This field is
   *  dead/ignored in subclasses that are guaranteed to have fixed-sized chunks
   *  such as file-backed Vecs. */
  final public long _espc[];

  /** Enum/factor/categorical names. */
  public String [] _domain;
  /** Time parse, index into Utils.TIME_PARSE, or -1 for not-a-time */
  public byte _time;
  /** RollupStats: min/max/mean of this Vec lazily computed.  */
  private double _min, _max, _mean, _sigma;
  long _size;
  boolean _isInt;               // All ints
  boolean _isUUID;              // All UUIDs (or zero or missing)
  /** The count of missing elements.... or -2 if we have active writers and no
   *  rollup info can be computed (because the vector is being rapidly
   *  modified!), or -1 if rollups have not been computed since the last
   *  modification.   */
  volatile long _naCnt=-1;

  private long _last_write_timestamp = System.currentTimeMillis();
  private long _checksum_timestamp = -1;
  private long _checksum = 0;

  /** Maximal size of enum domain */
  public static final int MAX_ENUM_SIZE = 10000;

  /** Main default constructor; requires the caller understand Chunk layout
   *  already, along with count of missing elements.  */
  public Vec( Key key, long espc[]) { this(key, espc, null); }
  public Vec( Key key, long espc[], String[] domain) { this(key,espc,domain,false,(byte)-1); }
  public Vec( Key key, long espc[], String[] domain, boolean hasUUID, byte time) {
    assert key._kb[0]==Key.VEC;
    _key = key;
    _espc = espc;
    _time = time;               // is-a-time, or not (and what flavor used to parse time)
    _isUUID = hasUUID;          // all-or-nothing UUIDs
    _domain = domain;
  }

  protected Vec( Key key, Vec v ) { this(key, v._espc); assert group()==v.group(); }

  public Vec [] makeZeros(int n){return makeZeros(n,null,null,null);}
  public Vec [] makeZeros(int n, String [][] domain, boolean[] uuids, byte[] times){ return makeCons(n, 0, domain, uuids, times);}
  public Vec [] makeCons(int n, final long l, String [][] domain, boolean[] uuids, byte[] times){
    if( _espc == null ) throw H2O.unimpl(); // need to make espc for e.g. NFSFileVecs!
    final int nchunks = nChunks();
    Key [] keys = group().addVecs(n);
    final Vec [] vs = new Vec[keys.length];
    for(int i = 0; i < vs.length; ++i)
      vs[i] = new Vec(keys[i],_espc,
                      domain == null ? null    : domain[i],
                      uuids  == null ? false   : uuids [i],
                      times  == null ? (byte)-1: times [i]);
    new DRemoteTask(){
      @Override public void lcompute(){
        addToPendingCount(vs.length);
        for(int i = 0; i < vs.length; ++i){
          final int fi = i;
          new H2O.H2OCountedCompleter(this){
            @Override public void compute2(){
              long row=0;                 // Start row
              Key k;
              for( int i=0; i<nchunks; i++ ) {
                long nrow = chunk2StartElem(i+1); // Next row
                if((k = vs[fi].chunkKey(i)).home())
                  DKV.put(k,new C0LChunk(l,(int)(nrow-row)),_fs);
                row = nrow;
              }
              tryComplete();
            }
          }.fork();
        }
        tryComplete();
      }
      @Override public final void lonCompletion( CountedCompleter caller ) {
        Futures fs = new Futures();
        for(Vec v:vs) if(v._key.home()) DKV.put(v._key,v,fs);
        fs.blockForPending();
      }
      @Override public void reduce(DRemoteTask drt){}
    }.invokeOnAllNodes();
    return vs;
  }

  /**
   * Create an array of Vecs from scratch
   * @param rows Length of each vec
   * @param cols Number of vecs
   * @param val Constant value (long)
   * @param domain Factor levels (for factor columns)
   * @return Array of Vecs
   */
  static public Vec [] makeNewCons(final long rows, final int cols, final long val, final String [][] domain){
    int chunks = Math.min((int)rows, 4*H2O.NUMCPUS*H2O.CLOUD.size());
    long[] espc = new long[chunks+1];
    for (int i = 0; i<=chunks; ++i)
      espc[i] = i * rows / chunks;
    Vec v = new Vec(Vec.newKey(), espc);
    return v.makeCons(cols, val, domain,null,null);
  }

   /** Make a new vector with the same size and data layout as the old one, and
   *  initialized to zero. */
  public Vec makeZero()                { return makeCon(0); }
  public Vec makeZero(String[] domain) { return makeCon(0, domain); }
  /** Make a new vector with the same size and data layout as the old one, and
   *  initialized to a constant. */
  public Vec makeCon( final long l ) { return makeCon(l, null); }
  public Vec makeCon( final long l, String[] domain ) {
    Futures fs = new Futures();
    if( _espc == null ) throw H2O.unimpl(); // need to make espc for e.g. NFSFileVecs!
    final int nchunks = nChunks();
    final Vec v0 = new Vec(group().addVecs(1)[0],_espc, domain);
    new DRemoteTask(){
      @Override public void lcompute(){
        long row=0;                 // Start row
        Key k;
        for( int i=0; i<nchunks; i++ ) {
          long nrow = chunk2StartElem(i+1); // Next row
          if((k = v0.chunkKey(i)).home())
            DKV.put(k,new C0LChunk(l,(int)(nrow-row)),_fs);
          row = nrow;
        }
        tryComplete();
      }
      @Override public void reduce(DRemoteTask drt){}
    }.invokeOnAllNodes();
    DKV.put(v0._key,v0,fs);
    fs.blockForPending();
    return v0;
  }
  public Vec makeCon( final double d ) {
    Futures fs = new Futures();
    if( _espc == null ) throw H2O.unimpl(); // need to make espc for e.g. NFSFileVecs!
    if( (long)d==d ) return makeCon((long)d);
    final int nchunks = nChunks();
    final Vec v0 = new Vec(group().addVecs(1)[0],_espc);
    new DRemoteTask(){
      @Override public void lcompute(){
        long row=0;                 // Start row
        Key k;
        for( int i=0; i<nchunks; i++ ) {
          long nrow = chunk2StartElem(i+1); // Next row
          if((k = v0.chunkKey(i)).home())
            DKV.put(k,new C0DChunk(d,(int)(nrow-row)),_fs);
          row = nrow;
        }
        tryComplete();
      }
      @Override public void reduce(DRemoteTask drt){}
    }.invokeOnAllNodes();
    DKV.put(v0._key,v0,fs);
    fs.blockForPending();
    return v0;
  }
  public static Vec makeSeq( int len ) {
    Futures fs = new Futures();
    AppendableVec av = new AppendableVec(VectorGroup.VG_LEN1.addVec());
    NewChunk nc = new NewChunk(av,0);
    for (int r = 0; r < len; r++) nc.addNum(r+1);
    nc.close(0,fs);
    Vec v = av.close(fs);
    fs.blockForPending();
    return v;
  }
  public static Vec makeConSeq(double x, int len) {
    Futures fs = new Futures();
    AppendableVec av = new AppendableVec(VectorGroup.VG_LEN1.addVec());
    NewChunk nc = new NewChunk(av,0);
    for (int r = 0; r < len; r++) nc.addNum(x);
    nc.close(0,fs);
    Vec v = av.close(fs);
    fs.blockForPending();
    return v;
  }

  /** Create a new 1-element vector in the shared vector group for 1-element vectors. */
  public static Vec make1Elem(double d) {
    return make1Elem(Vec.VectorGroup.VG_LEN1.addVec(), d);
  }
  /** Create a new 1-element vector representing a scalar value. */
  public static Vec make1Elem(Key key, double d) {
    assert key.isVec();
    Vec v = new Vec(key,new long[]{0,1});
    Futures fs = new Futures();
    DKV.put(v.chunkKey(0),new C0DChunk(d,1),fs);
    DKV.put(key,v,fs);
    fs.blockForPending();
    return v;
  }

  /** Create a vector transforming values according given domain map.
   * @see Vec#makeTransf(int[], int[], String[])
   */
  public Vec makeTransf(final int[][] map, String[] finalDomain) { return makeTransf(map[0], map[1], finalDomain); }
  /**
   * Creates a new transformation from given values to given indexes of
   * given domain.
   * @param values values being mapped from
   * @param indexes values being mapped to
   * @param domain domain of new vector
   * @return always return a new vector which maps given values into a new domain
   */
  Vec makeTransf(final int[] values, final int[] indexes, final String[] domain) {
    if( _espc == null ) throw H2O.unimpl();
    Vec v0 = new TransfVec(values, indexes, domain, this._key, group().addVecs(1)[0],_espc);
    UKV.put(v0._key,v0);
    return v0;
  }
  /**
   * Makes a new transformation vector with identity mapping.
   *
   * @return a new transformation vector
   * @see Vec#makeTransf(int[], int[], String[])
   */
  Vec makeIdentityTransf() {
    assert _domain != null : "Cannot make an identity transformation of non-enum vector!";
    return makeTransf(seq(0, _domain.length), null, _domain);
  }
  /**
   * Makes a new transformation vector from given values to
   * values 0..domain size
   * @param values values which are mapped from
   * @param domain target domain which is mapped to
   * @return a new transformation vector providing mapping between given values and target domain.
   * @see Vec#makeTransf(int[], int[], String[])
   */
  Vec makeSimpleTransf(long[] values, String[] domain) {
    int is[] = new int[values.length];
    for( int i=0; i<values.length; i++ ) is[i] = (int)values[i];
    return makeTransf(is, null, domain);
  }
  /** This Vec does not have dependent hidden Vec it uses.
   *
   * @return dependent hidden vector or null
   */
  public Vec masterVec() { return null; }

  /**
   * Adapt given vector v to this vector.
   * I.e., unify domains, compute transformation, and call makeTransf().
   *
   * This vector is a leader - it determines a domain (i.e., {@link #domain()}) and mapping between values stored in vector
   * and domain values.
   * The vector v can contain different domain (subset, superset), hence the values stored in the vector
   * has to be transformed to the values determined by this vector. The resulting vector domain is the
   * same as this vector domain.
   *
   * Always returns a new vector and user's responsibility is delete the vector.
   *
   * @param v vector which should be adapter in according this vector.
   * @param exact should vector match exactly (recommended value is true).
   * @return a new vector which implements transformation of original values.
   */
  /*// Not used any more in code ??
  public Vec adaptTo(Vec v, boolean exact) {
    assert isInt() : "This vector has to be int/enum vector!";
    int[] domain = null;
    // Compute domain of this vector
    // - if vector is enum, use domain directly
    // - if vector is int, then vector numeric domain is collected and transformed to string domain
    // and then adapted
    String[] sdomain =
        (_domain == null)
        ? Utils.toStringMap(domain = new CollectDomain(this).doAll(this).domain()) // it is number-column
        : domain(); // it is enum
    // Compute transformation - domain map - each value in an array is one value from vector domain, its index
    // represents an index into string domain representation.
    int[] domMap = Model.getDomainMapping(v._domain, sdomain, exact);
    if (domain!=null) {
      // do a mapping from INT -> ENUM -> this vector ENUM
      domMap = Utils.compose(Utils.mapping(domain), domMap);
    }
    return this.makeTransf(domMap, sdomain);
  }*/

  /** Number of elements in the vector.  Overridden by subclasses that compute
   *  length in an alternative way, such as file-backed Vecs. */
  public long length() { return _espc[_espc.length-1]; }

  /** Number of chunks.  Overridden by subclasses that compute chunks in an
   *  alternative way, such as file-backed Vecs. */
  public int nChunks() { return _espc.length-1; }

  /** Whether or not this column parsed as a time, and if so what pattern was used. */
  public final boolean isTime(){ return _time>=0; }
  public final int timeMode(){ return _time; }
  public final String timeParse(){ return ParseTime.TIME_PARSE[_time]; }

  /** Map the integer value for a enum/factor/categorical to it's String.
   *  Error if it is not an ENUM.  */
  public String domain(long i) { return _domain[(int)i]; }

  /** Return an array of domains.  This is eagerly manifested for enum or
   *  categorical columns.  Returns null for non-Enum/factor columns. */
  public String[] domain() { return _domain; }

  /** Returns cardinality for enum domain or -1 for other types. */
  public int cardinality() { return isEnum() ? _domain.length : -1; }

  /** Transform this vector to enum.
   *  If the vector is integer vector then its domain is collected and transformed to
   *  corresponding strings.
   *  If the vector is enum an identity transformation vector is returned.
   *  Transformation is done by a {@link TransfVec} which provides a mapping between values.
   *
   *  @return always returns a new vector and the caller is responsible for vector deletion!
   */
  public Vec toEnum() {
    if( isEnum() ) return this.makeIdentityTransf(); // Make an identity transformation of this vector
    if( !isInt() ) throw new IllegalArgumentException("Enum conversion only works on integer columns");
    long[] domain;
    String[] sdomain = Utils.toString(domain = new CollectDomain(this).doAll(this).domain());
    if( domain.length > MAX_ENUM_SIZE ) throw new IllegalArgumentException("Column domain is too large to be represented as an enum: " + domain.length + " > " + MAX_ENUM_SIZE);
    return this.makeSimpleTransf(domain, sdomain);
  }

  /** Default read/write behavior for Vecs.  File-backed Vecs are read-only. */
  protected boolean readable() { return true ; }
  /** Default read/write behavior for Vecs.  AppendableVecs are write-only. */
  protected boolean writable() { return true; }

  /** Return column min - lazily computed as needed. */
  public double min()  { return rollupStats()._min; }
  /** Return column max - lazily computed as needed. */
  public double max()  { return rollupStats()._max; }
  /** Return column mean - lazily computed as needed. */
  public double mean() { return rollupStats()._mean; }
  /** Return column standard deviation - lazily computed as needed. */
  public double sigma(){ return rollupStats()._sigma; }
  /** Return column missing-element-count - lazily computed as needed. */
  public long  naCnt() { return rollupStats()._naCnt; }
  /** Is all integers? */
  public boolean isInt(){return rollupStats()._isInt; }
  /** Size of compressed vector data. */
  public long byteSize(){return rollupStats()._size; }

  public long checksum() {
    final long now = _last_write_timestamp;  // TODO: someone can be writing while we're checksuming. . .
    if (-1 != now && now == _checksum_timestamp) {
      return _checksum;
    }
    final long checksum = new ChecksummerTask().doAll(this).getChecksum();

    new TAtomic<Vec>() {
      @Override public Vec atomic(Vec v) {
          if (v != null) {
              v._checksum = checksum;
              v._checksum_timestamp = now;
          } return v;
      }
    }.invoke(_key);

    this._checksum = checksum;
    this._checksum_timestamp = now;

    return checksum;
  }
  /** Is the column a factor/categorical/enum?  Note: all "isEnum()" columns
   *  are are also "isInt()" but not vice-versa. */
  public final boolean isEnum(){return _domain != null;}
  public final boolean isUUID(){return _isUUID;}
  /** Is the column constant.
   *
Returns true if the column contains only constant values and it is not full of NAs.
 */
  public final boolean isConst() { return min() == max(); }
  /** Is the column bad.
   *
Returns true if the column is full of NAs.

   */
  public final boolean isBad() { return naCnt() == length(); }
  /** Is the column contains float values. */
  public final boolean isFloat() { return !isEnum() && !isInt(); }
  public final boolean isByteVec() { return (this instanceof ByteVec); }

  Vec setRollupStats( RollupStats rs ) {
    _min  = rs._min; _max = rs._max; _mean = rs._mean;
    _sigma = Math.sqrt(rs._sigma / (rs._rows - 1));
    _size =rs._size;
    _isInt= rs._isInt;
    if( rs._rows == 0 )         // All rows missing?  Then no rollups
      _min = _max = _mean = _sigma = Double.NaN;
    _naCnt= rs._naCnt;          // Volatile write last to announce all stats ready
    return this;
  }
  Vec setRollupStats( Vec v ) {
    _min  = v._min;   _max   = v._max;
    _mean = v._mean;  _sigma = v._sigma;
    _size = v._size;  _isInt = v._isInt;
    _naCnt= v._naCnt;  // Volatile write last to announce all stats ready
    return this;
  }

  /** Compute the roll-up stats as-needed, and copy into the Vec object */
  public Vec rollupStats() { return rollupStats(null); }
  // Allow a bunch of rollups to run in parallel.  If Futures is passed in, run
  // the rollup in the background.  *Always* returns "this".
  public Vec rollupStats(Futures fs) {
    Vec vthis = DKV.get(_key).get();
    if( vthis._naCnt==-2 )
      throw new IllegalArgumentException("Cannot ask for roll-up stats while the vector is being actively written.");
    if( vthis._naCnt>= 0 )      // KV store has a better answer
      return vthis == this ? this : setRollupStats(vthis);

    // KV store reports we need to recompute
    RollupStats rs = new RollupStats().dfork(this);
    if(fs != null) fs.add(rs); else setRollupStats(rs.getResult());
    return this;
  }

  /** A private class to compute the rollup stats */
  private static class RollupStats extends MRTask2<RollupStats> {
    double _min=Double.MAX_VALUE, _max=-Double.MAX_VALUE, _mean, _sigma;
    long _rows, _naCnt, _size;
    boolean _isInt=true;

    @Override public void postGlobal(){
      final RollupStats rs = this;
      _fr.vecs()[0].setRollupStats(rs);
      // Now do this remotely also
      new TAtomic<Vec>() {
        @Override public Vec atomic(Vec v) {
          if( v!=null && v._naCnt == -1 ) v.setRollupStats(rs);  return v;
        }
      }.fork(_fr._keys[0]);
    }

    @Override public void map( Chunk c ) {
      _size = c.byteSize();
      // UUID columns do not compute min/max/mean/sigma
      if( c._vec._isUUID ) {
        _min = _max = _mean = _sigma = Double.NaN;
        for( int i=0; i<c._len; i++ ) {
          if( c.isNA0(i) ) _naCnt++;
          else _rows++;
        }
        return;
      }
      // All other columns have useful rollups
      for( int i=0; i<c._len; i++ ) {
        double d = c.at0(i);
        if( Double.isNaN(d) ) _naCnt++;
        else {
          if( d < _min ) _min = d;
          if( d > _max ) _max = d;
          _mean += d;
          _rows++;
          if( _isInt && ((long)d) != d ) _isInt = false;
        }
      }
      _mean = _mean / _rows;
      for( int i=0; i<c._len; i++ ) {
        if( !c.isNA0(i) ) {
          double d = c.at0(i);
          _sigma += (d - _mean) * (d - _mean);
        }
      }
    }
    @Override public void reduce( RollupStats rs ) {
      _min = Math.min(_min,rs._min);
      _max = Math.max(_max,rs._max);
      _naCnt += rs._naCnt;
      double delta = _mean - rs._mean;
      if (_rows == 0) { _mean = rs._mean;  _sigma = rs._sigma; }
      else if (rs._rows > 0) {
        _mean = (_mean*_rows + rs._mean*rs._rows)/(_rows + rs._rows);
        _sigma = _sigma + rs._sigma + delta*delta * _rows*rs._rows / (_rows+rs._rows);
      }
      _rows += rs._rows;
      _size += rs._size;
      _isInt &= rs._isInt;
    }
    // Just toooo common to report always.  Drowning in multi-megabyte log file writes.
    @Override public boolean logVerbose() { return false; }
  } // class RollupStats

  /** A private class to compute the rollup stats */
  private static class ChecksummerTask extends MRTask2<ChecksummerTask> {
    public long checksum = 0;
    public long getChecksum() { return checksum; }

    @Override public void map( Chunk c ) {
      long _start = c._start;

      for( int i=0; i<c._len; i++ ) {
        long l = 81985529216486895L; // 0x0123456789ABCDEF
        if (! c.isNA0(i))
          l = c.at80(i);
        long global_row = _start + i;

        checksum ^= (17 * global_row);
        checksum ^= (23 * l);
      }
    } // map()

    @Override public void reduce( ChecksummerTask that ) {
      this.checksum ^= that.checksum;
    }
  } // class ChecksummerTask

  /** Writing into this Vector from *some* chunk.  Immediately clear all caches
   *  (_min, _max, _mean, etc).  Can be called repeatedly from one or all
   *  chunks.  Per-chunk row-counts will not be changing, just row contents and
   *  caches of row contents. */
  void preWriting( ) {
    if( _naCnt == -2 ) return; // Already set
    _naCnt = -2;
    if( !writable() ) throw new IllegalArgumentException("Vector not writable");
    // Set remotely lazily.  This will trigger a cloud-wide invalidate of the
    // existing Vec, and eventually we'll have to load a fresh copy of the Vec
    // with active writing turned on, and caching disabled.
    new TAtomic<Vec>() {
      @Override public Vec atomic(Vec v) { if( v!=null ) v._naCnt=-2; return v; }
    }.invoke(_key);
  }

  /** Stop writing into this Vec.  Rollup stats will again (lazily) be computed. */
  public void postWrite() {
    Vec vthis = DKV.get(_key).get();
    if( vthis._naCnt==-2 ) {
      _naCnt = vthis._naCnt=-1;
      new TAtomic<Vec>() {
        @Override public Vec atomic(Vec v) {
          if( v != null ) {
            v._last_write_timestamp = System.currentTimeMillis();
            if (v._naCnt==-2 ) {
                v._naCnt=-1;
            } // _naCnt != -2
          } // ! null
          return v;
        }
      }.invoke(_key);
    }
  }

  /** Convert a row# to a chunk#.  For constant-sized chunks this is a little
   *  shift-and-add math.  For variable-sized chunks this is a binary search,
   *  with a sane API (JDK has an insane API).  Overridden by subclasses that
   *  compute chunks in an alternative way, such as file-backed Vecs. */
  int elem2ChunkIdx( long i ) {
    assert 0 <= i && i < length() : "0 <= "+i+" < "+length();
    int lo=0, hi = nChunks();
    while( lo < hi-1 ) {
      int mid = (hi+lo)>>>1;
      if( i < _espc[mid] ) hi = mid;
      else                 lo = mid;
    }
    while( _espc[lo+1] == i ) lo++;
    return lo;
  }

  /** Convert a chunk-index into a starting row #.  For constant-sized chunks
   *  this is a little shift-and-add math.  For variable-sized chunks this is a
   *  table lookup. */
  public long chunk2StartElem( int cidx ) { return _espc[cidx]; }

  /** Number of rows in chunk. Does not fetch chunk content. */
  public int chunkLen( int cidx ) { return (int) (_espc[cidx + 1] - _espc[cidx]); }

  /** Get a Vec Key from Chunk Key, without loading the Chunk */
  static public Key getVecKey( Key key ) {
    assert key._kb[0]==Key.DVEC;
    byte [] bits = key._kb.clone();
    bits[0] = Key.VEC;
    UDP.set4(bits,6,-1); // chunk#
    return Key.make(bits);
  }

  /** Get a Chunk Key from a chunk-index.  Basically the index-to-key map. */
  public Key chunkKey(int cidx ) {
    byte [] bits = _key._kb.clone();
    bits[0] = Key.DVEC;
    UDP.set4(bits,6,cidx); // chunk#
    return Key.make(bits);
  }
  /** Get a Chunk's Value by index.  Basically the index-to-key map,
   *  plus the {@code DKV.get()}.  Warning: this pulls the data locally;
   *  using this call on every Chunk index on the same node will
   *  probably trigger an OOM!  */
  public Value chunkIdx( int cidx ) {
    Value val = DKV.get(chunkKey(cidx));
    assert checkMissing(cidx,val);
    return val;
  }

  protected boolean checkMissing(int cidx, Value val) {
    if( val != null ) return true;
    System.out.println("Error: Missing chunk "+cidx+" for "+_key);
    return false;
  }

  /** Make a new random Key that fits the requirements for a Vec key. */
  static public Key newKey(){return newKey(Key.make());}

  public static final int KEY_PREFIX_LEN = 4+4+1+1;
  /** Make a new Key that fits the requirements for a Vec key, based on the
   *  passed-in key.  Used to make Vecs that back over e.g. disk files. */
  static Key newKey(Key k) {
    byte [] kb = k._kb;
    byte [] bits = MemoryManager.malloc1(kb.length+KEY_PREFIX_LEN);
    bits[0] = Key.VEC;
    bits[1] = -1;         // Not homed
    UDP.set4(bits,2,0);   // new group, so we're the first vector
    UDP.set4(bits,6,-1);  // 0xFFFFFFFF in the chunk# area
    System.arraycopy(kb, 0, bits, 4+4+1+1, kb.length);
    return Key.make(bits);
  }

  /** Make a Vector-group key.  */
  public Key groupKey(){
    byte [] bits = _key._kb.clone();
    bits[0] = Key.VGROUP;
    UDP.set4(bits, 2, -1);
    UDP.set4(bits, 6, -1);
    return Key.make(bits);
  }
  /**
   * Get the group this vector belongs to.
   * In case of a group with only one vector, the object actually does not exist in KV store.
   *
   * @return VectorGroup this vector belongs to.
   */
  public final VectorGroup group() {
    Key gKey = groupKey();
    Value v = DKV.get(gKey);
    if(v != null)return v.get(VectorGroup.class);
    // no group exists so we have to create one
    return new VectorGroup(gKey,1);
  }

  /** The Chunk for a chunk#.  Warning: this loads the data locally!  */
  public Chunk chunkForChunkIdx(int cidx) {
    long start = chunk2StartElem(cidx); // Chunk# to chunk starting element#
    Value dvec = chunkIdx(cidx);        // Chunk# to chunk data
    Chunk c = dvec.get();               // Chunk data to compression wrapper
    long cstart = c._start;             // Read once, since racily filled in
    Vec v = c._vec;
    if( cstart == start && v != null) return c;     // Already filled-in
    assert cstart == -1 || v == null;       // Was not filled in (everybody racily writes the same start value)
    c._vec = this;             // Fields not filled in by unpacking from Value
    c._start = start;          // Fields not filled in by unpacking from Value
    return c;
  }
  /** The Chunk for a row#.  Warning: this loads the data locally!  */
  private Chunk chunkForRow_impl(long i) { return chunkForChunkIdx(elem2ChunkIdx(i)); }

  // Cache of last Chunk accessed via at/set api
  transient Chunk _cache;
  /** The Chunk for a row#.  Warning: this loads the data locally!  */
  public final Chunk chunkForRow(long i) {
    Chunk c = _cache;
    return (c != null && c._chk2==null && c._start <= i && i < c._start+c._len) ? c : (_cache = chunkForRow_impl(i));
  }
  /** Fetch element the slow way, as a long.  Floating point values are
   *  silently rounded to an integer.  Throws if the value is missing. */
  public final long  at8( long i ) { return chunkForRow(i).at8(i); }
  /** Fetch element the slow way, as a double.  Missing values are
   *  returned as Double.NaN instead of throwing. */
  public final double at( long i ) { return chunkForRow(i).at(i); }
  /** Fetch the missing-status the slow way. */
  public final boolean isNA(long row){ return chunkForRow(row).isNA(row); }

  /** Fetch element the slow way, as a long.  Throws if the value is missing or not a UUID. */
  public final long  at16l( long i ) { return chunkForRow(i).at16l(i); }
  public final long  at16h( long i ) { return chunkForRow(i).at16h(i); }

  /** Write element the VERY slow way, as a long.  There is no way to write a
   *  missing value with this call.  Under rare circumstances this can throw:
   *  if the long does not fit in a double (value is larger magnitude than
   *  2^52), AND float values are stored in Vector.  In this case, there is no
   *  common compatible data representation.
   *
   *  NOTE: For a faster way, but still slow, use the Vec.Writer below.
   *  */
  public final long   set( long i, long   l) {
    Chunk ck = chunkForRow(i);
    long ret = ck.set(i,l);
    Futures fs = new Futures();
    ck.close(ck.cidx(), fs); //slow to do this for every set -> use Writer if writing many values
    fs.blockForPending();
    postWrite();
    return ret;
  }
  /** Write element the VERY slow way, as a double.  Double.NaN will be treated as
   *  a set of a missing element.
   *  */
  public final double set( long i, double d) {
    Chunk ck = chunkForRow(i);
    double ret = ck.set(i,d);
    Futures fs = new Futures();
    ck.close(ck.cidx(), fs); //slow to do this for every set -> use Writer if writing many values
    fs.blockForPending();
    postWrite();
    return ret;
  }
  /** Write element the VERY slow way, as a float.  Float.NaN will be treated as
   *  a set of a missing element.
   *  */
  public final float  set( long i, float  f) {
    Chunk ck = chunkForRow(i);
    float ret = ck.set(i, f);
    Futures fs = new Futures();
    ck.close(ck.cidx(), fs); //slow to do this for every set -> use Writer if writing many values
    fs.blockForPending();
    postWrite();
    return ret;
  }
  /** Set the element as missing the VERY slow way.  */
  public final boolean setNA( long i ) {
    Chunk ck = chunkForRow(i);
    boolean ret = ck.setNA(i);
    Futures fs = new Futures();
    ck.close(ck.cidx(), fs); //slow to do this for every set -> use Writer if writing many values
    fs.blockForPending();
    postWrite();
    return ret;
  }

  /**
   * More efficient way to write randomly to a Vec - still slow, but much faster than Vec.set()
   *
   * Usage:
   * Vec.Writer vw = vec.open();
   * vw.set(0, 3.32);
   * vw.set(1, 4.32);
   * vw.set(2, 5.32);
   * vw.close();
   */
  public final static class Writer {
    Vec _vec;
    private Writer(Vec v){
      _vec=v;
      _vec.preWriting();
    }
    public final long   set( long i, long   l) { return _vec.chunkForRow(i).set(i,l); }
    public final double set( long i, double d) { return _vec.chunkForRow(i).set(i,d); }
    public final float  set( long i, float  f) { return _vec.chunkForRow(i).set(i,f); }
    public final boolean setNA( long i ) { return _vec.chunkForRow(i).setNA(i); }
    public void close() {
      Futures fs = new Futures();
      _vec.close(fs);
      fs.blockForPending();
      _vec.postWrite();
    }
  }

  public final Writer open() {
    return new Writer(this);
  }

  /** Close all chunks that are local (not just the ones that are homed)
   * This should only be called from a Writer object
   * */
  private void close(Futures fs) {
    int nc = nChunks();
    for( int i=0; i<nc; i++ ) {
      if (H2O.get(chunkKey(i)) != null) {
        chunkForChunkIdx(i).close(i, fs);
      }
    }
  }

  /** Pretty print the Vec: [#elems, min/mean/max]{chunks,...} */
  @Override public String toString() {
    String s = "["+length()+(_naCnt<0 ? ", {" : ","+_min+"/"+_mean+"/"+_max+", "+PrettyPrint.bytes(_size)+", {");
    int nc = nChunks();
    for( int i=0; i<nc; i++ ) {
      s += chunkKey(i).home_node()+":"+chunk2StartElem(i)+":";
      // CNC: Bad plan to load remote data during a toString... messes up debug printing
      // Stupidly chunkForChunkIdx loads all data locally
      // s += chunkForChunkIdx(i).getClass().getSimpleName().replaceAll("Chunk","")+", ";
    }
    return s+"}]";
  }

  public void remove( Futures fs ) {
    for( int i=0; i<nChunks(); i++ )
      UKV.remove(chunkKey(i),fs);
  }

  @Override public boolean equals( Object o ) {
    return o instanceof Vec && ((Vec)o)._key.equals(_key);
  }
  @Override public int hashCode() { return _key.hashCode(); }

  /** Always makes a copy of the given vector which shares the same
   * group.
   *
   * The user is responsible for deleting the returned vector.
   *
   * This can be expensive operation since it can force copy of data
   * among nodes.
   *
   * @param vec vector which is intended to be copied
   * @return a copy of vec which shared the same {@link VectorGroup} with this vector
   */
  public Vec align(final Vec vec) {
    assert ! this.group().equals(vec.group()) : "Vector align expects a vector from different vector group";
    assert this._size == vec._size : "Trying to align vectors with different length!";
    Vec avec = makeZero(); // aligned vector
    new MRTask2() {
      @Override public void map(Chunk c0) {
        long srow = c0._start;
        for (int r = 0; r < c0._len; r++) c0.set0(r, vec.at(srow + r));
      }
    }.doAll(avec);
    avec._domain = _domain;
    return avec;
  }

  /**
   * Class representing the group of vectors.
   *
   * Vectors from the same group have same distribution of chunks among nodes.
   * Each vector is member of exactly one group.  Default group of one vector
   * is created for each vector.  Group of each vector can be retrieved by
   * calling group() method;
   *
   * The expected mode of operation is that user wants to add new vectors
   * matching the source.  E.g. parse creates several vectors (one for each
   * column) which are all colocated and are colocated with the original
   * bytevector.
   *
   * To do this, user should first ask for the set of keys for the new vectors
   * by calling addVecs method on the target group.
   *
   * Vectors in the group will have the same keys except for the prefix which
   * specifies index of the vector inside the group.  The only information the
   * group object carries is it's own key and the number of vectors it
   * contains(deleted vectors still count).
   *
   * Because vectors(and chunks) share the same key-pattern with the group,
   * default group with only one vector does not have to be actually created,
   * it is implicit.
   *
   * @author tomasnykodym
   *
   */
  public static class VectorGroup extends Iced {
    public static VectorGroup newVectorGroup(){
      return new Vec(Vec.newKey(),(long[])null).group();
    }
    // The common shared vector group for length==1 vectors
    public static VectorGroup VG_LEN1 = new VectorGroup();
    final int _len;
    final Key _key;
    private VectorGroup(Key key, int len){_key = key;_len = len;}
    public VectorGroup() {
      byte[] bits = new byte[26];
      bits[0] = Key.VGROUP;
      bits[1] = -1;
      UDP.set4(bits, 2, -1);
      UDP.set4(bits, 6, -1);
      UUID uu = UUID.randomUUID();
      UDP.set8(bits,10,uu.getLeastSignificantBits());
      UDP.set8(bits,18,uu. getMostSignificantBits());
      _key = Key.make(bits);
      _len = 0;
    }
    public Key vecKey(int vecId){
      byte [] bits = _key._kb.clone();
      bits[0] = Key.VEC;
      UDP.set4(bits,2,vecId);//
      return Key.make(bits);
    }
    /**
     * Task to atomically add vectors into existing group.
     * @author tomasnykodym
     */
    private static class AddVecs2GroupTsk extends TAtomic<VectorGroup>{
      final Key _key;
      int _n;          // INPUT: Keys to allocate; OUTPUT: start of run of keys
      private AddVecs2GroupTsk(Key key, int n){_key = key; _n = n;}
      @Override public VectorGroup atomic(VectorGroup old) {
        int n = _n;             // how many
        // If the old group is missing, assume it is the default group-of-self
        // (having 1 ID already allocated for self), not a new group with
        // zero prior vectors.
        _n = old==null ? 1 : old._len; // start of allocated key run
        return new VectorGroup(_key, n+_n);
      }
    }
    // reserve range of keys and return index of first new available key
    public int reserveKeys(final int n){
      AddVecs2GroupTsk tsk = new AddVecs2GroupTsk(_key, n);
      tsk.invoke(_key);
      return tsk._n;
    }
    /**
     * Gets the next n keys of this group.
     * Performs atomic update of the group object to assure we get unique keys.
     * The group size will be updated by adding n.
     *
     * @param n number of keys to make
     * @return arrays of unique keys belonging to this group.
     */
    public Key [] addVecs(final int n){
      AddVecs2GroupTsk tsk = new AddVecs2GroupTsk(_key, n);
      tsk.invoke(_key);
      Key [] res = new Key[n];
      for(int i = 0; i < n; ++i)
        res[i] = vecKey(i + tsk._n);
      return res;
    }
    /**
     * Shortcut for addVecs(1).
     * @see #addVecs(int)
     */
    public Key addVec() {
      return addVecs(1)[0];
    }

    @Override public String toString() {
      return "VecGrp "+_key.toString()+", next free="+_len;
    }

    @Override public boolean equals( Object o ) {
      return o instanceof VectorGroup && ((VectorGroup)o)._key.equals(_key);
    }
    @Override public int hashCode() {
      return _key.hashCode();
    }
  }

  /**
   * Method to change the domain of the Vec.
   *
   * Can only be applied to factors (Vec with non-null domain) and
   * domain can only be set to domain of the same or greater length.
   *
   * Updating the domain requires updating the Vec header in the K/V and since chunks cache Vec header references,
   * need to execute distributed task to flush (null) those references).
   *
   * @param newDomain
   */
  public void changeDomain(String [] newDomain){
    if(_domain == null)throw new RuntimeException("Setting a domain to a non-factor Vector, call as.Factor() instead.");
    if(newDomain == null)throw new RuntimeException("Can not set domain to null. You have to convert the vec to numbers explicitly");
    if(newDomain.length < _domain.length) throw new RuntimeException("Setting domain to incompatible size. New domain must be at least the same length!");
    _domain = newDomain;
    // update the vec header in the K/V
    DKV.put(_key,this);
    // now flush the cached vec header references (still pointing to the old guy)
    new MRTask2(){
      @Override public void map(Chunk c){c._vec = null;}
    }.doAll(this);
  }

  /** Collect numeric domain of given vector */
  public static class CollectDomain extends MRTask2<CollectDomain> {
    transient NonBlockingHashMapLong<Object> _uniques;
    @Override protected void setupLocal() { _uniques = new NonBlockingHashMapLong(); }
    public CollectDomain(Vec v) { }
    @Override public void map(Chunk ys) {
      for( int row=0; row<ys._len; row++ )
        if( !ys.isNA0(row) )
          _uniques.put(ys.at80(row),"");
    }

    @Override public void reduce(CollectDomain mrt) {
      if( _uniques == mrt._uniques ) return;
      _uniques.putAll(mrt._uniques);
    }

    @Override public AutoBuffer write( AutoBuffer ab ) {
      super.write(ab);
      return ab.putA8(_uniques==null ? null : _uniques.keySetLong());
    }

    @Override public Freezable read( AutoBuffer ab ) {
      super.read(ab);
      assert _uniques == null || _uniques.size()==0;
      long ls[] = ab.getA8();
      _uniques = new NonBlockingHashMapLong();
      if( ls != null ) for( long l : ls ) _uniques.put(l,"");
      return this;
    }
    @Override public void copyOver(Freezable that) {
      super.copyOver(that);
      _uniques = ((CollectDomain)that)._uniques;
    }

    /** Returns exact numeric domain of given vector computed by this task.
     * The domain is always sorted. Hence:
     *    domain()[0] - minimal domain value
     *    domain()[domain().length-1] - maximal domain value
     */
    public long[] domain() {
      long[] dom = _uniques.keySetLong();
      Arrays.sort(dom);
      return dom;
    }
  }
}


text:
package edu.emory.library.spotlight.tests;

import java.util.List;
import java.util.HashMap;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.IOException;

import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import static org.junit.Assert.*;

import org.mockito.Mockito;

/* PowerMock used to be able to mock static methods */
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

import edu.emory.library.spotlight.SpotlightClient;
import edu.emory.library.spotlight.SpotlightAnnotation;
import edu.emory.library.utils.EULHttpUtils;

@RunWith(PowerMockRunner.class)
@PrepareForTest(EULHttpUtils.class)
public class SpotlightClientTest {

    // sample text to be annotated
    static String text = "Michael Longley was born in Belfast, Northern Ireland.";
    // annotation result for above text
    static String anntotationResponse;

    SpotlightClient mockSpotlightClient;

    // method to read file into a string; used to load fixtures
    // FIXME: duplicated code copied from other tests!!
    public static String readFile( String file ) throws IOException {
        // changed to getResourceAsStream to read from classpath inside jar
        InputStream is = SpotlightClientTest.class.getResourceAsStream(file);
        BufferedReader reader = new BufferedReader( new InputStreamReader(is));
        String         line = null;
        StringBuilder  stringBuilder = new StringBuilder();
        String         ls = System.getProperty("line.separator");

        while( ( line = reader.readLine() ) != null ) {
            stringBuilder.append( line );
            stringBuilder.append( ls );
        }

        return stringBuilder.toString();
    }

    @BeforeClass
    public static void setUpClass() throws Exception {
        // load fixture data
        anntotationResponse = readFile("spotlightReturn.json");
    }

    @Before
    public void setUp() {
        // init mock client
        this.mockSpotlightClient = Mockito.mock(SpotlightClient.class);
    }

    @After
    public void tearDown() {
        this.mockSpotlightClient = null;
    }

    @Rule
    public ExpectedException exception = ExpectedException.none();

    @Test
    public void testAnnotate() throws Exception {
        PowerMockito.mockStatic(EULHttpUtils.class);

        Mockito.when(this.mockSpotlightClient.annotate(text)).thenCallRealMethod();

        HashMap headers = new HashMap<String, String>();
        headers.put("Accept", "application/json");
        // required when querying via POST
        headers.put("Content-Type", "application/x-www-form-urlencoded");

        HashMap params = new HashMap<String, String>();
        params.put("text", text);
        params.put("types", "Person,Place,Organisation");

        Mockito.when(EULHttpUtils.postUrlContents(Mockito.anyString(),
            Mockito.eq(headers), Mockito.eq(params))).thenReturn(anntotationResponse);

        List<SpotlightAnnotation> results = this.mockSpotlightClient.annotate(this.text);

        // inspect annotations initialized from fixture
        assertEquals(3, results.size());
        assertTrue(results.get(0) instanceof SpotlightAnnotation);

        // do some minimal inspection of the three results
        SpotlightAnnotation anno = results.get(0);
        assertEquals("http://dbpedia.org/resource/Michael_Longley", anno.getUri());
        assertEquals("Michael_Longley", anno.getId());
        assertEquals("Michael Longley", anno.getSurfaceForm());
        Integer expectedOffset = 0;
        assertEquals(expectedOffset, anno.getOffset());
        assertEquals("Personal", anno.getType());

        anno = results.get(1);
        assertEquals("born", anno.getSurfaceForm());
        expectedOffset = 20;
        assertEquals(expectedOffset, anno.getOffset());

        anno = results.get(2);
        assertEquals("Belfast, Northern Ireland", anno.getSurfaceForm());
        expectedOffset = 28;
        assertEquals(expectedOffset, anno.getOffset());
        assertEquals("Geographic", anno.getType());

        // TODO: test calling annotate with custom confidence/support values?
    }

    // TODO: can we test getLabel and getAbstract without querying dbpedia in unit tests?
    //@Test   // NOTE: disabling for now; re-enable to test when needed
    public void testDBpediaProperties() throws Exception {
        PowerMockito.mockStatic(EULHttpUtils.class);

        Mockito.when(this.mockSpotlightClient.annotate(text)).thenCallRealMethod();

        HashMap headers = new HashMap<String, String>();
        headers.put("Accept", "application/json");
        headers.put("Content-Type", "application/x-www-form-urlencoded");
        HashMap params = new HashMap<String, String>();
        params.put("text", text);
        params.put("types", "Person,Place,Organisation");
        Mockito.when(EULHttpUtils.postUrlContents(Mockito.anyString(),
            Mockito.eq(headers), Mockito.eq(params))).thenReturn(anntotationResponse);
        List<SpotlightAnnotation> results = this.mockSpotlightClient.annotate(this.text);

        SpotlightAnnotation anno = results.get(0);
        assertEquals("Michael Longley", anno.getLabel());
        assertEquals("Michael Longley, CBE (born 27 July 1939) is a Northern Irish poet from Belfast.",
            anno.getAbstract());

    }

}

redpajama_set_name: RedPajamaGithub


text:
"""Discover AVM FRITZ devices."""
from . import SSDPDiscoverable

class Discoverable(SSDPDiscoverable):
    """Add support for discovering AVM FRITZ devices."""

    def get_entries(self):
        """Get all AVM FRITZ entries."""
        return self.find_by_st("urn:schemas-upnp-org:device:fritzbox:1")


text:
.button {
  background-color: #cff;
}


text:
#ifndef __IDENTIFIER_INFO_H__
#define __IDENTIFIER_INFO_H__

#include "unicode/utypes.h"

#include "unicode/uniset.h"
#include "unicode/uspoof.h"
#include "uhash.h"

U_NAMESPACE_BEGIN

class ScriptSet;

// TODO(andy): review consistency of reference vs pointer arguments to the funcions.

/**
 * This class analyzes a possible identifier for script and identifier status. Use it by calling setIdentifierProfile
 * then setIdentifier. Available methods include:
 *

 *
call getScripts for the specific scripts in the identifier. The identifier contains at least one character in
 * each of these.
 *
call getAlternates to get cases where a character is not limited to a single script. For example, it could be
 * either Katakana or Hiragana.
 *
call getCommonAmongAlternates to find out if any scripts are common to all the alternates.
 *
call getNumerics to get a representative character (with value zero) for each of the decimal number systems in
 * the identifier.
 *
call getRestrictionLevel to see what the UTS36 restriction level is.
 *

 *
 * This is a port from ICU4J of class com.ibm.icu.text.IdentifierInfo
 */
class U_I18N_API IdentifierInfo : public UMemory {

  public:
    /**
     * Create an identifier info object. Subsequently, call setIdentifier(), etc.
     * @internal
     */
    IdentifierInfo(UErrorCode &status);

    /**
      * Destructor
      */
    virtual ~IdentifierInfo();

  private:
    /* Disallow copying for now. Can be added if there's a need. */
    IdentifierInfo(const IdentifierInfo &other);

  public:

    /**
     * Set the identifier profile: the characters that are to be allowed in the identifier.
     *
     * @param identifierProfile the characters that are to be allowed in the identifier
     * @return this
     * @internal
     */
    IdentifierInfo &setIdentifierProfile(const UnicodeSet &identifierProfile);

    /**
     * Get the identifier profile: the characters that are to be allowed in the identifier.
     *
     * @return The characters that are to be allowed in the identifier.
     * @internal
     */
    const UnicodeSet &getIdentifierProfile() const;

    /**
     * Set an identifier to analyze. Afterwards, call methods like getScripts()
     *
     * @param identifier the identifier to analyze
     * @param status Errorcode, set if errors occur.
     * @return this
     * @internal
     */
    IdentifierInfo &setIdentifier(const UnicodeString &identifier, UErrorCode &status);

    /**
     * Get the identifier that was analyzed. The returned string is owned by the ICU library,
     * and must not be deleted by the caller.
     *
     * @return the identifier that was analyzed.
     * @internal
     */
    const UnicodeString *getIdentifier() const;

    /**
     * Get the scripts found in the identifiers.
     *
     * @return the set of explicit scripts.
     * @internal
     */
    const ScriptSet *getScripts() const;

    /**
     * Get the set of alternate scripts found in the identifiers. That is, when a character can be in two scripts, then
     * the set consisting of those scripts will be returned.
     *
     * @return a uhash, with each key being of type (ScriptSet *).
     *         This is a set, not a map, so the value stored in the uhash is not relevant.
     *         (It is, in fact, 1).
     *         Ownership of the uhash and its contents remains with the IndetifierInfo object,
     *         and remains valid until a new identifer is set or until the object is deleted.
     * @internal
     */
    const UHashtable *getAlternates() const;

    /**
     * Get the representative characters (zeros) for the numerics found in the identifier.
     *
     * @return the set of explicit scripts.
     * @internal
     */
    const UnicodeSet *getNumerics() const;

    /**
     * Find out which scripts are in common among the alternates.
     *
     * @return the set of scripts that are in common among the alternates.
     * @internal
     */
    const ScriptSet *getCommonAmongAlternates() const;

    /**
      * Get the number of scripts appearing in the identifier.
      *   Note: Common and Inherited scripts are omitted from the count.
      *   Note: Result may be high when the identifier contains characters
      *         with alternate scripts. The distinction between
      *         0, 1 and > 1 will remain valid, however.
      * @return the number of scripts.
      */
    int32_t getScriptCount() const;

#if !UCONFIG_NO_NORMALIZATION

    /**
     * Find the "tightest" restriction level that the identifier satisfies.
     *
     * @return the restriction level.
     * @internal
     */
    URestrictionLevel getRestrictionLevel(UErrorCode &status) const;

#endif /*!UCONFIG_NO_NORMALIZATION */

    UnicodeString toString() const;

    /**
     * Produce a readable string of alternates.
     *
     * @param alternates a UHashtable of UScriptSets.
     *        Keys only, no meaningful values in the UHash.
     * @return display form
     * @internal
     */
    static UnicodeString &displayAlternates(UnicodeString &dest, const UHashtable *alternates, UErrorCode &status);

    /**
     * Static memory cleanup function.
     * @internal
     */
    static UBool      cleanup();
  private:

    IdentifierInfo  & clear();
    UBool             containsWithAlternates(const ScriptSet &container, const ScriptSet &containee) const;

    UnicodeString     *fIdentifier;
    ScriptSet         *fRequiredScripts;
    UHashtable        *fScriptSetSet;
    ScriptSet         *fCommonAmongAlternates;
    UnicodeSet        *fNumerics;
    UnicodeSet        *fIdentifierProfile;

    static UnicodeSet *ASCII;
    static ScriptSet  *JAPANESE;
    static ScriptSet  *CHINESE;
    static ScriptSet  *KOREAN;
    static ScriptSet  *CONFUSABLE_WITH_LATIN;

};

U_NAMESPACE_END

#endif // __IDENTIFIER_INFO_H__


text:
[![Build Status](https://travis-ci.org/davewwww/TaggedServices.svg?branch=master)](https://travis-ci.org/davewwww/TaggedServices) [![Coverage Status](https://coveralls.io/repos/davewwww/TaggedServices/badge.svg)](https://coveralls.io/r/davewwww/TaggedServices)

==============
TaggedServices
==============

Find and use your tagged services via service configuration instead of building compiler passes every time.

### Installation
=================

Add the CompilerPass to your AppKernel or a Bundle.

```php
#AppKernel.php

protected function buildContainer()
{
    $container = parent::buildContainer();
    $container->addCompilerPass(new TaggedServicesPass());
}
```

or to your Bundle

```php
#FooBundle.php

protected function build(ContainerBuilder $container)
{
    parent::build($container);
    $container->addCompilerPass(new TaggedServicesPass());
}
```

### Tag your services
=====================

Tag your services with your own tag as usual and give them an name with the 'type' parameter.

```yaml
#services.yml

services:
  my.service.foo:
    class: My\Service\Foo
    tags:
      - {name: "my.services", type: "foo"}

  my.service.bar:
    class: My\Service\Bar
    tags:
      - {name: "my.services", type: "bar"}
```

### Use your tagged services
============================

Now add the 'tagged_services' tag with the 'find_tag' parameter to the service that gets injected all tagged services.

```yaml
#services.yml

services:
  my.service.container:
    class: My\Service\MyServiceContainer
    arguments: [[]]
    tags:
      - { name: 'tagged_services', find_tag: 'my.services' }
```

Now your MyServiceContainer will get a array with all tagged services.

```php
#MyServiceContainer.php

class MyServiceContainer {

    private $myServices = array();
    private $myFooService;

    function __construct(array $myServices)
    {
        $this->myServices = $myServices;
        $this->myFooService = $myServices['foo'];
    }
}
```


text:
require 'fog/bluebox'
require 'fog/compute'

module Fog
  module Compute
    class Bluebox < Fog::Service

      requires :bluebox_api_key, :bluebox_customer_id
      recognizes :bluebox_host, :bluebox_port, :bluebox_scheme, :persistent

      model_path 'fog/bluebox/models/compute'
      model       :flavor
      collection  :flavors
      model       :image
      collection  :images
      model       :server
      collection  :servers
      model       :location
      collection  :locations

      request_path 'fog/bluebox/requests/compute'
      request :create_block
      request :destroy_block
      request :get_block
      request :get_blocks
      request :get_location
      request :get_locations
      request :get_product
      request :get_products
      request :get_template
      request :get_templates
      request :create_template
      request :destroy_template
      request :reboot_block

      class Mock

        def self.data
          @data ||= Hash.new do |hash, key|
            hash[key] = {}
          end
        end

        def self.reset
          @data = nil
        end

        def initialize(options={})
          @bluebox_api_key = options[:bluebox_api_key]
        end

        def data
          self.class.data[@bluebox_api_key]
        end

        def reset_data
          self.class.data.delete(@bluebox_api_key)
        end

      end

      class Real

        def initialize(options={})
          @bluebox_api_key      = options[:bluebox_api_key]
          @bluebox_customer_id  = options[:bluebox_customer_id]
          @connection_options   = options[:connection_options] || {}
          @host       = options[:bluebox_host]    || "boxpanel.bluebox.net"
          @persistent = options[:persistent]      || false
          @port       = options[:bluebox_port]    || 443
          @scheme     = options[:bluebox_scheme]  || 'https'
          @connection = Fog::Connection.new("#{@scheme}://#{@host}:#{@port}", @persistent, @connection_options)
        end

        def reload
          @connection.reset
        end

        def request(params)
          params[:headers] ||= {}
          params[:headers].merge!({
            'Authorization' => "Basic #{Base64.encode64([@bluebox_customer_id, @bluebox_api_key].join(':')).delete("\r\n")}"
          })

          begin
            response = @connection.request(params)
          rescue Excon::Errors::HTTPStatusError => error
            raise case error
            when Excon::Errors::NotFound
              Fog::Compute::Bluebox::NotFound.slurp(error)
            else
              error
            end
          end
          unless response.body.empty?
            response.body = Fog::JSON.decode(response.body)
          end
          response
        end

      end
    end
  end
end


text:
// MIT License
// Copyright (c) 2011-2016 Elisée Maurer, Sparklin Labs, Creative Patterns
// Copyright (c) 2016 Thomas Morgner, Rabbit-StewDio Ltd.
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
using System;
using System.Xml.Linq;

namespace Steropes.UI.Styles.Io.Values
{
  public class BoolValueStylePropertySerializer : IStylePropertySerializer
  {
    public BoolValueStylePropertySerializer()
    {
    }

    public Type TargetType => typeof(bool);

    public string TypeId => "bool";

    public object Parse(IStyleSystem styleSystem, XElement reader, IStylePropertyContext context)
    {
      return (bool)reader;
    }

    public void Write(IStyleSystem styleSystem, XElement propertyElement, object value)
    {
      propertyElement.Value = value?.ToString() ?? "false";
    }
  }
}


text:
from decimal import Decimal
from django.contrib.sites.models import Site
from django.db.models import Q
from livesettings import config_value
from l10n.utils import moneyfmt
from product.models import Option, ProductPriceLookup, OptionGroup, Discount, Product, split_option_unique_id
from satchmo_utils.numbers import round_decimal
import datetime
import logging
import types
import string

log = logging.getLogger('product.utils')

def calc_discounted_by_percentage(price, percentage):
    if not percentage:
        return price
    if percentage > 1:
        log.warn("Correcting discount percentage, should be less than 1, is %s", percentage)
        percentage = percentage/100

    work = price * (1-percentage)
    cents = Decimal("0.01")
    return work.quantize(cents)

def find_auto_discounts(product):
    if not type(product) in (types.ListType, types.TupleType):
        product = (product,)
    today = datetime.date.today()
    discs = Discount.objects.filter(automatic=True, active=True, startDate__lte=today, endDate__gt=today)
    return discs.filter(Q(valid_products__in=product) | Q(allValid=True)).order_by('-percentage')

def find_best_auto_discount(product):
    discs = find_auto_discounts(product)
    if len(discs) > 0:
        return discs[0]
    else:
        return None

def productvariation_details(product, include_tax, user, create=False):
    """Build the product variation details, for conversion to javascript.

    Returns variation detail dictionary built like so:
    details = {
        "OPTION_KEY" : {
            "SLUG": "Variation Slug",
            "PRICE" : {"qty" : "$price", [...]},
            "SALE" : {"qty" : "$price", [...]},
            "TAXED" : "$taxed price",   # omitted if no taxed price requested
            "QTY" : 1
        },
        [...]
    }
    """

    ignore_stock = config_value('PRODUCT','NO_STOCK_CHECKOUT')
    discount = find_best_auto_discount(product)
    use_discount = discount and discount.percentage > 0

    if include_tax:
        from tax.utils import get_tax_processor
        taxer = get_tax_processor(user=user)
        tax_class = product.taxClass

    details = {'SALE' : use_discount}

    variations = ProductPriceLookup.objects.filter(parentid=product.id).order_by("-price")
    if variations.count() == 0:
        if create:
            log.debug('Creating price lookup for %s', product)
            ProductPriceLookup.objects.smart_create_for_product(product)
            variations = ProductPriceLookup.objects.filter(parentid=product.id).order_by("-price")
        else:
            log.warning('You must run satchmo_rebuild_pricing and add it to a cron-job to run every day, or else the product details will not work for product detail pages.')
    for detl in variations:
        key = detl.key
        if details.has_key(key):
            detail = details[key]
            qty = detl.quantity
        else:
            detail = {}
            detail['SLUG'] = detl.productslug

            if not detl.active:
                qty = round_decimal('-1.0')
            elif ignore_stock:
                qty = round_decimal('10000.0')
            else:
                qty = round_decimal(detl.items_in_stock)

            detail['QTY'] = round_decimal(qty)

            detail['PRICE'] = {}

            if use_discount:
                detail['SALE'] = {}

            if include_tax:
                detail['TAXED'] = {}
                if use_discount:
                    detail['TAXED_SALE'] = {}

            details[key] = detail

        qtykey = "%d" % detl.quantity

        price = detl.dynamic_price

        detail['PRICE'][qtykey] = moneyfmt(price)
        if use_discount:
            detail['SALE'][qtykey] = moneyfmt(calc_discounted_by_percentage(price, discount.percentage))

        if include_tax:
            tax_price = taxer.by_price(tax_class, price) + price
            detail['TAXED'][qtykey] = moneyfmt(tax_price)
            if use_discount:
                detail['TAXED_SALE'][qtykey] = moneyfmt(calc_discounted_by_percentage(tax_price, discount.percentage))

    return details

def rebuild_pricing():
    site = Site.objects.get_current()
    for lookup in ProductPriceLookup.objects.filter(siteid=site.id):
        lookup.delete()

    products = Product.objects.active_by_site(site=site, variations=False)

    productct = products.count()
    pricect = 0

    for product in products:
        prices = ProductPriceLookup.objects.smart_create_for_product(product)
        pricect += len(prices)

    return productct, pricect

def serialize_options(product, selected_options=()):
    """
    Return a list of optiongroups and options for display to the customer.
    Only returns options that are actually used by members of this product.

    Return Value:
    [
    {
    name: 'group name',
    id: 'group id',
    items: [{
        name: 'opt name',
        value: 'opt value',
        price_change: 'opt price',
        selected: False,
        },{..}]
    },
    {..}
    ]

    Note: This doesn't handle the case where you have multiple options and
    some combinations aren't available. For example, you have option_groups
    color and size, and you have a yellow/large, a yellow/small, and a
    white/small, but you have no white/large - the customer will still see
    the options white and large.
    """
    all_options = product.get_valid_options()
    group_sortmap = OptionGroup.objects.get_sortmap()

    # first get all objects
    # right now we only have a list of option.unique_ids, and there are
    # probably a lot of dupes, so first list them uniquely
    values = []

    if all_options != [[]]:
        vals = {}
        groups = {}
        opts = {}
        serialized = {}

        for options in all_options:
            for option in options:
                if not opts.has_key(option):
                    k, v = split_option_unique_id(option)
                    vals[v] = False
                    groups[k] = False
                    opts[option] = None

        for option in Option.objects.filter(option_group__id__in = groups.keys(), value__in = vals.keys()):
            uid = option.unique_id
            if opts.has_key(uid):
                opts[uid] = option

        # now we have all the objects in our "opts" dictionary, so build the serialization dict

        for option in opts.values():
            if not serialized.has_key(option.option_group_id):
                serialized[option.option_group.id] = {
                    'name': option.option_group.translated_name(),
                    'description': option.option_group.translated_description(),
                    'id': option.option_group.id,
                    'items': [],
                }
            if not option in serialized[option.option_group_id]['items']:
                serialized[option.option_group_id]['items'] += [option]
                option.selected = option.unique_id in selected_options

        # first sort the option groups
        for k, v in serialized.items():
            values.append((group_sortmap[k], v))

        if values:
            values.sort()
            values = zip(*values)[1]

        #now go back and make sure option items are sorted properly.
        for v in values:
            v['items'] = _sort_options(v['items'])

    log.debug('serialized: %s', values)

    log.debug('Serialized Options %s: %s', product.product.slug, values)
    return values

def _sort_options(lst):
    work = [(opt.sort_order, opt) for opt in lst]
    work.sort()
    return zip(*work)[1]

# All the functions below are used to validate custom attributes
# associated with a product or category.
# Custom ones can be added to the list via the admin setting ATTRIBUTE_VALIDATION

def validation_simple(value, obj=None):
    """
    Validates that at least one character has been entered.
    Not change is made to the value.
    """
    if len(value) > 1:
        return True, value
    else:
        return False, value

def validation_integer(value, obj=None):
    """
   Validates that value is an integer number.
   No change is made to the value
    """
    try:
        check = int(value)
        return True, value
    except:
        return False, value

def validation_yesno(value, obj=None):
    """
    Validates that yes or no is entered.
    Converts the yes or no to capitalized version
    """
    if string.upper(value) in ["YES","NO"]:
        return True, string.capitalize(value)
    else:
        return False, value

def validation_decimal(value, obj=None):
    """
    Validates that the number can be converted to a decimal
    """
    try:
        check = Decimal(value)
        return True, value
    except:
        return False, value

def import_validator(validator):
    try:
        import_name, function_name = validator.rsplit('.', 1)
    except ValueError:
        # no dot; treat it as a global
        func = globals().get(validator, None)
        if not func:
            # we use ImportError to keep error handling for callers simple
            raise ImportError
        return validator
    else:
        # The below __import__() call is from python docs, and is equivalent to:
        #
        #   from import_name import function_name
        #
        import_module = __import__(import_name, globals(), locals(), [function_name])

        return getattr(import_module, function_name)

def validate_attribute_value(attribute, value, obj):
    """
    Helper function for forms that wish to validation a value for an
    AttributeOption.
    """
    return import_validator(attribute.validation)(value, obj)


text:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Saldo extends CI_Controller {
	public function __construct()
	{
		parent::__construct();
		// $this->load->model('saldo_model');
		if ( ! $this->session->userdata('logged_in'))
    {
      redirect();
    }
	}

	public function index()
	{
		$data['menu'] = "Pribadi";
		$data['submenu'] = "P_Tabungan";
		$data['body'] = "admin/saldo/saldoSelect";
		custom_layout($data);
	}
}

/* End of file Saldo.php */
/* Location: ./application/controllers/Saldo.php */


text:
package gov.va.isaac.util;

import gov.va.isaac.config.generated.StatedInferredOptions;
import gov.vha.isaac.metadata.coordinates.ViewCoordinates;
import gov.vha.isaac.metadata.source.IsaacMetadataAuxiliaryBinding;

import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.EnumSet;
import java.util.Set;
import java.util.UUID;

import org.apache.mahout.math.Arrays;
import org.ihtsdo.otf.tcc.api.concept.ConceptVersionBI;
import org.ihtsdo.otf.tcc.api.coordinate.Position;
import org.ihtsdo.otf.tcc.api.coordinate.Status;
import org.ihtsdo.otf.tcc.api.coordinate.ViewCoordinate;
import org.ihtsdo.otf.tcc.api.relationship.RelAssertionType;
import org.ihtsdo.otf.tcc.api.store.Ts;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class ViewCoordinateFactory {
	private static final Logger LOG = LoggerFactory.getLogger(ViewCoordinateFactory.class);

	public static interface ViewCoordinateProvider {
		public ViewCoordinate getViewCoordinate();
	}

	private ViewCoordinateFactory() {}

	public static ViewCoordinate getSystemViewCoordinate() {
		try {
			return ViewCoordinates.getDevelopmentStatedLatest();
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}

	public static ViewCoordinate getViewCoordinate(ViewCoordinateComponents components) {
		return getViewCoordinate(
				components.getPath(),
				components.getStatedInferredOption(),
				components.getStatuses(),
				components.getTime(),
				components.getModules());
	}
	public static ViewCoordinate getViewCoordinate(
			UUID path,
			StatedInferredOptions statedInferredOption,
			Set<Status> statusesSet,
			long time,
			Set<UUID> modules) {
		final EnumSet<Status> statuses = EnumSet.allOf(Status.class); // Have to have non-empty set to create
		statuses.clear();
		statuses.addAll(statusesSet);

		RelAssertionType relAssertionType = null;

		switch (statedInferredOption) {
		case STATED:
			relAssertionType = RelAssertionType.STATED;
			break;
		case INFERRED:
			relAssertionType = RelAssertionType.INFERRED;
			break;
		default:
			throw new IllegalArgumentException("Unsupported " + StatedInferredOptions.class.getName() + " value " + statedInferredOption + ".  Expected one of " + StatedInferredOptions.STATED + " or " + StatedInferredOptions.INFERRED);
		}

		try {
			if (path.equals(IsaacMetadataAuxiliaryBinding.DEVELOPMENT.getPrimodialUuid())
					&& statuses.size() == 2 && statuses.contains(Status.ACTIVE) && statuses.contains(Status.INACTIVE)
					&& relAssertionType == RelAssertionType.INFERRED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getDevelopmentInferredLatest();
			} else if  (path.equals(IsaacMetadataAuxiliaryBinding.DEVELOPMENT.getPrimodialUuid())
					&& statuses.size() == 1 && statuses.contains(Status.ACTIVE)
					&& relAssertionType == RelAssertionType.INFERRED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getDevelopmentInferredLatestActiveOnly();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.DEVELOPMENT.getPrimodialUuid())
					&& statuses.size() == 2 && statuses.contains(Status.ACTIVE) && statuses.contains(Status.INACTIVE)
					&& relAssertionType == RelAssertionType.STATED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getDevelopmentStatedLatest();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.DEVELOPMENT.getPrimodialUuid())
					&& statuses.size() == 1 && statuses.contains(Status.ACTIVE)
					&& relAssertionType == RelAssertionType.STATED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getDevelopmentStatedLatestActiveOnly();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.MASTER.getPrimodialUuid())
					&& statuses.size() == 2 && statuses.contains(Status.ACTIVE) && statuses.contains(Status.INACTIVE)
					&& relAssertionType == RelAssertionType.INFERRED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getMasterInferredLatest();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.MASTER.getPrimodialUuid())
					&& statuses.size() == 1 && statuses.contains(Status.ACTIVE)
					&& relAssertionType == RelAssertionType.INFERRED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getMasterInferredLatest();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.MASTER.getPrimodialUuid())
					&& statuses.size() == 2 && statuses.contains(Status.ACTIVE) && statuses.contains(Status.INACTIVE)
					&& relAssertionType == RelAssertionType.STATED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getMasterStatedLatest();
			} else if (path.equals(IsaacMetadataAuxiliaryBinding.MASTER.getPrimodialUuid())
					&& statuses.size() == 1 && statuses.contains(Status.ACTIVE)
					&& relAssertionType == RelAssertionType.STATED
					&& time == Long.MAX_VALUE
					&& (modules == null || modules.size() == 0)) {
				return ViewCoordinates.getMasterStatedLatestActiveOnly();
			} else {
				ConceptVersionBI pathConcept = OTFUtility.getConceptVersion(path, ViewCoordinates.getDevelopmentStatedLatest());
				String pathDesc = OTFUtility.getDescription(pathConcept).toLowerCase();
				String statusDesc = null;
				if (statuses.size() == 2 && statuses.contains(Status.ACTIVE) && statuses.contains(Status.INACTIVE)) {
					// noop
				} else if (statuses.size() == 1 && statuses.contains(Status.ACTIVE)) {
					statusDesc = "active-only";
				} else if (statuses.size() == 1 && statuses.contains(Status.INACTIVE)) {
					statusDesc = "inactive-only";
				}
				String relAssertionTypeDesc = relAssertionType.name().toLowerCase();
				String timeDesc = time == Long.MAX_VALUE ? "latest" : new SimpleDateFormat().format(new Date(time));
				String modulesDesc = null;
				if (modules != null && modules.size() > 0) {
					modulesDesc = Arrays.toString(modules.toArray());
				}

				String desc = pathDesc + " " + relAssertionTypeDesc;
				if (statusDesc != null) {
					desc += " " + statusDesc;
				}
				desc += " " + timeDesc;
				if (modulesDesc != null) {
					desc += " " + modulesDesc;
				}

				LOG.debug("Creating ad hoc VC: {}", desc);

				ViewCoordinate viewCoordinate = new ViewCoordinate(
						UUID.randomUUID(),
						desc,
						Ts.get().getMetadataVC());
				Position viewPosition = Ts.get().newPosition(
						Ts.get().getPath(pathConcept.getNid()),
						time);

				viewCoordinate.setViewPosition(viewPosition);
				viewCoordinate.setRelationshipAssertionType(relAssertionType);
				viewCoordinate.setAllowedStatus(statuses);
				viewCoordinate.setDescriptionLogicProfileSpec(IsaacMetadataAuxiliaryBinding.EL_PLUS_PLUS);
				viewCoordinate.setStatedAssemblageSpec(IsaacMetadataAuxiliaryBinding.EL_PLUS_PLUS_STATED_FORM);
				viewCoordinate.setInferredAssemblageSpec(IsaacMetadataAuxiliaryBinding.EL_PLUS_PLUS_INFERRED_FORM);
				viewCoordinate.setClassifierSpec(IsaacMetadataAuxiliaryBinding.SNOROCKET);
				viewCoordinate.getDescriptionTypePrefSpecs().add(IsaacMetadataAuxiliaryBinding.SYNONYM);
				viewCoordinate.getDescriptionTypePrefSpecs().add(IsaacMetadataAuxiliaryBinding.FULLY_SPECIFIED_NAME);
				viewCoordinate.getLangPrefSpecs().clear();
				viewCoordinate.getLangPrefSpecs().add(IsaacMetadataAuxiliaryBinding.US_ENGLISH_DIALECT);
				viewCoordinate.getLangPrefSpecs().add(IsaacMetadataAuxiliaryBinding.GB_ENGLISH_DIALECT);

				if (modules != null && modules.size() > 0) {
					throw new IllegalArgumentException("Passing modules to ViewCoordinate not yet supported");
				}

				return viewCoordinate;
			}
		} catch (IOException e) {
			throw new RuntimeException(e);
		}
	}
}


text:
//
//  MZFormSheetPresentationViewControllerAnimator.m
//  MZFormSheetPresentationViewControllerAnimator
//
//  Created by Michał Zaborowski on 24.02.2015.
//  Copyright (c) 2015 Michał Zaborowski. All rights reserved.
//
//  Permission is hereby granted, free of charge, to any person obtaining a copy
//  of this software and associated documentation files (the "Software"), to deal
//  in the Software without restriction, including without limitation the rights
//  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
//  copies of the Software, and to permit persons to whom the Software is
//  furnished to do so, subject to the following conditions:
//
//  The above copyright notice and this permission notice shall be included in
//  all copies or substantial portions of the Software.
//
//  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
//  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
//  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
//  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
//  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
//  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
//  THE SOFTWARE.

#import <UIKit/UIKit.h>
#import <MZAppearance/MZAppearance.h>
#import "MZTransition.h"

typedef void(^MZFormSheetPresentationControllerTransitionBeginCompletionHandler)(UIViewController * __nonnull presentingViewController);
typedef void(^MZFormSheetPresentationControllerTransitionEndCompletionHandler)(UIViewController * __nonnull presentingViewController, BOOL completed);
typedef void(^MZFormSheetPresentationControllerTapHandler)(CGPoint location);
typedef CGRect(^MZFormSheetPresentationFrameConfigurationHandler)(UIView * __nonnull presentedView, CGRect currentFrame);

typedef NS_ENUM(NSInteger, MZFormSheetActionWhenKeyboardAppears) {
    MZFormSheetActionWhenKeyboardAppearsDoNothing = 0,
    MZFormSheetActionWhenKeyboardAppearsCenterVertically,
    MZFormSheetActionWhenKeyboardAppearsMoveToTop,
    MZFormSheetActionWhenKeyboardAppearsMoveToTopInset,
    MZFormSheetActionWhenKeyboardAppearsAboveKeyboard
};

@interface MZFormSheetPresentationController : UIPresentationController <MZAppearance>
@property (nonatomic, strong, readonly, null_resettable) UIView *dimmingView;

/**
 *  The preferred size for the container's content. (required)
 */
@property (nonatomic, assign) CGSize contentViewSize MZ_APPEARANCE_SELECTOR;

/**
 Distance that the presented form sheet view is inset from the status bar in landscape orientation.
 By default, this is 6.0
 */
@property (nonatomic, assign) CGFloat landscapeTopInset MZ_APPEARANCE_SELECTOR;

/**
 Distance that the presented form sheet view is inset from the status bar in portrait orientation.
 By default, this is 66.0
 */
@property (nonatomic, assign) CGFloat portraitTopInset MZ_APPEARANCE_SELECTOR;

/**
 Returns whether the form sheet controller should dismiss after background view tap.
 By default, this is NO
 */
@property (nonatomic, assign) BOOL shouldDismissOnBackgroundViewTap MZ_APPEARANCE_SELECTOR;

/**
 Returns whether the form sheet controller should user motion effect.
 By default, this is NO
 */
@property (nonatomic, assign) BOOL shouldUseMotionEffect MZ_APPEARANCE_SELECTOR;

/**
 Center form sheet horizontally.
 By default, this is YES
 */
@property (nonatomic, assign) BOOL shouldCenterHorizontally MZ_APPEARANCE_SELECTOR;

/**
 Center form sheet vertically.
 By default, this is NO
 */
@property (nonatomic, assign) BOOL shouldCenterVertically MZ_APPEARANCE_SELECTOR;

/**
 The background color of the background view.
 By default, this is a black at with a 0.5 alpha component
 */
@property (nonatomic, strong, nullable) UIColor *backgroundColor MZ_APPEARANCE_SELECTOR;

/*
 The intensity of the blur effect. See UIBlurEffectStyle for valid options.
 By default, this is UIBlurEffectStyleLight
 */
@property (nonatomic, assign) UIBlurEffectStyle blurEffectStyle MZ_APPEARANCE_SELECTOR;

/*
 Apply background blur effect, this property need to be set before form sheet presentation
 By default, this is NO
 */
@property (nonatomic, assign) BOOL shouldApplyBackgroundBlurEffect MZ_APPEARANCE_SELECTOR;

/**
 The movement action to use when the keyboard appears.
 By default, this is MZFormSheetActionWhenKeyboardAppears.
 */
@property (nonatomic, assign) MZFormSheetActionWhenKeyboardAppears movementActionWhenKeyboardAppears MZ_APPEARANCE_SELECTOR;

/**
 Returns whether the background view be touch transparent.
 If transparent is set to YES, background view will not recive touch and didTapOnBackgroundViewCompletionHandler will not be called.
 Also will not be possible to dismiss form sheet on background tap.
 By default, this is NO.
 */
@property (nonatomic, assign, getter = isTransparentTouchEnabled) BOOL transparentTouchEnabled MZ_APPEARANCE_SELECTOR;

/**
 The handler to call when user tap on background view.
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationControllerTapHandler didTapOnBackgroundViewCompletionHandler;

/**
 *  Notifies the presentation controller that the presentation animations are about to start.
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationControllerTransitionBeginCompletionHandler presentationTransitionWillBeginCompletionHandler;

/**
 *  Notifies the presentation controller that the presentation animations finished.
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationControllerTransitionEndCompletionHandler presentationTransitionDidEndCompletionHandler;

/**
 *  Notifies the presentation controller that the dismissal animations are about to start.
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationControllerTransitionBeginCompletionHandler dismissalTransitionWillBeginCompletionHandler;

/**
 *  Notifies the presentation controller that the dismissal animations finished.
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationControllerTransitionEndCompletionHandler dismissalTransitionDidEndCompletionHandler;

/**
 *  This completion handler allow you to change frame during rotation and animations
 *  for presentedView
 */
@property (nonatomic, copy, nullable) MZFormSheetPresentationFrameConfigurationHandler frameConfigurationHandler;

/**
 *  This method recalculate presenting view frame
 */
- (void)layoutPresentingViewController;

@end


text:
<!DOCTYPE html>

    <meta charset="utf-8">
    <title>Bus Mall - Marketing Study</title>
    <link rel ="stylesheet" type="text/css" href="reset.css" />
    <link rel ="stylesheet" type="text/css" href="style.css" />

 Bus Mall - Marketing Study

 Thank you for participating in the Focus Group for Bus Mall.  Your input will help us tailor our catalog to the interest of numerous Puget Sound transit riders.

INSTRUCTION

    There will be a display of 3 product images at a time. Many of the images will appear multiple times.Please click on an image of the product that you would be most likely to buy. Note that after you have made 25 votes, you will be given an option to view the accumulative voting results and exit from the study.

      <button id="clickButton">View Result</button>

    <canvas id="click-chart" width="600px" height="300px"></canvas>


text:
package ru.job4j.config.model;

import java.sql.Timestamp;

/**
 * Created on 11.01.18.
 * Data base table image.
 * @author Wamdue
 * @version 1.0
 */
public class Item {
    /**
     * Record id.
     */
    private int id;
    /**
     * Task description.
     */
    private String description;
    /**
     * Creation date time.
     */
    private Timestamp created;
    /**
     * Task status.
     */
    private int status;

    /**
     * Get tesk id.
     * @return - id.
     */
    public int getId() {
        return id;
    }

    /**
     * Set task id.
     * @param id - new id.
     */
    public void setId(int id) {
        this.id = id;
    }

    /**
     * Get task description.
     * @return - description.
     */
    public String getDescription() {
        return description;
    }

    /**
     * Set task description.
     * @param description - new description.
     */
    public void setDescription(String description) {
        this.description = description;
    }

    /**
     * Get task creation time.
     * @return creation time.
     */
    public Timestamp getCreated() {
        return created;
    }

    /**
     * Set task creation time.
     * @param created - new time.
     */
    public void setCreated(Timestamp created) {
        this.created = created;
    }

    /**
     * Task status.
     * @return status.
     */
    public int getStatus() {
        return status;
    }

    /**
     * Set new task status.
     * @param status - new status.
     */
    public void setStatus(int status) {
        this.status = status;
    }
}


text:
function removeSelectArea(){
	$('#thumbnail').imgAreaSelect({remove: true});
}


text:
<?xml version="1.0" encoding="utf-8"?>
<resources>

    <string name="app_name">Ejercicio503</string>
    <string name="hello_world">Hello world!</string>
    <string name="action_settings">Settings</string>
    <string name="tvEstado">Estado</string>
    <string name="btnGrabar">Grabar</string>
    <string name="btnDetener">Detener</string>
    <string name="btnReproducir">Reproducir</string>

</resources>


text:
package org.kuali.continuity.admin.dao;

@Deprecated
public interface DependencyDAOFactory {

	DependencyDAO getDependencyDAO(boolean isAdmin);

}