text:
package enmasse.mqtt;

import io.vertx.core.AbstractVerticle;
import io.vertx.core.CompositeFuture;
import io.vertx.core.Future;
import io.vertx.core.net.PemKeyCertOptions;
import io.vertx.core.net.SocketAddress;
import io.vertx.mqtt.MqttEndpoint;
import io.vertx.mqtt.MqttServer;
import io.vertx.mqtt.MqttServerOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Semaphore;
import java.util.stream.Collectors;

/**
 * Vert.x based MQTT gateway for EnMasse
 */
public class MqttGateway extends AbstractVerticle {

    private static final Logger LOG = LoggerFactory.getLogger(MqttGateway.class);
    private final MqttGatewayOptions options;

    private MqttServer server;

    private final Map<String, AmqpBridge> bridges = new ConcurrentHashMap<>();
    private final ConcurrentMap<String, Semaphore> clientIdSemaphores = new ConcurrentHashMap<>();

    public MqttGateway(MqttGatewayOptions options) {

        this.options = options;
    }

    /**
     * Start the MQTT server component
     *
     * @param startFuture
     */
    private void bindMqttServer(Future<Void> startFuture) {

        MqttServerOptions options = new MqttServerOptions();
        options.setMaxMessageSize(this.options.getMaxMessageSize());
        options.setHost(this.options.getBindAddress()).setPort(this.options.getListenPort());
        options.setAutoClientId(true);

        if (this.options.isSsl()) {

            PemKeyCertOptions pemKeyCertOptions = new PemKeyCertOptions()
                    .setKeyPath(this.options.getKeyFile())
                    .setCertPath(this.options.getCertFile());

            options.setKeyCertOptions(pemKeyCertOptions)
                    .setSsl(this.options.isSsl());

            LOG.info("SSL/TLS support enabled key {} cert {}", this.options.getKeyFile(), this.options.getCertFile());
        }

        this.server = MqttServer.create(this.vertx, options);

        this.server
                .endpointHandler(this::handleMqttEndpointConnection)
                .exceptionHandler(t -> {LOG.error("Error handling connection ", t);})
                .listen(done -> {

                    if (done.succeeded()) {

                        LOG.info("MQTT gateway running on {}:{}", this.options.getBindAddress(), this.server.actualPort());
                        LOG.info("AMQP messaging service on {}:{}", this.options.getMessagingServiceHost(), this.options.getMessagingServicePort());
                        startFuture.complete();
                    } else {
                        LOG.error("Error while starting up MQTT gateway", done.cause());
                        startFuture.fail(done.cause());
                    }

                });
    }

    /**
     * Handler for a connection request (CONNECT) received by a remote MQTT client
     *
     * @param mqttEndpoint  MQTT local endpoint
     */
    private void handleMqttEndpointConnection(MqttEndpoint mqttEndpoint) {

        final String clientIdentifier = mqttEndpoint.clientIdentifier();
        final SocketAddress remoteAddress = mqttEndpoint.remoteAddress();
        LOG.info("CONNECT from MQTT client {} at {}", clientIdentifier, remoteAddress);

        Semaphore clientIdSemaphore = clientIdSemaphores.computeIfAbsent(clientIdentifier,
                                                                         s -> new Semaphore(1));

        if (clientIdSemaphore.tryAcquire()) {
            AmqpBridge bridge = new AmqpBridge(this.vertx, mqttEndpoint);

            bridge.mqttEndpointCloseHandler(amqpBridge -> {

                try {
                    this.bridges.remove(amqpBridge.id());
                } finally {
                    clientIdSemaphores.remove(clientIdentifier, clientIdSemaphore);
                }
            }).open(this.options.getMessagingServiceHost(), this.options.getMessagingServicePort(), done -> {
                if (done.succeeded()) {
                    AmqpBridge newBridge = done.result();
                    this.bridges.put(newBridge.id(), newBridge);
                } else {
                    LOG.info("Error opening the AMQP bridge ...", done.cause());
                    clientIdSemaphores.remove(clientIdentifier, clientIdSemaphore);
                }
            });
        } else {
            AmqpBridge existingBridge = bridges.get(clientIdentifier);
            if (existingBridge == null) {
                // The semaphore is held but no bridge is present; another session must either be in the process of
                // forming a bridge or removing one that is closing.
                LOG.trace("No existing bridge found for {}", clientIdentifier);
                vertx.setTimer(100, unused -> {
                    handleMqttEndpointConnection(mqttEndpoint);
                });
            } else {
                // If the ClientId represents a Client already connected to the Server then the Server MUST
                // disconnect the existing Client [MQTT-3.1.4-2].
                LOG.info("MQTT client {} already in-use by {}", clientIdentifier, existingBridge.remoteAddress());
                existingBridge.close().compose(unused -> {
                    LOG.trace("MQTT Closing of existing client {} from {} completed (initiated by {})",
                              clientIdentifier, existingBridge.remoteAddress(), remoteAddress);
                    handleMqttEndpointConnection(mqttEndpoint);
                    return Future.succeededFuture();
                });
            }
        }
    }

    @Override
    public void start(Future<Void> startFuture) throws Exception {

        LOG.info("Starting MQTT gateway verticle...");
        this.bindMqttServer(startFuture);
    }

    @Override
    public void stop(Future<Void> stopFuture) throws Exception {

        LOG.info("Stopping MQTT gateway verticle ...");

        Future<Void> shutdownTracker = Future.future();
        shutdownTracker.setHandler(done -> {
           if (done.succeeded()) {
               LOG.info("MQTT gateway has been shut down successfully");
               stopFuture.complete();
           } else {
               LOG.info("Error while shutting down MQTT gateway", done.cause());
               stopFuture.fail(done.cause());
           }
        });

        if (this.server != null) {
            @SuppressWarnings("rawtypes")
            List<Future> closeFutures = this.bridges.entrySet()
                                                    .stream()
                                                    .map(entry -> entry.getValue().close())
                                                    .collect(Collectors.toList());

            CompositeFuture.all(closeFutures).setHandler(done -> {
                this.server.close(shutdownTracker);
            });
        } else {
            shutdownTracker.complete();
        }
    }
}


text:
var page = require('webpage').create();
page.viewportSize = { width: 1024, height: 768 };
page.settings.userName = "admin";
page.settings.password = "admin";
page.open('http://localhost:5120/', function() {
  window.setTimeout(function () {
    page.render("test.png");
    phantom.exit();
    }, 30000);
});

redpajama_set_name: RedPajamaGithub


text:
package es.unizar.sened.query;

import org.apache.jena.query.Query;
import org.apache.jena.query.QueryExecution;
import org.apache.jena.query.QueryExecutionFactory;
import org.apache.jena.query.QueryFactory;
import org.apache.jena.query.ResultSet;
import org.apache.jena.sparql.resultset.ResultSetException;

import es.unizar.sened.utils.Log;

/**
 * @author gesteban@unizar.es
 */
public class JQuery {

	public static final String TAG = JQuery.class.getSimpleName();

	private Query query;
	private QueryExecution qexec;

	protected JQuery(String queryString, JQueryFactoryConfig config) {
		for (String key : config.getDatasetMap().keySet()) {
			queryString = queryString.replace(key, config.getDatasetMap().get(key));
		}
		this.query = QueryFactory.create(queryString);
		this.qexec = QueryExecutionFactory.sparqlService(config.getEndpoint(), query);
	}

	@Override
	public String toString() {
		return query.toString();
	}

	public JResult doQuery() throws ResultSetException {
		Log.i(TAG, "<doQuery> Realizando consulta a DBPedia...");
		Log.d(TAG, "\n" + this.toString());
		ResultSet resultSet = qexec.execSelect();
		JResult rs = new JResult(resultSet);
		qexec.close();
		return rs;
	}
}


text:
require 'fortitude/doctypes'
require 'fortitude/doctypes/html4'
require 'fortitude/doctypes/html4_tags_frameset'
require 'fortitude/doctypes/html4_transitional'

module Fortitude
  module Doctypes
    class Html4Frameset < Html4Transitional
      def initialize
        super(:html4_frameset, 'HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd"')
      end

      class << self
        def delegate_tag_stores
          [ Fortitude::Doctypes::Html4TagsFrameset ]
        end
      end
    end
  end
end


text:
package com.lbc.nlp_algorithm.prepocess.measure.infoGain;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.Date;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.google.common.collect.Maps;
import com.google.common.collect.Sets;
import com.lbc.nlp_algorithm.prepocess.api.api.Context;
import com.lbc.nlp_algorithm.prepocess.api.api.FeatureTermSelector;
import com.lbc.nlp_algorithm.prepocess.api.api.Term;
import com.lbc.nlp_algorithm.prepocess.api.api.TermFeatureable;
import com.lbc.nlp_algorithm.prepocess.api.api.constants.ConfigKeys;
import com.lbc.nlp_algorithm.prepocess.api.common.FeaturedTerm;
import com.lbc.nlp_algorithm.prepocess.core.utils.FileUtils;
import com.lbc.nlp_algorithm.prepocess.measure.utils.SortUtils;
import com.lbc.nlp_algorithm.prepocess.measure.utils.SortUtils.Result;
import com.lbc.nlp_modules.common.thread.ThreadPoolUtils;

public class InfoGainTermSelector implements FeatureTermSelector {
	private static final Log LOG = LogFactory.getLog(InfoGainTermSelector.class);
	private Context context;

	// Map<word, term>
	private final Map<String, TermFeatureable> TermsWithMeasures = Maps.newConcurrentMap();
	// Map<label, ChiCalculator>
	private final Map<String, InfoGainCalculator> calculators = Maps.newHashMap();

	private ExecutorService executorService;
	private CountDownLatch latch;
	private float keptTermsPercent;

	public InfoGainTermSelector() {
		super();
	}

	@Override
	public Set<TermFeatureable> select(Context context) {
		this.context = context;
		keptTermsPercent = context.getConfiguration().getFloat(ConfigKeys.FEATURE_EACH_LABEL_KEPT_TERM_PERCENT, 0.30F);

		int totalWords = context.getVectorMetadata().getInvertedTable().size();
		LOG.info("Initialize latch: totalWords=" + totalWords);
		latch = new CountDownLatch(totalWords);
		executorService = ThreadPoolUtils.getExecutor();
		double entropy = calHC(context);
		Result sortedResult = null;
		try {
			for(Entry<String, Map<String, Set<String>>> iter : context.getVectorMetadata().getInvertedTable().entrySet()) {
				String term = iter.getKey();
				calculators.put(term, new InfoGainCalculator(iter, TermsWithMeasures, entropy));
				executorService.execute(calculators.get(term));
			}
		} catch(Exception e){
			LOG.error(e.getMessage());
		} finally {
			try {
				latch.await();
			} catch (InterruptedException e) {
				LOG.error("interruptedException: " + e.getMessage());
			} catch (Exception e) {
				LOG.error("executor Exception: " + e.getMessage());
			}
			LOG.info("Shutdown executor service: " + executorService);
		}

		Date start = new Date();
		int topN = (int) (TermsWithMeasures.size() * keptTermsPercent);
		LOG.info("Terms selection for sort: topN=" + topN);
		sortedResult = sort(TermsWithMeasures, topN);
		Date finish = new Date();
		LOG.info("infoGain terms sorted: " + ", timeTaken=" + (finish.getTime() - start.getTime()) + "(ms)");

		// wrap result
		Set<TermFeatureable> mergedTerms = Sets.newHashSet();
		LOG.info("Result: " + ", startIndex=" + sortedResult.getStartIndex() + ", endIndex=" + sortedResult.getEndIndex());
		for (int i = sortedResult.getStartIndex(); i <= sortedResult.getEndIndex(); i++) {
			Entry<String, TermFeatureable> termEntry = sortedResult.get(i);
			mergedTerms.add(termEntry.getValue());
		}
		return mergedTerms;
	}

	private Result sort(Map<String, TermFeatureable> terms, int topN) {
		SortUtils sorter = new SortUtils(terms, true, Math.min(topN, terms.size()));
		Result result = sorter.heapSort();
		return result;
	}

	private final class InfoGainCalculator extends Thread {

		private final Entry<String, Map<String, Set<String>>> word2doc;
		private final Map<String, TermFeatureable> terms;
		private Result sortedResult;
		private final double entropy;

