text:
package org.achartengine.renderer;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

import org.achartengine.chart.PointStyle;
import org.achartengine.renderer.XYSeriesRenderer.FillOutsideLine.Type;

import android.graphics.Color;
import android.graphics.Paint.Align;

/**
 * A renderer for the XY type series.
 */
public class XYSeriesRenderer extends SimpleSeriesRenderer {
  /** If the chart points should be filled. */
  private boolean mFillPoints = false;
  /** If the chart should be filled outside its line. */
  private List<FillOutsideLine> mFillBelowLine = new ArrayList<FillOutsideLine>();
  /** The point style. */
  private PointStyle mPointStyle = PointStyle.POINT;
  /** The point stroke width */
  private float mPointStrokeWidth = 1;
  /** The chart line width. */
  private float mLineWidth = 1;
  /** If the values should be displayed above the chart points. */
  private boolean mDisplayChartValues;
  /** The minimum distance between displaying chart values. */
  private int mDisplayChartValuesDistance = 100;
  /** The chart values text size. */
  private float mChartValuesTextSize = 10;
  /** The chart values text alignment. */
  private Align mChartValuesTextAlign = Align.CENTER;
  /** The chart values spacing from the data point. */
  private float mChartValuesSpacing = 5f;
  /** The annotations text size. */
  private float mAnnotationsTextSize = 10;
  /** The annotations text alignment. */
  private Align mAnnotationsTextAlign = Align.CENTER;
  /** The annotations color. */
  private int mAnnotationsColor = DefaultRenderer.TEXT_COLOR;

  /**
   * A descriptor for the line fill behavior.
   */
  public static class FillOutsideLine implements Serializable {
    public enum Type {
      NONE, BOUNDS_ALL, BOUNDS_BELOW, BOUNDS_ABOVE, BELOW, ABOVE
    };

    /** The fill type. */
    private final Type mType;
    /** The fill color. */
    private int mColor = Color.argb(125, 0, 0, 200);
    /** The fill points index range. */
    private int[] mFillRange;

    /**
     * The line fill behavior.
     *
     * @param type the fill type
     */
    public FillOutsideLine(Type type) {
      this.mType = type;
    }

    /**
     * Returns the fill color.
     *
     * @return the fill color
     */
    public int getColor() {
      return mColor;
    }

    /**
     * Sets the fill color
     *
     * @param color the fill color
     */
    public void setColor(int color) {
      mColor = color;
    }

    /**
     * Returns the fill type.
     *
     * @return the fill type
     */
    public Type getType() {
      return mType;
    }

    /**
     * Returns the fill range which is the minimum and maximum data index values
     * for the fill.
     *
     * @return the fill range
     */
    public int[] getFillRange() {
      return mFillRange;
    }

    /**
     * Sets the fill range which is the minimum and maximum data index values
     * for the fill.
     *
     * @param range the fill range
     */
    public void setFillRange(int[] range) {
      mFillRange = range;
    }
  }

  /**
   * Returns if the chart should be filled below the line.
   *
   * @return the fill below line status
   *
   * @deprecated Use {@link #getFillOutsideLine()} instead.
   */
  @Deprecated
  public boolean isFillBelowLine() {
    return mFillBelowLine.size() > 0;
  }

  /**
   * Sets if the line chart should be filled below its line. Filling below the
   * line transforms a line chart into an area chart.
   *
   * @param fill the fill below line flag value
   *
   * @deprecated Use {@link #addFillOutsideLine(FillOutsideLine)} instead.
   */
  @Deprecated
  public void setFillBelowLine(boolean fill) {
    mFillBelowLine.clear();
    if (fill) {
      mFillBelowLine.add(new FillOutsideLine(Type.BOUNDS_ALL));
    } else {
      mFillBelowLine.add(new FillOutsideLine(Type.NONE));
    }
  }

  /**
   * Returns the type of the outside fill of the line.
   *
   * @return the type of the outside fill of the line.
   */
  public FillOutsideLine[] getFillOutsideLine() {
    return mFillBelowLine.toArray(new FillOutsideLine[0]);
  }

  /**
   * Sets if the line chart should be filled outside its line. Filling outside
   * with FillOutsideLine.INTEGRAL the line transforms a line chart into an area
   * chart.
   *
   * @param fill the type of the filling
   */
  public void addFillOutsideLine(FillOutsideLine fill) {
    mFillBelowLine.add(fill);
  }

  /**
   * Returns if the chart points should be filled.
   *
   * @return the points fill status
   */
  public boolean isFillPoints() {
    return mFillPoints;
  }

  /**
   * Sets if the chart points should be filled.
   *
   * @param fill the points fill flag value
   */
  public void setFillPoints(boolean fill) {
    mFillPoints = fill;
  }

  /**
   * Sets the fill below the line color.
   *
   * @param color the fill below line color
   *
   * @deprecated Use FillOutsideLine.setColor instead
   */
  @Deprecated
  public void setFillBelowLineColor(int color) {
    if (mFillBelowLine.size() > 0) {
      mFillBelowLine.get(0).setColor(color);
    }
  }

  /**
   * Returns the point style.
   *
   * @return the point style
   */
  public PointStyle getPointStyle() {
    return mPointStyle;
  }

  /**
   * Sets the point style.
   *
   * @param style the point style
   */
  public void setPointStyle(PointStyle style) {
    mPointStyle = style;
  }

  /**
   * Returns the point stroke width in pixels.
   *
   * @return the point stroke width in pixels
   */
  public float getPointStrokeWidth() {
    return mPointStrokeWidth;
  }

  /**
   * Sets the point stroke width in pixels.
   *
   * @param strokeWidth the point stroke width in pixels
   */
  public void setPointStrokeWidth(float strokeWidth) {
    mPointStrokeWidth = strokeWidth;
  }

  /**
   * Returns the chart line width.
   *
   * @return the line width
   */
  public float getLineWidth() {
    return mLineWidth;
  }

  /**
   * Sets the chart line width.
   *
   * @param lineWidth the line width
   */
  public void setLineWidth(float lineWidth) {
    mLineWidth = lineWidth;
  }

  /**
   * Returns if the chart point values should be displayed as text.
   *
   * @return if the chart point values should be displayed as text
   */
  public boolean isDisplayChartValues() {
    return mDisplayChartValues;
  }

  /**
   * Sets if the chart point values should be displayed as text.
   *
   * @param display if the chart point values should be displayed as text
   */
  public void setDisplayChartValues(boolean display) {
    mDisplayChartValues = display;
  }

  /**
   * Returns the chart values minimum distance.
   *
   * @return the chart values minimum distance
   */
  public int getDisplayChartValuesDistance() {
    return mDisplayChartValuesDistance;
  }

  /**
   * Sets chart values minimum distance.
   *
   * @param distance the chart values minimum distance
   */
  public void setDisplayChartValuesDistance(int distance) {
    mDisplayChartValuesDistance = distance;
  }

  /**
   * Returns the chart values text size.
   *
   * @return the chart values text size
   */
  public float getChartValuesTextSize() {
    return mChartValuesTextSize;
  }

  /**
   * Sets the chart values text size.
   *
   * @param textSize the chart values text size
   */
  public void setChartValuesTextSize(float textSize) {
    mChartValuesTextSize = textSize;
  }

  /**
   * Returns the chart values text align.
   *
   * @return the chart values text align
   */
  public Align getChartValuesTextAlign() {
    return mChartValuesTextAlign;
  }

  /**
   * Sets the chart values text align.
   *
   * @param align the chart values text align
   */
  public void setChartValuesTextAlign(Align align) {
    mChartValuesTextAlign = align;
  }

  /**
   * Returns the chart values spacing from the data point.
   *
   * @return the chart values spacing
   */
  public float getChartValuesSpacing() {
    return mChartValuesSpacing;
  }

  /**
   * Sets the chart values spacing from the data point.
   *
   * @param spacing the chart values spacing (in pixels) from the chart data
   *          point
   */
  public void setChartValuesSpacing(float spacing) {
    mChartValuesSpacing = spacing;
  }

  /**
   * Returns the annotations text size.
   *
   * @return the annotations text size
   */
  public float getAnnotationsTextSize() {
    return mAnnotationsTextSize;
  }

  /**
   * Sets the annotations text size.
   *
   * @param textSize the annotations text size
   */
  public void setAnnotationsTextSize(float textSize) {
    mAnnotationsTextSize = textSize;
  }

  /**
   * Returns the annotations text align.
   *
   * @return the annotations text align
   */
  public Align getAnnotationsTextAlign() {
    return mAnnotationsTextAlign;
  }

  /**
   * Sets the annotations text align.
   *
   * @param align the chart values text align
   */
  public void setAnnotationsTextAlign(Align align) {
    mAnnotationsTextAlign = align;
  }

  /**
   * Returns the annotations color.
   *
   * @return the annotations color
   */
  public int getAnnotationsColor() {
    return mAnnotationsColor;
  }

  /**
   * Sets the annotations color.
   *
   * @param color the annotations color
   */
  public void setAnnotationsColor(int color) {
    mAnnotationsColor = color;
  }

}


text:
package guitests;

import org.junit.Test;

import seedu.task.testutil.TypicalTestTasks;

import static org.junit.Assert.assertTrue;

public class ClearCommandTest extends TaskManagerGuiTest {

    @Test
    public void clear() {

        //verify a non-empty list can be cleared
        assertTrue(taskListPanel.isListMatching(td.getTypicalTasks()));
        assertClearCommandSuccess();

        //verify other commands can work after a clear command
        commandBox.runCommand("add Help Jim with his task, at 2016-10-25 9am");
        assertTrue(taskListPanel.isListMatching(TypicalTestTasks.taskH));
        commandBox.runCommand("delete 1");
        assertListSize(0);

        //verify clear command works when the list is empty
        assertClearCommandSuccess();
    }

    private void assertClearCommandSuccess() {
        commandBox.runCommand("clear");
        assertListSize(0);
        assertResultMessage("Task manager has been cleared!");
    }
}

redpajama_set_name: RedPajamaGithub


text:
#region Licence

#endregion

using System;

namespace WmcSoft.Collections.Graphs
{
    /// <summary>
    /// Checks if the <see cref="Graph"/> has a cycle.
    /// </summary>
    public struct CycleAlgorithm
    {
        private readonly bool[] _marked;
        private bool _hasCycle;

        public CycleAlgorithm(IGraph graph) {
            if (graph == null) throw new ArgumentNullException(nameof(graph));

            _marked = new bool[graph.VerticeCount];
            _hasCycle = false;
            for (int s = 0; s < graph.VerticeCount; s++) {
                if (!_marked[s])
                    Process(graph, s, s);
            }
        }

        public bool HasCycle {
            get { return _hasCycle; }
        }

        private void Process(IGraph graph, int v, int u) {
            _marked[v] = true;
            foreach (var w in graph.Adjacents(v)) {
                if (!_marked[w]) {
                    Process(graph, w, v);
                } else if (w != u) {
                    _hasCycle = true; // explores the complete graph eventhough we know the answer...
                }
            }
        }
    }
}


