text:
package org.apache.geode.cache.query.internal.index;

import static java.util.Objects.hash;

import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry;
import java.util.NoSuchElementException;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentNavigableMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.geode.cache.EntryDestroyedException;
import org.apache.geode.cache.Region;
import org.apache.geode.cache.RegionAttributes;
import org.apache.geode.cache.query.IndexMaintenanceException;
import org.apache.geode.cache.query.QueryService;
import org.apache.geode.cache.query.TypeMismatchException;
import org.apache.geode.cache.query.internal.CompiledComparison;
import org.apache.geode.cache.query.internal.DefaultQuery;
import org.apache.geode.cache.query.internal.index.AbstractIndex.InternalIndexStatistics;
import org.apache.geode.cache.query.internal.parse.OQLLexerTokenTypes;
import org.apache.geode.cache.query.internal.types.TypeUtils;
import org.apache.geode.internal.cache.CachedDeserializable;
import org.apache.geode.internal.cache.InternalCache;
import org.apache.geode.internal.cache.LocalRegion;
import org.apache.geode.internal.cache.NonTXEntry;
import org.apache.geode.internal.cache.RegionEntry;
import org.apache.geode.internal.cache.Token;
import org.apache.geode.internal.cache.persistence.query.CloseableIterator;
import org.apache.geode.pdx.internal.PdxInstanceImpl;

/**
 * The in-memory index storage
 *
 * @since GemFire 8.0
 */
public class MemoryIndexStore implements IndexStore {
  /**
   * Map for valueOf(indexedExpression)=>RegionEntries. SortedMap<Object, (RegionEntry |
   * List<RegionEntry>)>. Package access for unit tests.
   */
  final ConcurrentNavigableMap valueToEntriesMap =
      new ConcurrentSkipListMap(TypeUtils.getExtendedNumericComparator());

  // number of keys
  private final AtomicInteger numIndexKeys = new AtomicInteger(0);

  // Map for RegionEntries=>value of indexedExpression (reverse map)
  private ConcurrentMap entryToValuesMap;

  private final InternalIndexStatistics internalIndexStats;

  private final InternalCache cache;

  private final Region region;

  private boolean indexOnRegionKeys;

  private boolean indexOnValues;

  // Used as a place holder for an indexkey collection for when a thread is about to change
  // the collection from index elem to concurrent hash set. Solution for #47475 where
  // we could be missing removes due to different threads grabbing occurrences of the same
  // index elem (or collection), one would transition and addAll to a new collection,
  // while the other would execute a remove on the index elem.
  // both would complete but the remove would have been lost because we had already added it to the
  // new collection
  private final Object TRANSITIONING_TOKEN = new IndexElemArray(1);

  MemoryIndexStore(Region region, InternalIndexStatistics internalIndexStats, InternalCache cache) {
    this.region = region;
    RegionAttributes ra = region.getAttributes();
    // Initialize the reverse-map if in-place modification is set by the
    // application.
    if (IndexManager.isObjectModificationInplace()) {
      entryToValuesMap = new ConcurrentHashMap(ra.getInitialCapacity(), ra.getLoadFactor(),
          ra.getConcurrencyLevel());
    }
    this.internalIndexStats = internalIndexStats;
    this.cache = cache;
  }

  @Override
  public void updateMapping(Object indexKey, Object oldKey, RegionEntry re, Object oldValue)
      throws IMQException {
    try {

      if (DefaultQuery.testHook != null) {
        DefaultQuery.testHook.doTestHook(
            DefaultQuery.TestHook.SPOTS.BEFORE_ADD_OR_UPDATE_MAPPING_OR_DESERIALIZING_NTH_STREAMINGOPERATION,
            null, null);
      }

      // Check if reverse-map is present.
      if (IndexManager.isObjectModificationInplace()) {
        // If reverse map get the old index key from reverse map.
        if (entryToValuesMap.containsKey(re)) {
          oldKey = entryToValuesMap.get(re);
        }
      } else {
        // Check if the old value and new value same.
        // If they are same, that means the value got updated in place.
        // In the absence of reverse-map find the old index key from
        // forward map.
        if (oldValue != null && oldValue == getTargetObjectInVM(re)) {
          oldKey = getOldKey(indexKey, re);
        }
      }

      // No need to update the map if new and old index key are same.
      if (oldKey != null && oldKey.equals(TypeUtils.indexKeyFor(indexKey))) {
        return;
      }

      boolean retry = false;
      indexKey = TypeUtils.indexKeyFor(indexKey);
      if (indexKey.equals(QueryService.UNDEFINED)) {
        Object targetObject = getTargetObjectForUpdate(re);
        if (Token.isInvalidOrRemoved(targetObject)) {
          if (oldKey != null) {
            basicRemoveMapping(oldKey, re, false);
          }
          return;
        }
      }

      do {
        retry = false;
        Object regionEntries = valueToEntriesMap.putIfAbsent(indexKey, re);
        if (regionEntries == TRANSITIONING_TOKEN) {
          retry = true;
          continue;
        } else if (regionEntries == null) {
          if (indexKey != IndexManager.NULL && indexKey != QueryService.UNDEFINED) {
            internalIndexStats.incNumKeys(1);
          }
          numIndexKeys.incrementAndGet();
        } else if (regionEntries instanceof RegionEntry) {
          IndexElemArray elemArray = new IndexElemArray();
          if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook.doTestHook(
                DefaultQuery.TestHook.SPOTS.BEGIN_TRANSITION_FROM_REGION_ENTRY_TO_ELEMARRAY, null,
                null);
          }
          elemArray.add(regionEntries);
          elemArray.add(re);
          if (!valueToEntriesMap.replace(indexKey, regionEntries, elemArray)) {
            retry = true;
          }
          if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook
                .doTestHook(DefaultQuery.TestHook.SPOTS.TRANSITIONED_FROM_REGION_ENTRY_TO_ELEMARRAY,
                    null, null);
          }
          if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook.doTestHook(
                DefaultQuery.TestHook.SPOTS.COMPLETE_TRANSITION_FROM_REGION_ENTRY_TO_ELEMARRAY,
                null, null);
          }
        } else if (regionEntries instanceof IndexConcurrentHashSet) {
          // This synchronized is for avoiding conflcts with remove of
          // ConcurrentHashSet when set size becomes zero during
          // basicRemoveMapping();
          synchronized (regionEntries) {
            ((IndexConcurrentHashSet) regionEntries).add(re);
          }
          if (regionEntries != valueToEntriesMap.get(indexKey)) {
            retry = true;
          }
        } else {
          IndexElemArray elemArray = (IndexElemArray) regionEntries;
          synchronized (elemArray) {
            int threshold = IndexManager.INDEX_ELEMARRAY_THRESHOLD;
            if (IndexManager.INDEX_ELEMARRAY_THRESHOLD_FOR_TESTING > 0) {
              threshold = IndexManager.INDEX_ELEMARRAY_THRESHOLD_FOR_TESTING;
            }
            if (elemArray.size() >= threshold) {
              IndexConcurrentHashSet set =
                  new IndexConcurrentHashSet(IndexManager.INDEX_ELEMARRAY_THRESHOLD + 20, 0.75f, 1);
              // Replace first so that we are sure that the set is placed in
              // index then we should add old elements in the new set.

              if (DefaultQuery.testHook != null) {
                DefaultQuery.testHook.doTestHook(
                    DefaultQuery.TestHook.SPOTS.BEGIN_TRANSITION_FROM_ELEMARRAY_TO_CONCURRENT_HASH_SET,
                    null, null);
              }
              // on a remove from the elem array, another thread could start and complete its remove
              // at this point, that is why we need to replace before adding the elem array elements
              // once we put this set into the forward map, we know any future removes are either
              // captured
              // by our instance of the elem array, or the remove operations will need to do a
              // retry?
              if (!valueToEntriesMap.replace(indexKey, regionEntries, TRANSITIONING_TOKEN)) {
                retry = true;
              } else {
                if (DefaultQuery.testHook != null) {
                  DefaultQuery.testHook
                      .doTestHook(DefaultQuery.TestHook.SPOTS.TRANSITIONED_FROM_ELEMARRAY_TO_TOKEN,
                          null, null);
                }
                set.add(re);
                set.addAll(elemArray);
                if (!valueToEntriesMap.replace(indexKey, TRANSITIONING_TOKEN, set)) {
                  // This should never happen. If we see this in the log, then something is wrong
                  // with the TRANSITIONING TOKEN and synchronization of changing collection types
                  // we should then just go from RE to CHS and completely remove the Elem Array.
                  region.getCache().getLogger().warning(
                      "Unable to transition from index elem to concurrent hash set.  Index needs to be recreated");
                  throw new IndexMaintenanceException(
                      "Unable to transition from index elem to concurrent hash set.  Index needs to be recreated");
                }
                if (DefaultQuery.testHook != null) {
                  DefaultQuery.testHook.doTestHook(
                      DefaultQuery.TestHook.SPOTS.COMPLETE_TRANSITION_FROM_ELEMARRAY_TO_CONCURRENT_HASH_SET,
                      null, null);
                }
              }
            } else {
              elemArray.add(re);
              if (regionEntries != valueToEntriesMap.get(indexKey)) {
                retry = true;
              }
            }
          }
        }