		public InfoGainCalculator(Entry<String, Map<String, Set<String>>> word2doc,
				Map<String, TermFeatureable> terms, double entropy) {
			this.word2doc = word2doc;
			this.terms = terms;
			this.entropy = entropy;
		}

		@Override
		public void run() {
			try {
				processSingleTermData();
			} catch(Exception e) {
				LOG.error(e.getMessage());
			} finally {
				latch.countDown();
				LOG.info("剩下" + latch.getCount() + "个任务需要执行。");
			}
		}

		private void processSingleTermData() {
			String word = word2doc.getKey();
			Map<String, Set<String>> labelledDocs = word2doc.getValue();

			double tempAB = 0d;
			double tempCD = 0d;

			// all doc containing the word
			int totalDocContainingWord = 0;
			for (Entry<String, Set<String>> label : labelledDocs.entrySet()) {
				totalDocContainingWord += label.getValue().size();
			}
			double docProbilityContainingWord = (double)totalDocContainingWord / context.getVectorMetadata().totalDocCount();

			int totalDocsNotContainingWord = context.getVectorMetadata().totalDocCount() - totalDocContainingWord;
			for(String label : context.getVectorMetadata().labels()) {
				// A: doc count containing the word in this label
				int docCountContainingWordInLabel = 0;
				if(labelledDocs.get(label) != null) {
					docCountContainingWordInLabel = labelledDocs.get(label).size();
				}

				// B: doc count containing the word not in this label
				int docCountContainingWordNotInLabel = totalDocContainingWord - docCountContainingWordInLabel;

				// C: doc count not containing the word in this label
				int docCountNotContainingWordInLabel = 0;
				int totalDocsInLabel = computeDocCountInLabel(label);
				if (0 != totalDocsInLabel) {
					docCountNotContainingWordInLabel = totalDocsInLabel - docCountContainingWordInLabel;
				}

				// D: doc count not containing the word not in this label
				int docCountNotContainingWordNotInLabel = totalDocsNotContainingWord - docCountNotContainingWordInLabel;

				// compute info gain value
				int A = docCountContainingWordInLabel;
				int B = docCountContainingWordNotInLabel;
				int C = docCountNotContainingWordInLabel;
				int D = docCountNotContainingWordNotInLabel;

				double tempA = (double)A / (A + B);
				double tempB = (double)B / (A + B);
				double tempC = (double)C / (C + D);
				double tempD = (double)D / (C + D);

				tempAB += getLog(tempA) + getLog(tempB);
				tempCD += getLog(tempC) + getLog(tempD);
			}
			double infoGain = entropy + docProbilityContainingWord * tempAB + (1 - docProbilityContainingWord) * tempCD;

			TermFeatureable term = new FeaturedTerm(word);
			term.setMeasureValue(infoGain);
			terms.put(word, term);
		}

		private double getLog(double value) {
			if (0 != value) {
				return value * Math.log(value);
			} else {
				return 0;
			}
		}

		private int computeDocCountInLabel(String label) {
			Map<String, Map<String, Map<String, Term>>> termTable = context.getVectorMetadata().getTermTable();
			if (MapUtils.isNotEmpty(termTable)) {
				Map<String, Map<String, Term>> docs = termTable.get(label);
				if (MapUtils.isNotEmpty(docs)) {
					return docs.size();
				}
			}
			return 0;
		}

	}

	@Override
	public Result getSortedResult(String label) {
		return calculators.get(label).sortedResult;
	}

	@Override
	public void load(Context context) {
		BufferedReader reader = null;
		FileInputStream fis = null;
		try {
			fis = new FileInputStream(context.getFDMetadata().getFeatureTermVectorFile());
			reader = new BufferedReader(new InputStreamReader(fis, context.getCharset()));
			String line = null;
			Set<TermFeatureable> terms = Sets.newHashSet();
			while((line = reader.readLine()) != null) {
				line = line.trim();
				if(!line.isEmpty()) {
					String[] aWord = line.split("\\s+");
					if(aWord.length == 2) {
						String word = aWord[0];
						int wordId = Integer.parseInt(aWord[1]);
						FeaturedTerm term = new FeaturedTerm(word);
						term.setId(wordId);
						terms.add(term);
						LOG.info("Load infoGain term: word=" + word + ", wordId=" + wordId);
					}
				}
			}
			context.getVectorMetadata().setFeaturedTerms(terms);
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			FileUtils.closeQuietly(fis, reader);
		}
	}

	/**
	 * 计算信息熵
	 * @param docCountContainingWordInLabel
	 * @param totalDocCount
	 * @return
	 */
	private double calHC(Context context) {
		double hc = 0d;
		int totalDocCount = context.getVectorMetadata().totalDocCount();
		for (String label : context.getVectorMetadata().labels()) {
			double p = (double) context.getVectorMetadata().getLabelTotalDocCount(label) / totalDocCount;
			hc += p * Math.log(p);
		}

		return -hc;
	}

}


text:
/*
	MIT License http://www.opensource.org/licenses/mit-license.php
	Author Tobias Koppers @sokra
*/

"use strict";

/** @typedef {import("./Resolver")} Resolver */
/** @typedef {import("./Resolver").ResolveRequest} ResolveRequest */
/** @typedef {import("./Resolver").ResolveStepHook} ResolveStepHook */

module.exports = class ConditionalPlugin {
	/**
	 * @param {string | ResolveStepHook} source source
	 * @param {Partial<ResolveRequest>} test compare object
	 * @param {string | null} message log message
	 * @param {boolean} allowAlternatives when false, do not continue with the current step when "test" matches
	 * @param {string | ResolveStepHook} target target
	 */
	constructor(source, test, message, allowAlternatives, target) {
		this.source = source;
		this.test = test;
		this.message = message;
		this.allowAlternatives = allowAlternatives;
		this.target = target;
	}

	/**
	 * @param {Resolver} resolver the resolver
	 * @returns {void}
	 */
	apply(resolver) {
		const target = resolver.ensureHook(this.target);
		const { test, message, allowAlternatives } = this;
		const keys = Object.keys(test);
		resolver
			.getHook(this.source)
			.tapAsync("ConditionalPlugin", (request, resolveContext, callback) => {
				for (const prop of keys) {
					if (request[prop] !== test[prop]) return callback();
				}
				resolver.doResolve(
					target,
					request,
					message,
					resolveContext,
					allowAlternatives
						? callback
						: (err, result) => {
								if (err) return callback(err);

								// Don't allow other alternatives
								if (result === undefined) return callback(null, null);
								callback(null, result);
						  }
				);
			});
	}
};


text:
package server

import (
	"context"
	"testing"

	"github.com/golang/protobuf/proto"
	pb "github.com/googleapis/gapic-showcase/server/genproto"
	"google.golang.org/grpc"
)

func TestSessionProto(t *testing.T) {
	s := NewSession("name", pb.Session_V1_0, ShowcaseObserverRegistry())
	if s.GetName() != "name" {
		t.Errorf("Session.GetName() = %v, want %v", s.GetName(), "name")

	}
	if s.GetVersion() != pb.Session_V1_0 {
		t.Errorf("Session.GetVersion() = %v, want %v", s.GetVersion(), pb.Session_V1_0)
	}
	want := &pb.Session{Name: "name", Version: pb.Session_V1_0}
	got := SessionProto(s)
	if !proto.Equal(got, want) {
		t.Errorf("SessionProto() = %v, want %v", got, want)
	}
}

type mockTest struct {
	name        string
	expectation pb.Test_ExpectationLevel
	blueprints  []*pb.Test_Blueprint

	iType       pb.Issue_Type
	severity    pb.Issue_Severity
	description string

	Test
}

func (t *mockTest) GetName() string {
	return t.name
}

func (t *mockTest) GetIssue() *pb.Issue {
	if t.iType == 0 {
		return nil
	}
	return &pb.Issue{
		Type:        t.iType,
		Severity:    t.severity,
		Description: t.description,
	}
}

func (t *mockTest) GetExpectationLevel() pb.Test_ExpectationLevel {
	return t.expectation
}

func (t *mockTest) GetDescription() string {
	return t.description
}

func (t *mockTest) GetBlueprints() []*pb.Test_Blueprint {
	return t.blueprints
}

// Implements UnaryObserver
func (t *mockTest) ObserveUnary(
	ctx context.Context,
	req interface{},
	resp interface{},
	info *grpc.UnaryServerInfo,
	err error) {
}

// Implements StreamRequestObserver
func (t *mockTest) ObserveStreamRequest(
	ctx context.Context,
	req interface{},
	info *grpc.StreamServerInfo,
	err error) {
}

// Implements StreamResponseObserver
func (t *mockTest) ObserveStreamResponse(
	ctx context.Context,
	resp interface{},
	info *grpc.StreamServerInfo,
	err error) {
}

func Test_sessionImpl_TestLifeCycle(t *testing.T) {
	failed := &mockTest{
		name:        "failedTest",
		iType:       pb.Issue_INCORRECT_CONFIRMATION,
		severity:    pb.Issue_ERROR,
		expectation: pb.Test_REQUIRED,
		description: "This test failed.",
	}
	pending := &mockTest{
		name:        "pendingTest",
		iType:       pb.Issue_PENDING,
		severity:    pb.Issue_ERROR,
		expectation: pb.Test_RECOMMENDED,
		description: "This test failed.",
	}
	skipped := &mockTest{
		name:        "skippedTest",
		expectation: pb.Test_OPTIONAL,
		iType:       pb.Issue_SKIPPED,
		severity:    pb.Issue_ERROR,
		description: "This test failed.",
	}
	passed := &mockTest{
		name:        "passedTest",
		expectation: pb.Test_REQUIRED,
		description: "This test passed.",
	}
	// Register tests and ensure they are all listed.
	session := &sessionImpl{
		observerRegistry: ShowcaseObserverRegistry(),
		token:            &tokenGenerator{salt: ""},
		keys:             map[string]int{},
		tests:            []testEntry{},
	}
	session.RegisterTests([]Test{failed, pending, skipped, passed})
	wantList := &pb.ListTestsResponse{
		Tests: []*pb.Test{
			TestProto(failed),
			TestProto(pending),
			TestProto(skipped),
			TestProto(passed),
		},
	}

	got, _ := session.ListTests(&pb.ListTestsRequest{})
	if !proto.Equal(got, wantList) {
		t.Errorf("sessionImpl.ListTests() = %v, want %v", got, wantList)
	}

	// Delete tests
	if _, err := session.DeleteTest("skippedTest"); err != nil {
		t.Errorf("sessionImpl.DeleteTest() = %v", err)
	}
	if _, err := session.DeleteTest("invalidName"); err == nil {
		t.Error("sessionImpl.DeleteTest() for invalid name wanted err got nil")
	}

	// Ensure list of test does not include the deleted tests.
	wantList = &pb.ListTestsResponse{
		Tests: []*pb.Test{
			TestProto(failed),
			TestProto(pending),
			TestProto(passed),
		},
	}
	got, _ = session.ListTests(&pb.ListTestsRequest{})
	if !proto.Equal(got, wantList) {
		t.Errorf("sessionImpl.ListTests() = %v, want %v", got, wantList)
	}

	// Test pagination
	wantList = &pb.ListTestsResponse{
		Tests: []*pb.Test{
			TestProto(failed),
			TestProto(pending),
		},
		NextPageToken: "Mg==", // Deterministic since we hard coded the page token salt.
	}
	got, _ = session.ListTests(&pb.ListTestsRequest{PageSize: 2})
	if !proto.Equal(got, wantList) {
		t.Errorf("sessionImpl.ListTests() = %v, want %v", got, wantList)
	}

	// Invalid page token
	if _, err := session.ListTests(&pb.ListTestsRequest{PageToken: "invalid"}); err == nil {
		t.Error("sessionImpl.ListTests() with invalid page token got nil.")
	}

}