text:
cask :v1 => 'skype' do

  if MacOS.release <= :mountain_lion
    version '6.15.0.335'
    sha256 '592abdd157df12d718576a86c8f8e62fced55292fd7e6909d53aa5eaaa9218f4'
    url "http://download.skype.com/macosx/Skype_#{version}.dmg"
  else
    version :latest
    sha256 :no_check
    url 'https://www.skype.com/go/getskype-macosx.dmg'
  end

  name 'Skype'
  homepage 'http://www.skype.com'
  license :gratis

  app 'Skype.app'

  zap :delete => [
                  '~/Library/Application Support/Skype',
                  '~/Library/Caches/com.plausiblelabs.crashreporter.data/com.skype.skype',
                  '~/Library/Caches/com.skype.skype',
                  '~/Library/Preferences/com.skype.skype.plist',
                  '~/Library/Preferences/com.skype.skypewifi.plist',
                  '~/Library/Saved Application State/com.skype.skype.savedState',
                 ]
end


text:
package com.despegar.soffheap.perftest

import com.google.caliper.Param
import com.despegar.soffheap.map.SoffHeapMap
import com.despegar.soffheap.PojoValue
import scala.collection.mutable.ListBuffer
import java.util.HashMap
import com.despegar.soffheap.map.SoffHeapMapBuilder

// a caliper benchmark is a class that extends com.google.caliper.Benchmark
// the SimpleScalaBenchmark trait does it and also adds some convenience functionality
class OffheapBenchmark extends SimpleScalaBenchmark {
  // to make your benchmark depend on one or more parameterized values, create fields with the name you want
  // the parameter to be known by, and add this annotation (see @Param javadocs for more details)
  // caliper will inject the respective value at runtime and make sure to run all combinations
//  @Param(Array("10", "100", "1000", "10000"))
  @Param(Array("10000"))
  val arrays: Int = 0

  @Param(Array("100"))
  val elements: Int = 0

  var snapshot: SoffHeapMap[String, Array[PojoValue]] = _
  var fstSnapshot: SoffHeapMap[String, Array[PojoValue]] = _
  var hashmap: HashMap[String, Array[PojoValue]] = _

  override def setUp() {
    // set up all your benchmark data here
    if (snapshot != null) {
      snapshot.clear()
    }
    snapshot = new SoffHeapMapBuilder[String,Array[PojoValue]]().withMaximumHeapElements(10).build()
    hashmap = new HashMap[String, Array[PojoValue]]()

    (1 to arrays) foreach {
       arrayIndex =>
       val listBuffer: ListBuffer[PojoValue] = ListBuffer.empty
		     (1 to elements) foreach { i => listBuffer += new PojoValue(s"value$i", i) }
       val value = listBuffer.toArray
       val key = s"key-$arrayIndex"
         	 snapshot.put(key, value)
         	 hashmap.put(key, value)
         	 fstSnapshot.put(key, value)
    }
  }

  def timeHashMap(reps: Int) = repeat(reps) {
         (1 to arrays) map { arrayIndex =>
           val key = s"key-$arrayIndex"
           val obj =   hashmap.get(key)
         }
  }

  def timeOffheapKryoSnapshot(reps: Int) = repeat(reps) {
         (1 to arrays) map { arrayIndex =>
           val key = s"key-$arrayIndex"
           val obj =   snapshot.get(key)
         }
  }

  override def tearDown() {
    // clean up after yourself if required
  }

}


text:
.. _manual-views:

################
Dropwizard Views
################

.. highlight:: text

.. rubric:: The ``dropwizard-views`` module provides you with simple, fast HTML views using the
            Freemarker_ templating library.

.. _Freemarker: http://freemarker.sourceforge.net/

To enable views for your :ref:`service <man-core-service>`, add the ``ViewBundle``:

.. code-block:: java

    public MyService() {
        super("my-service");
        addBundle(new ViewBundle());
    }

Then, in your :ref:`resource method <man-core-resources>`, add a ``View`` class:

.. code-block:: java

    public class PersonView extends View {
        private final Person person;

        public PersonView(Person person) {
            super("person.ftl");
            this.person = person;
        }

        public Person getPerson() {
            return person;
        }
    }

``person.ftl`` is the path of the template relative to the class name. If this class was
``com.example.service.PersonView``, Dropwizard would then look for the file
``src/main/resources/com/example/service/person.ftl``.

.. tip::

    Dropwizard Views also support localized template files. It picks up the client's locale from
    their ``Accept-Language``, so you can add a French template in ``person_fr.ftl`` or a Canadian
    template in ``person_en_CA.ftl``.

Your template file might look something like this:

.. code-block:: html
    :emphasize-lines: 1, 5

    <#-- @ftlvariable name="" type="com.example.views.PersonView" -->

Hello, ${person.name?html}!

The ``@fltvariable`` lets Freemarker (and any Freemarker IDE plugins you may be using) that the
root object is a ``com.example.views.PersonView`` instance. If you attempt to call a property which
doesn't exist on ``PersonView``--``getConnectionPool()``, for example--it will flag that line in
your IDE.

Once you have your view and Freemarker template, you can simply return an instance of your ``View``
subclass:

.. code-block:: java

    @Path("/people/{id}")
    @Produces(MediaType.TEXT_HTML)
    public class PersonResource {
        private final PersonDAO dao;

        public PersonResource(PersonDAO dao) {
            this.dao = dao;
        }

        @GET
        public PersonView getPerson(@PathParam("id") String id) {
            return new PersonView(dao.find(id));
        }
    }

.. tip::

    Jackson can also serialize your views, allowing you to serve both ``text/html`` and
    ``application/json`` with a single representation class.

For more information on how to use Freemarker, see the `Freemarker`_ documentation.


text:
function format(options, param, data, callback) {
		if (!options.username || !options.password) {
			return callback(new Error('Need basic auth info.'));
		}
		param.auth = options.username + ':' + options.password;
		callback(null, param);
}

module.exports = format;


text:
package com.iggroup.webapi.samples.client.rest.dto.prices.getPricesByNumberOfPointsV2;

import java.math.BigDecimal;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;

/*
Historical price data allowance
*/
@JsonIgnoreProperties(ignoreUnknown = true)
public class Allowance {

/*
The number of data points still available to fetch within the current allowance period
*/
private Integer remainingAllowance;

/*
The number of data points the API key and account combination is allowed to fetch in any given allowance period
*/
private Integer totalAllowance;

/*
The number of seconds till the current allowance period will end and the remaining allowance field is reset
*/
private Integer allowanceExpiry;

public Integer getRemainingAllowance() { return remainingAllowance; }
public void setRemainingAllowance(Integer remainingAllowance) { this.remainingAllowance=remainingAllowance; }
public Integer getTotalAllowance() { return totalAllowance; }
public void setTotalAllowance(Integer totalAllowance) { this.totalAllowance=totalAllowance; }
public Integer getAllowanceExpiry() { return allowanceExpiry; }
public void setAllowanceExpiry(Integer allowanceExpiry) { this.allowanceExpiry=allowanceExpiry; }
}


text:
package org.apache.asterix.app.nc;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.stream.Collectors;

import org.apache.asterix.common.api.IDatasetLifecycleManager;
import org.apache.asterix.common.api.INcApplicationContext;
import org.apache.asterix.common.config.ReplicationProperties;
import org.apache.asterix.common.context.DatasetInfo;
import org.apache.asterix.common.context.IndexInfo;
import org.apache.asterix.common.dataflow.DatasetLocalResource;
import org.apache.asterix.common.exceptions.ACIDException;
import org.apache.asterix.common.ioopcallbacks.LSMIOOperationCallback;
import org.apache.asterix.common.storage.DatasetResourceReference;
import org.apache.asterix.common.storage.IIndexCheckpointManager;
import org.apache.asterix.common.storage.IIndexCheckpointManagerProvider;
import org.apache.asterix.common.transactions.Checkpoint;
import org.apache.asterix.common.transactions.ICheckpointManager;
import org.apache.asterix.common.transactions.ILogReader;
import org.apache.asterix.common.transactions.ILogRecord;
import org.apache.asterix.common.transactions.IRecoveryManager;
import org.apache.asterix.common.transactions.ITransactionContext;
import org.apache.asterix.common.transactions.ITransactionSubsystem;
import org.apache.asterix.common.transactions.LogType;
import org.apache.asterix.common.transactions.TxnId;
import org.apache.asterix.transaction.management.opcallbacks.AbstractIndexModificationOperationCallback;
import org.apache.asterix.transaction.management.resource.PersistentLocalResourceRepository;
import org.apache.asterix.transaction.management.service.logging.LogManager;
import org.apache.asterix.transaction.management.service.recovery.AbstractCheckpointManager;
import org.apache.asterix.transaction.management.service.recovery.TxnEntityId;
import org.apache.asterix.transaction.management.service.transaction.TransactionManagementConstants;
import org.apache.commons.io.FileUtils;
import org.apache.hyracks.api.application.INCServiceContext;
import org.apache.hyracks.api.exceptions.ErrorCode;
import org.apache.hyracks.api.exceptions.HyracksDataException;
import org.apache.hyracks.api.lifecycle.ILifeCycleComponent;
import org.apache.hyracks.storage.am.common.impls.NoOpIndexAccessParameters;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentId;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMComponentId.IdCompareResult;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMDiskComponent;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperation;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIOOperation.LSMIOOperationStatus;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIndex;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexAccessor;
import org.apache.hyracks.storage.am.lsm.common.api.ILSMIndexOperationContext;
import org.apache.hyracks.storage.am.lsm.common.impls.AbstractLSMIndex;
import org.apache.hyracks.storage.am.lsm.common.impls.LSMComponentId;
import org.apache.hyracks.storage.common.IIndex;
import org.apache.hyracks.storage.common.LocalResource;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.Logger;

/**
 * This is the Recovery Manager and is responsible for rolling back a
 * transaction as well as doing a system recovery.
 */
public class RecoveryManager implements IRecoveryManager, ILifeCycleComponent {

    public static final boolean IS_DEBUG_MODE = false;
    private static final long SMALLEST_POSSIBLE_LSN = 0;
    private static final Logger LOGGER = org.apache.logging.log4j.LogManager.getLogger();
    private final ITransactionSubsystem txnSubsystem;
    private final LogManager logMgr;
    private final boolean replicationEnabled;
    private static final String RECOVERY_FILES_DIR_NAME = "recovery_temp";
    private Map<Long, JobEntityCommits> jobId2WinnerEntitiesMap = null;
    private final long cachedEntityCommitsPerJobSize;
    protected final PersistentLocalResourceRepository localResourceRepository;
    private final ICheckpointManager checkpointManager;
    private SystemState state;
    protected final INCServiceContext serviceCtx;
    protected final INcApplicationContext appCtx;
    private static final TxnId recoveryTxnId = new TxnId(-1);