        // Add to reverse Map with the new value.
        if (!retry) {

          // remove from forward map in case of update
          // oldKey is not null only for an update
          if (oldKey != null) {
            basicRemoveMapping(oldKey, re, false);
          }

          if (IndexManager.isObjectModificationInplace()) {
            entryToValuesMap.put(re, indexKey);
          }
        }
      } while (retry);
    } catch (TypeMismatchException ex) {
      throw new IMQException("Could not add object of type " + indexKey.getClass().getName(), ex);
    }
    internalIndexStats.incNumValues(1);
  }

  /**
   * Find the old key by traversing the forward map in case of in-place update modification If not
   * found it means the value object was modified with same value. So oldKey is same as newKey.
   *
   */
  private Object getOldKey(Object newKey, RegionEntry entry) throws TypeMismatchException {
    for (Object mapEntry : valueToEntriesMap.entrySet()) {
      Object regionEntries = ((Entry) mapEntry).getValue();
      Object indexKey = ((Entry) mapEntry).getKey();
      // if more than one index key maps to the same RegionEntry that
      // means there has been an in-place modification
      if (TypeUtils.compare(indexKey, newKey, CompiledComparison.TOK_NE).equals(Boolean.TRUE)) {
        if (regionEntries instanceof RegionEntry && regionEntries.equals(entry)) {
          return indexKey;
        } else if (regionEntries instanceof Collection) {
          Collection coll = (Collection) regionEntries;
          if (coll.contains(entry)) {
            return indexKey;
          }
        }
      }
    }
    return newKey;
  }

  @Override
  public void addMapping(Object indexKey, RegionEntry re) throws IMQException {
    // for add, oldkey is null
    updateMapping(indexKey, null, re, null);
  }

  @Override
  public void removeMapping(Object indexKey, RegionEntry re) throws IMQException {
    // Remove from forward map
    boolean found = basicRemoveMapping(indexKey, re, true);
    // Remove from reverse map.
    // We do NOT need to synchronize here as different RegionEntries will be
    // operating concurrently i.e. different keys in entryToValuesMap which
    // is a concurrent map.
    if (found && IndexManager.isObjectModificationInplace()) {
      entryToValuesMap.remove(re);
    }
  }

  private boolean basicRemoveMapping(Object key, RegionEntry entry, boolean findOldKey)
      throws IMQException {
    boolean found = false;
    boolean possiblyAlreadyRemoved = false;
    try {
      Object newKey = convertToIndexKey(key, entry);
      if (DefaultQuery.testHook != null) {
        DefaultQuery.testHook.doTestHook(DefaultQuery.TestHook.SPOTS.ATTEMPT_REMOVE, null, null);
      }
      boolean retry = false;
      do {
        retry = false;
        Object regionEntries = valueToEntriesMap.get(newKey);
        if (regionEntries == TRANSITIONING_TOKEN) {
          if (DefaultQuery.testHook != null) {
            DefaultQuery.testHook.doTestHook(DefaultQuery.TestHook.SPOTS.ATTEMPT_RETRY, null, null);
          }
          retry = true;
          continue;
        } else if (regionEntries != null) {
          if (regionEntries instanceof RegionEntry) {
            found = regionEntries == entry;
            if (found) {
              if (valueToEntriesMap.remove(newKey, regionEntries)) {
                if (newKey != IndexManager.NULL && newKey != QueryService.UNDEFINED) {
                  internalIndexStats.incNumKeys(-1);
                }
                numIndexKeys.decrementAndGet();
              } else {
                // is another thread has since done an add and shifted us into a collection
                retry = true;
              }
            }
          } else {
            Collection entries = (Collection) regionEntries;
            if (DefaultQuery.testHook != null) {
              DefaultQuery.testHook
                  .doTestHook(DefaultQuery.TestHook.SPOTS.BEGIN_REMOVE_FROM_ELEM_ARRAY, null, null);
            }
            found = entries.remove(entry);
            if (DefaultQuery.testHook != null) {
              DefaultQuery.testHook
                  .doTestHook(DefaultQuery.TestHook.SPOTS.REMOVE_CALLED_FROM_ELEM_ARRAY, null,
                      null);
            }
            // This could be IndexElementArray and might be changing to Set
            // If the remove occurred before changing to a set, then next time it will not be
            // "found"
            // However the end effect would be that it was removed
            if (entries instanceof IndexElemArray) {
              if (!valueToEntriesMap.replace(newKey, entries, entries)) {
                retry = true;
                possiblyAlreadyRemoved = found;
                continue;
              }
            }

            if (entries.isEmpty()) {
              // because entries collection is empty, remove and decrement
              // value
              synchronized (entries) {
                if (entries.isEmpty()) {
                  if (valueToEntriesMap.remove(newKey, entries)) {
                    if (newKey != IndexManager.NULL && newKey != QueryService.UNDEFINED) {
                      internalIndexStats.incNumKeys(-1);
                    }
                    numIndexKeys.decrementAndGet();
                  }
                }
              }
            }
            if (DefaultQuery.testHook != null) {
              DefaultQuery.testHook
                  .doTestHook(DefaultQuery.TestHook.SPOTS.COMPLETE_REMOVE_FROM_ELEM_ARRAY, null,
                      null);
            }
          }
        }
      } while (retry);
    } catch (TypeMismatchException ex) {
      throw new IMQException("Could not add object of type " + key.getClass().getName(), ex);
    }
    if (found) {
      // Update stats if entry was actually removed
      internalIndexStats.incNumValues(-1);
    } else if (!found && !possiblyAlreadyRemoved && !IndexManager.isObjectModificationInplace()
        && key != null) {
      // if there is an inplace-modification find old key by iterating
      // over fwd map and then remove the mapping
      if (findOldKey) {
        try {
          Object oldKey = getOldKey(key, entry);
          found = basicRemoveMapping(oldKey, entry, false);
        } catch (TypeMismatchException e) {
          throw new IMQException("Could not find old key: " + key.getClass().getName(), e);
        }
      }
    }
    return found;
  }

  private Object convertToIndexKey(Object key, RegionEntry entry) throws TypeMismatchException {
    Object newKey;
    if (IndexManager.isObjectModificationInplace() && entryToValuesMap.containsKey(entry)) {
      newKey = entryToValuesMap.get(entry);
    } else {
      newKey = TypeUtils.indexKeyFor(key);
    }
    return newKey;
  }

  @Override
  public CloseableIterator<IndexStoreEntry> get(Object indexKey) {
    return new MemoryIndexStoreIterator(
        valueToEntriesMap.subMap(indexKey, true, indexKey, true), indexKey, null);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> iterator(Object start, boolean startInclusive,
      Object end, boolean endInclusive, Collection keysToRemove) {
    if (start == null) {
      return new MemoryIndexStoreIterator(valueToEntriesMap.headMap(end, endInclusive), null,
          keysToRemove);
    }
    return new MemoryIndexStoreIterator(
        valueToEntriesMap.subMap(start, startInclusive, end, endInclusive), null,
        keysToRemove);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> iterator(Object start, boolean startInclusive,
      Collection keysToRemove) {
    return new MemoryIndexStoreIterator(valueToEntriesMap.tailMap(start, startInclusive), null,
        keysToRemove);
  }

  public Iterator<IndexStoreEntry> getKeysIterator() {
    return new MemoryIndexStoreKeyIterator(valueToEntriesMap);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> iterator(Collection keysToRemove) {
    return new MemoryIndexStoreIterator(valueToEntriesMap, null, keysToRemove);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> descendingIterator(Object start, boolean startInclusive,
      Object end, boolean endInclusive, Collection keysToRemove) {
    if (start == null) {
      return new MemoryIndexStoreIterator(
          valueToEntriesMap.headMap(end, endInclusive).descendingMap(), null, keysToRemove);
    }
    return new MemoryIndexStoreIterator(
        valueToEntriesMap.subMap(start, startInclusive, end, endInclusive).descendingMap(),
        null, keysToRemove);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> descendingIterator(Object start, boolean startInclusive,
      Collection keysToRemove) {
    return new MemoryIndexStoreIterator(
        valueToEntriesMap.tailMap(start, startInclusive).descendingMap(), null, keysToRemove);
  }

  @Override
  public CloseableIterator<IndexStoreEntry> descendingIterator(Collection keysToRemove) {
    return new MemoryIndexStoreIterator(valueToEntriesMap.descendingMap(), null, keysToRemove);
  }

  @Override
  public boolean isIndexOnRegionKeys() {
    return indexOnRegionKeys;
  }

  @Override
  public void setIndexOnRegionKeys(boolean indexOnRegionKeys) {
    this.indexOnRegionKeys = indexOnRegionKeys;
  }

  @Override
  public boolean isIndexOnValues() {
    return indexOnValues;
  }

  @Override
  public void setIndexOnValues(boolean indexOnValues) {
    this.indexOnValues = indexOnValues;
  }

  /**
   * Get the object of interest from the region entry. For now it always gets the deserialized
   * value.
   */
  @Override
  public Object getTargetObject(RegionEntry entry) {
    if (indexOnValues) {
      Object o = entry.getValue((LocalRegion) region);
      try {
        if (o == Token.INVALID) {
          return null;
        }
        if (o instanceof CachedDeserializable) {
          return ((CachedDeserializable) o).getDeserializedValue(region, entry);
        }
      } catch (EntryDestroyedException ignore) {
        return null;
      }
      return o;
    } else if (indexOnRegionKeys) {
      return entry.getKey();
    }
    return new CachedEntryWrapper(new NonTXEntry((LocalRegion) region, entry));
  }

  @Override
  public Object getTargetObjectInVM(RegionEntry entry) {
    if (indexOnValues) {
      Object o = entry.getValueInVM((LocalRegion) region);
      try {
        if (o == Token.INVALID) {
          return null;
        }
        if (o instanceof CachedDeserializable) {
          return ((CachedDeserializable) o).getDeserializedValue(region, entry);
        }
      } catch (EntryDestroyedException ede) {
        return null;
      }
      return o;
    } else if (indexOnRegionKeys) {
      return entry.getKey();
    }
    return new NonTXEntry((LocalRegion) region, entry);
  }

  private Object getTargetObjectForUpdate(RegionEntry entry) {
    if (indexOnValues) {
      Object o = entry.getValue((LocalRegion) region);
      try {
        if (o == Token.INVALID) {
          return Token.INVALID;
        }
        if (o instanceof CachedDeserializable) {
          return ((CachedDeserializable) o).getDeserializedValue(region, entry);
        }
      } catch (EntryDestroyedException ede) {
        return Token.INVALID;
      }
      return o;
    } else if (indexOnRegionKeys) {
      return entry.getKey();
    }
    return new NonTXEntry((LocalRegion) region, entry);
  }

  @Override
  public boolean clear() {
    valueToEntriesMap.clear();
    if (IndexManager.isObjectModificationInplace()) {
      entryToValuesMap.clear();
    }
    numIndexKeys.set(0);
    return true;
  }

  @Override
  public int size(Object key) {
    Object obj = valueToEntriesMap.get(key);
    if (obj != null) {
      return obj instanceof RegionEntry ? 1 : ((Collection) obj).size();
    } else {
      return 0;
    }
  }

  @Override
  public int size() {
    return numIndexKeys.get();
  }

  private class MemoryIndexStoreKeyIterator implements Iterator<IndexStoreEntry> {

    private final Map valuesToEntriesMap;
    private Object currKey;
    private Iterator<Map.Entry> mapIterator;

    public MemoryIndexStoreKeyIterator(Map valuesToEntriesMap) {
      this.valuesToEntriesMap = valuesToEntriesMap;
    }

    @Override
    public boolean hasNext() {
      if (mapIterator == null) {
        mapIterator = valuesToEntriesMap.entrySet().iterator();
      }
      if (mapIterator.hasNext()) {
        Map.Entry currentEntry = mapIterator.next();
        currKey = currentEntry.getKey();
        if (currKey == IndexManager.NULL || currKey == QueryService.UNDEFINED) {
          return hasNext();
        }
        return currKey != null;
      }
      return false;
    }

    @Override
    public MemoryIndexStoreKey next() {
      return new MemoryIndexStoreKey(currKey);
    }
  }

  /**
   * A bi-directional iterator over the CSL. Iterates over the entries of CSL where entry is a
   * mapping (value -> Collection) as well as over the Collection.
   */
  private class MemoryIndexStoreIterator implements CloseableIterator<IndexStoreEntry> {
    final Map map;
    Object indexKey;
    Collection keysToRemove;
    Iterator<Map.Entry> mapIterator;
    Iterator valuesIterator;
    Object currKey;
    Object currValue; // RegionEntry
    final long iteratorStartTime;
    MemoryIndexStoreEntry currentEntry;

    MemoryIndexStoreIterator(Map submap, Object indexKey, Collection keysToRemove) {
      this(submap, indexKey, keysToRemove, cache.cacheTimeMillis());
    }

    private MemoryIndexStoreIterator(Map submap, Object indexKey, Collection keysToRemove,
        long iteratorStartTime) {
      map = submap;
      this.indexKey = indexKey;
      this.keysToRemove = keysToRemove == null ? null : new HashSet(keysToRemove);
      this.iteratorStartTime = iteratorStartTime;
      currentEntry = new MemoryIndexStoreEntry(iteratorStartTime);
    }

    /**
     * This iterator iterates over the CSL map as well as on the collection of values for each entry
     * in the map. If the map has next element, check if the previous valuesIterator (iterator on
     * the Collection) has been created or has finished iterating. If not created, create an
     * iterator on the Collection. If created and not finished, return, so that the next() call
     * would create a new InMemoryIndexStorageEntry for the current key and next RE from the
     * collection of values.
     */
    @Override
    public boolean hasNext() {
      // return previous collection of values if not over
      if (valuesIterator != null && valuesIterator.hasNext()) {
        return true;
      }
      // sets the next values iterator
      if (mapIterator == null) {
        mapIterator = map.entrySet().iterator();
      }
      if (mapIterator.hasNext()) {
        // set the next entry in the map as current
        Map.Entry currentMapEntry = mapIterator.next();
        // set the index key
        currKey = currentMapEntry.getKey();
        // if the index key in currentIndexEntry is present in the
        // keysToRemove collection or is Undefined or Null
        // skip the current map entry and advance to the
        // next entry in the index map.
        // skipping null & undefined is required so that they do not get
        // into results of range queries.
        // equality and not equality for null/undefined would create
        // valuesIterator so it would not come here
        if (currKey != indexKey
            && (currKey == QueryService.UNDEFINED || currKey == IndexManager.NULL
                || keysToRemove != null && removeFromKeysToRemove(keysToRemove, currKey))) {
          return hasNext();
        }
        // iterator on the collection of values for the index key
        Object values = currentMapEntry.getValue();
        if (values instanceof Collection) {
          valuesIterator = ((Collection) values).iterator();
        } else {
          valuesIterator = null;
          currValue = values;
        }
        return values != null && (values instanceof RegionEntry || valuesIterator.hasNext());
      }

      currKey = null;
      return false;
    }

    /**
     * returns a new InMemoryIndexStorageEntry with current index key and its next value which is
     * the next RE in the collection. Make sure hasNext() has been called before calling this method
     */
    @Override
    public MemoryIndexStoreEntry next() {
      if (valuesIterator == null) {
        currentEntry.setMemoryIndexStoreEntry(currKey, (RegionEntry) currValue);
        return currentEntry;
      }

      RegionEntry re = (RegionEntry) valuesIterator.next();
      if (re == null) {
        throw new NoSuchElementException();
      }

      currentEntry.setMemoryIndexStoreEntry(currKey, re);
      return currentEntry;
    }

    @Override
    public void remove() {
      mapIterator.remove();
    }

    @Override
    public void close() {
      // do nothing
    }

    public boolean removeFromKeysToRemove(Collection keysToRemove, Object key) {
      Iterator iterator = keysToRemove.iterator();
      while (iterator.hasNext()) {
        try {
          if (TypeUtils.compare(key, iterator.next(), OQLLexerTokenTypes.TOK_EQ)
              .equals(Boolean.TRUE)) {
            iterator.remove();
            return true;
          }
        } catch (TypeMismatchException e) {
          // they are not equals, so we just continue iterating
        }
      }
      return false;
    }
  }

  @Override
  public String printAll() {
    StringBuilder sb = new StringBuilder();
    for (final Object item : valueToEntriesMap.entrySet()) {
      Entry mapEntry = (Entry) item;
      sb.append("Key: " + mapEntry.getKey());
      Object value = mapEntry.getValue();
      if (value instanceof Collection) {
        for (final Object o : (Collection) value) {
          sb.append(" Value:" + getTargetObject((RegionEntry) o));
        }
      } else {
        sb.append(" Value:" + getTargetObject((RegionEntry) value));
      }

      sb.append("\n");

    }
    return sb.toString();
  }

  class MemoryIndexStoreKey implements IndexStoreEntry {
    private final Object indexKey;

    public MemoryIndexStoreKey(Object indexKey) {
      this.indexKey = indexKey;
    }

    @Override

    public Object getDeserializedKey() {
      return indexKey;
    }

    @Override
    public Object getDeserializedValue() {
      throw new UnsupportedOperationException();
    }

    @Override
    public Object getDeserializedRegionKey() {
      throw new UnsupportedOperationException();
    }

    @Override
    public boolean isUpdateInProgress() {
      throw new UnsupportedOperationException();
    }
  }
  /**
   * A wrapper over the entry in the CSL index map. It maps IndexKey -> RegionEntry
   */
  class MemoryIndexStoreEntry implements IndexStoreEntry {
    private Object deserializedIndexKey;
    private RegionEntry regionEntry;
    private boolean updateInProgress;
    private Object value;
    private final long iteratorStartTime;

    private MemoryIndexStoreEntry(long iteratorStartTime) {
      this.iteratorStartTime = iteratorStartTime;
    }

    public void setMemoryIndexStoreEntry(Object deserializedIndexKey, RegionEntry regionEntry) {
      this.deserializedIndexKey = deserializedIndexKey;
      this.regionEntry = regionEntry;
      updateInProgress = regionEntry.isUpdateInProgress();
      value = getTargetObject(regionEntry);
    }

    @Override
    public Object getDeserializedKey() {
      return deserializedIndexKey;
    }

    @Override
    public Object getDeserializedValue() {
      return value;
    }

    @Override
    public Object getDeserializedRegionKey() {
      return regionEntry.getKey();
    }

    public RegionEntry getRegionEntry() {
      return regionEntry;
    }

    @Override
    public boolean isUpdateInProgress() {
      return updateInProgress || regionEntry.isUpdateInProgress()
      // The index update could have started just before the iterator was created. The entry still
      // needs to be re-evaluated in this case.
          || IndexManager.needsRecalculation(iteratorStartTime, regionEntry.getLastModified());
    }
  }

  public class CachedEntryWrapper {

    private final Object key;
    private final Object value;

    public CachedEntryWrapper(NonTXEntry entry) {
      if (IndexManager.testHook != null) {
        IndexManager.testHook.hook(201);
      }
      key = entry.getKey();
      value = entry.getValue();
    }

    public Object getKey() {
      return key;
    }

    public Object getValue() {
      return value;
    }

    public String toString() {
      return "CachedEntryWrapper@"
          + Integer.toHexString(System.identityHashCode(this)) + ' ' + key
          + ' ' + value;
    }

    @Override
    public boolean equals(Object obj) {
      if (!(obj instanceof CachedEntryWrapper)) {
        return false;
      }
      CachedEntryWrapper object = (CachedEntryWrapper) obj;
      if (!getKey().equals(object.getKey())) {
        if (!(getKey() instanceof PdxInstanceImpl)) {
          return false;
        }
        if (!(object.getKey() instanceof PdxInstanceImpl)) {
          return false;
        }
        PdxInstanceImpl pdxkey1 = (PdxInstanceImpl) getKey();
        PdxInstanceImpl pdxkey2 = (PdxInstanceImpl) object.getKey();
        if (!pdxkey1.equals(pdxkey2)) {
          return false;
        }
      }
      if (!getValue().equals(object.getValue())) {
        if (!(getValue() instanceof PdxInstanceImpl)) {
          return false;
        }
        if (!(object.getValue() instanceof PdxInstanceImpl)) {
          return false;
        }
        PdxInstanceImpl pdxvalue1 = (PdxInstanceImpl) getValue();
        PdxInstanceImpl pdxvalue2 = (PdxInstanceImpl) object.getValue();
        if (!pdxvalue1.equals(pdxvalue2)) {
          return false;
        }
      }

      return true;
    }

    @Override
    public int hashCode() {
      return hash(key, value);
    }

  }

}


text:
package com.teamcenter.TcLoadSimulate.Core;

import java.lang.reflect.Constructor;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.TableItem;

import com.teamcenter.TcLoadSimulate.TcLoadSimulate;
import com.teamcenter.TcLoadSimulate.Core.Events.Console;
import com.teamcenter.TcLoadSimulate.Modules.Login;
import com.teamcenter.services.strong.core.SessionService;
import com.teamcenter.soa.client.Connection;

/**
 * Class that contains functionality for running all defined module occurrences
 * in a sequence.
 *
 * @date Changed so that ProgressEvent is instantiated with the Worker object
 */
@XmlType
public final class Worker extends ApplicationObject implements Runnable {
	public Mode mode = Mode.STOPPED;
	public Status status = Status.NONE;
	public int tasks = 0;
	public int iterations = 0;
	public int totalIterations;
	public int totalTasks;
	private Module module;

	@XmlTransient
	public Thread myThread = null;

	/**
	 * Sequence of module occurrences that are to be iterated.
	 */
	@XmlElementWrapper(name = "sequence")
	@XmlElement(name = "mod_occ")
	public ModuleOcc[] sequenceList;

	/**
	 * Each worker have its own tableitem object for displaying information in
	 * the GUI table.
	 */
	private TableItem tableItem;

	/**
	 * The Teamcenter connection object.
	 */
	private Connection connection;

	public TableItem getTableItem() {
		return tableItem;
	}

	public String getModuleType() {
		return module.type;
	}

	public String getModuleTimeDelta() {
		return module.getTimeDelta();
	}

	public String getModuleMiscInfo() {
		return module.getMiscInfo();
	}

	public String getIterations() {
		if (totalIterations == 0)
			return String.format("%d", iterations);
		else
			return String.format("%d/%d", iterations, totalIterations);
	}

	public String getPercent() {
		if (totalIterations == 0)
			return "---";
		else
			return String.format("%d %%",
					Math.round((float) tasks / totalTasks * 100));
	}

	/**
	 * Intializes the thread before execution.
	 *
	 * @return The thread object.
	 * @throws Exception
	 */
	public void start() {
		if (mode == Mode.STOPPED && !Shutdown.isShutdownInitiated()) {
			myThread = new Thread(this, id);
			Shutdown.registerThread(myThread);
			myThread.setDaemon(true);
			myThread.start();
		}
	}

	public void stop() {
		if (mode == Mode.STARTED) {
			myThread.interrupt();
		}
	}

	/**
	 * Convenience class to merge two arrays, the primary has higher priority
	 * than secondary.
	 *
	 * @param primary
	 *            Master array
	 * @param secondary
	 *            Secondary array
	 * @return A merged array
	 */
	private Setting[] mergeSettings(Setting[] primary, Setting[] secondary) {
		List<Setting> temp = null;

		if (primary == null && secondary == null)
			return null;
		else if (primary != null && secondary == null)
			return primary;
		else if (primary == null && secondary != null)
			return secondary;
		else {
			temp = new ArrayList<Setting>(Arrays.asList(primary));

			for (Setting sec : secondary) {
				boolean exist = false;
				for (Setting pri : temp) {
					if (pri.name.equals(sec.name)) {
						exist = true;
						break;
					}
				}
				if (!exist)
					temp.add(sec);
			}
		}

		return temp.toArray(new Setting[temp.size()]);
	}

	/**
	 * Creates worker specific instances of all modules with reflection. This is
	 * needed to make every worker fully thread-safe.
	 *
	 * @throws Exception
	 */
	public final void initialize() throws Exception {
		for (ModuleOcc mo : sequenceList) {
			Module mod = Application.getModule(mo.refid);
			// Some reflection to get our modules into new instances of
			// correct class
			Class<?> classObj = Class
					.forName("com.teamcenter.TcLoadSimulate.Modules."
							+ mod.type);
			Constructor<?> construct = classObj.getConstructor(String.class,
					String.class, Setting[].class);
			mo.moduleObj = (Module) construct.newInstance(mod.id, mod.type,
					mergeSettings(mo.settingsList, mod.settingsList));
		}
		if (TcLoadSimulate.gui) {
			final TableItem tableItem = new TableItem(UserInterface.getTable(),
					SWT.NONE);
			tableItem.setData("worker", this);
			this.tableItem = tableItem;
			tableItem.setText(new String[] { null, null, "---", id, "---",
					"---", "---", "---" });
			addEventListener(TcLoadSimulate.userInterface);
		}
		addEventListener(TcLoadSimulate.logger);
	}

	public final void runModule(ModuleOcc mo) throws Exception {
		// Get module for current task
		module = mo.moduleObj;

		// Enter running phase
		status = Status.RUNNING;
		fireEvent();

		try {
			if (module instanceof Login)
				connection = module.run();
			else {
				if (mo.probability == 100 || rnd.nextInt(100) <= mo.probability)
					module.run(connection);
				else
					return;
			}
		} catch (InterruptedException e) {
			throw e;
		} catch (Exception e) {
			if (!module.continueOnError()) {
				throw e;
			}
			status = Status.ERROR;
			fireEvent();
			Console.err(e);
			module.retrySleep();
			runModule(mo);
		}
		// Enter sleep phase
		status = Status.SLEEPING;
		fireEvent();
		module.resetRetryCount();
		module.sleep();
	}

	/**
	 * Run the module occurrence sequence for a defined number of iterations.
	 *
	 * @see java.lang.Runnable#run()
	 */
	@Override
	public final void run() {
		Console.out(id, "Starting thread");

		try {
			mode = Mode.STARTED;
			status = Status.NONE;
			fireEvent();

			tasks = 0;
			totalTasks = 0;
			totalIterations = getSettingAsInt("iterations");
			for (ModuleOcc mo : sequenceList) {
				if (mo.runonce.equals("false"))
					totalTasks += totalIterations;
				else
					totalTasks++;
			}

			for (iterations = 1; totalIterations == 0 || iterations <= totalIterations; iterations++) {
				for (ModuleOcc mo : sequenceList) {
					if (mo.runonce.equals("false")
							|| (mo.runonce.equals("start") && iterations == 1)
							|| (mo.runonce.equals("end") && iterations == totalIterations)) {
						tasks++;

						runModule(mo);
					}
				}
			}
			iterations = totalIterations;
			status = Status.FINISHED;
		} catch (InterruptedException e) {
			status = Status.FINISHED;
		} catch (Exception e) {
			status = Status.ERROR;
			Console.err(e);
		} finally {
			mode = Mode.STOPPED;
			fireEvent();
			// Make sure the session is logged out
			try {
				if (connection != null) {
					SessionService ss = SessionService.getService(connection);
					ss.logout();
					connection = null;
				}
			} catch (Exception e) {
			}

			Console.out(id, "Stopping thread");
		}
	}
}

redpajama_set_name: RedPajamaGithub


text:
* Fix Sprockets 3 integration. Thanks @suzan2go and @ccallebs!

### 2.7.0 - 2015-04-17

* compatibility with Sprockets 3
* Drop Rails 3.x support

### 2.6.0 - 2014-11-07

* Update to Less.rb v2.6.
* Merge PR #88 'Fix dropped import dependencies'.

### 2.5.0 - 2014-03-11

* Update to Less.rb v2.5 and follow version mirror. Fixes #84.

### 2.4.2 - 2013-09-07

* Another stab at better initialization process. Fixes #68. Fixes #62.
  NOTE: If you were using `less-rails.after.load_config_initializers`, please
  change your initializer to use `less-rails.before.load_config_initializers`.

### 2.4.1 - 2013-09-07

* Fix import hooks to allow relative paths to files. Fixes #72 and #64.
* Use config.(before|after)_initialize for better railtie pattern. Fixed #68.

### 2.4.0 - 2013-09-04

* Moving to less.rb 2.4.x which is current v### 1.4.2 of less.

### 2.3.3 - 2013-04-16

* Implement dumpLineNumbers functionality. Thanks @matthew342.

### 2.3.2 - 2013-03-06

* Rails 4 compatability. Thanks @zhengjia.

### 2.3.1 - 2013-03-06

* Update to less gem ### 2.3.1 which really uses less v### 1.3.3

### 2.3.0 - 2013-03-06

* Update to less gem ### 2.3.0 thanks @leifcr

### 2.2.6 - 2012-10-31

* Accidental release. Nothing new.

### 2.2.5 - 2012-10-28

* Real Rails 4 compatability thanks to @yalab

### 2.2.4 - 2012-10-20

* Rails 4 compatability with Sprockets vs app.assets.

### 2.2.3 - 2012-05-27

* Add default_mime_type to template class since it does not inherit from Tilt's.
  Should fix https://github.com/metaskills/less-rails/issues/35

### 2.2.2 - 2012-04-25

* Remove explicit dependency on therubyracer
* Add jruby and jruby --1.9 to travis configuration
* Officially support JRuby

### 2.2.1 - 2012-04-15

* Make it usable with therubyrhino (and older versions of therubyracer as well). Fixes #36.

### 2.2.0 - 2012-03-29

* Upgrade to therubyracer 0.10.x call semantics. Fixes #34.

### 2.1.8 - 2012-03-15

* Work with edge rails/sprockets. Fixes #31.

### 2.1.7 - 2012-03-07

* More defensive railtie when examing asset paths. Fixes #30.

### 2.1.6 - 2012-02-16

* Nested imports recursively declare sprockets dependencies. Fixes #26.

### 2.1.4, ### 2.1.5 - 2012-01-31

* More friendly import processor with missing files. Fixes #13.

### 2.1.3 - 2012-01-23

* Make sure vendor/assets/stylesheets .less files work.

### 2.1.2 - 2011-12-20

* No notes.

### 2.1.1 - 2011-11-24

* All app asset stylesheet paths are added to less paths.

### 2.1.0 - 2011-11-18

* Remove our basic CssCompressor since it can not handle real world general purpose JS
  compression. Instead set parse compression and recommend final YUI Compressor. Fixes #7.
* Import preprocessor so @import'ed less files are automatic asset dependencies. Fixes #3.

### 2.0.3 - 2011-11-13

* Add generator support. Fixes #8.
* Add a Less::Rails::CssCompressor if config.assets.compress is true. Fixes #7.

### 2.0.2 - 2011-10-09

* Extend LESS with Rails asset pipeline helpers.
* New testing support with MiniTest::Spec and dummy Rails::Application.
* New config.options hash passed down to the #to_css method.

### 2.0.1 - 2011-09-28

* Fix require of less/rails/railtie.rb. Thanks Benoit Bénézech (bbenezech).

### 2.0.0 - 2011-09-25

* Initial 2.0 release. Heavily inspired/copied code from sass-rails.

### 1.0.0 - 2010-02-02

* Original project at http://github.com/yeastymobs/less-rails


text:
#include "stdafx.h"

#include "mscl/Exceptions.h"
#include "SyncSamplingPacket_v2_aspp3.h"
#include "mscl/MicroStrain/SampleUtils.h"
#include "mscl/MicroStrain/Wireless/ChannelMask.h"
#include "mscl/TimeSpan.h"
#include "mscl/TimestampCounter.h"
#include "mscl/Types.h"
#include "mscl/Utils.h"

namespace mscl
{

    SyncSamplingPacket_v2_aspp3::SyncSamplingPacket_v2_aspp3(const WirelessPacket& packet)
    {
        //construct the data packet from the wireless packet passed in
        m_nodeAddress              = packet.nodeAddress();
        m_deliveryStopFlags        = packet.deliveryStopFlags();
        m_type                     = packet.type();
        m_nodeRSSI                 = packet.nodeRSSI();
        m_baseRSSI                 = packet.baseRSSI();
        m_frequency                = packet.frequency();
        m_payload                  = packet.payload();
        m_payloadOffsetChannelData = PAYLOAD_OFFSET_CHANNEL_DATA;

        //parse the data sweeps in the packet
        parseSweeps();
    }

    void SyncSamplingPacket_v2_aspp3::parseSweeps()
    {
        //read the values from the payload
        //model number
        uint16 channelMask          = m_payload.read_uint16(PAYLOAD_OFFSET_CHANNEL_MASK);
        uint8 sampleRate            = m_payload.read_uint8(PAYLOAD_OFFSET_SAMPLE_RATE);
        uint16 tick                 = m_payload.read_uint16(PAYLOAD_OFFSET_TICK);
        uint64 timestamp            = m_payload.read_uint64(PAYLOAD_OFFSET_TS);

        m_dataType = static_cast<WirelessTypes::DataType>(m_payload.read_uint8(PAYLOAD_OFFSET_DATA_TYPE));

        if(!timestampWithinRange(Timestamp(timestamp)))
        {
            throw Error("Timestamp is out of range");
        }

        //build the ChannelMask from the channel mask
        ChannelMask channels(channelMask);

        //calculate the size of a single sweep
        m_sweepSize = channels.count() * WirelessTypes::dataTypeSize(m_dataType);

        //if the sweep size is 0 (no channels active)
        if(m_sweepSize == 0)
        {
            //we only want to insert 1 sweep
            m_numSweeps = 1;
        }
        else
        {
            //calculate the number of sweeps in this packet
            m_numSweeps = (m_payload.size() - PAYLOAD_OFFSET_CHANNEL_DATA) / m_sweepSize;
        }

        //if we still have no sweeps, there was an error in the packet
        if(m_numSweeps == 0) { throw Error("Invalid Packet"); }

        //create a SampleRate object from the sampleRate byte
        SampleRate currentRate = SampleUtils::convertToSampleRate(sampleRate);

        TimestampCounter tsCounter(currentRate, timestamp);

        //there are multiple sweeps in a Sync Sampling (buffered) packet
        for(uint32 sweepItr = 0; sweepItr < m_numSweeps; sweepItr++)
        {
            //build a sweep to add
            DataSweep sweep;
            sweep.samplingType(DataSweep::samplingType_SyncSampling);
            sweep.frequency(m_frequency);
            sweep.tick(tick++);
            sweep.nodeAddress(m_nodeAddress);
            sweep.sampleRate(currentRate);

            //build this sweep's timestamp
            sweep.timestamp(Timestamp(tsCounter.time()));
            tsCounter.advance();

            //get this sweep's node and base rssi values
            sweep.nodeRssi(m_nodeRSSI);
            sweep.baseRssi(m_baseRSSI);

            //cals applied if the data type is float
            sweep.calApplied(WirelessTypes::isCalApplied(m_dataType));

            ChannelData chData;

            //the index of the channel data
            int chDataIndex = 0;

            uint8 lastActiveCh = channels.lastChEnabled();

            //loop through all the channels
            for(uint8 chItr = 1; chItr <= lastActiveCh; ++chItr)
            {
                //if the current channel is enabled
                if(channels.enabled(chItr))
                {
                    //insert the data point into the ChannelData object for the wireless channel
                    addDataPoint(chData, (chItr), chDataIndex, sweepItr, wirelessChannelFromChNum(chItr));

                    chDataIndex++;
                }
            }

            //add the channel data to the sweep
            sweep.data(chData);

            //add the sweep to the container of sweeps
            addSweep(sweep);
        }
    }

    bool SyncSamplingPacket_v2_aspp3::integrityCheck(const WirelessPacket& packet)
    {
        WirelessPacket::Payload payload = packet.payload();

        //verify the payload size
        if(payload.size() < PAYLOAD_OFFSET_CHANNEL_DATA)
        {
            //payload must have at least 14 bytes to be valid
            return false;
        }

        //verify the delivery stop flags are what we expected
        if(!packet.deliveryStopFlags().pc)
        {
            //packet not intended for the PC
            return false;
        }

        //read the data type
        uint8 dataType = payload.read_uint8(PAYLOAD_OFFSET_DATA_TYPE);

        //verify the data type
        if(dataType < WirelessTypes::dataType_first || dataType > WirelessTypes::dataType_last)
        {
            //the data type is invalid
            return false;
        }

        //verify the packet type is correct
        if(packet.type() != packetType_SyncSampling_16ch)
        {
            //packet is not a Sync Sampling packet
            return false;
        }

        //calculate the number of active channels
        uint32 channels = ChannelMask(payload.read_uint16(PAYLOAD_OFFSET_CHANNEL_MASK)).count();

        //calculate the size of a single data point
        uint32 dataSize = WirelessTypes::dataTypeSize(static_cast<WirelessTypes::DataType>(dataType));

        uint32 recordSize = channels * dataSize;

        //if record size is zero, something is wrong. Bail now before divide by zero
        if(recordSize <= 0)
        {
            return false;
        }

        //the number of channel data bytes
        size_t numChannelBytes = payload.size() - PAYLOAD_OFFSET_CHANNEL_DATA;

        //verify that there are actually channel data bytes
        if(numChannelBytes == 0)
        {
            return false;
        }

        //verify the payload contains a correct number of bytes
        if(numChannelBytes % recordSize != 0)
        {
            return false;
        }

        //packet looks valid
        return true;
    }

    UniqueWirelessPacketId SyncSamplingPacket_v2_aspp3::getUniqueId(const WirelessPacket& packet)
    {
        //return the tick value
        return packet.payload().read_uint16(PAYLOAD_OFFSET_TICK);
    }
}


text:
module.exports = {
  PROJECT_NAME: 'hz_pictionary',
};


text:
/**
 * Module dependencies.
 */

var Parser = require('./parser')
  , EventEmitter = require('events').EventEmitter
  , Evaluator = require('./visitor/evaluator')
  , Normalizer = require('./visitor/normalizer')
  , events = new EventEmitter
  , utils = require('./utils')
  , nodes = require('./nodes')
  , join = require('path').join;

/**
 * Expose `Renderer`.
 */

module.exports = Renderer;

/**
 * Initialize a new `Renderer` with the given `str` and `options`.
 *
 * @param {String} str
 * @param {Object} options
 * @api public
 */

function Renderer(str, options) {
  options = options || {};
  options.globals = options.globals || {};
  options.functions = options.functions || {};
  options.use = options.use || [];
  options.use = Array.isArray(options.use) ? options.use : [options.use];
  options.imports = [join(__dirname, 'functions/index.styl')].concat(options.imports || []);
  options.paths = options.paths || [];
  options.filename = options.filename || 'stylus';
  options.Evaluator = options.Evaluator || Evaluator;
  this.options = options;
  this.str = str;
  this.events = events;
};

/**
 * Inherit from `EventEmitter.prototype`.
 */

Renderer.prototype.__proto__ = EventEmitter.prototype;

/**
 * Expose events explicitly.
 */

module.exports.events = events;

/**
 * Parse and evaluate AST, then callback `fn(err, css, js)`.
 *
 * @param {Function} fn
 * @api public
 */

Renderer.prototype.render = function(fn){
  var parser = this.parser = new Parser(this.str, this.options);

  // use plugin(s)
  for (var i = 0, len = this.options.use.length; i < len; i++) {
    this.use(this.options.use[i]);
  }

  try {
    nodes.filename = this.options.filename;
    // parse
    var ast = parser.parse();

    // evaluate
    this.evaluator = new this.options.Evaluator(ast, this.options);
    this.nodes = nodes;
    this.evaluator.renderer = this;
    ast = this.evaluator.evaluate();

    // normalize
    var normalizer = new Normalizer(ast, this.options);
    ast = normalizer.normalize();

    // compile
    var compiler = this.options.sourcemap
      ? new (require('./visitor/sourcemapper'))(ast, this.options)
      : new (require('./visitor/compiler'))(ast, this.options)
      , css = compiler.compile();

    // expose sourcemap
    if (this.options.sourcemap) this.sourcemap = compiler.map.toJSON();
  } catch (err) {
    var options = {};
    options.input = err.input || this.str;
    options.filename = err.filename || this.options.filename;
    options.lineno = err.lineno || parser.lexer.lineno;
    options.column = err.column || parser.lexer.column;
    if (!fn) throw utils.formatException(err, options);
    return fn(utils.formatException(err, options));
  }

  // fire `end` event
  var listeners = this.listeners('end');
  if (fn) listeners.push(fn);
  for (var i = 0, len = listeners.length; i < len; i++) {
    var ret = listeners[i](null, css);
    if (ret) css = ret;
  }
  if (!fn) return css;
};

/**
 * Get dependencies of the compiled file.
 *
 * @param {String} [filename]
 * @return {Array}
 * @api public
 */

Renderer.prototype.deps = function(filename){
  var opts = utils.merge({ cache: false }, this.options);
  if (filename) opts.filename = filename;

  var DepsResolver = require('./visitor/deps-resolver')
    , parser = new Parser(this.str, opts);

  try {
    nodes.filename = opts.filename;
    // parse
    var ast = parser.parse()
      , resolver = new DepsResolver(ast, opts);

    // resolve dependencies
    return resolver.resolve();
  } catch (err) {
    var options = {};
    options.input = err.input || this.str;
    options.filename = err.filename || opts.filename;
    options.lineno = err.lineno || parser.lexer.lineno;
    options.column = err.column || parser.lexer.column;
    throw utils.formatException(err, options);
  }
};

/**
 * Set option `key` to `val`.
 *
 * @param {String} key
 * @param {Mixed} val
 * @return {Renderer} for chaining
 * @api public
 */

Renderer.prototype.set = function(key, val){
  this.options[key] = val;
  return this;
};

/**
 * Get option `key`.
 *
 * @param {String} key
 * @return {Mixed} val
 * @api public
 */

Renderer.prototype.get = function(key){
  return this.options[key];
};

/**
 * Include the given `path` to the lookup paths array.
 *
 * @param {String} path
 * @return {Renderer} for chaining
 * @api public
 */

Renderer.prototype.include = function(path){
  this.options.paths.push(path);
  return this;
};

/**
 * Use the given `fn`.
 *
 * This allows for plugins to alter the renderer in
 * any way they wish, exposing paths etc.
 *
 * @param {Function}
 * @return {Renderer} for chaining
 * @api public
 */

Renderer.prototype.use = function(fn){
  fn.call(this, this);
  return this;
};

/**
 * Define function or global var with the given `name`. Optionally
 * the function may accept full expressions, by setting `raw`
 * to `true`.
 *
 * @param {String} name
 * @param {Function|Node} fn
 * @return {Renderer} for chaining
 * @api public
 */

Renderer.prototype.define = function(name, fn, raw){
  fn = utils.coerce(fn, raw);

  if (fn.nodeName) {
    this.options.globals[name] = fn;
    return this;
  }

  // function
  this.options.functions[name] = fn;
  if (undefined != raw) fn.raw = raw;
  return this;
};

/**
 * Import the given `file`.
 *
 * @param {String} file
 * @return {Renderer} for chaining
 * @api public
 */

Renderer.prototype.import = function(file){
  this.options.imports.push(file);
  return this;
};


text:
from __future__ import absolute_import

from . import CommentTestCase

class CommentFeedTests(CommentTestCase):
    urls = 'regressiontests.comment_tests.urls'
    feed_url = '/rss/comments/'

    def test_feed(self):
        response = self.client.get(self.feed_url)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response['Content-Type'], 'application/rss+xml; charset=utf-8')
        self.assertContains(response, '<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0">')
        self.assertContains(response, '<title>example.com comments</title>')
        self.assertContains(response, '<link>http://example.com/</link>')
        self.assertContains(response, '</rss>')


text:
import { mount } from '@vue/test-utils'
import VirtualList from '../src/index'
import { VirtualProps } from '../src/props'
import Item from './item.vue'
import { getDatas } from './util'

describe('element', () => {
  const Instance = mount({
    name: 'test',
    components: {
      'virtual-list': VirtualList
    },
    template: `
      <div id="app">
        <virtual-list class="my-list" style="height: 300px; overflow-y: auto;"
          :data-key="'id'"
          :data-sources="items"
          :data-component="item"
          :root-tag="'article'"
          :wrap-tag="'section'"
          :wrap-class="'wrap-class-aaa'"
          :item-tag="'p'"
          :item-class="'item-class-bbb'"
          :item-class-add="addItemClass"
        />
      </div>
    `,
    data () {
      return {
        items: getDatas(1000),
        item: Item
      }
    },
    methods: {
      addItemClass (index) {
        return 'extra-item-' + index
      }
    }
  })

  it('check mount', () => {
    expect(Instance.name()).toBe('test')
    expect(Instance.is('div')).toBe(true)
    expect(Instance.isVueInstance()).toBe(true)
    expect(Instance.find('.my-list').exists()).toBe(true)
  })

  it('check element tag and class', () => {
    const vmData = Instance.vm.$data
    const vslVm = Instance.find('.my-list').vm
    const rootEl = vslVm.$el
    expect(rootEl.tagName.toLowerCase()).toBe('article')

    const wrapperEl = rootEl.firstElementChild

    // wrapper element and padding style
    expect(wrapperEl.getAttribute('role')).toBe('group')
    expect(!!rootEl.style.padding).toBe(false)
    expect(!!wrapperEl.style.padding).toBe(true)
    expect(wrapperEl.className).toBe('wrap-class-aaa')
    expect(wrapperEl.tagName.toLowerCase()).toBe('section')

    // render number keeps by default
    expect(wrapperEl.childNodes.length).toBe(VirtualProps.keeps.default)

    // items render content
    for (let i = 0; i < wrapperEl.childNodes.length; i++) {
      const itemEl = wrapperEl.childNodes[i]
      expect(itemEl.className).toBe(`item-class-bbb extra-item-${i}`)
      expect(itemEl.tagName.toLowerCase()).toBe('p')

      // item inner render (see ./item.vue)
      const itemInnerEl = itemEl.firstElementChild
      expect(itemInnerEl.className).toBe('inner')
      expect(itemInnerEl.querySelector('.index').textContent).toBe(`${i}`)
      expect(itemInnerEl.querySelector('.source').textContent).toBe(vmData.items[i].text)
    }
  })
})


text:
"""All routes regarding authentication."""

from datetime import datetime
from flask import jsonify
from sqlalchemy import or_
from webargs.flaskparser import use_args

from server import user_bp
from server.extensions import db
from server.models import User
from server.responses import bad_request
from server.schemas.user import UserSchema
from server.validation.user import login_fields
from server.helpers.decorators import login_exempt

@user_bp.route('/api/auth/login', methods=['POST'])
@login_exempt
@use_args(login_fields)
def login(args):
    """Endpoint for login.

    Check if we can login with the credentials. We try to get the
    user by searching email and nickname for the given identifier.
    """
    identifier = args['identifier']
    password = args['password']

    # Check if the user exists
    user = db.session.query(User) \
        .filter(or_(User.nickname == identifier, User.email == identifier)) \
        .one_or_none()

    if user is None:
        return bad_request('Unknown credentials or wrong password.')

    # Validate password
    valid_password = user.verify_password(password)
    if not valid_password:
        return bad_request('Unknown credentials or wrong password.')

    if not user.has_valid_auth_token:
        user.generate_auth_token()
    user.last_login_at = datetime.utcnow()
    db.session.add(user)
    db.session.commit()

    schema = UserSchema()
    return jsonify(schema.dump(user).data)


text:
<?php

namespace Plum\Plum;

use Exception;

/**
 * ResultTest.
 *
 * @author    Florian Eckerstorfer <florian@eckerstorfer.co>
 * @copyright 2014-2015 Florian Eckerstorfer
 * @group     unit
 */
class ResultTest extends \PHPUnit_Framework_TestCase
{
    /** @var Result */
    private $result;

    public function setUp()
    {
        $this->result = new Result();
    }

    /**
     * @test
     * @covers Plum\Plum\Result::incReadCount()
     * @covers Plum\Plum\Result::getReadCount()
     */
    public function incReadCountShouldIncreaseReadCount()
    {
        $this->assertInstanceOf(
            'Plum\Plum\Result',
            $this->result->incReadCount()
        );

        $this->assertEquals(1, $this->result->getReadCount());
    }

    /**
     * @test
     * @covers Plum\Plum\Result::incWriteCount()
     * @covers Plum\Plum\Result::getWriteCount()
     */
    public function incWriteCountShouldIncreaseWriteCount()
    {
        $this->assertInstanceOf(
            'Plum\Plum\Result',
            $this->result->incWriteCount()
        );

        $this->assertEquals(1, $this->result->getWriteCount());
    }

    /**
     * @test
     * @covers Plum\Plum\Result::incItemWriteCount()
     * @covers Plum\Plum\Result::getItemWriteCount()
     */
    public function incItemWriteCountShouldIncreaseWriteCount()
    {
        $this->assertInstanceOf(
            'Plum\Plum\Result',
            $this->result->incItemWriteCount()
        );

        $this->assertEquals(1, $this->result->getItemWriteCount());
    }

    /**
     * @test
     * @covers Plum\Plum\Result::addException()
     * @covers Plum\Plum\Result::getExceptions()
     * @covers Plum\Plum\Result::getErrorCount()
     */
    public function addExceptionShouldAddException()
    {
        $exception = new Exception();
        $this->assertInstanceOf(
            'Plum\Plum\Result',
            $this->result->addException($exception)
        );

        $this->assertContains($exception, $this->result->getExceptions());
        $this->assertEquals(1, $this->result->getErrorCount());
    }
}


text:
/**
 * @author rooke[hankewins@gmail.com]
 * @fileoverview comb library
 */
// comb-core.js
// comb 核心方法
(function(){

}).call(this);

// comb-load.js
// comb 加载管理机制
(function(comb, root, doc){

})(comb, this, document);


text:
package self.micromagic.util;

import java.io.IOException;
import java.io.OutputStream;

public class MultiOutputStream extends OutputStream
{
	private OutputStream out1;
	private OutputStream out2;

	public MultiOutputStream(OutputStream out1, OutputStream out2)
	{
		this.out1 = out1;
		this.out2 = out2;
	}

	public void write(int b)
			throws IOException
	{
		this.out1.write(b);
		this.out2.write(b);
	}

	public void write(byte b[])
			throws IOException
	{
		this.out1.write(b);
		this.out2.write(b);
	}

	public void write(byte b[], int off, int len)
			throws IOException
	{
		this.out1.write(b, off, len);
		this.out2.write(b, off, len);
	}

	public void flush()
			throws IOException
	{
		this.out1.flush();
		this.out2.flush();
	}

	public void close()
			throws IOException
	{
		this.out1.close();
		this.out2.close();
	}

}


text:
This is a simple F# type provider.  It has separate design-time and runtime assemblies.

Paket is used to acquire the type provider SDK and build the nuget package (you can remove this use of paket if you like)

Building:

    .paket\paket.exe update

    dotnet build -c release

    .paket\paket.exe pack src\QueryableProvider.Runtime\paket.template --version 0.0.1


text:
#ifdef  __cplusplus
extern "C" {
#endif

#ifdef OPENSSL_ALGORITHM_DEFINES
# error OPENSSL_ALGORITHM_DEFINES no longer supported
#endif

/*
 * OpenSSL was configured with the following options:
 */

#ifndef OPENSSL_SYS_WIN64A
# define OPENSSL_SYS_WIN64A 1
#endif
#ifndef OPENSSL_NO_COMP
# define OPENSSL_NO_COMP
#endif
#ifndef OPENSSL_NO_MD2
# define OPENSSL_NO_MD2
#endif
#ifndef OPENSSL_NO_RC5
# define OPENSSL_NO_RC5
#endif
#ifndef OPENSSL_THREADS
# define OPENSSL_THREADS
#endif
#ifndef OPENSSL_NO_AFALGENG
# define OPENSSL_NO_AFALGENG
#endif
#ifndef OPENSSL_NO_ASAN
# define OPENSSL_NO_ASAN
#endif
#ifndef OPENSSL_NO_CRYPTO_MDEBUG
# define OPENSSL_NO_CRYPTO_MDEBUG
#endif
#ifndef OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
# define OPENSSL_NO_CRYPTO_MDEBUG_BACKTRACE
#endif
#ifndef OPENSSL_NO_EC_NISTP_64_GCC_128
# define OPENSSL_NO_EC_NISTP_64_GCC_128
#endif
#ifndef OPENSSL_NO_EGD
# define OPENSSL_NO_EGD
#endif
#ifndef OPENSSL_NO_FUZZ_AFL
# define OPENSSL_NO_FUZZ_AFL
#endif
#ifndef OPENSSL_NO_FUZZ_LIBFUZZER
# define OPENSSL_NO_FUZZ_LIBFUZZER
#endif
#ifndef OPENSSL_NO_HEARTBEATS
# define OPENSSL_NO_HEARTBEATS
#endif
#ifndef OPENSSL_NO_MSAN
# define OPENSSL_NO_MSAN
#endif
#ifndef OPENSSL_NO_SCTP
# define OPENSSL_NO_SCTP
#endif
#ifndef OPENSSL_NO_SSL_TRACE
# define OPENSSL_NO_SSL_TRACE
#endif
#ifndef OPENSSL_NO_SSL3
# define OPENSSL_NO_SSL3
#endif
#ifndef OPENSSL_NO_SSL3_METHOD
# define OPENSSL_NO_SSL3_METHOD
#endif
#ifndef OPENSSL_NO_UBSAN
# define OPENSSL_NO_UBSAN
#endif
#ifndef OPENSSL_NO_UNIT_TEST
# define OPENSSL_NO_UNIT_TEST
#endif
#ifndef OPENSSL_NO_WEAK_SSL_CIPHERS
# define OPENSSL_NO_WEAK_SSL_CIPHERS
#endif
#ifndef OPENSSL_NO_AFALGENG
# define OPENSSL_NO_AFALGENG
#endif

/*
 * Sometimes OPENSSSL_NO_xxx ends up with an empty file and some compilers
 * don't like that.  This will hopefully silence them.
 */
#define NON_EMPTY_TRANSLATION_UNIT static void *dummy = &dummy;

/*
 * Applications should use -DOPENSSL_API_COMPAT=<version> to suppress the
 * declarations of functions deprecated in or before <version>. Otherwise, they
 * still won't see them if the library has been built to disable deprecated
 * functions.
 */
#if defined(OPENSSL_NO_DEPRECATED)
# define DECLARE_DEPRECATED(f)
#elif __GNUC__ > 3 || (__GNUC__ == 3 && __GNUC_MINOR__ > 0)
# define DECLARE_DEPRECATED(f)    f __attribute__ ((deprecated));
#else
# define DECLARE_DEPRECATED(f)   f;
#endif

#ifndef OPENSSL_FILE
# ifdef OPENSSL_NO_FILENAMES
#  define OPENSSL_FILE ""
#  define OPENSSL_LINE 0
# else
#  define OPENSSL_FILE __FILE__
#  define OPENSSL_LINE __LINE__
# endif
#endif

#ifndef OPENSSL_MIN_API
# define OPENSSL_MIN_API 0
#endif

#if !defined(OPENSSL_API_COMPAT) || OPENSSL_API_COMPAT < OPENSSL_MIN_API
# undef OPENSSL_API_COMPAT
# define OPENSSL_API_COMPAT OPENSSL_MIN_API
#endif

#if OPENSSL_API_COMPAT < 0x10100000L
# define DEPRECATEDIN_1_1_0(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_1_0(f)
#endif

#if OPENSSL_API_COMPAT < 0x10000000L
# define DEPRECATEDIN_1_0_0(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_1_0_0(f)
#endif

#if OPENSSL_API_COMPAT < 0x00908000L
# define DEPRECATEDIN_0_9_8(f)   DECLARE_DEPRECATED(f)
#else
# define DEPRECATEDIN_0_9_8(f)
#endif

#define OPENSSL_CPUID_OBJ

/* Generate 80386 code? */
#undef I386_ONLY

#undef OPENSSL_UNISTD
#define OPENSSL_UNISTD <unistd.h>

#define OPENSSL_EXPORT_VAR_AS_FUNCTION

/*
 * The following are cipher-specific, but are part of the public API.
 */
#if !defined(OPENSSL_SYS_UEFI)
# undef BN_LLONG
/* Only one for the following should be defined */
# undef SIXTY_FOUR_BIT_LONG
# define SIXTY_FOUR_BIT
# undef THIRTY_TWO_BIT
#endif

#define RC4_INT unsigned int

#ifdef  __cplusplus
}
#endif


text:
// Based upon the excellent jsx-transpiler by Ingvar Stepanyan (RReverser)
// https://github.com/RReverser/jsx-transpiler

// jsx

import isString from "lodash/lang/isString";
import * as messages from "../../messages";
import esutils from "esutils";
import * as react from "./react";
import * as t from "../../types";

export default function (opts) {
  var visitor = {};

  visitor.JSXIdentifier = function (node) {
    if (node.name === "this" && this.isReferenced()) {
      return t.thisExpression();
    } else if (esutils.keyword.isIdentifierNameES6(node.name)) {
      node.type = "Identifier";
    } else {
      return t.literal(node.name);
    }
  };

  visitor.JSXNamespacedName = function () {
    throw this.errorWithNode(messages.get("JSXNamespacedTags"));
  };

  visitor.JSXMemberExpression = {
    exit(node) {
      node.computed = t.isLiteral(node.property);
      node.type = "MemberExpression";
    }
  };

  visitor.JSXExpressionContainer = function (node) {
    return node.expression;
  };

  visitor.JSXAttribute = {
    enter(node) {
      var value = node.value;
      if (t.isLiteral(value) && isString(value.value)) {
        value.value = value.value.replace(/\n\s+/g, " ");
      }
    },

    exit(node) {
      var value = node.value || t.literal(true);
      return t.inherits(t.property("init", node.name, value), node);
    }
  };

  visitor.JSXOpeningElement = {
    exit(node, parent, scope, file) {
      parent.children = react.buildChildren(parent);

      var tagExpr = node.name;
      var args = [];

      var tagName;
      if (t.isIdentifier(tagExpr)) {
        tagName = tagExpr.name;
      } else if (t.isLiteral(tagExpr)) {
        tagName = tagExpr.value;
      }

      var state = {
        tagExpr: tagExpr,
        tagName: tagName,
        args:    args
      };

      if (opts.pre) {
        opts.pre(state, file);
      }

      var attribs = node.attributes;
      if (attribs.length) {
        attribs = buildJSXOpeningElementAttributes(attribs, file);
      } else {
        attribs = t.literal(null);
      }

      args.push(attribs);

      if (opts.post) {
        opts.post(state, file);
      }

      return state.call || t.callExpression(state.callee, args);
    }
  };

  /**
   * The logic for this is quite terse. It's because we need to
   * support spread elements. We loop over all attributes,
   * breaking on spreads, we then push a new object containg
   * all prior attributes to an array for later processing.
   */

  var buildJSXOpeningElementAttributes = function (attribs, file) {
    var _props = [];
    var objs = [];

    var pushProps = function () {
      if (!_props.length) return;

      objs.push(t.objectExpression(_props));
      _props = [];
    };

    while (attribs.length) {
      var prop = attribs.shift();
      if (t.isJSXSpreadAttribute(prop)) {
        pushProps();
        objs.push(prop.argument);
      } else {
        _props.push(prop);
      }
    }

    pushProps();

    if (objs.length === 1) {
      // only one object
      attribs = objs[0];
    } else {
      // looks like we have multiple objects
      if (!t.isObjectExpression(objs[0])) {
        objs.unshift(t.objectExpression([]));
      }

      // spread it
      attribs = t.callExpression(
        file.addHelper("extends"),
        objs
      );
    }

    return attribs;
  };

  visitor.JSXElement = {
    exit(node) {
      var callExpr = node.openingElement;

      callExpr.arguments = callExpr.arguments.concat(node.children);

      if (callExpr.arguments.length >= 3) {
        callExpr._prettyCall = true;
      }

      return t.inherits(callExpr, node);
    }
  };

  return visitor;
}


text:
//Set Module's Height script

function setModulesHeight() {
	var regexp = new RegExp("_mod([0-9]+)$");

	if ($$('.jm-module')) {
		var modules = $$('.jm-module');
		modules.each(function(element) {
			var match = regexp.exec(element.className);
			if (match) {
				var modHeight = parseInt(match[1]);
				var module_in = element.getElement('.jm-module-in');
				if (module_in) {
					module_in.setStyle('height', modHeight);
				}
			}
		});
	}

}

window.addEvent('domready', function() {
	setModulesHeight();
});

//jQuery 'Back to Top' script

jQuery(document).ready(function(){
    // hide #jm-back-top first
    jQuery("#jm-back-top").hide();
    // fade in #jm-back-top
    jQuery(function () {
        jQuery(window).scroll(function () {
            if (jQuery(this).scrollTop() > 100) {
                jQuery('#jm-back-top').fadeIn();
            } else {
                jQuery('#jm-back-top').fadeOut();
            }
        });
        // scroll body to 0px on click
        jQuery('#jm-back-top a').click(function () {
            jQuery('body,html').animate({
                scrollTop: 0
            }, 800);
            return false;
        });
    });
});

//Document Text Resizer script (May 14th, 08'): By JavaScript Kit: http://www.javascriptkit.com

var documenttextsizer = {

	prevcontrol : '', //remember last control clicked on/ selected
	existingclasses : '',

	setpageclass : function(control, newclass) {
		if (this.prevcontrol != '')
			this.css(this.prevcontrol, 'selectedtoggler', 'remove')
		//de-select previous control, by removing 'selectedtoggler' from it
		document.documentElement.className = this.existingclasses + ' ' + newclass//apply new class to document
		this.css(control, 'selectedtoggler', 'add')//select current control
		this.setCookie('pagesetting', newclass, 5)//remember new class added to document for 5 days
		this.prevcontrol = control
	},

	css : function(el, targetclass, action) {
		var needle = new RegExp("(^|\\s+)" + targetclass + "($|\\s+)", "ig")
		if (action == "check")
			return needle.test(el.className)
		else if (action == "remove")
			el.className = el.className.replace(needle, "")
		else if (action == "add")
			el.className += " " + targetclass
	},

	getCookie : function(Name) {
		var re = new RegExp(Name + "=[^;]+", "i");
		//construct RE to search for target name/value pair
		if (document.cookie.match(re))//if cookie found
			return document.cookie.match(re)[0].split("=")[1]
		//return its value
		return null
	},

	setCookie : function(name, value, days) {
		if ( typeof days != "undefined") {//if set persistent cookie
			var expireDate = new Date()
			var expstring = expireDate.setDate(expireDate.getDate() + days)
			document.cookie = name + "=" + value + "; path=/; expires=" + expireDate.toGMTString()
		} else//else if this is a session only cookie
			document.cookie = name + "=" + value
	},

	setup : function(targetclass) {
		this.existingclasses = document.documentElement.className//store existing CSS classes on HTML element, if any
		var persistedsetting = this.getCookie('pagesetting')
		var alllinks = document.getElementsByTagName("a")
		for (var i = 0; i < alllinks.length; i++) {
			if (this.css(alllinks[i], targetclass, "check")) {
				if (alllinks[i].getAttribute("rel") == persistedsetting)//if this control's rel attribute matches persisted doc CSS class name
					this.setpageclass(alllinks[i], alllinks[i].getAttribute("rel"))
				//apply persisted class to document
				alllinks[i].onclick = function() {
					documenttextsizer.setpageclass(this, this.getAttribute("rel"))
					return false
				}
			}
		}
	}
}


text:
#ifndef SkGlyphBuffer_DEFINED
#define SkGlyphBuffer_DEFINED

#include "src/core/SkEnumerate.h"
#include "src/core/SkGlyph.h"
#include "src/core/SkZip.h"

#include <climits>

class SkStrikeForGPU;
struct SkGlyphPositionRoundingSpec;
class SkPath;
class SkDrawable;

// SkSourceGlyphBuffer is the source of glyphs between the different stages of glyph drawing.
// It starts with the glyphs and positions from the SkGlyphRun as the first source. When glyphs
// are reject by a stage they become the source for the next stage.
class SkSourceGlyphBuffer {
public:
    SkSourceGlyphBuffer() = default;

    void setSource(SkZip<const SkGlyphID, const SkPoint> source) {
        this->~SkSourceGlyphBuffer();
        new (this) SkSourceGlyphBuffer{source};
    }

    void reset();

    void reject(size_t index) {
        SkASSERT(index < fSource.size());
        if (!this->sourceIsRejectBuffers()) {
            // Need to expand the buffers for first use. All other reject sets will be fewer than
            // this one.
            auto [glyphID, pos] = fSource[index];
            fRejectedGlyphIDs.push_back(glyphID);
            fRejectedPositions.push_back(pos);
            fRejectSize++;
        } else {
            SkASSERT(fRejectSize < fRejects.size());
            fRejects[fRejectSize++] = fSource[index];
        }
    }

    void reject(size_t index, int rejectedMaxDimension) {
        auto [prevMin, prevMax] = fMaxDimensionHintForRejects;
        fMaxDimensionHintForRejects =
                {std::min(prevMin, rejectedMaxDimension),
                 std::max(prevMax, rejectedMaxDimension)};
        this->reject(index);
    }

    SkZip<const SkGlyphID, const SkPoint> flipRejectsToSource() {
        fRejects = SkMakeZip(fRejectedGlyphIDs, fRejectedPositions).first(fRejectSize);
        fSource = fRejects;
        fRejectSize = 0;
        fMaxDimensionHintForSource = fMaxDimensionHintForRejects;
        fMaxDimensionHintForRejects = {INT_MAX, 0};
        return fSource;
    }

    SkZip<const SkGlyphID, const SkPoint> source() const { return fSource; }

    std::tuple<int, int> maxDimensionHint() const {return fMaxDimensionHintForSource;}

private:
    SkSourceGlyphBuffer(const SkZip<const SkGlyphID, const SkPoint>& source) {
        fSource = source;
    }
    bool sourceIsRejectBuffers() const {
        return fSource.get<0>().data() == fRejectedGlyphIDs.data();
    }

    SkZip<const SkGlyphID, const SkPoint> fSource;
    size_t fRejectSize{0};

    // Calculate the smallest and largest max glyph dimension. fMaxDimensionHintForSource captures
    // fMaxDimensionHintForRejects when flipping rejects to the source.
    std::tuple<int, int> fMaxDimensionHintForSource{INT_MAX, 0};
    std::tuple<int, int> fMaxDimensionHintForRejects{INT_MAX, 0};

    SkZip<SkGlyphID, SkPoint> fRejects;
    SkSTArray<4, SkGlyphID> fRejectedGlyphIDs;
    SkSTArray<4, SkPoint> fRejectedPositions;
};

// A memory format that allows an SkPackedGlyphID, SkGlyph*, and SkPath* to occupy the same
// memory. This allows SkPackedGlyphIDs as input, and SkGlyph*/SkPath* as output using the same
// memory.
class SkGlyphVariant {
public:
    SkGlyphVariant() : fV{nullptr} { }
    SkGlyphVariant& operator= (SkPackedGlyphID packedID) {
        fV.packedID = packedID;
        SkDEBUGCODE(fTag = kPackedID);
        return *this;
    }
    SkGlyphVariant& operator= (const SkGlyph* glyph) {
        fV.glyph = glyph;
        SkDEBUGCODE(fTag = kGlyph);
        return *this;

    }
    SkGlyphVariant& operator= (const SkPath* path) {
        fV.path = path;
        SkDEBUGCODE(fTag = kPath);
        return *this;
    }
    SkGlyphVariant& operator= (SkDrawable* drawable) {
        fV.drawable = drawable;
        SkDEBUGCODE(fTag = kDrawable);
        return *this;
    }

    const SkGlyph* glyph() const {
        SkASSERT(fTag == kGlyph);
        return fV.glyph;
    }
    const SkPath* path() const {
        SkASSERT(fTag == kPath);
        return fV.path;
    }
    SkDrawable* drawable() const {
        SkASSERT(fTag == kDrawable);
        return fV.drawable;
    }
    SkPackedGlyphID packedID() const {
        SkASSERT(fTag == kPackedID);
        return fV.packedID;
    }

    operator SkPackedGlyphID()  const { return this->packedID(); }
    operator const SkGlyph*()   const { return this->glyph();    }
    operator const SkPath*()    const { return this->path();     }
    operator const SkDrawable*()const { return this->drawable(); }

private:
    union {
        const SkGlyph* glyph;
        const SkPath* path;
        SkDrawable* drawable;
        SkPackedGlyphID packedID;
    } fV;

#ifdef SK_DEBUG
    enum {
        kEmpty,
        kPackedID,
        kGlyph,
        kPath,
        kDrawable,
    } fTag{kEmpty};
#endif
};

// A buffer for converting SkPackedGlyph to SkGlyph* or SkPath*. Initially the buffer contains
// SkPackedGlyphIDs, but those are used to lookup SkGlyph*/SkPath* which are then copied over the
// SkPackedGlyphIDs.
class SkDrawableGlyphBuffer {
public:
    void ensureSize(size_t size);

    // Load the buffer with SkPackedGlyphIDs and positions at (0, 0) ready to finish positioning
    // during drawing.
    void startSource(const SkZip<const SkGlyphID, const SkPoint>& source);

    // Load the buffer with SkPackedGlyphIDs and positions using the device transform.
    void startBitmapDevice(
            const SkZip<const SkGlyphID, const SkPoint>& source,
            SkPoint origin, const SkMatrix& viewMatrix,
            const SkGlyphPositionRoundingSpec& roundingSpec);

    // Load the buffer with SkPackedGlyphIDs, calculating positions so they can be constant.
    //
    // The positions are calculated integer positions in devices space, and the mapping of the
    // the source origin through the initial matrix is returned. It is given that these positions
    // are only reused when the blob is translated by an integral amount. Thus the shifted
    // positions are given by the following equation where (ix, iy) is the integer positions of
    // the glyph, initialMappedOrigin is (0,0) in source mapped to the device using the initial
    // matrix, and newMappedOrigin is (0,0) in source mapped to the device using the current
    // drawing matrix.
    //
    //    (ix', iy') = (ix, iy) + round(newMappedOrigin - initialMappedOrigin)
    //
    // In theory, newMappedOrigin - initialMappedOrigin should be integer, but the vagaries of
    // floating point don't guarantee that, so force it to integer.
    void startGPUDevice(
            const SkZip<const SkGlyphID, const SkPoint>& source,
            const SkMatrix& drawMatrix,
            const SkGlyphPositionRoundingSpec& roundingSpec);

    SkString dumpInput() const;

    // The input of SkPackedGlyphIDs
    SkZip<SkGlyphVariant, SkPoint> input() {
        SkASSERT(fPhase == kInput);
        SkDEBUGCODE(fPhase = kProcess);
        return SkZip<SkGlyphVariant, SkPoint>{fInputSize, fMultiBuffer.get(), fPositions};
    }

    // Store the glyph in the next slot, using the position information located at index from.
    void accept(SkGlyph* glyph, size_t from) {
        SkASSERT(fPhase == kProcess);
        SkASSERT(fAcceptedSize <= from);
        fPositions[fAcceptedSize] = fPositions[from];
        fMultiBuffer[fAcceptedSize] = glyph;
        fAcceptedSize++;
    }

    // Store the path in the next slot, using the position information located at index from.
    void accept(const SkPath* path, size_t from) {
        SkASSERT(fPhase == kProcess);
        SkASSERT(fAcceptedSize <= from);
        fPositions[fAcceptedSize] = fPositions[from];
        fMultiBuffer[fAcceptedSize] = path;
        fAcceptedSize++;
    }

    // Store drawable in the next slot, using the position information located at index from.
    void accept(SkDrawable* drawable, size_t from) {
        SkASSERT(fPhase == kProcess);
        SkASSERT(fAcceptedSize <= from);
        fPositions[fAcceptedSize] = fPositions[from];
        fMultiBuffer[fAcceptedSize] = drawable;
        fAcceptedSize++;
    }

    // The result after a series of `accept` of accepted SkGlyph* or SkPath*.
    SkZip<SkGlyphVariant, SkPoint> accepted() {
        SkASSERT(fPhase == kProcess);
        SkDEBUGCODE(fPhase = kDraw);
        return SkZip<SkGlyphVariant, SkPoint>{fAcceptedSize, fMultiBuffer.get(), fPositions};
    }

    bool empty() const {
        SkASSERT(fPhase == kProcess || fPhase == kDraw);
        return fAcceptedSize == 0;
    }

    void reset();

    template <typename Fn>
    void forEachInput(Fn&& fn) {
        for (auto [i, packedID, pos] : SkMakeEnumerate(this->input())) {
            fn(i, packedID.packedID(), pos);
        }
    }

private:
    size_t fMaxSize{0};
    size_t fInputSize{0};
    size_t fAcceptedSize{0};
    SkAutoTArray<SkGlyphVariant> fMultiBuffer;
    SkAutoTMalloc<SkPoint> fPositions;

#ifdef SK_DEBUG
    enum {
        kReset,
        kInput,
        kProcess,
        kDraw
    } fPhase{kReset};
#endif
};
#endif  // SkGlyphBuffer_DEFINED


text:
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements.  See the NOTICE file
distributed with this work for additional information
regarding copyright ownership.  The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License.  You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied.  See the License for the
specific language governing permissions and limitations
under the License.
-->

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>org.apache.maven.plugins.maven-javadoc-plugin.unit</groupId>
  <artifactId>subpackages-test</artifactId>
  <packaging>jar</packaging>
  <version>1.0-SNAPSHOT</version>
  <inceptionYear>2006</inceptionYear>
  <name>Maven Javadoc Plugin Subpackages Test</name>
  <url>http://maven.apache.org</url>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-javadoc-plugin</artifactId>
        <configuration>
          <project implementation="org.apache.maven.plugin.javadoc.stubs.SubpackagesTestMavenProjectStub"/>
          <localRepository>${localRepository}</localRepository>
          <outputDirectory>${basedir}/target/test/unit/subpackages-test/target/site/apidocs</outputDirectory>
          <javadocOptionsDir>${basedir}/target/test/unit/subpackages-test/target/javadoc-bundle-options</javadocOptionsDir>
          <breakiterator>false</breakiterator>
          <old>false</old>
          <show>protected</show>
          <quiet>true</quiet>
          <verbose>false</verbose>
          <author>true</author>
          <encoding>ISO-8859-1</encoding>
          <docfilessubdirs>false</docfilessubdirs>
          <linksource>false</linksource>
          <nocomment>false</nocomment>
          <nodeprecated>false</nodeprecated>
          <nodeprecatedlist>false</nodeprecatedlist>
          <nohelp>false</nohelp>
          <noindex>false</noindex>
          <nonavbar>false</nonavbar>
          <nosince>false</nosince>
          <notree>false</notree>
          <serialwarn>false</serialwarn>
          <splitindex>false</splitindex>
          <stylesheet>java</stylesheet>
          <groups/>
          <tags/>
          <use>true</use>
          <version>true</version>
          <windowtitle>Maven Javadoc Plugin Subpackages Test 1.0-SNAPSHOT API</windowtitle>
          <sourcepath>${basedir}/src/test/resources/unit/subpackages-test</sourcepath>
          <subpackages>subpackages.test</subpackages>
          <excludePackageNames>subpackages.test.excluded:subpackages.test.included.exclude</excludePackageNames>
          <debug>true</debug>
          <failOnError>true</failOnError>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>


text:
<?php

namespace SMW\MediaWiki\Search;

use SearchResult;

/**
 * @ingroup SMW
 *
 * @licence GNU GPL v2+
 * @since   2.1
 *
 * @author  Stephan Gambke
 */
class SearchResultSet extends \SearchResultSet {

	private $pages;
	private $count = null;

	public function __construct( \SMWQueryResult $result, $count = null ) {

		$this->pages = $result->getResults();
		$this->count = $count;
	}

	/**
	 * Return number of rows included in this result set.
	 *
	 * @return int|void
	 */
	public function numRows() {
		return count( $this->pages );
	}

	/**
	 * Return true if results are included in this result set.
	 *
	 * @return bool
	 */
	public function hasResults() {
		return $this->numRows() > 0;
	}

	/**
	 * Fetches next search result, or false.
	 *
	 * @return SearchResult
	 */
	public function next() {
		return ( list( , $page ) = each( $this->pages ) ) !== false ? ( SearchResult::newFromTitle( $page->getTitle() ) ) : false;
	}

	/**
	 * Returns true, so Special:Search won't offer the user a link to a create
	 * a page named by the search string because the name would contain the
	 * search syntax, i.e. the SMW query.
	 *
	 * @return bool
	 */
	public function searchContainedSyntax() {
		return true;
	}

	public function getTotalHits() {
		return $this->count;
	}

	/**
	 * Return an array of regular expression fragments for matching
	 * the search terms as parsed by the engine in a text extract.
	 *
	 * This is a temporary hack for MW versions that can not cope
	 * with no search term being returned (<1.24).
	 *
	 * @deprecated remove once min supported MW version has \SearchHighlighter::highlightNone()
	 *
	 * @return string[]
	 */
	public function termMatches() {

		if ( method_exists( '\SearchHighlighter', 'highlightNone' ) ) {
			return array();
		}

		// Will cause the highlighter to match every line start, thus returning the first few lines of found pages.
		return array( '^' );
	}
}


text:
<?php

namespace App\UserBundle\Form;

use App\UserBundle\Entity\User;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\Validator\Constraints\NotBlank;

class RegistrationFormType extends AbstractType
{
    public function buildForm(FormBuilderInterface $builder, array $options)
    {
        $builder->add('firstName', 'text', [
            'label' => 'property.firstName',
            'constraints' => [
                new NotBlank()
            ]
        ]);

        $builder->add('lastName', 'text', [
            'label' => 'property.lastName'
        ]);

        $builder->add('gender', 'text', [
            'label' => 'profile.gender'
        ]);

        $builder->add(
            'email',
            'email',
            array(
                'label' => 'property.email'
            )
        );

        $builder->add(
            'gender',
            'choice',
            array(

                'label' => 'Пол',
                'choices' => array(
                    User::GENDER_MALE => 'Мужской',
                    User::GENDER_FEMALE => 'Женский'
                )
            )
        );

        $builder->remove('username');

        $builder->add(
        'plainPassword',
        'repeated',
        array(
            'type' => 'password',
            'first_options' => array('label' => 'property.new_password'),
            'second_options' => array('label' => 'property.confirm_password'),
            'invalid_message' => 'form.validate.match_password',
            'required' => false,
        )
    );
    }

    public function getParent()
    {
        return 'fos_user_registration';
    }

    public function getName()
    {
        return 'app_user_registration';
    }
}


text:
============
Contributing
============
.. include:: ../../.github/CONTRIBUTING.rst


text:
package com.google.android.exoplayer2.upstream;

import android.net.Uri;
import android.support.annotation.Nullable;
import com.google.android.exoplayer2.C;
import java.io.IOException;

/**
 * A component from which streams of data can be read.
 */
public interface DataSource {

  /**
   * A factory for {@link DataSource} instances.
   */
  interface Factory {

    /**
     * Creates a {@link DataSource} instance.
     */
    DataSource createDataSource();

  }

  /**
   * Opens the source to read the specified data.
   *

   * Note: If an {@link IOException} is thrown, callers must still call {@link #close()} to ensure
   * that any partial effects of the invocation are cleaned up.
   *
   * @param dataSpec Defines the data to be read.
   * @throws IOException If an error occurs opening the source. {@link DataSourceException} can be
   *     thrown or used as a cause of the thrown exception to specify the reason of the error.
   * @return The number of bytes that can be read from the opened source. For unbounded requests
   *     (i.e. requests where {@link DataSpec#length} equals {@link C#LENGTH_UNSET}) this value
   *     is the resolved length of the request, or {@link C#LENGTH_UNSET} if the length is still
   *     unresolved. For all other requests, the value returned will be equal to the request's
   *     {@link DataSpec#length}.
   */
  long open(DataSpec dataSpec) throws IOException;

  /**
   * Reads up to {@code length} bytes of data and stores them into {@code buffer}, starting at
   * index {@code offset}.
   *

   * If {@code length} is zero then 0 is returned. Otherwise, if no data is available because the
   * end of the opened range has been reached, then {@link C#RESULT_END_OF_INPUT} is returned.
   * Otherwise, the call will block until at least one byte of data has been read and the number of
   * bytes read is returned.
   *
   * @param buffer The buffer into which the read data should be stored.
   * @param offset The start offset into {@code buffer} at which data should be written.
   * @param readLength The maximum number of bytes to read.
   * @return The number of bytes read, or {@link C#RESULT_END_OF_INPUT} if no data is available
   *     because the end of the opened range has been reached.
   * @throws IOException If an error occurs reading from the source.
   */
  int read(byte[] buffer, int offset, int readLength) throws IOException;

  /**
   * When the source is open, returns the {@link Uri} from which data is being read. The returned
   * {@link Uri} will be identical to the one passed {@link #open(DataSpec)} in the {@link DataSpec}
   * unless redirection has occurred. If redirection has occurred, the {@link Uri} after redirection
   * is returned.
   *
   * @return The {@link Uri} from which data is being read, or null if the source is not open.
   */
  @Nullable Uri getUri();

  /**
   * Closes the source.
   *

   * Note: This method must be called even if the corresponding call to {@link #open(DataSpec)}
   * threw an {@link IOException}. See {@link #open(DataSpec)} for more details.
   *
   * @throws IOException If an error occurs closing the source.
   */
  void close() throws IOException;

}


text:
require 'ancestry'

class OrchestrationStack < ApplicationRecord
  require_nested :Status

  include NewWithTypeStiMixin
  include AsyncDeleteMixin
  include ProcessTasksMixin
  include OwnershipMixin
  include RetirementMixin
  include TenantIdentityMixin
  include CustomActionsMixin
  include SupportsFeatureMixin
  include CiFeatureMixin
  include CloudTenancyMixin
  include EmsRefreshMixin

  acts_as_miq_taggable

  has_ancestry

  belongs_to :ext_management_system, :foreign_key => :ems_id
  belongs_to :tenant
  belongs_to :cloud_tenant

  has_many   :authentication_orchestration_stacks
  has_many   :authentications, :through => :authentication_orchestration_stacks
  has_many   :parameters, :dependent => :destroy, :foreign_key => :stack_id, :class_name => "OrchestrationStackParameter"
  has_many   :outputs,    :dependent => :destroy, :foreign_key => :stack_id, :class_name => "OrchestrationStackOutput"
  has_many   :resources,  :dependent => :destroy, :foreign_key => :stack_id, :class_name => "OrchestrationStackResource"

  has_many   :authentication_orchestration_stacks, :dependent => :destroy
  has_many   :authentications, :through => :authentication_orchestration_stacks

  has_many   :direct_vms,             :class_name => "ManageIQ::Providers::CloudManager::Vm"
  has_many   :direct_security_groups, :class_name => "SecurityGroup"
  has_many   :direct_cloud_networks,  :class_name => "CloudNetwork"
  has_many   :service_resources, :as => :resource
  has_many   :direct_services, :through => :service_resources, :source => :service

  virtual_has_one  :direct_service,       :class_name => 'Service'
  virtual_has_one  :service,              :class_name => 'Service'

  virtual_has_many :vms, :class_name => "ManageIQ::Providers::CloudManager::Vm"
  virtual_has_many :security_groups
  virtual_has_many :cloud_networks
  virtual_has_many :orchestration_stacks

  virtual_total :total_vms, :vms
  virtual_total :total_security_groups, :security_groups
  virtual_total :total_cloud_networks, :cloud_networks

  virtual_column :stdout, :type => :string

  scope :without_type, ->(type) { where.not(:type => type) }

  alias_method :orchestration_stack_parameters, :parameters
  alias_method :orchestration_stack_outputs,    :outputs
  alias_method :orchestration_stack_resources,  :resources

  supports :retire

  def orchestration_stacks
    children
  end

  def direct_service
    direct_services.first || (root.direct_services.first if root != self)
  end

  def service
    direct_service.try(:root_service) || (root.direct_service.try(:root_service) if root != self)
  end

  def indirect_vms
    MiqPreloader.preload_and_map(children, :direct_vms)
  end

  def vms
    directs_and_indirects(:direct_vms)
  end

  def security_groups
    directs_and_indirects(:direct_security_groups)
  end

  def cloud_networks
    directs_and_indirects(:direct_cloud_networks)
  end

  def directs_and_indirects(direct_attrs)
    MiqPreloader.preload_and_map(subtree, direct_attrs)
  end

  def stdout(format = nil)
    format.nil? ? try(:raw_stdout) : try(:raw_stdout, format)
  end

  def allow_retire_request_creation?
    MiqRequest.with_type("OrchestrationStackRetireRequest").where(:approval_state => "pending_approval").find_each do |request|
      if request.options.try(:[], :src_ids)&.include?(id)
        next if request.request_state == "finished" || request.status == "Error"

        _log.warn("MiqRequest with id:#{request.id} to retire Orchestra tionStack name:'#{name}' id:#{id} already created but not approved yet")
        return false
      end
    end

    true
  end

  private :directs_and_indirects

  def self.create_stack(orchestration_manager, stack_name, template, options = {})
    raw_create_stack(orchestration_manager, stack_name, template, options)
  end

  def self.raw_create_stack(_orchestration_manager, _stack_name, _template, _options = {})
    raise NotImplementedError, _("raw_create_stack must be implemented in a subclass")
  end

  def raw_update_stack(_template, _options = {})
    raise NotImplementedError, _("raw_update_stack must be implemented in a subclass")
  end

  def valid_service_orchestration_resource
    true
  end

  def my_zone
    ext_management_system.try(:my_zone)
  end

  def update_stack(template, options = {})
    raw_update_stack(template, options)
  end

  def raw_delete_stack
    raise NotImplementedError, _("raw_delete_stack must be implemented in a subclass")
  end

  def delete_stack
    raw_delete_stack
  end

  def raw_status
    raise NotImplementedError, _("raw_status must be implemented in a subclass")
  end

  def raw_exists?
    rstatus = raw_status
    rstatus && !rstatus.deleted?
  rescue MiqException::MiqOrchestrationStackNotExistError
    false
  end
end