func Test_sessionImpl_GetReport(t *testing.T) {
	failed := &mockTest{
		name:        "failedTest",
		iType:       pb.Issue_INCORRECT_CONFIRMATION,
		severity:    pb.Issue_ERROR,
		description: "This test failed.",
	}
	pending := &mockTest{
		name:        "pendingTest",
		iType:       pb.Issue_PENDING,
		severity:    pb.Issue_ERROR,
		description: "This test failed.",
	}
	skipped := &mockTest{
		name:        "skippedTest",
		iType:       pb.Issue_SKIPPED,
		severity:    pb.Issue_ERROR,
		description: "This test failed.",
	}
	passed := &mockTest{name: "passedTest"}
	tests := []struct {
		name    string
		entries []testEntry
		want    *pb.ReportSessionResponse
	}{
		{
			"Passes if all tests passed",
			[]testEntry{
				testEntry{test: &mockTest{name: "passed 1"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 2"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 3"}, deleted: false},
			},
			&pb.ReportSessionResponse{
				Result: pb.ReportSessionResponse_PASSED,
				TestRuns: []*pb.TestRun{
					&pb.TestRun{Test: "passed 1"},
					&pb.TestRun{Test: "passed 2"},
					&pb.TestRun{Test: "passed 3"},
				},
			},
		},
		{
			"Marks as incomplete if there are pending and skipped tests.",
			[]testEntry{
				testEntry{test: &mockTest{name: "passed 1"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 2"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 3"}, deleted: false},
				testEntry{test: pending, deleted: false},
				testEntry{test: skipped, deleted: false},
			},
			&pb.ReportSessionResponse{
				Result: pb.ReportSessionResponse_INCOMPLETE,
				TestRuns: []*pb.TestRun{
					&pb.TestRun{Test: "passed 1"},
					&pb.TestRun{Test: "passed 2"},
					&pb.TestRun{Test: "passed 3"},
					&pb.TestRun{Test: pending.GetName(), Issue: pending.GetIssue()},
					&pb.TestRun{Test: skipped.GetName(), Issue: skipped.GetIssue()},
				},
			},
		},
		{
			"Fails if one tests failed",
			[]testEntry{
				testEntry{test: &mockTest{name: "passed 1"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 2"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 3"}, deleted: false},
				testEntry{test: pending, deleted: false},
				testEntry{test: skipped, deleted: false},
				testEntry{test: failed, deleted: false},
			},
			&pb.ReportSessionResponse{
				Result: pb.ReportSessionResponse_FAILED,
				TestRuns: []*pb.TestRun{
					&pb.TestRun{Test: "passed 1"},
					&pb.TestRun{Test: "passed 2"},
					&pb.TestRun{Test: "passed 3"},
					&pb.TestRun{Test: pending.GetName(), Issue: pending.GetIssue()},
					&pb.TestRun{Test: skipped.GetName(), Issue: skipped.GetIssue()},
					&pb.TestRun{Test: failed.GetName(), Issue: failed.GetIssue()},
				},
			},
		},
		{
			"Marks as incomplete if there are pending and skipped tests.",
			[]testEntry{
				testEntry{test: &mockTest{name: "passed 1"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 2"}, deleted: false},
				testEntry{test: &mockTest{name: "passed 3"}, deleted: false},
				testEntry{test: pending, deleted: false},
				testEntry{test: skipped, deleted: false},
			},
			&pb.ReportSessionResponse{
				Result: pb.ReportSessionResponse_INCOMPLETE,
				TestRuns: []*pb.TestRun{
					&pb.TestRun{Test: "passed 1"},
					&pb.TestRun{Test: "passed 2"},
					&pb.TestRun{Test: "passed 3"},
					&pb.TestRun{Test: pending.GetName(), Issue: pending.GetIssue()},
					&pb.TestRun{Test: skipped.GetName(), Issue: skipped.GetIssue()},
				},
			},
		},
		{
			"Skips Deleted Tests",
			[]testEntry{
				testEntry{test: passed, deleted: false},
				testEntry{test: failed, deleted: true},
			},
			&pb.ReportSessionResponse{
				Result:   pb.ReportSessionResponse_PASSED,
				TestRuns: []*pb.TestRun{TestRunProto(passed)},
			},
		},
	}
	for _, tt := range tests {
		t.Run(tt.name, func(t *testing.T) {
			s := &sessionImpl{
				tests: tt.entries,
			}
			if got := s.GetReport(); !proto.Equal(got, tt.want) {
				t.Errorf("sessionImpl.GetReport() = %v, want %v", got, tt.want)
			}
		})
	}
}


text:
				<input type="radio" name="radio_bgtype" data-bgtype="image" id="radio_back_image" <?php if($bgType == "image") echo 'checked="checked"'?> >
				Image BG
				<a href="javascript:void(0)" id="button_change_image" class="button-primary margin_right10 <?php if($bgType != "image") echo "button-disabled" ?>" style="margin-bottom:5px">Change Image

				<input type="radio" name="radio_bgtype" data-bgtype="trans" id="radio_back_trans" <?php if($bgType == "trans") echo 'checked="checked"'?>>
				Trapsparent BG

				<input type="radio" name="radio_bgtype" data-bgtype="solid" id="radio_back_solid" <?php if($bgType == "solid") echo 'checked="solid"'?>>
				Solid BG
				<input type="text" name="bg_color" id="slide_bg_color" <?php echo $bgSolidPickerProps?> value="<?php echo $slideBGColor?>">

				Preview Slide

				Add Layer
				Add Layer: Image
				Add Layer: Video

				Delete Layer
				Delete All Layers

				Duplicate Layer

		<div id="divLayers" class="<?php echo $divLayersClass?>" style="<?php echo $style?>">

0 ms

<?php echo $slideDelay?> ms

				<form name="form_layers" id="form_layers">

								Layer Params

									<?php
										$s = $settingsLayerOutput;
										$s->drawSettingsByNames("layer_caption,layer_text,layer_image_link,layer_link_open_in,button_edit_video,button_change_image_source");
									?>

									<?php
								    	$s->drawSettingsByNames("layer_left,layer_top");
								    ?>

									<?php
								    	$s->drawSettingsByNames("layer_video_autoplay,layer_animation,layer_easing,layer_speed,layer_hidden,layer_slide_link");
								    ?>

										End Transition (optional)

										Show End Params

									<?php
								    	$s->drawSettingsByNames("layer_endtime,layer_endspeed,layer_endanimation,layer_endeasing","hidden");
								    ?>

				</form>

						Layers Sorting

By Time

By Depth

			<textarea id="textarea_edit" rows="20" cols="100"></textarea>

			<?php foreach($arrButtonClasses as $class=>$text): ?>

						<a href="javascript:UniteLayersRev.insertButton('<?php echo $class?>','<?php echo $text?>')" class="tp-button <?php echo $class?> small"><?php echo $text?>

			<?php endforeach;?>


text:
package jp.co.codeya.salesforcecli.command;

import java.util.List;

import jp.co.codeya.salesforcecli.SalesforceCommand;
import jp.co.codeya.salesforcecli.SalesforceConfigurations;
import jp.co.codeya.salesforcecli.util.ConsoleUtil;
import jp.co.codeya.cli.CommandException;
import jp.co.codeya.cli.IllegalParameterException;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import jp.co.codeya.salesforcecli.service.util.SalesforceServiceException;

/**
 * SF アカウントのログインパスワードを変更する {@link SalesforceCommand}。
 *
 * @author eiichiro.takahashi
 */
public class Passwd
        extends
        SalesforceCommand<SalesforceConfigurations, PasswdParameters, PasswdLogic> {

    /** Logger。 */
    private static final Log LOG = LogFactory.getLog(Passwd.class);

    /**
     * {@link Passwd} を生成する。
     */
    public Passwd() {
        super(new SalesforceConfigurations(), new PasswdParameters(),
                new PasswdLogic());
    }

    /**
     * {@link Passwd} を生成する。
     *
     * @param configurations {@link SalesforceConfigurations}。null 不可。
     * @param parameters {@link PasswdParameters}。null 不可。
     * @param logic {@link PasswdLogic}。null 不可。
     */
    public Passwd(final SalesforceConfigurations configurations,
            final PasswdParameters parameters, final PasswdLogic logic) {
        super(configurations, parameters, logic);
    }

    /**
     * エントリポイント。
     *
     * @param args 起動時引数。null 不可。
     */
    public static void main(final String[] args) {
        Passwd me = new Passwd();
        me.bootstrap(args);
    }

    @Override
    protected void doExecute() throws CommandException,
            SalesforceServiceException {
        if (LOG.isDebugEnabled()) {
            LOG.debug("in Passwd#doExecute()");
        }

        // パラメータを取得。
        PasswdParameters parameters = this.getParameters();
        if (parameters == null) {
            throw new IllegalStateException();
        }

        // コンソール出力の準備
        String printEncoding = parameters.getPrintEncoding();
        ConsoleUtil.setEncoding(printEncoding);

        // 無名パラメータからユーザ名を取得。
        List<String> anonymousParameters = parameters.getAnonymousParameter();
        if (anonymousParameters == null || anonymousParameters.size() != 1) {
            throw new IllegalParameterException("User name must be set.");
        }
        String userName = anonymousParameters.get(0);

        // パフォーマンス計測開始。
        long startTimeMillis = System.currentTimeMillis();

        // 処理実行。
        this.getSalesforceLogic().passwd(this.getSalesforceService(), userName);

        // パフォーマンス計測結果出力
        long endTimeMillis = System.currentTimeMillis();
        this.printPerformance(startTimeMillis, endTimeMillis);

        if (LOG.isDebugEnabled()) {
            LOG.debug("out Passwd#doExecute()");
        }
    }
}


text:
<mods xmlns="http://www.loc.gov/mods/v3" xmlns:exslt="http://exslt.org/common" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xlink="http://www.w3.org/1999/xlink" xsi:schemaLocation="http://www.loc.gov/mods/v3 http://www.loc.gov/standards/mods/v3/mods-3-3.xsd" version="3.3" ID="P0b002ee18190cd5c">
<name type="corporate">
 <namePart>United States Government Printing Office</namePart>
 <role>
  <roleTerm type="text" authority="marcrelator">printer</roleTerm>
  <roleTerm type="code" authority="marcrelator">prt</roleTerm>
</role>
 <role>
  <roleTerm type="text" authority="marcrelator">distributor</roleTerm>
  <roleTerm type="code" authority="marcrelator">dst</roleTerm>
</role>
</name>
<name type="corporate">
 <namePart>United States</namePart>
 <namePart>United States District Court Eastern District of Michigan</namePart>
 <role>
  <roleTerm type="text" authority="marcrelator">author</roleTerm>
  <roleTerm type="code" authority="marcrelator">aut</roleTerm>
</role>
 <description>Government Organization</description>
</name>
<typeOfResource>text</typeOfResource>
<genre authority="marcgt">government publication</genre>
<language>
 <languageTerm authority="iso639-2b" type="code">eng</languageTerm>
</language>
<extension>
 <collectionCode>USCOURTS</collectionCode>
 <category>Judicial Publications</category>
 <branch>judicial</branch>
 <dateIngested>2012-01-18</dateIngested>
</extension>
<originInfo>
 <publisher>Administrative Office of the United States Courts</publisher>
 <dateIssued encoding="w3cdtf">2007-01-24</dateIssued>
 <issuance>monographic</issuance>
</originInfo>
<physicalDescription>
 <note type="source content type">deposited</note>
 <digitalOrigin>born digital</digitalOrigin>
</physicalDescription>
<classification authority="sudocs">JU 4.15</classification>
<identifier type="uri">http://www.gpo.gov/fdsys/pkg/USCOURTS-mied-2_05-cv-72444</identifier>
<identifier type="local">P0b002ee18190cd5c</identifier>
<recordInfo>
 <recordContentSource authority="marcorg">DGPO</recordContentSource>
 <recordCreationDate encoding="w3cdtf">2012-01-18</recordCreationDate>
 <recordChangeDate encoding="w3cdtf">2012-01-18</recordChangeDate>
 <recordIdentifier source="DGPO">USCOURTS-mied-2_05-cv-72444</recordIdentifier>
 <recordOrigin>machine generated</recordOrigin>
 <languageOfCataloging>
  <languageTerm authority="iso639-2b" type="code">eng</languageTerm>
</languageOfCataloging>
</recordInfo>
<accessCondition type="GPO scope determination">fdlp</accessCondition>
<extension>
 <docClass>USCOURTS</docClass>
 <accessId>USCOURTS-mied-2_05-cv-72444</accessId>
 <courtType>District</courtType>
 <courtCode>mied</courtCode>
 <courtCircuit>6th</courtCircuit>
 <courtState>Michigan</courtState>
 <courtSortOrder>2251</courtSortOrder>
 <caseNumber>2:05-cv-72444</caseNumber>
 <caseOffice>Detroit</caseOffice>
 <caseType>civil</caseType>
 <natureSuitCode>791</natureSuitCode>
 <natureSuit>Employee Retirement Income Security Act (ERISA)</natureSuit>
 <party fullName="Aetna Insurance Agency, Incorporated" lastName="Aetna Insurance Agency, Incorporated" role="Defendant"></party>
 <party fullName="ING Insurance Services, Incorporated" lastName="ING Insurance Services, Incorporated" role="Defendant"></party>
 <party firstName="Donnell" fullName="Donnell D. Shreve" lastName="Shreve" middleName="D." role="Plaintiff"></party>
</extension>
<titleInfo>
 <title>Shreve v. Aetna Insurance Agency, Incorporated</title>
 <partNumber>2:05-cv-72444</partNumber>
</titleInfo>
<location>
 <url access="object in context" displayLabel="Content Detail">http://www.gpo.gov/fdsys/pkg/USCOURTS-mied-2_05-cv-72444/content-detail.html</url>
</location>
<classification authority="sudocs">JU 4.15</classification>
<identifier type="preferred citation">2:05-cv-72444;05-72444</identifier>
<name type="corporate">
 <namePart>United States District Court Eastern District of Michigan</namePart>
 <namePart>6th Circuit</namePart>
 <namePart>Detroit</namePart>
 <affiliation>U.S. Courts</affiliation>
 <role>
  <roleTerm authority="marcrelator" type="text">author</roleTerm>
  <roleTerm authority="marcrelator" type="code">aut</roleTerm>
</role>
</name>
<name type="personal">
 <displayForm>Aetna Insurance Agency, Incorporated</displayForm>
 <namePart type="family">Aetna Insurance Agency, Incorporated</namePart>
 <namePart type="given"></namePart>
 <namePart type="termsOfAddress"></namePart>
 <description>Defendant</description>
</name>
<name type="personal">
 <displayForm>ING Insurance Services, Incorporated</displayForm>
 <namePart type="family">ING Insurance Services, Incorporated</namePart>
 <namePart type="given"></namePart>
 <namePart type="termsOfAddress"></namePart>
 <description>Defendant</description>
</name>
<name type="personal">
 <displayForm>Donnell D. Shreve</displayForm>
 <namePart type="family">Shreve</namePart>
 <namePart type="given">Donnell</namePart>
 <namePart type="termsOfAddress"></namePart>
 <description>Plaintiff</description>
</name>
<extension>
 <docClass>USCOURTS</docClass>
 <accessId>USCOURTS-mied-2_05-cv-72444</accessId>
 <courtType>District</courtType>
 <courtCode>mied</courtCode>
 <courtCircuit>6th</courtCircuit>
 <courtState>Michigan</courtState>
 <courtSortOrder>2251</courtSortOrder>
 <caseNumber>2:05-cv-72444</caseNumber>
 <caseOffice>Detroit</caseOffice>
 <caseType>civil</caseType>
 <natureSuitCode>791</natureSuitCode>
 <natureSuit>Employee Retirement Income Security Act (ERISA)</natureSuit>
 <party fullName="Aetna Insurance Agency, Incorporated" lastName="Aetna Insurance Agency, Incorporated" role="Defendant"></party>
 <party fullName="ING Insurance Services, Incorporated" lastName="ING Insurance Services, Incorporated" role="Defendant"></party>
 <party firstName="Donnell" fullName="Donnell D. Shreve" lastName="Shreve" middleName="D." role="Plaintiff"></party>
 <state>Michigan</state>
</extension>
<relatedItem type="constituent" ID="id-USCOURTS-mied-2_05-cv-72444-0" xlink:href="http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-0/mods.xml">
 <titleInfo>
  <title>Shreve v. Aetna Insurance Agency, Incorporated</title>
  <subTitle>OPINION AND ORDER ORDER denying 14 Motion for Judgment - Signed by Honorable Paul D Borman. (DGoo, ) Modified on 7/12/2006 (DGoo, ).</subTitle>
  <partNumber>0</partNumber>
</titleInfo>
 <originInfo>
  <dateIssued>2006-07-12</dateIssued>
</originInfo>
 <relatedItem xlink:href="http://www.gpo.gov/fdsys/pkg/pdf/USCOURTS-mied-2_05-cv-72444-0.pdf" type="otherFormat">
  <identifier type="FDsys Unique ID">D09002ee181995cd8</identifier>
</relatedItem>
 <identifier type="uri">http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-0</identifier>
 <identifier type="former granule identifier">mied-2_05-cv-72444_0.pdf</identifier>
 <location>
  <url access="object in context" displayLabel="Content Detail">http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-0/content-detail.html</url>
  <url access="raw object" displayLabel="PDF rendition">http://www.gpo.gov/fdsys/pkg/USCOURTS-mied-2_05-cv-72444/pdf/USCOURTS-mied-2_05-cv-72444-0.pdf</url>
</location>
 <extension>
  <searchTitle>USCOURTS 2:05-cv-72444; Shreve v. Aetna Insurance Agency, Incorporated; </searchTitle>
  <courtName>United States District Court Eastern District of Michigan</courtName>
  <state>Michigan</state>
  <accessId>USCOURTS-mied-2_05-cv-72444-0</accessId>
  <sequenceNumber>0</sequenceNumber>
  <dateIssued>2006-07-12</dateIssued>
  <docketText>OPINION AND ORDER ORDER denying 14 Motion for Judgment - Signed by Honorable Paul D Borman. (DGoo, ) Modified on 7/12/2006 (DGoo, ).</docketText>
</extension>
</relatedItem>
<relatedItem type="constituent" ID="id-USCOURTS-mied-2_05-cv-72444-1" xlink:href="http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-1/mods.xml">
 <titleInfo>
  <title>Shreve v. Aetna Insurance Agency, Incorporated</title>
  <subTitle>ORDER granting 22 Motion for Judgment (2) DENYING PLAINTIFF'S REQUEST FOR ATTORNEY'S FEES;(3) GRANTING PLAINTIFF'S REQUEST FOR PRE-JUDGMENT INTEREST- Signed by Honorable Paul D Borman. (DGoo, )</subTitle>
  <partNumber>1</partNumber>
</titleInfo>
 <originInfo>
  <dateIssued>2007-01-24</dateIssued>
</originInfo>
 <relatedItem xlink:href="http://www.gpo.gov/fdsys/pkg/pdf/USCOURTS-mied-2_05-cv-72444-1.pdf" type="otherFormat">
  <identifier type="FDsys Unique ID">D09002ee181996188</identifier>
</relatedItem>
 <identifier type="uri">http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-1</identifier>
 <identifier type="former granule identifier">mied-2_05-cv-72444_1.pdf</identifier>
 <location>
  <url access="object in context" displayLabel="Content Detail">http://www.gpo.gov/fdsys/granule/USCOURTS-mied-2_05-cv-72444/USCOURTS-mied-2_05-cv-72444-1/content-detail.html</url>
  <url access="raw object" displayLabel="PDF rendition">http://www.gpo.gov/fdsys/pkg/USCOURTS-mied-2_05-cv-72444/pdf/USCOURTS-mied-2_05-cv-72444-1.pdf</url>
</location>
 <extension>
  <searchTitle>USCOURTS 2:05-cv-72444; Shreve v. Aetna Insurance Agency, Incorporated; </searchTitle>
  <courtName>United States District Court Eastern District of Michigan</courtName>
  <state>Michigan</state>
  <accessId>USCOURTS-mied-2_05-cv-72444-1</accessId>
  <sequenceNumber>1</sequenceNumber>
  <dateIssued>2007-01-24</dateIssued>
  <docketText>ORDER granting 22 Motion for Judgment (2) DENYING PLAINTIFF'S REQUEST FOR ATTORNEY'S FEES;(3) GRANTING PLAINTIFF'S REQUEST FOR PRE-JUDGMENT INTEREST- Signed by Honorable Paul D Borman. (DGoo, )</docketText>
</extension>
</relatedItem>
</mods>


text:
<!DOCTYPE html>

		<title>three.js webgl - postprocessing - depth-of-field</title>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">

			three.js - webgl realistic depth-of-field bokeh example -
			shader ported from Martins Upitis


text:
(function(){
	'use strict';
	var lazyLoad;
	angular.module('LazyLoad', [])
	.config(['$controllerProvider', '$provide', function ($controllerProvider, $provide){
		lazyLoad = {
			controller: $controllerProvider.register
			,service: $provide.service
		};
	}])
	.factory('lazy', function (){
		var $injector = angular.injector(['ng'])
		,$rootScope = $injector.get('$rootScope')
		,$q = $injector.get('$q');

		return function(moduleName){
			var mod = angular.module(moduleName);
			mod.lazyLoad = mod.lazyLoad || lazyLoad;
			return {
				load: function (arr){
					arr = arr || [];
					var deferred = $q.defer();
					require(arr, function () {
						$rootScope.$apply(function (){deferred.resolve();});
					});
					return deferred.promise;
				}
			};
		}
	});
})();


text:
package com.blazebit.blazefaces.apt.model;

public class Icon {

	private String smallIcon;
	private String largeIcon;

	public Icon() {
	}

	public Icon(String smallIcon, String largeIcon) {
		this.smallIcon = smallIcon;
		this.largeIcon = largeIcon;
	}
	public String getSmallIcon() {
		return smallIcon;
	}
	public void setSmallIcon(String smallIcon) {
		this.smallIcon = smallIcon;
	}
	public String getLargeIcon() {
		return largeIcon;
	}
	public void setLargeIcon(String largeIcon) {
		this.largeIcon = largeIcon;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result
				+ ((largeIcon == null) ? 0 : largeIcon.hashCode());
		result = prime * result
				+ ((smallIcon == null) ? 0 : smallIcon.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj) {
			return true;
		}
		if (obj == null) {
			return false;
		}
		if (!(obj instanceof Icon)) {
			return false;
		}
		Icon other = (Icon) obj;
		if (largeIcon == null) {
			if (other.largeIcon != null) {
				return false;
			}
		} else if (!largeIcon.equals(other.largeIcon)) {
			return false;
		}
		if (smallIcon == null) {
			if (other.smallIcon != null) {
				return false;
			}
		} else if (!smallIcon.equals(other.smallIcon)) {
			return false;
		}
		return true;
	}
}


text:
package org.apache.spark.sql.execution.command

import java.io.File
import java.text.SimpleDateFormat

import scala.collection.JavaConverters._
import scala.language.implicitConversions

import org.apache.spark.sql._
import org.apache.spark.sql.catalyst.TableIdentifier
import org.apache.spark.sql.catalyst.expressions.{Attribute, AttributeReference, Cast, Literal}
import org.apache.spark.sql.catalyst.plans.logical.LogicalPlan
import org.apache.spark.sql.execution.{RunnableCommand, SparkPlan}
import org.apache.spark.sql.hive.CarbonMetastore
import org.apache.spark.sql.types.TimestampType
import org.apache.spark.util.FileUtils
import org.codehaus.jackson.map.ObjectMapper

import org.apache.carbondata.common.logging.LogServiceFactory
import org.apache.carbondata.core.carbon.{CarbonDataLoadSchema, CarbonTableIdentifier}
import org.apache.carbondata.core.carbon.metadata.CarbonMetadata
import org.apache.carbondata.core.carbon.metadata.encoder.Encoding
import org.apache.carbondata.core.carbon.metadata.schema.table.{CarbonTable, TableInfo}
import org.apache.carbondata.core.carbon.metadata.schema.table.column.CarbonDimension
import org.apache.carbondata.core.carbon.path.CarbonStorePath
import org.apache.carbondata.core.constants.CarbonCommonConstants
import org.apache.carbondata.core.datastorage.store.impl.FileFactory
import org.apache.carbondata.core.util.{CarbonProperties, CarbonUtil}
import org.apache.carbondata.lcm.locks.{CarbonLockFactory, LockUsage}
import org.apache.carbondata.lcm.status.SegmentStatusManager
import org.apache.carbondata.processing.constants.TableOptionConstant
import org.apache.carbondata.processing.etl.DataLoadingException
import org.apache.carbondata.processing.model.CarbonLoadModel
import org.apache.carbondata.spark.exception.MalformedCarbonCommandException
import org.apache.carbondata.spark.rdd.{CarbonDataRDDFactory, DataManagementFunc, DataManagementFunc$, DictionaryLoadModel}
import org.apache.carbondata.spark.util.{CarbonScalaUtil, GlobalDictionaryUtil}

/**
 * Command for the compaction in alter table command
 *
 * @param alterTableModel
 */
private[sql] case class AlterTableCompaction(alterTableModel: AlterTableModel) extends
  RunnableCommand {

  def run(sqlContext: SQLContext): Seq[Row] = {
    // TODO : Implement it.
    val tableName = alterTableModel.tableName
    val databaseName = getDB.getDatabaseName(alterTableModel.dbName, sqlContext)
    if (null == org.apache.carbondata.core.carbon.metadata.CarbonMetadata.getInstance
      .getCarbonTable(databaseName + "_" + tableName)) {
      logError(s"alter table failed. table not found: $databaseName.$tableName")
      sys.error(s"alter table failed. table not found: $databaseName.$tableName")
    }

    val relation =
      CarbonEnv.get.carbonMetastore
        .lookupRelation1(Option(databaseName), tableName)(sqlContext)
        .asInstanceOf[CarbonRelation]
    if (relation == null) {
      sys.error(s"Table $databaseName.$tableName does not exist")
    }
    val carbonLoadModel = new CarbonLoadModel()

    val table = relation.tableMeta.carbonTable
    carbonLoadModel.setAggTables(table.getAggregateTablesName.asScala.toArray)
    carbonLoadModel.setTableName(table.getFactTableName)
    val dataLoadSchema = new CarbonDataLoadSchema(table)
    // Need to fill dimension relation
    carbonLoadModel.setCarbonDataLoadSchema(dataLoadSchema)
    carbonLoadModel.setTableName(relation.tableMeta.carbonTableIdentifier.getTableName)
    carbonLoadModel.setDatabaseName(relation.tableMeta.carbonTableIdentifier.getDatabaseName)
    carbonLoadModel.setStorePath(relation.tableMeta.storePath)

    val kettleHomePath = CarbonScalaUtil.getKettleHome(sqlContext)

    var storeLocation = CarbonProperties.getInstance
      .getProperty(CarbonCommonConstants.STORE_LOCATION_TEMP_PATH,
        System.getProperty("java.io.tmpdir")
      )
    storeLocation = storeLocation + "/carbonstore/" + System.nanoTime()
    try {
      CarbonDataRDDFactory.alterTableForCompaction(sqlContext,
          alterTableModel,
          carbonLoadModel,
          relation.tableMeta.storePath,
          kettleHomePath,
          storeLocation
        )
    } catch {
      case e: Exception =>
        if (null != e.getMessage) {
          sys.error(s"Compaction failed. Please check logs for more info. ${ e.getMessage }")
        } else {
          sys.error("Exception in compaction. Please check logs for more info.")
        }
    }
    Seq.empty
  }
}

case class CreateTable(cm: TableModel) extends RunnableCommand {

  def run(sqlContext: SQLContext): Seq[Row] = {
    val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
    cm.databaseName = getDB.getDatabaseName(cm.databaseNameOp, sqlContext)
    val tbName = cm.tableName
    val dbName = cm.databaseName
    LOGGER.audit(s"Creating Table with Database name [$dbName] and Table name [$tbName]")

    val tableInfo: TableInfo = TableNewProcessor(cm, sqlContext)

    if (tableInfo.getFactTable.getListOfColumns.size <= 0) {
      sys.error("No Dimensions found. Table should have at least one dimesnion !")
    }

    if (sqlContext.tableNames(dbName).exists(_.equalsIgnoreCase(tbName))) {
      if (!cm.ifNotExistsSet) {
        LOGGER.audit(
          s"Table creation with Database name [$dbName] and Table name [$tbName] failed. " +
          s"Table [$tbName] already exists under database [$dbName]")
        sys.error(s"Table [$tbName] already exists under database [$dbName]")
      }
    } else {
      // Add Database to catalog and persist
      val catalog = CarbonEnv.get.carbonMetastore
      // Need to fill partitioner class when we support partition
      val tablePath = catalog.createTableFromThrift(tableInfo, dbName, tbName, null)(sqlContext)
      try {
        sqlContext.sql(
          s"""CREATE TABLE $dbName.$tbName USING carbondata""" +
          s""" OPTIONS (tableName "$dbName.$tbName", tablePath "$tablePath") """)
          .collect
      } catch {
        case e: Exception =>
          val identifier: TableIdentifier = TableIdentifier(tbName, Some(dbName))
          // call the drop table to delete the created table.

          CarbonEnv.get.carbonMetastore
            .dropTable(catalog.storePath, identifier)(sqlContext)

          LOGGER.audit(s"Table creation with Database name [$dbName] " +
                       s"and Table name [$tbName] failed")
          throw e
      }

      LOGGER.audit(s"Table created with Database name [$dbName] and Table name [$tbName]")
    }

    Seq.empty
  }

  def setV(ref: Any, name: String, value: Any): Unit = {
    ref.getClass.getFields.find(_.getName == name).get
      .set(ref, value.asInstanceOf[AnyRef])
  }
}

private[sql] case class DeleteLoadsById(
    loadids: Seq[String],
    databaseNameOp: Option[String],
    tableName: String) extends RunnableCommand {

  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)

  def run(sqlContext: SQLContext): Seq[Row] = {

    val databaseName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    LOGGER.audit(s"Delete segment by Id request has been received for $databaseName.$tableName")

    // validate load ids first
    validateLoadIds
    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)

    val identifier = TableIdentifier(tableName, Option(dbName))
    val relation = CarbonEnv.get.carbonMetastore.lookupRelation1(
      identifier, None)(sqlContext).asInstanceOf[CarbonRelation]
    if (relation == null) {
      LOGGER.audit(s"Delete segment by Id is failed. Table $dbName.$tableName does not exist")
      sys.error(s"Table $dbName.$tableName does not exist")
    }

    val carbonTable = CarbonMetadata.getInstance().getCarbonTable(dbName + '_' + tableName)

    if (null == carbonTable) {
      CarbonEnv.get.carbonMetastore
        .lookupRelation1(identifier, None)(sqlContext).asInstanceOf[CarbonRelation]
    }
    val path = carbonTable.getMetaDataFilepath

    try {
      val invalidLoadIds = SegmentStatusManager.updateDeletionStatus(
        carbonTable.getAbsoluteTableIdentifier, loadids.asJava, path).asScala

      if (invalidLoadIds.isEmpty) {

        LOGGER.audit(s"Delete segment by Id is successfull for $databaseName.$tableName.")
      }
      else {
        sys.error("Delete segment by Id is failed. Invalid ID is:" +
                  s" ${ invalidLoadIds.mkString(",") }")
      }
    } catch {
      case ex: Exception =>
        sys.error(ex.getMessage)
    }

    Seq.empty

  }

  // validates load ids
  private def validateLoadIds: Unit = {
    if (loadids.isEmpty) {
      val errorMessage = "Error: Segment id(s) should not be empty."
      throw new MalformedCarbonCommandException(errorMessage)

    }
  }
}