    public RecoveryManager(INCServiceContext serviceCtx, ITransactionSubsystem txnSubsystem) {
        this.serviceCtx = serviceCtx;
        this.txnSubsystem = txnSubsystem;
        this.appCtx = txnSubsystem.getApplicationContext();
        logMgr = (LogManager) txnSubsystem.getLogManager();
        ReplicationProperties repProperties = appCtx.getReplicationProperties();
        replicationEnabled = repProperties.isReplicationEnabled();
        localResourceRepository = (PersistentLocalResourceRepository) appCtx.getLocalResourceRepository();
        cachedEntityCommitsPerJobSize = txnSubsystem.getTransactionProperties().getJobRecoveryMemorySize();
        checkpointManager = txnSubsystem.getCheckpointManager();
    }

    /**
     * returns system state which could be one of the three states: HEALTHY, RECOVERING, CORRUPTED.
     * This state information could be used in a case where more than one thread is running
     * in the bootstrap process to provide higher availability. In other words, while the system
     * is recovered, another thread may start a new transaction with understanding the side effect
     * of the operation, or the system can be recovered concurrently. This kind of concurrency is
     * not supported, yet.
     */
    @Override
    public SystemState getSystemState() throws ACIDException {
        //read checkpoint file
        Checkpoint checkpointObject = checkpointManager.getLatest();
        if (checkpointObject == null) {
            //The checkpoint file doesn't exist => Failure happened during NC initialization.
            //Retry to initialize the NC by setting the state to PERMANENT_DATA_LOSS
            state = SystemState.PERMANENT_DATA_LOSS;
            LOGGER.info("The checkpoint file doesn't exist: systemState = PERMANENT_DATA_LOSS");
            return state;
        }
        long readableSmallestLSN = logMgr.getReadableSmallestLSN();
        if (logMgr.getAppendLSN() == readableSmallestLSN) {
            if (checkpointObject.getMinMCTFirstLsn() != AbstractCheckpointManager.SHARP_CHECKPOINT_LSN) {
                LOGGER.warn("Some(or all) of transaction log files are lost.");
                //No choice but continuing when the log files are lost.
            }
            state = SystemState.HEALTHY;
        } else if (checkpointObject.getCheckpointLsn() == logMgr.getAppendLSN()
                && checkpointObject.getMinMCTFirstLsn() == AbstractCheckpointManager.SHARP_CHECKPOINT_LSN) {
            state = SystemState.HEALTHY;
        } else {
            state = SystemState.CORRUPTED;
        }
        return state;
    }

    @Override
    public void startLocalRecovery(Set<Integer> partitions) throws IOException, ACIDException {
        state = SystemState.RECOVERING;
        LOGGER.info("starting recovery ...");

        long readableSmallestLSN = logMgr.getReadableSmallestLSN();
        Checkpoint checkpointObject = checkpointManager.getLatest();
        long lowWaterMarkLSN = checkpointObject.getMinMCTFirstLsn();
        if (lowWaterMarkLSN < readableSmallestLSN) {
            lowWaterMarkLSN = readableSmallestLSN;
        }

        //delete any recovery files from previous failed recovery attempts
        deleteRecoveryTemporaryFiles();

        //get active partitions on this node
        replayPartitionsLogs(partitions, logMgr.getLogReader(true), lowWaterMarkLSN);
    }

    @Override
    public synchronized void replayPartitionsLogs(Set<Integer> partitions, ILogReader logReader, long lowWaterMarkLSN)
            throws IOException, ACIDException {
        try {
            Set<Long> winnerJobSet = startRecoverysAnalysisPhase(partitions, logReader, lowWaterMarkLSN);
            startRecoveryRedoPhase(partitions, logReader, lowWaterMarkLSN, winnerJobSet);
        } finally {
            logReader.close();
            deleteRecoveryTemporaryFiles();
        }
    }

    private synchronized Set<Long> startRecoverysAnalysisPhase(Set<Integer> partitions, ILogReader logReader,
            long lowWaterMarkLSN) throws IOException, ACIDException {
        int updateLogCount = 0;
        int entityCommitLogCount = 0;
        int jobCommitLogCount = 0;
        int abortLogCount = 0;
        Set<Long> winnerJobSet = new HashSet<>();
        jobId2WinnerEntitiesMap = new HashMap<>();
        //set log reader to the lowWaterMarkLsn
        ILogRecord logRecord;
        logReader.setPosition(lowWaterMarkLSN);
        logRecord = logReader.next();
        while (logRecord != null) {
            if (IS_DEBUG_MODE) {
                LOGGER.info(logRecord.getLogRecordForDisplay());
            }
            switch (logRecord.getLogType()) {
                case LogType.UPDATE:
                    if (partitions.contains(logRecord.getResourcePartition())) {
                        updateLogCount++;
                    }
                    break;
                case LogType.JOB_COMMIT:
                    winnerJobSet.add(logRecord.getTxnId());
                    cleanupTxnCommits(logRecord.getTxnId());
                    jobCommitLogCount++;
                    break;
                case LogType.ENTITY_COMMIT:
                    if (partitions.contains(logRecord.getResourcePartition())) {
                        analyzeEntityCommitLog(logRecord);
                        entityCommitLogCount++;
                    }
                    break;
                case LogType.ABORT:
                    abortLogCount++;
                    break;
                case LogType.FLUSH:
                case LogType.WAIT:
                case LogType.WAIT_FOR_FLUSHES:
                case LogType.MARKER:
                case LogType.FILTER:
                    break;
                default:
                    throw new ACIDException("Unsupported LogType: " + logRecord.getLogType());
            }
            logRecord = logReader.next();
        }

        //prepare winners for search after analysis is done to flush anything remaining in memory to disk.
        for (JobEntityCommits winners : jobId2WinnerEntitiesMap.values()) {
            winners.prepareForSearch();
        }

        LOGGER.info("Logs analysis phase completed.");
        LOGGER.info("Analysis log count update/entityCommit/jobCommit/abort = " + updateLogCount + "/"
                + entityCommitLogCount + "/" + jobCommitLogCount + "/" + abortLogCount);

        return winnerJobSet;
    }

    private void cleanupTxnCommits(long txnId) {
        if (jobId2WinnerEntitiesMap.containsKey(txnId)) {
            JobEntityCommits jobEntityWinners = jobId2WinnerEntitiesMap.get(txnId);
            //to delete any spilled files as well
            jobEntityWinners.clear();
            jobId2WinnerEntitiesMap.remove(txnId);
        }
    }

    private void analyzeEntityCommitLog(ILogRecord logRecord) throws IOException {
        long txnId = logRecord.getTxnId();
        JobEntityCommits jobEntityWinners;
        if (!jobId2WinnerEntitiesMap.containsKey(txnId)) {
            jobEntityWinners = new JobEntityCommits(txnId);
            if (needToFreeMemory()) {
                // If we don't have enough memory for one more job,
                // we will force all jobs to spill their cached entities to disk.
                // This could happen only when we have many jobs with small
                // number of records and none of them have job commit.
                freeJobsCachedEntities(txnId);
            }
            jobId2WinnerEntitiesMap.put(txnId, jobEntityWinners);
        } else {
            jobEntityWinners = jobId2WinnerEntitiesMap.get(txnId);
        }
        jobEntityWinners.add(logRecord);
    }

    private synchronized void startRecoveryRedoPhase(Set<Integer> partitions, ILogReader logReader,
            long lowWaterMarkLSN, Set<Long> winnerTxnSet) throws IOException, ACIDException {
        int redoCount = 0;
        long txnId = 0;

        long resourceId;
        long maxDiskLastLsn;
        long lsn = -1;
        ILSMIndex index = null;
        LocalResource localResource = null;
        DatasetLocalResource localResourceMetadata = null;
        boolean foundWinner = false;
        JobEntityCommits jobEntityWinners = null;

        IDatasetLifecycleManager datasetLifecycleManager = appCtx.getDatasetLifecycleManager();
        final IIndexCheckpointManagerProvider indexCheckpointManagerProvider =
                ((INcApplicationContext) (serviceCtx.getApplicationContext())).getIndexCheckpointManagerProvider();

        Map<Long, LocalResource> resourcesMap = localResourceRepository.loadAndGetAllResources();
        final Map<Long, Long> resourceId2MaxLSNMap = new HashMap<>();
        TxnEntityId tempKeyTxnEntityId = new TxnEntityId(-1, -1, -1, null, -1, false);

        ILogRecord logRecord = null;
        try {
            logReader.setPosition(lowWaterMarkLSN);
            logRecord = logReader.next();
            while (logRecord != null) {
                if (IS_DEBUG_MODE) {
                    LOGGER.info(logRecord.getLogRecordForDisplay());
                }
                lsn = logRecord.getLSN();
                txnId = logRecord.getTxnId();
                foundWinner = false;
                switch (logRecord.getLogType()) {
                    case LogType.UPDATE:
                        if (partitions.contains(logRecord.getResourcePartition())) {
                            if (winnerTxnSet.contains(txnId)) {
                                foundWinner = true;
                            } else if (jobId2WinnerEntitiesMap.containsKey(txnId)) {
                                jobEntityWinners = jobId2WinnerEntitiesMap.get(txnId);
                                tempKeyTxnEntityId.setTxnId(txnId, logRecord.getDatasetId(), logRecord.getPKHashValue(),
                                        logRecord.getPKValue(), logRecord.getPKValueSize());
                                if (jobEntityWinners.containsEntityCommitForTxnId(lsn, tempKeyTxnEntityId)) {
                                    foundWinner = true;
                                }
                            }
                            if (!foundWinner) {
                                break;
                            }
                        }
                        //fall through as FILTER is a subset of UPDATE
                    case LogType.FILTER:
                        if (partitions.contains(logRecord.getResourcePartition())) {
                            resourceId = logRecord.getResourceId();
                            localResource = resourcesMap.get(resourceId);
                            /*******************************************************************
                             * [Notice]
                             * -> Issue
                             * Delete index may cause a problem during redo.
                             * The index operation to be redone couldn't be redone because the corresponding index
                             * may not exist in NC due to the possible index drop DDL operation.
                             * -> Approach
                             * Avoid the problem during redo.
                             * More specifically, the problem will be detected when the localResource of
                             * the corresponding index is retrieved, which will end up with 'null'.
                             * If null is returned, then just go and process the next
                             * log record.
                             *******************************************************************/
                            if (localResource == null) {
                                LOGGER.log(Level.WARN, "resource was not found for resource id " + resourceId);
                                logRecord = logReader.next();
                                continue;
                            }
                            /*******************************************************************/

                            //get index instance from IndexLifeCycleManager
                            //if index is not registered into IndexLifeCycleManager,
                            //create the index using LocalMetadata stored in LocalResourceRepository
                            //get partition path in this node
                            localResourceMetadata = (DatasetLocalResource) localResource.getResource();
                            index = (ILSMIndex) datasetLifecycleManager.get(localResource.getPath());
                            if (index == null) {
                                //#. create index instance and register to indexLifeCycleManager
                                index = (ILSMIndex) localResourceMetadata.createInstance(serviceCtx);
                                datasetLifecycleManager.register(localResource.getPath(), index);
                                datasetLifecycleManager.open(localResource.getPath());
                                try {
                                    final DatasetResourceReference resourceReference =
                                            DatasetResourceReference.of(localResource);
                                    maxDiskLastLsn =
                                            indexCheckpointManagerProvider.get(resourceReference).getLowWatermark();
                                } catch (HyracksDataException e) {
                                    datasetLifecycleManager.close(localResource.getPath());
                                    throw e;
                                }
                                //#. set resourceId and maxDiskLastLSN to the map
                                resourceId2MaxLSNMap.put(resourceId, maxDiskLastLsn);
                            } else {
                                maxDiskLastLsn = resourceId2MaxLSNMap.get(resourceId);
                            }
                            // lsn @ maxDiskLastLsn is either a flush log or a master replica log
                            if (lsn >= maxDiskLastLsn) {
                                redo(logRecord, datasetLifecycleManager);
                                redoCount++;
                            }
                        }
                        break;
                    case LogType.FLUSH:
                        int partition = logRecord.getResourcePartition();
                        if (partitions.contains(partition)) {
                            int datasetId = logRecord.getDatasetId();
                            if (!datasetLifecycleManager.isRegistered(datasetId)) {
                                // it's possible this dataset has been dropped
                                logRecord = logReader.next();
                                continue;
                            }
                            DatasetInfo dsInfo = datasetLifecycleManager.getDatasetInfo(datasetId);
                            // we only need to flush open indexes here (opened by previous update records)
                            // if an index has no ongoing updates, then it's memory component must be empty
                            // and there is nothing to flush
                            for (final IndexInfo iInfo : dsInfo.getIndexes().values()) {
                                if (iInfo.isOpen() && iInfo.getPartition() == partition) {
                                    Long maxLsnBeforeFlush = resourceId2MaxLSNMap.get(iInfo.getResourceId());
                                    if (maxLsnBeforeFlush != null) {
                                        // If there was at least one update to the resource.
                                        // IMPORTANT: Don't remove the check above
                                        // This check is to support indexes without transaction logs
                                        maxDiskLastLsn = maxLsnBeforeFlush;
                                        index = iInfo.getIndex();
                                        if (logRecord.getLSN() > maxDiskLastLsn
                                                && !index.isCurrentMutableComponentEmpty()) {
                                            // schedule flush
                                            redoFlush(index, logRecord);
                                            redoCount++;
                                        } else {
                                            // TODO: update checkpoint file?
                                        }
                                    } else {
                                        // TODO: update checkpoint file?
                                    }
                                }
                            }
                        }
                        break;
                    case LogType.JOB_COMMIT:
                    case LogType.ENTITY_COMMIT:
                    case LogType.ABORT:
                    case LogType.WAIT:
                    case LogType.WAIT_FOR_FLUSHES:
                    case LogType.MARKER:
                        //do nothing
                        break;
                    default:
                        throw new ACIDException("Unsupported LogType: " + logRecord.getLogType());
                }
                logRecord = logReader.next();
            }
            LOGGER.info("Logs REDO phase completed. Redo logs count: " + redoCount);
        } finally {
            txnSubsystem.getTransactionManager().ensureMaxTxnId(txnId);
            //close all indexes
            Set<Long> resourceIdList = resourceId2MaxLSNMap.keySet();
            for (long r : resourceIdList) {
                datasetLifecycleManager.close(resourcesMap.get(r).getPath());
            }
        }
    }