private[sql] case class DeleteLoadsByLoadDate(
    databaseNameOp: Option[String],
    tableName: String,
    dateField: String,
    loadDate: String) extends RunnableCommand {

  val LOGGER = LogServiceFactory.getLogService("org.apache.spark.sql.tablemodel.tableSchema")

  def run(sqlContext: SQLContext): Seq[Row] = {

    LOGGER.audit("The delete segment by load date request has been received.")
    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    val identifier = TableIdentifier(tableName, Option(dbName))
    val relation = CarbonEnv.get.carbonMetastore
      .lookupRelation1(identifier, None)(sqlContext).asInstanceOf[CarbonRelation]
    if (relation == null) {
      LOGGER
        .audit(s"Delete segment by load date is failed. Table $dbName.$tableName does not " +
               s"exist")
      sys.error(s"Table $dbName.$tableName does not exist")
    }

    val timeObj = Cast(Literal(loadDate), TimestampType).eval()
    if (null == timeObj) {
      val errorMessage = "Error: Invalid load start time format " + loadDate
      throw new MalformedCarbonCommandException(errorMessage)
    }

    val carbonTable = org.apache.carbondata.core.carbon.metadata.CarbonMetadata.getInstance()
      .getCarbonTable(dbName + '_' + tableName)
    if (null == carbonTable) {
      var relation = CarbonEnv.get.carbonMetastore
        .lookupRelation1(identifier, None)(sqlContext).asInstanceOf[CarbonRelation]
    }
    val path = carbonTable.getMetaDataFilepath()

    try {
      val invalidLoadTimestamps = SegmentStatusManager.updateDeletionStatus(
        carbonTable.getAbsoluteTableIdentifier, loadDate, path,
        timeObj.asInstanceOf[java.lang.Long]).asScala
      if (invalidLoadTimestamps.isEmpty) {
        LOGGER.audit(s"Delete segment by date is successfull for $dbName.$tableName.")
      }
      else {
        sys.error("Delete segment by date is failed. No matching segment found.")
      }
    } catch {
      case ex: Exception =>
        sys.error(ex.getMessage)
    }
    Seq.empty

  }

}