    private boolean needToFreeMemory() {
        return Runtime.getRuntime().freeMemory() < cachedEntityCommitsPerJobSize;
    }

    @Override
    public long getMinFirstLSN() throws HyracksDataException {
        long minFirstLSN = getLocalMinFirstLSN();

        //if replication is enabled, consider replica resources min LSN
        if (replicationEnabled) {
            long remoteMinFirstLSN = getRemoteMinFirstLSN();
            minFirstLSN = Math.min(minFirstLSN, remoteMinFirstLSN);
        }

        return minFirstLSN;
    }

    @Override
    public long getLocalMinFirstLSN() throws HyracksDataException {
        final IDatasetLifecycleManager datasetLifecycleManager = appCtx.getDatasetLifecycleManager();
        List<IIndex> openIndexList = datasetLifecycleManager.getOpenResources();
        long firstLSN;
        //the min first lsn can only be the current append or smaller
        long minFirstLSN = logMgr.getAppendLSN();
        if (!openIndexList.isEmpty()) {
            for (IIndex index : openIndexList) {
                LSMIOOperationCallback ioCallback =
                        (LSMIOOperationCallback) ((ILSMIndex) index).getIOOperationCallback();
                if (!((AbstractLSMIndex) index).isCurrentMutableComponentEmpty() || ioCallback.hasPendingFlush()) {
                    firstLSN = ioCallback.getPersistenceLsn();
                    minFirstLSN = Math.min(minFirstLSN, firstLSN);
                }
            }
        }
        return minFirstLSN;
    }

    private long getRemoteMinFirstLSN() throws HyracksDataException {
        // find the min first lsn of partitions that are replicated on this node
        final Set<Integer> allPartitions = localResourceRepository.getAllPartitions();
        final Set<Integer> masterPartitions = appCtx.getReplicaManager().getPartitions();
        allPartitions.removeAll(masterPartitions);
        return getPartitionsMinLSN(allPartitions);
    }

    private long getPartitionsMinLSN(Set<Integer> partitions) throws HyracksDataException {
        final IIndexCheckpointManagerProvider idxCheckpointMgrProvider = appCtx.getIndexCheckpointManagerProvider();
        long minRemoteLSN = Long.MAX_VALUE;
        for (Integer partition : partitions) {
            final List<DatasetResourceReference> partitionResources = localResourceRepository.getResources(resource -> {
                DatasetLocalResource dsResource = (DatasetLocalResource) resource.getResource();
                return dsResource.getPartition() == partition;
            }).values().stream().map(DatasetResourceReference::of).collect(Collectors.toList());
            for (DatasetResourceReference indexRef : partitionResources) {
                try {
                    final IIndexCheckpointManager idxCheckpointMgr = idxCheckpointMgrProvider.get(indexRef);
                    if (idxCheckpointMgr.getCheckpointCount() > 0) {
                        long remoteIndexMaxLSN = idxCheckpointMgrProvider.get(indexRef).getLowWatermark();
                        minRemoteLSN = Math.min(minRemoteLSN, remoteIndexMaxLSN);
                    }
                } catch (Exception e) {
                    LOGGER.warn("Failed to get min LSN of resource {}", indexRef, e);
                    // ensure no logs will be deleted in case of unexpected failures
                    return SMALLEST_POSSIBLE_LSN;
                }
            }
        }
        return minRemoteLSN;
    }

    @Override
    public synchronized void replayReplicaPartitionLogs(Set<Integer> partitions, boolean flush)
            throws HyracksDataException {
        //replay logs > minLSN that belong to these partitions
        try {
            checkpointManager.secure(recoveryTxnId);
            long minLSN = getPartitionsMinLSN(partitions);
            long readableSmallestLSN = logMgr.getReadableSmallestLSN();
            if (minLSN < readableSmallestLSN) {
                minLSN = readableSmallestLSN;
            }
            replayPartitionsLogs(partitions, logMgr.getLogReader(true), minLSN);
            if (flush) {
                appCtx.getDatasetLifecycleManager().flushAllDatasets();
            }
        } catch (IOException | ACIDException e) {
            throw HyracksDataException.create(e);
        } finally {
            checkpointManager.completed(recoveryTxnId);
        }
    }

    @Override
    public File createJobRecoveryFile(long txnId, String fileName) throws IOException {
        String recoveryDirPath = getRecoveryDirPath();
        Path jobRecoveryFolder = Paths.get(recoveryDirPath + File.separator + txnId);
        if (!Files.exists(jobRecoveryFolder)) {
            Files.createDirectories(jobRecoveryFolder);
        }

        File jobRecoveryFile = new File(jobRecoveryFolder.toString() + File.separator + fileName);
        if (!jobRecoveryFile.exists()) {
            if (!jobRecoveryFile.createNewFile()) {
                throw new IOException("Failed to create file: " + fileName + " for txn id(" + txnId + ")");
            }
        } else {
            throw new IOException("File: " + fileName + " for txn id(" + txnId + ") already exists");
        }
        return jobRecoveryFile;
    }

    @Override
    public void deleteRecoveryTemporaryFiles() {
        String recoveryDirPath = getRecoveryDirPath();
        Path recoveryFolderPath = Paths.get(recoveryDirPath);
        FileUtils.deleteQuietly(recoveryFolderPath.toFile());
    }

    private String getRecoveryDirPath() {
        String logDir = logMgr.getLogManagerProperties().getLogDir();
        if (!logDir.endsWith(File.separator)) {
            logDir += File.separator;
        }

        return logDir + RECOVERY_FILES_DIR_NAME;
    }

    private void freeJobsCachedEntities(long requestingTxnId) throws IOException {
        if (jobId2WinnerEntitiesMap != null) {
            for (Entry<Long, JobEntityCommits> jobEntityCommits : jobId2WinnerEntitiesMap.entrySet()) {
                //if the job is not the requester, free its memory
                if (jobEntityCommits.getKey() != requestingTxnId) {
                    jobEntityCommits.getValue().spillToDiskAndfreeMemory();
                }
            }
        }
    }