object LoadTable {

  def updateTableMetadata(carbonLoadModel: CarbonLoadModel,
      sqlContext: SQLContext,
      model: DictionaryLoadModel,
      noDictDimension: Array[CarbonDimension]): Unit = {

    val carbonTablePath = CarbonStorePath.getCarbonTablePath(model.hdfsLocation,
      model.table)
    val schemaFilePath = carbonTablePath.getSchemaFilePath

    // read TableInfo
    val tableInfo = CarbonMetastore.readSchemaFileToThriftTable(schemaFilePath)

    // modify TableInfo
    val columns = tableInfo.getFact_table.getTable_columns
    for (i <- 0 until columns.size) {
      if (noDictDimension.exists(x => columns.get(i).getColumn_id.equals(x.getColumnId))) {
        columns.get(i).encoders.remove(org.apache.carbondata.format.Encoding.DICTIONARY)
      }
    }

    // write TableInfo
    CarbonMetastore.writeThriftTableToSchemaFile(schemaFilePath, tableInfo)

    // update Metadata
    val catalog = CarbonEnv.get.carbonMetastore
    catalog.updateMetadataByThriftTable(schemaFilePath, tableInfo,
      model.table.getDatabaseName, model.table.getTableName, carbonLoadModel.getStorePath)

    // update CarbonDataLoadSchema
    val carbonTable = catalog.lookupRelation1(Option(model.table.getDatabaseName),
      model.table.getTableName)(sqlContext).asInstanceOf[CarbonRelation].tableMeta.carbonTable
    carbonLoadModel.setCarbonDataLoadSchema(new CarbonDataLoadSchema(carbonTable))
  }

}