    @Override
    public void rollbackTransaction(ITransactionContext txnContext) throws ACIDException {
        long abortedTxnId = txnContext.getTxnId().getId();
        // Obtain the first/last log record LSNs written by the Job
        long firstLSN = txnContext.getFirstLSN();
        /*
         * The effect of any log record with LSN below minFirstLSN has already been written to disk and
         * will not be rolled back. Therefore, we will set the first LSN of the job to the maximum of
         * minFirstLSN and the job's first LSN.
         */
        try {
            long localMinFirstLSN = getLocalMinFirstLSN();
            firstLSN = Math.max(firstLSN, localMinFirstLSN);
        } catch (HyracksDataException e) {
            throw new ACIDException(e);
        }
        long lastLSN = txnContext.getLastLSN();
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("rollbacking transaction log records from " + firstLSN + " to " + lastLSN);
        }
        // check if the transaction actually wrote some logs.
        if (firstLSN == TransactionManagementConstants.LogManagerConstants.TERMINAL_LSN || firstLSN > lastLSN) {
            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("no need to roll back as there were no operations by the txn " + txnContext.getTxnId());
            }
            return;
        }

        // While reading log records from firstLsn to lastLsn, collect uncommitted txn's Lsns
        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("collecting loser transaction's LSNs from " + firstLSN + " to " + lastLSN);
        }

        Map<TxnEntityId, List<Long>> jobLoserEntity2LSNsMap = new HashMap<>();
        TxnEntityId tempKeyTxnEntityId = new TxnEntityId(-1, -1, -1, null, -1, false);
        int updateLogCount = 0;
        int entityCommitLogCount = 0;
        long logTxnId;
        long currentLSN = -1;
        TxnEntityId loserEntity;
        List<Long> undoLSNSet = null;
        //get active partitions on this node
        Set<Integer> activePartitions = appCtx.getReplicaManager().getPartitions();
        ILogReader logReader = logMgr.getLogReader(false);
        try {
            logReader.setPosition(firstLSN);
            ILogRecord logRecord = null;
            while (currentLSN < lastLSN) {
                logRecord = logReader.next();
                if (logRecord == null) {
                    break;
                } else {
                    currentLSN = logRecord.getLSN();

                    if (IS_DEBUG_MODE) {
                        LOGGER.info(logRecord.getLogRecordForDisplay());
                    }
                }
                logTxnId = logRecord.getTxnId();
                if (logTxnId != abortedTxnId) {
                    continue;
                }
                tempKeyTxnEntityId.setTxnId(logTxnId, logRecord.getDatasetId(), logRecord.getPKHashValue(),
                        logRecord.getPKValue(), logRecord.getPKValueSize());
                switch (logRecord.getLogType()) {
                    case LogType.UPDATE:
                        if (activePartitions.contains(logRecord.getResourcePartition())) {
                            undoLSNSet = jobLoserEntity2LSNsMap.get(tempKeyTxnEntityId);
                            if (undoLSNSet == null) {
                                loserEntity =
                                        new TxnEntityId(logTxnId, logRecord.getDatasetId(), logRecord.getPKHashValue(),
                                                logRecord.getPKValue(), logRecord.getPKValueSize(), true);
                                undoLSNSet = new LinkedList<>();
                                jobLoserEntity2LSNsMap.put(loserEntity, undoLSNSet);
                            }
                            undoLSNSet.add(currentLSN);
                            updateLogCount++;
                            if (IS_DEBUG_MODE) {
                                LOGGER.info(Thread.currentThread().getId() + "======> update[" + currentLSN + "]:"
                                        + tempKeyTxnEntityId);
                            }
                        }
                        break;
                    case LogType.ENTITY_COMMIT:
                        if (activePartitions.contains(logRecord.getResourcePartition())) {
                            jobLoserEntity2LSNsMap.remove(tempKeyTxnEntityId);
                            entityCommitLogCount++;
                            if (IS_DEBUG_MODE) {
                                LOGGER.info(Thread.currentThread().getId() + "======> entity_commit[" + currentLSN + "]"
                                        + tempKeyTxnEntityId);
                            }
                        }
                        break;
                    case LogType.JOB_COMMIT:
                        throw new ACIDException("Unexpected LogType(" + logRecord.getLogType() + ") during abort.");
                    case LogType.ABORT:
                    case LogType.FLUSH:
                    case LogType.FILTER:
                    case LogType.WAIT:
                    case LogType.WAIT_FOR_FLUSHES:
                    case LogType.MARKER:
                        //ignore
                        break;
                    default:
                        throw new ACIDException("Unsupported LogType: " + logRecord.getLogType());
                }
            }

            if (currentLSN != lastLSN) {
                throw new ACIDException("LastLSN mismatch: lastLSN(" + lastLSN + ") vs currentLSN(" + currentLSN
                        + ") during abort( " + txnContext.getTxnId() + ")");
            }

            //undo loserTxn's effect
            LOGGER.log(Level.INFO, "undoing loser transaction's effect");

            final IDatasetLifecycleManager datasetLifecycleManager = appCtx.getDatasetLifecycleManager();
            //TODO sort loser entities by smallest LSN to undo in one pass.
            Iterator<Entry<TxnEntityId, List<Long>>> iter = jobLoserEntity2LSNsMap.entrySet().iterator();
            int undoCount = 0;
            while (iter.hasNext()) {
                Map.Entry<TxnEntityId, List<Long>> loserEntity2LSNsMap = iter.next();
                undoLSNSet = loserEntity2LSNsMap.getValue();
                // The step below is important since the upsert operations must be done in reverse order.
                Collections.reverse(undoLSNSet);
                for (long undoLSN : undoLSNSet) {
                    //here, all the log records are UPDATE type. So, we don't need to check the type again.
                    //read the corresponding log record to be undone.
                    logRecord = logReader.read(undoLSN);
                    if (logRecord == null) {
                        throw new ACIDException("IllegalState exception during abort( " + txnContext.getTxnId() + ")");
                    }
                    if (IS_DEBUG_MODE) {
                        LOGGER.info(logRecord.getLogRecordForDisplay());
                    }
                    undo(logRecord, datasetLifecycleManager);
                    undoCount++;
                }
            }

            if (LOGGER.isInfoEnabled()) {
                LOGGER.info("undone loser transaction's effect");
                LOGGER.info("[RecoveryManager's rollback log count] update/entityCommit/undo:" + updateLogCount + "/"
                        + entityCommitLogCount + "/" + undoCount);
            }
        } finally {
            logReader.close();
        }
    }

    @Override
    public void start() {
        //no op
    }

    @Override
    public void stop(boolean dumpState, OutputStream os) throws IOException {
    }

    @Override
    public void dumpState(OutputStream os) throws IOException {
        // do nothing
    }

    private static void undo(ILogRecord logRecord, IDatasetLifecycleManager datasetLifecycleManager) {
        try {
            ILSMIndex index =
                    (ILSMIndex) datasetLifecycleManager.getIndex(logRecord.getDatasetId(), logRecord.getResourceId());
            ILSMIndexAccessor indexAccessor = index.createAccessor(NoOpIndexAccessParameters.INSTANCE);
            ILSMIndexOperationContext opCtx = indexAccessor.getOpContext();
            opCtx.setFilterSkip(true);
            try {
                switch (logRecord.getNewOp()) {
                    case AbstractIndexModificationOperationCallback.INSERT_BYTE:
                        indexAccessor.forceDelete(logRecord.getNewValue());
                        break;
                    case AbstractIndexModificationOperationCallback.DELETE_BYTE:
                        // use the same logic to undo delete as undo upsert, since
                        // the old value could be null as well if the deleted record is from disk component
                    case AbstractIndexModificationOperationCallback.UPSERT_BYTE:
                        // undo, upsert the old value if found, otherwise, physical delete
                        undoUpsertOrDelete(indexAccessor, logRecord);
                        break;
                    case AbstractIndexModificationOperationCallback.FILTER_BYTE:
                        //do nothing, can't undo filters
                        break;
                    default:
                        throw new IllegalStateException("Unsupported OperationType: " + logRecord.getNewOp());
                }
            } finally {
                indexAccessor.destroy();
            }
        } catch (Exception e) {
            throw new IllegalStateException("Failed to undo", e);
        }
    }

    private static void undoUpsertOrDelete(ILSMIndexAccessor indexAccessor, ILogRecord logRecord)
            throws HyracksDataException {
        if (logRecord.getOldValue() == null) {
            try {
                indexAccessor.forcePhysicalDelete(logRecord.getNewValue());
            } catch (HyracksDataException hde) {
                // Since we're undoing according the write-ahead log, the actual upserting tuple
                // might not have been written to memory yet.
                if (hde.getErrorCode() != ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
                    throw hde;
                }
            }
        } else {
            indexAccessor.forceUpsert(logRecord.getOldValue());
        }
    }

    private static void redo(ILogRecord logRecord, IDatasetLifecycleManager datasetLifecycleManager) {
        try {
            int datasetId = logRecord.getDatasetId();
            long resourceId = logRecord.getResourceId();
            ILSMIndex index = (ILSMIndex) datasetLifecycleManager.getIndex(datasetId, resourceId);
            ILSMIndexAccessor indexAccessor = index.createAccessor(NoOpIndexAccessParameters.INSTANCE);
            ILSMIndexOperationContext opCtx = indexAccessor.getOpContext();
            opCtx.setFilterSkip(true);
            opCtx.setRecovery(true);
            if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.INSERT_BYTE) {
                indexAccessor.forceInsert(logRecord.getNewValue());
            } else if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.DELETE_BYTE) {
                indexAccessor.forceDelete(logRecord.getNewValue());
            } else if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.UPSERT_BYTE) {
                // redo, upsert the new value
                indexAccessor.forceUpsert(logRecord.getNewValue());
            } else if (logRecord.getNewOp() == AbstractIndexModificationOperationCallback.FILTER_BYTE) {
                opCtx.setFilterSkip(false);
                indexAccessor.updateFilter(logRecord.getNewValue());
            } else {
                throw new IllegalStateException("Unsupported OperationType: " + logRecord.getNewOp());
            }
        } catch (Exception e) {
            throw new IllegalStateException("Failed to redo", e);
        }
    }

    private static void redoFlush(ILSMIndex index, ILogRecord logRecord) throws HyracksDataException {
        long flushLsn = logRecord.getLSN();
        Map<String, Object> flushMap = new HashMap<>();
        flushMap.put(LSMIOOperationCallback.KEY_FLUSH_LOG_LSN, flushLsn);
        ILSMIndexAccessor accessor = index.createAccessor(NoOpIndexAccessParameters.INSTANCE);
        accessor.getOpContext().setParameters(flushMap);
        long minId = logRecord.getFlushingComponentMinId();
        long maxId = logRecord.getFlushingComponentMaxId();
        ILSMComponentId id = new LSMComponentId(minId, maxId);
        flushMap.put(LSMIOOperationCallback.KEY_NEXT_COMPONENT_ID, index.getCurrentMemoryComponent().getId());
        if (!index.getDiskComponents().isEmpty()) {
            ILSMDiskComponent diskComponent = index.getDiskComponents().get(0);
            ILSMComponentId maxDiskComponentId = diskComponent.getId();
            if (maxDiskComponentId.compareTo(id) != IdCompareResult.LESS_THAN) {
                throw new IllegalStateException("Illegal state of component Id. Max disk component Id "
                        + maxDiskComponentId + " should be less than redo flush component Id " + id);
            }
        }
        index.getCurrentMemoryComponent().resetId(id, true);
        ILSMIOOperation flush = accessor.scheduleFlush();
        try {
            flush.sync();
        } catch (InterruptedException e) {
            Thread.currentThread().interrupt();
            throw HyracksDataException.create(e);
        }
        if (flush.getStatus() == LSMIOOperationStatus.FAILURE) {
            throw HyracksDataException.create(flush.getFailure());
        }
        index.resetCurrentComponentIndex();
    }

    private class JobEntityCommits {
        private static final String PARTITION_FILE_NAME_SEPARATOR = "_";
        private final long txnId;
        private final Set<TxnEntityId> cachedEntityCommitTxns = new HashSet<>();
        private final List<File> jobEntitCommitOnDiskPartitionsFiles = new ArrayList<>();
        //a flag indicating whether all the the commits for this jobs have been added.
        private boolean preparedForSearch = false;
        private TxnEntityId winnerEntity = null;
        private int currentPartitionSize = 0;
        private long partitionMaxLSN = 0;
        private String currentPartitonName;

        public JobEntityCommits(long txnId) {
            this.txnId = txnId;
        }

        public void add(ILogRecord logRecord) throws IOException {
            if (preparedForSearch) {
                throw new IOException("Cannot add new entity commits after preparing for search.");
            }
            winnerEntity = new TxnEntityId(logRecord.getTxnId(), logRecord.getDatasetId(), logRecord.getPKHashValue(),
                    logRecord.getPKValue(), logRecord.getPKValueSize(), true);
            cachedEntityCommitTxns.add(winnerEntity);
            //since log file is read sequentially, LSNs are always increasing
            partitionMaxLSN = logRecord.getLSN();
            currentPartitionSize += winnerEntity.getCurrentSize();
            //if the memory budget for the current partition exceeded the limit, spill it to disk and free memory
            if (currentPartitionSize >= cachedEntityCommitsPerJobSize) {
                spillToDiskAndfreeMemory();
            }
        }

        public void spillToDiskAndfreeMemory() throws IOException {
            if (cachedEntityCommitTxns.size() > 0) {
                if (!preparedForSearch) {
                    writeCurrentPartitionToDisk();
                }
                cachedEntityCommitTxns.clear();
                partitionMaxLSN = 0;
                currentPartitionSize = 0;
                currentPartitonName = "";
            }
        }

        /**
         * Call this method when no more entity commits will be added to this job.
         *
         * @throws IOException
         */
        public void prepareForSearch() throws IOException {
            //if we have anything left in memory, we need to spill them to disk before searching other partitions.
            //However, if we don't have anything on disk, we will search from memory only
            if (jobEntitCommitOnDiskPartitionsFiles.size() > 0) {
                spillToDiskAndfreeMemory();
            } else {
                //set the name of the current in memory partition to the current partition
                currentPartitonName = getPartitionName(partitionMaxLSN);
            }
            preparedForSearch = true;
        }

        public boolean containsEntityCommitForTxnId(long logLSN, TxnEntityId txnEntityId) throws IOException {
            //if we don't have any partitions on disk, search only from memory
            if (jobEntitCommitOnDiskPartitionsFiles.size() == 0) {
                return cachedEntityCommitTxns.contains(txnEntityId);
            } else {
                //get candidate partitions from disk
                ArrayList<File> candidatePartitions = getCandidiatePartitions(logLSN);
                for (File partition : candidatePartitions) {
                    if (serachPartition(partition, txnEntityId)) {
                        return true;
                    }
                }
            }
            return false;
        }

        /**
         * @param logLSN
         * @return partitions that have a max LSN > logLSN
         */
        public ArrayList<File> getCandidiatePartitions(long logLSN) {
            ArrayList<File> candidiatePartitions = new ArrayList<>();
            for (File partition : jobEntitCommitOnDiskPartitionsFiles) {
                String partitionName = partition.getName();
                // entity commit log must come after the update log,
                // therefore, consider only partitions with max LSN > logLSN
                if (getPartitionMaxLSNFromName(partitionName) > logLSN) {
                    candidiatePartitions.add(partition);
                }
            }

            return candidiatePartitions;
        }

        public void clear() {
            cachedEntityCommitTxns.clear();
            for (File partition : jobEntitCommitOnDiskPartitionsFiles) {
                partition.delete();
            }
            jobEntitCommitOnDiskPartitionsFiles.clear();
        }

        private boolean serachPartition(File partition, TxnEntityId txnEntityId) throws IOException {
            //load partition from disk if it is not  already in memory
            if (!partition.getName().equals(currentPartitonName)) {
                loadPartitionToMemory(partition, cachedEntityCommitTxns);
                currentPartitonName = partition.getName();
            }
            return cachedEntityCommitTxns.contains(txnEntityId);
        }

        private String getPartitionName(long maxLSN) {
            return txnId + PARTITION_FILE_NAME_SEPARATOR + maxLSN;
        }

        private long getPartitionMaxLSNFromName(String partitionName) {
            return Long.valueOf(partitionName.substring(partitionName.indexOf(PARTITION_FILE_NAME_SEPARATOR) + 1));
        }

        private void writeCurrentPartitionToDisk() throws IOException {
            //if we don't have enough memory to allocate for this partition,
            // we will ask recovery manager to free memory
            if (needToFreeMemory()) {
                freeJobsCachedEntities(txnId);
            }
            //allocate a buffer that can hold the current partition
            ByteBuffer buffer = ByteBuffer.allocate(currentPartitionSize);
            for (Iterator<TxnEntityId> iterator = cachedEntityCommitTxns.iterator(); iterator.hasNext();) {
                TxnEntityId txnEntityId = iterator.next();
                //serialize the object and remove it from memory
                txnEntityId.serialize(buffer);
                iterator.remove();
            }
            //name partition file based on job id and max lsn
            File partitionFile = createJobRecoveryFile(txnId, getPartitionName(partitionMaxLSN));
            //write file to disk
            try (FileOutputStream fileOutputstream = new FileOutputStream(partitionFile, false);
                    FileChannel fileChannel = fileOutputstream.getChannel()) {
                buffer.flip();
                while (buffer.hasRemaining()) {
                    fileChannel.write(buffer);
                }
            }
            jobEntitCommitOnDiskPartitionsFiles.add(partitionFile);
        }

        private void loadPartitionToMemory(File partition, Set<TxnEntityId> partitionTxn) throws IOException {
            partitionTxn.clear();
            //if we don't have enough memory to a load partition, we will ask recovery manager to free memory
            if (needToFreeMemory()) {
                freeJobsCachedEntities(txnId);
            }
            ByteBuffer buffer = ByteBuffer.allocateDirect((int) partition.length());
            //load partition to memory
            try (InputStream is = new FileInputStream(partition)) {
                int readByte;
                while ((readByte = is.read()) != -1) {
                    buffer.put((byte) readByte);
                }
            }
            buffer.flip();
            TxnEntityId temp;
            while (buffer.remaining() != 0) {
                temp = TxnEntityId.deserialize(buffer);
                partitionTxn.add(temp);
            }
        }
    }
}