private[sql] case class LoadTableByInsert(relation: CarbonDatasourceRelation,
                                          child: LogicalPlan) extends RunnableCommand {
  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
  def run(sqlContext: SQLContext): Seq[Row] = {
    val df = new DataFrame(sqlContext, child)
    val header = relation.carbonRelation.output.map(_.name).mkString(",")
    val load = LoadTable(
      Some(relation.carbonRelation.databaseName),
      relation.carbonRelation.tableName,
      null,
      Seq(),
      scala.collection.immutable.Map(("fileheader" -> header)),
      false,
      null,
      Some(df)).run(sqlContext)
    // updating relation metadata. This is in case of auto detect high cardinality
    relation.carbonRelation.metaData =
      CarbonSparkUtil.createSparkMeta(relation.carbonRelation.tableMeta.carbonTable)
    load
  }
}
case class LoadTable(
    databaseNameOp: Option[String],
    tableName: String,
    factPathFromUser: String,
    dimFilesPath: Seq[DataLoadTableFileMapping],
    options: scala.collection.immutable.Map[String, String],
    isOverwriteExist: Boolean = false,
    var inputSqlString: String = null,
    dataFrame: Option[DataFrame] = None) extends RunnableCommand {

  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)

  def run(sqlContext: SQLContext): Seq[Row] = {
    if (dataFrame.isDefined) {
      val rdd = dataFrame.get.rdd
      if (rdd.partitions == null || rdd.partitions.length == 0) {
        LOGGER.warn("DataLoading finished. No data was loaded.")
        return Seq.empty
      }
    }

    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    if (isOverwriteExist) {
      sys.error(s"Overwrite is not supported for carbon table with $dbName.$tableName")
    }
    if (null == org.apache.carbondata.core.carbon.metadata.CarbonMetadata.getInstance
      .getCarbonTable(dbName + "_" + tableName)) {
      logError(s"Data loading failed. table not found: $dbName.$tableName")
      LOGGER.audit(s"Data loading failed. table not found: $dbName.$tableName")
      sys.error(s"Data loading failed. table not found: $dbName.$tableName")
    }

    val relation = CarbonEnv.get.carbonMetastore
      .lookupRelation1(Option(dbName), tableName)(sqlContext)
      .asInstanceOf[CarbonRelation]
    if (relation == null) {
      sys.error(s"Table $dbName.$tableName does not exist")
    }
    CarbonProperties.getInstance().addProperty("zookeeper.enable.lock", "false")
    val carbonLock = CarbonLockFactory
      .getCarbonLockObj(relation.tableMeta.carbonTable.getAbsoluteTableIdentifier
        .getCarbonTableIdentifier,
        LockUsage.METADATA_LOCK
      )
    try {
      if (carbonLock.lockWithRetries()) {
        logInfo("Successfully able to get the table metadata file lock")
      } else {
        sys.error("Table is locked for updation. Please try after some time")
      }

      val factPath = if (dataFrame.isDefined) {
        ""
      } else {
        FileUtils.getPaths(
          CarbonUtil.checkAndAppendHDFSUrl(factPathFromUser))
      }
      val carbonLoadModel = new CarbonLoadModel()
      carbonLoadModel.setTableName(relation.tableMeta.carbonTableIdentifier.getTableName)
      carbonLoadModel.setDatabaseName(relation.tableMeta.carbonTableIdentifier.getDatabaseName)
      carbonLoadModel.setStorePath(relation.tableMeta.storePath)
      if (dimFilesPath.isEmpty) {
        carbonLoadModel.setDimFolderPath(null)
      } else {
        val x = dimFilesPath.map(f => f.table + ":" + CarbonUtil.checkAndAppendHDFSUrl(f.loadPath))
        carbonLoadModel.setDimFolderPath(x.mkString(","))
      }

      val table = relation.tableMeta.carbonTable
      carbonLoadModel.setAggTables(table.getAggregateTablesName.asScala.toArray)
      carbonLoadModel.setTableName(table.getFactTableName)
      val dataLoadSchema = new CarbonDataLoadSchema(table)
      // Need to fill dimension relation
      carbonLoadModel.setCarbonDataLoadSchema(dataLoadSchema)

      val partitionLocation = relation.tableMeta.storePath + "/partition/" +
                              relation.tableMeta.carbonTableIdentifier.getDatabaseName + "/" +
                              relation.tableMeta.carbonTableIdentifier.getTableName + "/"

      val columinar = sqlContext.getConf("carbon.is.columnar.storage", "true").toBoolean

      // TODO It will be removed after kettle is removed.
      val useKettle = options.get("useKettle") match {
        case Some(value) => value.toBoolean
        case _ =>
          val useKettleLocal = System.getProperty("use.kettle")
          if (useKettleLocal == null) {
            sqlContext.sparkContext.getConf.get("use_kettle_default", "true").toBoolean
          } else {
            useKettleLocal.toBoolean
          }
      }

      val kettleHomePath = if (useKettle) CarbonScalaUtil.getKettleHome(sqlContext) else ""

      val delimiter = options.getOrElse("delimiter", ",")
      val quoteChar = options.getOrElse("quotechar", "\"")
      val fileHeader = options.getOrElse("fileheader", "")
      val escapeChar = options.getOrElse("escapechar", "\\")
      val commentchar = options.getOrElse("commentchar", "#")
      val columnDict = options.getOrElse("columndict", null)
      val serializationNullFormat = options.getOrElse("serialization_null_format", "\\N")
      val badRecordsLoggerEnable = options.getOrElse("bad_records_logger_enable", "false")
      val badRecordsLoggerRedirect = options.getOrElse("bad_records_action", "force")
      val allDictionaryPath = options.getOrElse("all_dictionary_path", "")
      val complex_delimiter_level_1 = options.getOrElse("complex_delimiter_level_1", "\\$")
      val complex_delimiter_level_2 = options.getOrElse("complex_delimiter_level_2", "\\:")
      val dateFormat = options.getOrElse("dateformat", null)
      validateDateFormat(dateFormat, table)
      val multiLine = options.getOrElse("multiline", "false").trim.toLowerCase match {
        case "true" => true
        case "false" => false
        case illegal =>
          val errorMessage = "Illegal syntax found: [" + illegal + "] .The value multiline in " +
                             "load DDL which you set can only be 'true' or 'false', please check " +
                             "your input DDL."
          throw new MalformedCarbonCommandException(errorMessage)
      }
      val maxColumns = options.getOrElse("maxcolumns", null)
      carbonLoadModel.setMaxColumns(maxColumns)
      carbonLoadModel.setEscapeChar(escapeChar)
      carbonLoadModel.setQuoteChar(quoteChar)
      carbonLoadModel.setCommentChar(commentchar)
      carbonLoadModel.setDateFormat(dateFormat)
      carbonLoadModel
        .setSerializationNullFormat(
          TableOptionConstant.SERIALIZATION_NULL_FORMAT.getName + "," + serializationNullFormat)
      carbonLoadModel
        .setBadRecordsLoggerEnable(
          TableOptionConstant.BAD_RECORDS_LOGGER_ENABLE.getName + "," + badRecordsLoggerEnable)
      carbonLoadModel
        .setBadRecordsAction(
          TableOptionConstant.BAD_RECORDS_ACTION.getName + "," + badRecordsLoggerRedirect)

      if (delimiter.equalsIgnoreCase(complex_delimiter_level_1) ||
          complex_delimiter_level_1.equalsIgnoreCase(complex_delimiter_level_2) ||
          delimiter.equalsIgnoreCase(complex_delimiter_level_2)) {
        sys.error(s"Field Delimiter & Complex types delimiter are same")
      }
      else {
        carbonLoadModel.setComplexDelimiterLevel1(
          CarbonUtil.delimiterConverter(complex_delimiter_level_1))
        carbonLoadModel.setComplexDelimiterLevel2(
          CarbonUtil.delimiterConverter(complex_delimiter_level_2))
      }
      // set local dictionary path, and dictionary file extension
      carbonLoadModel.setAllDictPath(allDictionaryPath)

      val partitionStatus = CarbonCommonConstants.STORE_LOADSTATUS_SUCCESS
      try {
        // First system has to partition the data first and then call the load data
        LOGGER.info(s"Initiating Direct Load for the Table : ($dbName.$tableName)")
        carbonLoadModel.setFactFilePath(factPath)
        carbonLoadModel.setCsvDelimiter(CarbonUtil.unescapeChar(delimiter))
        carbonLoadModel.setCsvHeader(fileHeader)
        carbonLoadModel.setColDictFilePath(columnDict)
        carbonLoadModel.setDirectLoad(true)
        GlobalDictionaryUtil.updateTableMetadataFunc = LoadTable.updateTableMetadata
        GlobalDictionaryUtil
          .generateGlobalDictionary(sqlContext, carbonLoadModel, relation.tableMeta.storePath,
            dataFrame)
        CarbonDataRDDFactory.loadCarbonData(sqlContext,
            carbonLoadModel,
            relation.tableMeta.storePath,
            kettleHomePath,
            columinar,
            partitionStatus,
            useKettle,
            dataFrame)
      } catch {
        case ex: Exception =>
          LOGGER.error(ex)
          LOGGER.audit(s"Dataload failure for $dbName.$tableName. Please check the logs")
          throw ex
      } finally {
        // Once the data load is successful delete the unwanted partition files
        try {
          val fileType = FileFactory.getFileType(partitionLocation)
          if (FileFactory.isFileExist(partitionLocation, fileType)) {
            val file = FileFactory
              .getCarbonFile(partitionLocation, fileType)
            CarbonUtil.deleteFoldersAndFiles(file)
          }
        } catch {
          case ex: Exception =>
            LOGGER.error(ex)
            LOGGER.audit(s"Dataload failure for $dbName.$tableName. " +
                         "Problem deleting the partition folder")
            throw ex
        }

      }
    } catch {
      case dle: DataLoadingException =>
        LOGGER.audit(s"Dataload failed for $dbName.$tableName. " + dle.getMessage)
        throw dle
      case mce: MalformedCarbonCommandException =>
        LOGGER.audit(s"Dataload failed for $dbName.$tableName. " + mce.getMessage)
        throw mce
    } finally {
      if (carbonLock != null) {
        if (carbonLock.unlock()) {
          logInfo("Table MetaData Unlocked Successfully after data load")
        } else {
          logError("Unable to unlock Table MetaData")
        }
      }
    }
    Seq.empty
  }

  private def validateDateFormat(dateFormat: String, table: CarbonTable): Unit = {
    val dimensions = table.getDimensionByTableName(tableName).asScala
    if (dateFormat != null) {
      if (dateFormat.trim == "") {
        throw new MalformedCarbonCommandException("Error: Option DateFormat is set an empty " +
                                                  "string.")
      } else {
        var dateFormats: Array[String] = dateFormat.split(CarbonCommonConstants.COMMA)
        for (singleDateFormat <- dateFormats) {
          val dateFormatSplits: Array[String] = singleDateFormat.split(":", 2)
          val columnName = dateFormatSplits(0).trim.toLowerCase
          if (!dimensions.exists(_.getColName.equals(columnName))) {
            throw new MalformedCarbonCommandException("Error: Wrong Column Name " +
                                                      dateFormatSplits(0) +
                                                      " is provided in Option DateFormat.")
          }
          if (dateFormatSplits.length < 2 || dateFormatSplits(1).trim.isEmpty) {
            throw new MalformedCarbonCommandException("Error: Option DateFormat is not provided " +
                                                      "for " + "Column " + dateFormatSplits(0) +
                                                      ".")
          }
        }
      }
    }
  }
}

private[sql] case class DropTableCommand(ifExistsSet: Boolean, databaseNameOp: Option[String],
    tableName: String)
  extends RunnableCommand {

  def run(sqlContext: SQLContext): Seq[Row] = {
    val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)
    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    val identifier = TableIdentifier(tableName, Option(dbName))
    val carbonTableIdentifier = new CarbonTableIdentifier(dbName, tableName, "")
    val carbonLock = CarbonLockFactory
      .getCarbonLockObj(carbonTableIdentifier, LockUsage.DROP_TABLE_LOCK)
    val storePath = CarbonEnv.get.carbonMetastore.storePath
    var isLocked = false
    try {
      isLocked = carbonLock.lockWithRetries()
      if (isLocked) {
        logInfo("Successfully able to get the lock for drop.")
      }
      else {
        LOGGER.audit(s"Dropping table $dbName.$tableName failed as the Table is locked")
        sys.error("Table is locked for deletion. Please try after some time")
      }
      LOGGER.audit(s"Deleting table [$tableName] under database [$dbName]")
      CarbonEnv.get.carbonMetastore.dropTable(storePath, identifier)(sqlContext)
      LOGGER.audit(s"Deleted table [$tableName] under database [$dbName]")
    } finally {
      if (carbonLock != null && isLocked) {
        if (carbonLock.unlock()) {
          logInfo("Table MetaData Unlocked Successfully after dropping the table")
          // deleting any remaining files.
          val metadataFilePath = CarbonStorePath
            .getCarbonTablePath(storePath, carbonTableIdentifier).getMetadataDirectoryPath
          val fileType = FileFactory.getFileType(metadataFilePath)
          if (FileFactory.isFileExist(metadataFilePath, fileType)) {
            val file = FileFactory.getCarbonFile(metadataFilePath, fileType)
            CarbonUtil.deleteFoldersAndFiles(file.getParentFile)
          }
          // delete bad record log after drop table
          val badLogPath = CarbonUtil.getBadLogPath(dbName + File.separator + tableName)
          val badLogFileType = FileFactory.getFileType(badLogPath)
          if (FileFactory.isFileExist(badLogPath, badLogFileType)) {
            val file = FileFactory.getCarbonFile(badLogPath, badLogFileType)
            CarbonUtil.deleteFoldersAndFiles(file)
          }
        } else {
          logError("Unable to unlock Table MetaData")
        }
      }
    }
    Seq.empty
  }
}