text:
layout: page
title: Cohen International Award Ceremony
date: 2016-05-24
author: Joshua Clark
tags: weekly links, java
status: published
summary: Duis dapibus in lorem sed laoreet. Class aptent.
banner: images/banner/leisure-01.jpg
booking:
  startDate: 02/22/2017
  endDate: 02/25/2017
  ctyhocn: BUFATHX
  groupCode: CIAC
published: true
---
Cras interdum, urna tincidunt condimentum scelerisque, nisi est volutpat ex, in accumsan dolor sem ac ipsum. Etiam pretium commodo tellus, vel tincidunt quam ornare ut. Nunc sed velit neque. Cras ac mauris nec dolor sodales lacinia bibendum eget nisl. Nullam convallis urna quis orci malesuada, sit amet lobortis diam egestas. Nam vestibulum aliquet lectus, commodo dignissim neque consequat sed. Morbi in consequat nibh. Praesent maximus lacus vitae diam varius rhoncus. In hac habitasse platea dictumst. Nunc quis elit ex. Ut euismod lectus at enim rhoncus, nec mattis libero vestibulum. Phasellus feugiat cursus dolor dapibus porta.

1 Nulla quis dui vitae elit lacinia fringilla
1 Etiam lobortis ex vitae pulvinar lacinia
1 In quis felis at lectus fermentum dictum vitae vel nunc
1 Curabitur bibendum felis nec mi pretium sodales
1 Nulla suscipit mi a enim consequat feugiat.

Fusce tincidunt purus neque, at luctus est condimentum ut. Ut facilisis lobortis magna hendrerit mattis. Pellentesque varius augue sed fringilla lobortis. Phasellus tincidunt sed odio ac bibendum. Morbi scelerisque, augue sit amet porta rutrum, velit velit consequat urna, ac pellentesque purus erat et turpis. Aliquam vel justo blandit, pulvinar enim fringilla, pulvinar nulla. In lacinia, tellus id cursus bibendum, nisi velit ultricies dui, non mollis quam mi in felis. Curabitur condimentum non leo quis efficitur.
Pellentesque mollis facilisis velit, quis molestie tortor dignissim sed. Phasellus tempor justo sagittis, lacinia ex ut, eleifend massa. Sed eu tincidunt dui, vel consequat elit. Donec sodales sapien sit amet sodales sollicitudin. Nunc vestibulum malesuada metus. Phasellus id blandit ipsum. Suspendisse at egestas lacus. Etiam consequat, velit id finibus molestie, risus ipsum elementum purus, ut laoreet dui risus rhoncus ligula. Aliquam ipsum felis, hendrerit a leo in, consectetur mattis mi. Sed sodales justo vitae est iaculis feugiat. Etiam commodo maximus massa, non lobortis turpis gravida quis.


text:
"""MyOffers URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/1.9/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.conf.urls import url, include
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""
from django.urls import path
from . import views

urlpatterns = [
    path('', views.index, name='index'),
    path('access-denied/', views.access_denied_view, name='access_denied_view'),
    path('invalid-request/', views.invalid_request_view, name='invalid_request_view'),
    path('under-construction/', views.under_construction_view, name='under_construction_view'),
]


text:
package com.google.sampling.experiential.dao;

import java.sql.SQLException;
import java.text.ParseException;
import java.util.List;

import com.google.sampling.experiential.model.Event;

public interface CSEventDao {

  boolean insertSingleEventOnly(Event event) throws SQLException, ParseException, NumberFormatException, Exception;

  boolean insertSingleEventOnlyOldFormat(Event event) throws SQLException, ParseException;

  void updateGroupName(List<Long> eventIdsToBeUpdatedWithNewGroupName, List<String> eventIdsOldGroupName,
                       String featureName) throws SQLException;

  Long getNumberOfEvents(Long experimentId) throws SQLException;

  boolean updateAllEventsData(Long experimentId) throws SQLException;
}


text:
module Govuk
  module DummyContentStore
    VERSION = "0.0.5"
  end
end


text:
<?php

namespace Engine\SDK\RX\Abstraction;

use Throwable;

/**
 * Interface Observer
 *
 * @package Engine\SDK\RX\Abstraction
 */
interface Observer
{
    public function onNext($event);

    public function onError(Throwable $throwable, $event);

    public function onComplete();
}


text:
package org.robolectric.shadows;

import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.robolectric.TestRunners;

import static org.assertj.core.api.Assertions.assertThat;

@RunWith(TestRunners.WithDefaults.class)
public class ShadowIntentFilterTest {
  @Test
  public void copyConstructorTest() throws Exception {
    String action = "test";
    IntentFilter intentFilter = new IntentFilter(action);
    IntentFilter copy = new IntentFilter(intentFilter);
    assertThat(copy.hasAction("test"));
  }

  @Test
  public void setsPriority() throws Exception {
    IntentFilter filter = new IntentFilter();
    filter.setPriority(123);
    assertThat(filter.getPriority()).isEqualTo(123);
  }

  @Test
  public void addDataScheme_shouldAddTheDataScheme() throws Exception {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("http");
    intentFilter.addDataScheme("ftp");

    assertThat(intentFilter.getDataScheme(0)).isEqualTo("http");
    assertThat(intentFilter.getDataScheme(1)).isEqualTo("ftp");
  }

  @Test
  public void addDataAuthority_shouldAddTheDataAuthority() throws Exception {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataAuthority("test.com", "8080");
    intentFilter.addDataAuthority("example.com", "42");

    assertThat(intentFilter.getDataAuthority(0).getHost()).isEqualTo("test.com");
    assertThat(intentFilter.getDataAuthority(0).getPort()).isEqualTo(8080);
    assertThat(intentFilter.getDataAuthority(1).getHost()).isEqualTo("example.com");
    assertThat(intentFilter.getDataAuthority(1).getPort()).isEqualTo(42);
  }

  @Test
  public void addDataType_shouldAddTheDataType() throws Exception {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataType("image/test");

    assertThat(intentFilter.getDataType(0)).isEqualTo("image/test");
  }

  @Test
  public void hasAction() {
    IntentFilter intentFilter = new IntentFilter();
    assertThat(intentFilter.hasAction("test")).isFalse();
    intentFilter.addAction("test");

    assertThat(intentFilter.hasAction("test")).isTrue();
  }

  @Test
  public void hasDataScheme() {
    IntentFilter intentFilter = new IntentFilter();
    assertThat(intentFilter.hasDataScheme("test")).isFalse();
    intentFilter.addDataScheme("test");

    assertThat(intentFilter.hasDataScheme("test")).isTrue();
  }

  @Test
  public void hasDataType() throws IntentFilter.MalformedMimeTypeException{
    IntentFilter intentFilter = new IntentFilter();
    assertThat(intentFilter.hasDataType("image/test")).isFalse();
    intentFilter.addDataType("image/test");

    assertThat(intentFilter.hasDataType("image/test")).isTrue();
  }

  @Test
  public void matchDataAuthority_matchHostAndPort() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataAuthority("testHost1", "1");
    intentFilter.addDataAuthority("testHost2", "2");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    Uri uriTest2 = Uri.parse("http://testHost2:2");
    assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(
        IntentFilter.MATCH_CATEGORY_HOST + IntentFilter.MATCH_CATEGORY_PORT + IntentFilter.MATCH_ADJUSTMENT_NORMAL);
    assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(
        IntentFilter.MATCH_CATEGORY_HOST + IntentFilter.MATCH_CATEGORY_PORT + IntentFilter.MATCH_ADJUSTMENT_NORMAL);
  }

  @Test
  public void matchDataAuthority_matchHostWithNoPort() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataAuthority("testHost1", "-1");
    intentFilter.addDataAuthority("testHost2", "-1");

    Uri uriTest1 = Uri.parse("http://testHost1:100");
    Uri uriTest2 = Uri.parse("http://testHost2:200");
    assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(
        IntentFilter.MATCH_CATEGORY_HOST + IntentFilter.MATCH_ADJUSTMENT_NORMAL);
    assertThat(intentFilter.matchDataAuthority(uriTest2)).isEqualTo(
        IntentFilter.MATCH_CATEGORY_HOST + IntentFilter.MATCH_ADJUSTMENT_NORMAL);
  }

  @Test
  public void matchDataAuthority_NoMatch() {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataAuthority("testHost1", "1");
    intentFilter.addDataAuthority("testHost2", "2");

    // Port doesn't match
    Uri uriTest1 = Uri.parse("http://testHost1:2");
    // Host doesn't match
    Uri uriTest2 = Uri.parse("http://testHost3:2");
    assertThat(intentFilter.matchDataAuthority(uriTest1)).isEqualTo(
        IntentFilter.NO_MATCH_DATA);
    assertThat(intentFilter.matchDataAuthority(uriTest2)).isEqualTo(
        IntentFilter.NO_MATCH_DATA);
  }

  @Test
  public void matchData_MatchAll() throws IntentFilter.MalformedMimeTypeException{
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataType("image/test");
    intentFilter.addDataScheme("http");
    intentFilter.addDataAuthority("testHost1", "1");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    assertThat(intentFilter.matchData("image/test", "http", uriTest1))
        .isGreaterThanOrEqualTo(0);
  }

  @Test
  public void matchData_MatchType() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataType("image/test");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    assertThat(intentFilter.matchData("image/test", "http", uriTest1))
        .isGreaterThanOrEqualTo(0);
  }

  @Test
  public void matchData_MatchScheme() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("http");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    assertThat(intentFilter.matchData(null, "http", uriTest1))
        .isGreaterThanOrEqualTo(0);
  }

  @Test
  public void matchData_MatchEmpty() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();

    assertThat(intentFilter.matchData(null, "noscheme", null))
        .isGreaterThanOrEqualTo(0);
  }

  @Test
  public void matchData_NoMatchType() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataType("image/testFail");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    assertThat(intentFilter.matchData("image/test", "http", uriTest1))
        .isLessThan(0);
  }

  @Test
  public void matchData_NoMatchScheme() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("http");
    intentFilter.addDataType("image/test");

    Uri uriTest1 = Uri.parse("https://testHost1:1");
    assertThat(intentFilter.matchData("image/test", "https", uriTest1))
        .isLessThan(0);
  }

  @Test
  public void matchData_NoMatchDataAuthority() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataType("image/test");
    intentFilter.addDataScheme("http");
    intentFilter.addDataAuthority("testHost1", "1");

    Uri uriTest1 = Uri.parse("http://testHost1:2");
    assertThat(intentFilter.matchData("image/test", "http", uriTest1))
        .isLessThan(0);
  }

  @Test
  public void matchData_MatchSchemeNoMatchType() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("http");
    intentFilter.addDataType("image/testFail");

    Uri uriTest1 = Uri.parse("http://testHost1:1");
    assertThat(intentFilter.matchData("image/test", "http", uriTest1))
        .isLessThan(0);
  }

  @Test
  public void matchData_MatchesPartialType() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("content");
    intentFilter.addDataType("image/*");

    Uri uri = Uri.parse("content://authority/images");
    assertThat(intentFilter.matchData("image/test", "content", uri)).isGreaterThanOrEqualTo(0);
    assertThat(intentFilter.matchData("video/test", "content", uri)).isLessThan(0);
  }

  @Test
  public void matchData_MatchesAnyTypeAndSubtype() throws IntentFilter.MalformedMimeTypeException {
    IntentFilter intentFilter = new IntentFilter();
    intentFilter.addDataScheme("content");
    intentFilter.addDataType("*/*");

    Uri uri = Uri.parse("content://authority/images");
    assertThat(intentFilter.matchData("image/test", "content", uri)).isGreaterThanOrEqualTo(0);
    assertThat(intentFilter.matchData("image/*", "content", uri)).isGreaterThanOrEqualTo(0);
    assertThat(intentFilter.matchData("video/test", "content", uri)).isGreaterThanOrEqualTo(0);
    assertThat(intentFilter.matchData("video/*", "content", uri)).isGreaterThanOrEqualTo(0);
  }
}


text:
var RED = require(process.env.NODE_RED_HOME+"/red/red");
var util = require("util");
var parseString = require('xml2js').parseString;
var gotEyes = false;
try {
    var eyes = require("eyes");
    gotEyes = true;
} catch(e) {
    util.log("[73-parsexml.js] Note: Module 'eyes' not installed. (not needed, but useful)");
}

function Xml2jsNode(n) {
    RED.nodes.createNode(this,n);
    this.useEyes = n.useEyes;
    var node = this;
    this.on("input", function(msg) {
        try {
            parseString(msg.payload, {strict:true,async:true}, function (err, result) {
            //parseString(msg.payload, {strict:false,async:true}, function (err, result) {
                if (err) { node.error(err); }
                else {
                    msg.payload = result;
                    node.send(msg);
                    if (node.useEyes == true) {
                        if (gotEyes == true) { eyes.inspect(msg); }
                        else { node.log(JSON.stringify(msg)); }
                    }
                }
            });
        }
        catch(e) { util.log("[73-parsexml.js] "+e); }
    });
}
RED.nodes.registerType("xml2js",Xml2jsNode);


text:
import java.util.Random;
import java.util.ArrayList;

public class QAgent implements Agent {
  public QAgent() {
    this.rand = new Random();
  }

  public void initialize(int numOfStates, int numOfActions) {
    this.qValue = new double[numOfStates][numOfActions];
    this.numOfStates = numOfStates;
    this.numOfActions = numOfActions;
    for(int i = 0;i<numOfStates;i++)
    	for(int j = 0; j<numOfActions;j++){
    		qValue[i][j]=0;
    	}
  }

  /*private double bestUtility(int state) {

  }*/

  public int chooseAction(int state) {
	  int randNum = rand.nextInt(100);
	  if(randNum<=epsilon*100)
		  return rand.nextInt(this.numOfActions);
	  double highestQ = qValue[state][0];
	  int chosenAction = 0;
	  for(int i = 1;i<numOfActions;i++){
		  if(qValue[state][i]>highestQ || (qValue[state][i]==highestQ && rand.nextInt(100) > 50))
		  {
				  highestQ = qValue[state][i];
				  chosenAction = i;
		  }
	  }
	  return chosenAction;

  }

  private double findNextStepBest(int state){
	  double bestQ = qValue[state][0];
	  for(int i = 1;i<numOfActions;i++){
		  if(bestQ<qValue[state][i])
			  bestQ = qValue[state][i];
	  }
	  return bestQ;
  }

  public void updatePolicy(double reward, int action,
                           int oldState, int newState) {
	  double QbeforeUpdate = qValue[oldState][action];
	  qValue[oldState][action] = QbeforeUpdate  + rate*(reward + discount*findNextStepBest(newState) - QbeforeUpdate);
  }

  public Policy getPolicy() {
	  int[] actions = new int[numOfStates];
	  for(int i=0;i<numOfStates;i++){
		  actions[i] = chooseAction(i);
	  }
	  return new Policy(actions);

  }

  private static final double discount = 0.9;
  private static final double rate = 0.1;
  private static final double epsilon = 0.0;

  private Random rand;
  private int numOfStates;
  private int numOfActions;
  private double[][] qValue;
}


text:
package com.reason.bs;

import com.google.common.annotations.*;
import com.intellij.openapi.project.*;
import com.intellij.openapi.util.*;
import com.intellij.openapi.vfs.*;
import com.reason.*;
import com.reason.esy.*;
import com.reason.ide.*;
import com.reason.ide.settings.*;
import org.jetbrains.annotations.*;

import java.util.*;

import static com.reason.Platform.*;
import static com.reason.bs.BsConstants.*;

public class BsPlatform {
    private static final Log LOG = Log.create("bs.platform");

    private BsPlatform() {
    }

    /**
     * Finds the "nearest" `bsconfig.json` to a given file. Searches up the file-system until a
     * `bsconfig.json` is found or the project root is reached.
     *
     * @param project    project to use
     * @param sourceFile starting point for search
     * @return `bsconfig.json` file, if found
     */
    public static @NotNull Optional<VirtualFile> findBsConfig(@NotNull Project project, @NotNull VirtualFile sourceFile) {
        return ORFileUtils.findAncestor(project, BS_CONFIG_FILENAME, sourceFile);
    }

    public static @NotNull Optional<VirtualFile> findContentRoot(@NotNull Project project, @NotNull VirtualFile sourceFile) {
        return findBsConfig(project, sourceFile).map(VirtualFile::getParent);
    }

    public static @NotNull Optional<VirtualFile> findBsbExecutable(@NotNull Project project, @NotNull VirtualFile sourceFile) {
        return findBsConfig(project, sourceFile)
                .flatMap(bsConfig -> {
                    VirtualFile bsPlatform = findBsPlatformPathForConfigFile(project, bsConfig).orElse(null);
                    if (bsPlatform != null) {
                        return findBinaryInBsPlatform(BSB_EXE_NAME, bsPlatform);
                    } else {
                        // maybe a yarn v2 monorepo ? continue to parent to find a node_modules, unless root is reached
                        return ORFileUtils.findAncestor(project, NODE_MODULES, bsConfig.getParent()).
                                flatMap(nodeModules -> findBsPlatformPathInNodeModules(project, nodeModules).
                                        flatMap(bsPlatformDirectory -> findBinaryInBsPlatform(BSB_EXE_NAME, bsPlatformDirectory)));
                    }
                });
    }

    public static @NotNull Optional<VirtualFile> findBscExecutable(@NotNull Project project, @NotNull VirtualFile sourceFile) {
        return findBsConfig(project, sourceFile)
                .flatMap(bsContent -> {
                    VirtualFile bsPlatform = findBsPlatformPathForConfigFile(project, bsContent).orElse(null);
                    if (bsPlatform != null) {
                        return findBinaryInBsPlatform(BSC_EXE_NAME, bsPlatform);
                    } else {
                        // maybe a yarn v2 monorepo ? continue to parent to find a node_modules, unless root is reached
                        return ORFileUtils.findAncestor(project, NODE_MODULES, bsContent.getParent()).
                                flatMap(nodeModules -> findBsPlatformPathInNodeModules(project, nodeModules).
                                        flatMap(bsPlatformDirectory -> findBinaryInBsPlatform(BSC_EXE_NAME, bsPlatformDirectory)));
                    }
                });
    }

    public static Optional<VirtualFile> findEsyExecutable(@NotNull Project project) {
        String esyExecutable = ORSettings.getInstance(project).getEsyExecutable();
        if (esyExecutable.isEmpty()) {
            return Esy.findEsyExecutable();
        }
        return Optional.ofNullable(LocalFileSystem.getInstance().findFileByPath(esyExecutable));
    }

    public static Optional<VirtualFile> findRefmtExecutable(@NotNull Project project, @NotNull VirtualFile sourceFile) {
        VirtualFile bsPlatformDirectory = findBsConfig(project, sourceFile)
                .map(bsContent -> findBsPlatformPathForConfigFile(project, bsContent)
                        .orElseGet(() ->
                                // maybe a yarn v2 monorepo ? continue to parent to find a node_modules, unless root is reached
                                ORFileUtils.findAncestor(project, NODE_MODULES, bsContent.getParent())
                                        .flatMap(nodeModules -> findBsPlatformPathInNodeModules(project, nodeModules))
                                        .orElse(null))).orElse(null);
        if (bsPlatformDirectory == null) {
            return Optional.empty();
        }

        Optional<VirtualFile> binaryInBsPlatform;

        // first, try standard name
        binaryInBsPlatform = findBinaryInBsPlatform(REFMT_EXE_NAME, bsPlatformDirectory);
        if (!binaryInBsPlatform.isPresent()) {
            // next, try alternative names
            binaryInBsPlatform = findBinaryInBsPlatform("refmt3", bsPlatformDirectory);
            if (!binaryInBsPlatform.isPresent()) {
                binaryInBsPlatform = findBinaryInBsPlatform("bsrefmt", bsPlatformDirectory);
            }
        }

        return binaryInBsPlatform;
    }

    private static Optional<VirtualFile> findBsPlatformPathInNodeModules(@NotNull Project project, @NotNull VirtualFile nodeModules) {
        VirtualFile bsPlatform = nodeModules.findFileByRelativePath(BS_PLATFORM_NAME);
        if (bsPlatform == null) {
            VirtualFile bsbBinary = nodeModules.findFileByRelativePath(".bin/" + BSB_EXE_NAME);
            if (bsbBinary != null) {
                // This must be a mono-repo, only the .bin is found
                VirtualFile canonicalFile = bsbBinary.getCanonicalFile();
                if (canonicalFile != null) {
                    if (bsbBinary.is(VFileProperty.SYMLINK)) {
                        // Mac/Linux: .bin contains symlinks to real exe, must follow
                        VirtualFile canonicalBsPlatformDirectory = canonicalFile.getParent();
                        while (canonicalBsPlatformDirectory != null
                                && !canonicalBsPlatformDirectory.getName().equals(BS_PLATFORM_NAME)) {
                            canonicalBsPlatformDirectory = canonicalBsPlatformDirectory.getParent();
                        }
                        return Optional.ofNullable(canonicalBsPlatformDirectory);
                    } else {
                        // Windows: no symlinks, only bat files
                        return ORFileUtils.findAncestor(project, NODE_MODULES, nodeModules.getParent())
                                .map(nodeModules2 -> nodeModules2.findFileByRelativePath(BS_PLATFORM_NAME));
                    }
                }
            }
        }
        return Optional.ofNullable(bsPlatform).filter(VirtualFile::isDirectory);
    }

    private static Optional<VirtualFile> findBsPlatformPathForConfigFile(@NotNull Project project, @NotNull VirtualFile bsConfigFile) {
        VirtualFile parentDir = bsConfigFile.getParent();
        VirtualFile bsPlatform = parentDir.findFileByRelativePath("node_modules/" + BS_PLATFORM_NAME);
        if (bsPlatform == null) {
            VirtualFile bsbBinary = parentDir.findFileByRelativePath("node_modules/.bin/" + BSB_EXE_NAME);
            if (bsbBinary != null) {
                // This must be a mono-repo, only the .bin is found
                VirtualFile canonicalFile = bsbBinary.getCanonicalFile();
                if (canonicalFile != null) {
                    if (bsbBinary.is(VFileProperty.SYMLINK)) {
                        // Mac/Linux: .bin contains symlinks to real exe, must follow
                        VirtualFile canonicalBsPlatformDirectory = canonicalFile.getParent();
                        while (canonicalBsPlatformDirectory != null
                                && !canonicalBsPlatformDirectory.getName().equals(BS_PLATFORM_NAME)) {
                            canonicalBsPlatformDirectory = canonicalBsPlatformDirectory.getParent();
                        }
                        return Optional.ofNullable(canonicalBsPlatformDirectory);
                    } else {
                        // Windows: no symlinks, only bat files
                        return ORFileUtils.findAncestor(project, NODE_MODULES, parentDir.getParent())
                                .map(nodeModules -> nodeModules.findFileByRelativePath(BS_PLATFORM_NAME));
                    }
                }
            }
        }
        return Optional.ofNullable(bsPlatform).filter(VirtualFile::isDirectory);
    }

    private static Optional<VirtualFile> findBinaryInBsPlatform(@NotNull String executableName, @NotNull VirtualFile bsPlatformDirectory) {
        String platform = getOsBsPrefix();
        if (platform == null) {
            LOG.warn("Unable to determine OS prefix.");
            return Optional.empty();
        }

        VirtualFile executable;

        // first, try to find platform-specific binary
        executable = bsPlatformDirectory.findFileByRelativePath(platform + "/" + executableName + WINDOWS_EXECUTABLE_SUFFIX);
        if (executable == null) {
            // next, try to find platform-agnostic wrappers
            executable = bsPlatformDirectory.findFileByRelativePath(executableName + getOsBinaryWrapperExtension());
            if (executable == null) {
                // last, try old locations of binary
                executable = bsPlatformDirectory.findFileByRelativePath("bin/" + executableName + WINDOWS_EXECUTABLE_SUFFIX);
                if (executable == null) {
                    executable = bsPlatformDirectory.findFileByRelativePath("lib/" + executableName + WINDOWS_EXECUTABLE_SUFFIX);
                }
            }
        }

        return Optional.ofNullable(executable);
    }

    @VisibleForTesting
    static @NotNull String getOsBinaryWrapperExtension() {
        return SystemInfo.isWindows ? ".cmd" : "";
    }

    @VisibleForTesting
    static @Nullable String getOsBsPrefix() {
        if (SystemInfo.isWindows) {
            return "win32";
        }
        if (SystemInfo.isLinux) {
            return "linux";
        }
        if (SystemInfo.isMac) {
            return "darwin";
        }
        return null;
    }
}


text:
#!/usr/bin/env node
/*jshint strict:true node:true es5:true onevar:true laxcomma:true laxbreak:true eqeqeq:true immed:true latedef:true*/
(function () {
  "use strict";

  var btoa = require('../index')
    ;

  console.log(btoa(process.argv[2]));
}());


text:
page_title: "vagrant version - Command-Line Interface"
sidebar_current: "cli-version"
---

# Version

**Command: `vagrant version`**

This command tells you the version of Vagrant you have installed
as well as the latest version of Vagrant that is currently available.

In order to determine the latest available Vagrant version, this
command must make a network call. If you only want to see the currently
installed version, use `vagrant --version`.


text:
<ion-header>
  <ion-navbar>
    <button ion-button menuToggle>
      <ion-icon name="menu"></ion-icon>
    </button>
    <ion-title>Home</ion-title>
  </ion-navbar>
</ion-header>

<ion-content padding>

</ion-content>


text:
import requests
from config import settings

def choose(text, choices, retry=0):
    try:
        if retry > 3:
            return False

        params = {
            'text': text,
            'choices': (','.join(choices)).lower()
        }

        r = requests.get(settings.SELECT_SOLVER_BASE + '/choose.json', params=params)

        if "Internal Server Error" in r.text:
            return None

        return r.text.replace('"','')
    except:
        return choose(text, choices, retry=retry+1)


text:
require 'sinatra'
require 'eventmachine'
require 'json'
require 'time'

require_relative 'discovery'
require_relative 'overview'
require_relative 'historical_data'

module VistaTV
  module StatsServer
    class WebServer < Sinatra::Base

      configure do
        set :threaded, true
        set :root,     File.dirname(__FILE__) + '/../'
        set :static,   false
      end

      get "/" do
        redirect '/status'
      end

      get '/status' do
        content_type 'text/plain', :charset => 'utf-8'
        "VistaTV Stats Web Server up and running"
      end

      get '/discovery.json' do
        content_type 'application/json', :charset => 'utf-8'
        discovery = Discovery.new
        JSON.generate(discovery.data)
      end

      get '/latest.json' do
        overview = Overview.new(settings.logger)
        data = overview.data
        content_type 'application/json', :charset => 'utf-8'
        JSON.generate(data)
      end

      get '/:service/historical.json' do |service|
        current_time = Time.now
        historical_data = HistoricalData.new(settings.logger)
        data = historical_data.query(current_time, service)
        content_type 'application/json', :charset => 'utf-8'
        JSON.generate(data)
      end
    end
  end
end