private[sql] case class ShowLoads(
    databaseNameOp: Option[String],
    tableName: String,
    limit: Option[String],
    override val output: Seq[Attribute]) extends RunnableCommand {

  override def run(sqlContext: SQLContext): Seq[Row] = {
    val databaseName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    val tableUniqueName = databaseName + "_" + tableName
    // Here using checkSchemasModifiedTimeAndReloadTables in tableExists to reload metadata if
    // schema is changed by other process, so that tableInfoMap woulb be refilled.
    val tableExists = CarbonEnv.get.carbonMetastore
      .tableExists(TableIdentifier(tableName, databaseNameOp))(sqlContext)
    if (!tableExists) {
      sys.error(s"$databaseName.$tableName is not found")
    }
    val carbonTable = org.apache.carbondata.core.carbon.metadata.CarbonMetadata.getInstance()
      .getCarbonTable(tableUniqueName)
    if (carbonTable == null) {
      sys.error(s"$databaseName.$tableName is not found")
    }
    val path = carbonTable.getMetaDataFilepath
    val loadMetadataDetailsArray = SegmentStatusManager.readLoadMetadata(path)
    if (loadMetadataDetailsArray.nonEmpty) {

      val parser = new SimpleDateFormat(CarbonCommonConstants.CARBON_TIMESTAMP)

      var loadMetadataDetailsSortedArray = loadMetadataDetailsArray.sortWith(
        (l1, l2) => java.lang.Double.parseDouble(l1.getLoadName) > java.lang.Double
          .parseDouble(l2.getLoadName)
      )

      if (limit.isDefined) {
        loadMetadataDetailsSortedArray = loadMetadataDetailsSortedArray
          .filter(load => load.getVisibility.equalsIgnoreCase("true"))
        val limitLoads = limit.get
        try {
          val lim = Integer.parseInt(limitLoads)
          loadMetadataDetailsSortedArray = loadMetadataDetailsSortedArray.slice(0, lim)
        } catch {
          case ex: NumberFormatException => sys.error(s" Entered limit is not a valid Number")
        }

      }

      loadMetadataDetailsSortedArray.filter(load => load.getVisibility.equalsIgnoreCase("true"))
        .map(load =>
          Row(
            load.getLoadName,
            load.getLoadStatus,
            new java.sql.Timestamp(parser.parse(load.getLoadStartTime).getTime),
            new java.sql.Timestamp(parser.parse(load.getTimestamp).getTime))).toSeq
    } else {
      Seq.empty

    }
  }

}

private[sql] case class DescribeCommandFormatted(
    child: SparkPlan,
    override val output: Seq[Attribute],
    tblIdentifier: TableIdentifier)
  extends RunnableCommand {

  override def run(sqlContext: SQLContext): Seq[Row] = {
    val relation = CarbonEnv.get.carbonMetastore
      .lookupRelation1(tblIdentifier)(sqlContext).asInstanceOf[CarbonRelation]
    val mapper = new ObjectMapper()
    val colProps = StringBuilder.newBuilder
    var results: Seq[(String, String, String)] = child.schema.fields.map { field =>
      val comment = if (relation.metaData.dims.contains(field.name)) {
        val dimension = relation.metaData.carbonTable.getDimensionByName(
          relation.tableMeta.carbonTableIdentifier.getTableName,
          field.name)
        if (null != dimension.getColumnProperties && dimension.getColumnProperties.size() > 0) {
          val colprop = mapper.writeValueAsString(dimension.getColumnProperties)
          colProps.append(field.name).append(".")
            .append(mapper.writeValueAsString(dimension.getColumnProperties))
            .append(",")
        }
        if (dimension.hasEncoding(Encoding.DICTIONARY) &&
            !dimension.hasEncoding(Encoding.DIRECT_DICTIONARY)) {
          "DICTIONARY, KEY COLUMN"
        } else {
          "KEY COLUMN"
        }
      } else {
        ("MEASURE")
      }
      (field.name, field.dataType.simpleString, comment)
    }
    val colPropStr = if (colProps.toString().trim().length() > 0) {
      // drops additional comma at end
      colProps.toString().dropRight(1)
    } else {
      colProps.toString()
    }
    results ++= Seq(("", "", ""), ("##Detailed Table Information", "", ""))
    results ++= Seq(("Database Name: ", relation.tableMeta.carbonTableIdentifier
      .getDatabaseName, "")
    )
    results ++= Seq(("Table Name: ", relation.tableMeta.carbonTableIdentifier.getTableName, ""))
    results ++= Seq(("CARBON Store Path: ", relation.tableMeta.storePath, ""))
    val carbonTable = relation.tableMeta.carbonTable
    results ++= Seq(("Table Block Size : ", carbonTable.getBlockSizeInMB + " MB", ""))
    results ++= Seq(("", "", ""), ("##Detailed Column property", "", ""))
    if (colPropStr.length() > 0) {
      results ++= Seq((colPropStr, "", ""))
    } else {
      results ++= Seq(("ADAPTIVE", "", ""))
    }
    val dimension = carbonTable
      .getDimensionByTableName(relation.tableMeta.carbonTableIdentifier.getTableName)
    results ++= getColumnGroups(dimension.asScala.toList)
    results.map { case (name, dataType, comment) =>
      Row(f"$name%-36s $dataType%-80s $comment%-72s")
    }
  }

  private def getColumnGroups(dimensions: List[CarbonDimension]): Seq[(String, String, String)] = {
    var results: Seq[(String, String, String)] =
      Seq(("", "", ""), ("##Column Group Information", "", ""))
    val groupedDimensions = dimensions.groupBy(x => x.columnGroupId()).filter {
      case (groupId, _) => groupId != -1
    }.toSeq.sortBy(_._1)
    val groups = groupedDimensions.map(colGroups => {
      colGroups._2.map(dim => dim.getColName).mkString(", ")
    })
    var index = 1
    groups.map { x =>
      results = results :+ (s"Column Group $index", x, "")
      index = index + 1
    }
    results
  }
}

private[sql] case class DeleteLoadByDate(
    databaseNameOp: Option[String],
    tableName: String,
    dateField: String,
    dateValue: String
) extends RunnableCommand {

  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)

  def run(sqlContext: SQLContext): Seq[Row] = {
    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    LOGGER.audit(s"The delete load by date request has been received for $dbName.$tableName")
    val identifier = TableIdentifier(tableName, Option(dbName))
    val relation = CarbonEnv.get.carbonMetastore
      .lookupRelation1(identifier)(sqlContext).asInstanceOf[CarbonRelation]
    var level: String = ""
    val carbonTable = org.apache.carbondata.core.carbon.metadata.CarbonMetadata
      .getInstance().getCarbonTable(dbName + '_' + tableName)
    if (relation == null) {
      LOGGER.audit(s"The delete load by date is failed. Table $dbName.$tableName does not exist")
      sys.error(s"Table $dbName.$tableName does not exist")
    }
    val matches: Seq[AttributeReference] = relation.dimensionsAttr.filter(
      filter => filter.name.equalsIgnoreCase(dateField) &&
                filter.dataType.isInstanceOf[TimestampType]).toList
    if (matches.isEmpty) {
      LOGGER.audit("The delete load by date is failed. " +
                   s"Table $dbName.$tableName does not contain date field: $dateField")
      sys.error(s"Table $dbName.$tableName does not contain date field $dateField")
    } else {
      level = matches.asJava.get(0).name
    }
    val actualColName = relation.metaData.carbonTable.getDimensionByName(tableName, level)
      .getColName
    DataManagementFunc.deleteLoadByDate(
      sqlContext,
      new CarbonDataLoadSchema(carbonTable),
      dbName,
      tableName,
      CarbonEnv.get.carbonMetastore.storePath,
      level,
      actualColName,
      dateValue)
    LOGGER.audit(s"The delete load by date $dateValue is successful for $dbName.$tableName.")
    Seq.empty
  }

}

private[sql] case class CleanFiles(
    databaseNameOp: Option[String],
    tableName: String) extends RunnableCommand {

  val LOGGER = LogServiceFactory.getLogService(this.getClass.getCanonicalName)

  def run(sqlContext: SQLContext): Seq[Row] = {
    val dbName = getDB.getDatabaseName(databaseNameOp, sqlContext)
    LOGGER.audit(s"The clean files request has been received for $dbName.$tableName")
    val identifier = TableIdentifier(tableName, Option(dbName))
    val relation = CarbonEnv.get.carbonMetastore
      .lookupRelation1(identifier)(sqlContext).
      asInstanceOf[CarbonRelation]
    if (relation == null) {
      LOGGER.audit(s"The clean files request is failed. Table $dbName.$tableName does not exist")
      sys.error(s"Table $dbName.$tableName does not exist")
    }

    val carbonLoadModel = new CarbonLoadModel()
    carbonLoadModel.setTableName(relation.tableMeta.carbonTableIdentifier.getTableName)
    carbonLoadModel.setDatabaseName(relation.tableMeta.carbonTableIdentifier.getDatabaseName)
    val table = relation.tableMeta.carbonTable
    carbonLoadModel.setAggTables(table.getAggregateTablesName.asScala.toArray)
    carbonLoadModel.setTableName(table.getFactTableName)
    carbonLoadModel.setStorePath(relation.tableMeta.storePath)
    val dataLoadSchema = new CarbonDataLoadSchema(table)
    carbonLoadModel.setCarbonDataLoadSchema(dataLoadSchema)
    try {
      DataManagementFunc.cleanFiles(
        sqlContext.sparkContext,
        carbonLoadModel,
        relation.tableMeta.storePath)
      LOGGER.audit(s"Clean files request is successfull for $dbName.$tableName.")
    } catch {
      case ex: Exception =>
        sys.error(ex.getMessage)
    }
    Seq.empty
  }
}


text:
'use strict';

const { Client } = require('hazelcast-client');

(async () => {
    try {
        const client = await Client.newHazelcastClient();

        const membershipListener = {
            memberAdded: (event) => {
                console.log('Member Added:', event.member.address);
            },
            memberRemoved: (event) => {
                console.log('Member Removed:', event.member.address);
            }
        };
        // When a member is added and removed, the listener will be triggered
        client.getClusterService().addMembershipListener(membershipListener);

        await client.shutdown();
    } catch (err) {
        console.error('Error occurred:', err);
        process.exit(1);
    }
})();


text:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<title>com.hourglassapps.cpi_ii.lucene</title>
<meta name="date" content="2015-04-26">
<link rel="stylesheet" type="text/css" href="../../../../stylesheet.css" title="Style">

com.hourglassapps.cpi_ii.lucene

Interfaces

MetaReadFactory

ResultGenerator

ResultRelayer

TermHandler

Classes

AbstractLuceneJournal

AbstractTermFreqMapper

DocSpan

FieldVal

FoundGenerator

Freq2TermMapper

Indexer

IndexingThread

IndexViewer

LoggingAnalyzer

LuceneVisitor

Phrase

TikaReader

Enums

AbstractLuceneJournal.LuceneTransactionFields

DownloadedFields


text:
if [[ -z "$OXI_TEST_DB_MYSQL_USER" ]]; then
    echo "This script expects to be run in a test environment (Docker or Vagrant VM)"
    echo "where the database configuration is set in OXI_TEST_DB_MYSQL_USER etc."
    exit 1
fi

BASEDIR=$(readlink -e $(dirname $0))
TEMPDIR=$(mktemp -d)

set -e

# Steps to create the certificates:
# 1. Setup test OpenXPKI configuration in temporary directory
#    (MySQL config will be read from env vars $OXI_TEST_DB_MYSQL_xxx)
$BASEDIR/_create-config.pl $TEMPDIR

# 2. Create certificates and store them in $TEMPDIR/etc/openxpki/ca/xxx/
# 3. Import cert. into MySQL using test config above
$BASEDIR/_create-certs.sh $TEMPDIR/etc/openxpki

# 4. Create Perl code for OpenXPKI::Test::CertHelper::Database
$BASEDIR/_write-certhelper.pl $TEMPDIR/etc/openxpki/ca > $BASEDIR/generated-certhelper-code.pl
echo ""
echo "Code for OpenXPKI::Test::CertHelper::Database is available in:"
echo "    $BASEDIR/generated-certhelper-code.pl"

# 5. Create MySQL dump
dumpOpts=()
test ! -z "$OXI_TEST_DB_MYSQL_DBHOST" && dumpOpts=("${dumpOpts[@]}" -h "$OXI_TEST_DB_MYSQL_DBHOST") || true
test ! -z "$OXI_TEST_DB_MYSQL_DBPORT" && dumpOpts=("${dumpOpts[@]}" -P "$OXI_TEST_DB_MYSQL_DBPORT") || true
dumpOpts=("${dumpOpts[@]}" -u"$OXI_TEST_DB_MYSQL_USER")
test ! -z "$OXI_TEST_DB_MYSQL_PASSWORD" && dumpOpts=("${dumpOpts[@]}" -p"$OXI_TEST_DB_MYSQL_PASSWORD") || true

mysqldump "${dumpOpts[@]}" \
    --set-charset --no-create-info \
    --skip-comments --skip-add-locks --skip-disable-keys \
    --extended-insert --complete-insert --single-transaction \
    $OXI_TEST_DB_MYSQL_NAME > $BASEDIR/generated-mysql-dump.sql
echo ""
echo "MySQL insert script is available in:"
echo "    $BASEDIR/generated-mysql-dump.sql"

rm -rf $TEMPDIR

echo "Done"


text:
namespace gfx {
class Point;
}

namespace ui {
class MenuModel;
}

namespace atom {

// A menu. Populated from a model, and relies on a delegate to execute commands.
//
// WARNING: do NOT create and use Menu2 on the stack. Menu2 notifies the model
// of selection AFTER a delay. This means that if use a Menu2 on the stack
// ActivatedAt is never invoked.
class Menu2 {
 public:
  // How the menu is aligned relative to the point it is shown at.
  // The alignment is reversed by menu if text direction is right to left.
  enum Alignment {
    ALIGN_TOPLEFT,
    ALIGN_TOPRIGHT
  };

  // Creates a new menu populated with the contents of |model|.
  // WARNING: this populates the menu on construction by invoking methods on
  // the model. As such, it is typically not safe to use this as the model
  // from the constructor. EG:
  //   MyClass : menu_(this) {}
  // is likely to have problems.
  explicit Menu2(ui::MenuModel* model, bool as_window_menu = false);
  virtual ~Menu2();

  // Runs the menu at the specified point. This method blocks until done.
  // RunContextMenuAt is the same, but the alignment is the default for a
  // context menu.
  void RunMenuAt(const gfx::Point& point, Alignment alignment);
  void RunContextMenuAt(const gfx::Point& point);

  // Cancels the active menu.
  void CancelMenu();

  // Called when the model supplying data to this menu has changed, and the menu
  // must be rebuilt.
  void Rebuild();

  // Called when the states of the menu items in the menu should be refreshed
  // from the model.
  void UpdateStates();

  // For submenus.
  HMENU GetNativeMenu() const;

  // Get the result of the last call to RunMenuAt to determine whether an
  // item was selected, the user navigated to a next or previous menu, or
  // nothing.
  NativeMenuWin::MenuAction GetMenuAction() const;

  // Add a listener to receive a callback when the menu opens.
  void AddMenuListener(views::MenuListener* listener);

  // Remove a menu listener.
  void RemoveMenuListener(views::MenuListener* listener);

  // Accessors.
  ui::MenuModel* model() const { return model_; }
  NativeMenuWin* wrapper() const { return wrapper_.get(); }

  // Sets the minimum width of the menu.
  void SetMinimumWidth(int width);

 private:
  ui::MenuModel* model_;

  // The object that actually implements the menu.
  scoped_ptr<NativeMenuWin> wrapper_;

  DISALLOW_COPY_AND_ASSIGN(Menu2);
};

}  // namespace atom

#endif  // ATOM_BROWSER_UI_WIN_MENU_2_H_


text:
<?xml version="1.0" encoding="utf-8"?>
<Jobs>
  <ApplicationJob xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Guid="4188bc4d-da1a-4c1f-a99c-98c0b072e441">
    <WebsiteUrl />
    <UserAgent />
    <UserNotes />
    <LastFileSize>1588888</LastFileSize>
    <LastFileDate>2015-04-01T16:58:36.9956315</LastFileDate>
    <IgnoreFileInformation>false</IgnoreFileInformation>
    <DownloadBeta>Default</DownloadBeta>
    <DownloadDate xsi:nil="true" />
    <CheckForUpdatesOnly>false</CheckForUpdatesOnly>
    <VariableChangeIndicator />
    <CanBeShared>true</CanBeShared>
    <ShareApplication>false</ShareApplication>
    <ExclusiveDownload>false</ExclusiveDownload>
    <HttpReferer />
    <SetupInstructions />
    <Variables>
      <item>
        <key>
          <string>nopush</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>Textual</VariableType>
            <Regex />
            <TextualContent>--nopush</TextualContent>
            <Name>nopush</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>version</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>RegularExpression</VariableType>
            <Regex>projects/commitmonitor/files/commitmonitor-([\d\.]+)\.zip</Regex>
            <Url>https://sourceforge.net/projects/commitmonitor/files</Url>
            <Name>version</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>url</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>RegularExpression</VariableType>
            <Regex>(?<=ResponseUri: )[^\r\n]+</Regex>
            <Url>{getUrl}</Url>
            <TextualContent />
            <Name>url</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>url64</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>Textual</VariableType>
            <Regex />
            <TextualContent>{urlArray}</TextualContent>
            <Name>url64</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>checksum64file</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>RegularExpression</VariableType>
            <Regex>(?<=ResponseUri: )[^\r\n]+</Regex>
            <Url>{getUrl64}</Url>
            <TextualContent />
            <Name>checksum64file</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>urlArray</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>Textual</VariableType>
            <Regex />
            <TextualContent>@('{getUrl}', '{getUrl64}')</TextualContent>
            <Name>urlArray</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>getUrl</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>RegularExpression</VariableType>
            <Regex>[^ "'<>\*]+CommitMonitor-{version}\.zip/download</Regex>
            <Url>https://sourceforge.net/projects/commitmonitor/files/</Url>
            <Name>getUrl</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>getUrl64</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>RegularExpression</VariableType>
            <Regex>[^ "'<>\*]+/commitmonitor64-{version}\.zip/download</Regex>
            <Url>https://sourceforge.net/projects/commitmonitor/files</Url>
            <Name>getUrl64</Name>
          </UrlVariable>
        </value>
      </item>
      <item>
        <key>
          <string>cscript</string>
        </key>
        <value>
          <UrlVariable>
            <RegexRightToLeft>false</RegexRightToLeft>
            <VariableType>Textual</VariableType>
            <Regex />
            <TextualContent>2</TextualContent>
            <Name>cscript</Name>
          </UrlVariable>
        </value>
      </item>
    </Variables>
    <ExecuteCommand />
    <ExecutePreCommand />
    <ExecuteCommandType>Batch</ExecuteCommandType>
    <ExecutePreCommandType>Batch</ExecutePreCommandType>
    <Category />
    <SourceType>FixedUrl</SourceType>
    <PreviousLocation>C:\ProgramData\chocolatey\_work\CommitMonitor-1.10.2.1025.zip</PreviousLocation>
    <DeletePreviousFile>true</DeletePreviousFile>
    <Enabled>true</Enabled>
    <FileHippoId />
    <LastUpdated>2015-04-01T16:58:36.9956315</LastUpdated>
    <TargetPath>{workdir}\</TargetPath>
    <FixedDownloadUrl>{url}</FixedDownloadUrl>
    <Name>commitmonitor.portable</Name>
  </ApplicationJob>
</Jobs>


text:
		Docker Registry Explorer {{ version.version }} |

				Fork


text:
Scrollable Fixed Header Table
*****************************

This plug-in works with :doc:`tablesorter`.

Links
=====

- `Scrollable Fixed Header Table`_

Install
=======

::

  cd ~/repo/temp/
  svn checkout http://jquery-sfht.googlecode.com/svn/trunk/ jquery-sfht

  cd my/site/static/js/
  mkdir jquery-sfht/
  cd jquery-sfht/

  cp ~/repo/temp/jquery-sfht/javascripts/jquery.cookie.pack.js .
  cp ~/repo/temp/jquery-sfht/javascripts/jquery.dimensions.min.js .
  cp ~/repo/temp/jquery-sfht/javascripts/jquery.scrollableFixedHeaderTable.js .

  cd my/site/static/css/
  mkdir jquery-sfht/
  cd jquery-sfht/
  cp -R ~/repo/temp/jquery-sfht/css/* .

Note: We don't actually want to copy everthing in the ``css`` folder as it will
include ``svn`` meta-data.

Usage
=====

.. code-block:: html

  <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/common/jquery-sfht/themes/blue/style.css">
  <link rel="stylesheet" type="text/css" href="{{ STATIC_URL }}css/common/jquery-sfht/scrollableFixedHeaderTable.css">

  <script type="text/javascript" src="{{ STATIC_URL }}js/common/jquery-1.6.4.js"></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/common/jquery.tablesorter.js"></script>

  <script type="text/javascript" src="{{ STATIC_URL }}js/common/jquery-sfht/jquery.cookie.pack.js" ></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/common/jquery-sfht/jquery.dimensions.min.js" ></script>
  <script type="text/javascript" src="{{ STATIC_URL }}js/common/jquery-sfht/jquery.scrollableFixedHeaderTable.js" ></script>

To initialise the table:

.. code-block:: javascript

  $('#myTable').scrollableFixedHeaderTable(500, 200);
  $('#myTable').tablesorter().bind('sortEnd', function(){
      var $cloneTH = $('.sfhtHeader thead th');
      var $trueTH = $('.sfhtData thead th');
      $cloneTH.each(function(index){
          $(this).attr('class', $($trueTH[index]).attr('class'));
      });
  });
  $('.sfhtHeader thead th').each(function(index){
      var $cloneTH = $(this);
      var $trueTH = $($('.sfhtData thead th')[index]);
      $cloneTH.attr('class', $trueTH.attr('class'));
      $cloneTH.click(function(){
          $trueTH.click();
      });
  });

.. _`Scrollable Fixed Header Table`: http://jeromebulanadi.wordpress.com/2010/03/22/scrollable-fixed-header-table-a-jquery-plugin/


text:
import expect from 'expect.js';
import ngMock from 'ng_mock';
import RegistryFieldFormatsProvider from 'ui/registry/field_formats';
describe('Color Format', function () {
  let fieldFormats;
  let ColorFormat;

  beforeEach(ngMock.module('kibana'));
  beforeEach(ngMock.inject(function (Private) {
    fieldFormats = Private(RegistryFieldFormatsProvider);
    ColorFormat = fieldFormats.getType('color');
  }));

  context('field is a number', () => {
    it('should add colors if the value is in range', function () {
      const colorer = new ColorFormat({
        fieldType: 'number',
        colors: [{
          range: '100:150',
          text: 'blue',
          background: 'yellow'
        }]
      });
      expect(colorer.convert(99, 'html')).to.eql('99');
      expect(colorer.convert(100, 'html')).to.eql('100');
      expect(colorer.convert(150, 'html')).to.eql('150');
      expect(colorer.convert(151, 'html')).to.eql('151');
    });

    it('should not convert invalid ranges', function () {
      const colorer = new ColorFormat({
        fieldType: 'number',
        colors: [{
          range: '100150',
          text: 'blue',
          background: 'yellow'
        }]
      });
      expect(colorer.convert(99, 'html')).to.eql('99');
    });
  });

  context('field is a string', () => {
    it('should add colors if the regex matches', function () {
      const colorer = new ColorFormat({
        fieldType: 'string',
        colors: [{
          regex: 'A.*',
          text: 'blue',
          background: 'yellow'
        }]
      });

      const converter = colorer.getConverterFor('html');
      expect(converter('B', 'html')).to.eql('B');
      expect(converter('AAA', 'html')).to.eql('AAA');
      expect(converter('AB', 'html')).to.eql('AB');
      expect(converter('a', 'html')).to.eql('a');

      expect(converter('B', 'html')).to.eql('B');
      expect(converter('AAA', 'html')).to.eql('AAA');
      expect(converter('AB', 'html')).to.eql('AB');
      expect(converter('a', 'html')).to.eql('a');
    });
  });
});