text:
package de.ids_mannheim.korap.index;

import java.util.*;
import java.io.*;

import de.ids_mannheim.korap.index.MultiTerm;
import de.ids_mannheim.korap.index.MultiTermToken;
import de.ids_mannheim.korap.query.wrap.SpanSegmentQueryWrapper;
import de.ids_mannheim.korap.query.wrap.SpanRegexQueryWrapper;
import de.ids_mannheim.korap.query.wrap.SpanSequenceQueryWrapper;
import de.ids_mannheim.korap.query.SpanWithinQuery;

import de.ids_mannheim.korap.util.CorpusDataException;

import static de.ids_mannheim.korap.Test.*;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.analysis.TokenFilter;
import org.apache.lucene.analysis.TokenStream;
import org.apache.lucene.analysis.tokenattributes.CharTermAttribute;

import org.apache.lucene.index.Term;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.index.TermContext;

import org.apache.lucene.index.DocsAndPositionsEnum;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.IndexWriterConfig.OpenMode;
import org.apache.lucene.index.LeafReaderContext;

import org.apache.lucene.queryparser.classic.ParseException;
import org.apache.lucene.queryparser.classic.QueryParser;

import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.TermQuery;
import org.apache.lucene.search.BooleanClause;
import org.apache.lucene.search.BooleanQuery;
import org.apache.lucene.search.PhraseQuery;
import org.apache.lucene.search.NumericRangeQuery;
import org.apache.lucene.search.spans.Spans;
import org.apache.lucene.search.spans.SpanQuery;
import org.apache.lucene.search.spans.SpanOrQuery;
import org.apache.lucene.search.spans.SpanMultiTermQueryWrapper;
import org.apache.lucene.search.spans.SpanTermQuery;
import org.apache.lucene.search.spans.SpanNearQuery;
import org.apache.lucene.search.spans.SpanNotQuery;
import org.apache.lucene.search.spans.NearSpansOrdered;
import org.apache.lucene.search.WildcardQuery;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.RegexpQuery;

import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.store.SimpleFSDirectory; // temporary

import org.apache.lucene.util.Version;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.Bits;

import static org.junit.Assert.*;
import org.junit.Test;
import org.junit.Ignore;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;

@RunWith(JUnit4.class)
public class TestIndex { // extends LuceneTestCase {
    // Create index in RAM
    //    private Directory index = new RAMDirectory();

    private Directory index = new RAMDirectory();

    @Test
    public void multiTerm () throws CorpusDataException {
        MultiTerm test = new MultiTerm("test");
        assertEquals(test.getTerm(), "test");
        assertEquals(test.getPayload(), null);
        assertEquals(test.getStart(), 0);
        assertEquals(test.getEnd(), 0);
        assertFalse(test.hasStoredOffsets());
        assertEquals(test.toString(), "test");

        test = new MultiTerm("test#0-4");
        assertEquals(test.getTerm(), "test");
        assertEquals(test.getPayload(), null);
        assertEquals(test.getStart(), 0);
        assertEquals(test.getEnd(), 4);
        assertFalse(test.hasStoredOffsets());
        assertEquals(test.toString(), "test#0-4");

        test = new MultiTerm("<>:s:test#0-4$<i>67");
        assertEquals(test.getTerm(), "<>:s:test");
        assertEquals(test.getPayload().toString(), "[0 0 0 43]");
        assertEquals(test.getStart(), 0);
        assertEquals(test.getEnd(), 4);
        assertFalse(test.hasStoredOffsets());
        assertTrue(test.toString().startsWith("<>:s:test#0-4$"));

        test = new MultiTerm("xip/l:\\#normal#0-5$<i>3999");
        assertEquals(test.getTerm(), "xip/l:#normal");
        assertEquals(test.getPayload().toString(), "[0 0 f 9f]");
        assertEquals(test.getStart(), 0);
        assertEquals(test.getEnd(), 5);
        assertFalse(test.hasStoredOffsets());
        assertTrue(test.toString().startsWith("xip/l:\\#normal#0-5$"));
    };

    @Test
    public void multiTermToken () throws CorpusDataException {
        MultiTermToken test = new MultiTermToken("hunde", "pos:n", "m:gen:pl");
        assertEquals(test.terms.get(0).term, "hunde");
        assertEquals(test.terms.get(1).term, "pos:n");
        assertEquals(test.terms.get(2).term, "m:gen:pl");

        test = new MultiTermToken("hunde", "pos:n", "m:gen:pl");
        assertEquals(test.terms.get(0).term, "hunde");
        assertEquals(test.terms.get(1).term, "pos:n");
        assertEquals(test.terms.get(2).term, "m:gen:pl");
    };

    private List initIndexer () throws IOException {
        List<Map<String, String>> list = new ArrayList<>();

        Map<String, String> d1 = new HashMap<String, String>();
        d1.put("id", "w1");
        d1.put("corpus", "wiki");
        d1.put("author", "Nils Diewald");
        d1.put("title", "Wikipedia");
        d1.put("subtitle", "A test");
        d1.put("pubDate", "20130701");
        d1.put("pubPlace", "Mannheim");
        d1.put("textClass", "news sports");
        d1.put("textStr", "Er nahm den Hunden die Angst.");
        d1.put("text", "Er#0-2|PPER|er|c:nom;p:3;n:sg;g:masc|<>:s#0-29$<i>7 "
                + "nahm#3-7|VVFIN|nehmen|p:3;n:sg;t:past;m:ind| "
                + "den#8-11|ART|der|c:acc;n:sg;g:masc| "
                + "Hunden#12-18|NN|hund|c:acc;n:sg;g:masc| "
                + "die#19-22|ART|der|c:nom;n:sg;g:fem| "
                + "Angst#23-28|NN|angst|c:nom;n:sg;g:fem| " + ".#28-29|$.|.||");
        list.add(d1);

        Map<String, String> d2 = new HashMap<String, String>();

        d2.put("id", "w2");
        d2.put("corpus", "wiki");
        d2.put("author", "Peter Thomas");
        d2.put("title", "Waldartikel");
        d2.put("subtitle", "Another test");
        d2.put("pubDate", "20130723");
        d2.put("pubPlace", "Bielefeld");
        d2.put("textClass", "news");
        d2.put("textStr", "Sie liefen durch den Wald.");
        d2.put("text", "Sie#0-3|PPER|sie|c:nom;p:3;n:pl;g:all|<>:s#0-26$<i>6 "
                + "liefen#4-10|VVFIN|laufen|p:3;n:pl;t:past;m:ind| "
                + "durch#11-16|APPR|durch|| "
                + "den#17-20|ART|der|c:acc;n:sg;g:masc| "
                + "Wald#21-25|NN|wald|c:acc;n:sg;g:masc| " + ".#25-26|$.|.||");
        list.add(d2);

        Map<String, String> d3 = new HashMap<String, String>();
        d3.put("id", "w3");
        d3.put("corpus", "zeitung");
        d3.put("author", "Michael Meier");
        d3.put("title", "Angst");
        d3.put("subtitle", "Starr vor Angst");
        d3.put("pubDate", "20130713");
        d3.put("pubPlace", "Bielefeld");
        d3.put("textClass", "sports");
        d3.put("textStr",
                "Er wagte nicht, sich zu ruehren. Er war starr vor Angst.");
        d3.put("text", "Er#0-2|PPER|er|c:nom;n:sg;g:masc;p:3|<>:s#0-32$<i>8 "
                + "wagte#3-8|VVFIN|wagen|p:3;n:sg;t:past;m:ind| "
                + "nicht#9-14|PTKNEG|nicht|| " + ",#14-15|$,|,|| "
                + "sich#16-20|PRF|sich|c:acc;p:3;n:sg| "
                + "zu#21-23|PTKZU|zu|| " + "ruehren#24-31|VVFIN|ruehren|| "
                + ".#31-32|$.|.|| "
                + "Er#33-35|PPER|er|c:nom;p:3;n:sg;g:masc|<>:s#33-56$<i>14 "
                + "war#36-39|VAFIN|sein|p:3;n:sg;t:past;m:ind| "
                + "starr#40-45|ADJD|starr|comp:pos| " + "vor#46-49|APPR|vor|| "
                + "Angst#50-55|NN|angst|c:dat;n:sg;g:fem| " + ".#55-56|$.|.||");
        list.add(d3);

        return list;
    };

    @Test
    public void indexLucene () throws Exception {

        // Base analyzer for searching and indexing
        StandardAnalyzer analyzer = new StandardAnalyzer();

        // Based on
        // http://lucene.apache.org/core/4_0_0/core/org/apache/lucene/
        // analysis/Analyzer.html?is-external=true

        // Create configuration with base analyzer
        IndexWriterConfig config = new IndexWriterConfig(analyzer);

        // Add a document 1 with the correct fields
        IndexWriter w = new IndexWriter(index, config);

        Collection docs = initIndexer();

        @SuppressWarnings("unchecked")
        Iterator<Map<String, String>> i = (Iterator<Map<String, String>>) docs
                .iterator();

        for (; i.hasNext();) {
            addDoc(w, i.next());
        };

        assertEquals(3, w.numDocs());

        w.close();

        // Check directory
        DirectoryReader reader = DirectoryReader.open(index);
        assertEquals(docs.size(), reader.maxDoc());
        assertEquals(docs.size(), reader.numDocs());

        // Check searcher
        IndexSearcher searcher = new IndexSearcher(reader);

        // textClass
        // All texts of text class "news"
        assertEquals(2,
                searcher.search(new TermQuery(new Term("textClass", "news")),
                        10).totalHits);

        // textClass
        // All texts of text class "sports"
        assertEquals(2,
                searcher.search(new TermQuery(new Term("textClass", "sports")),
                        10).totalHits);

        // TextIndex
        // All docs containing "l:nehmen"
        assertEquals(1,
                searcher.search(new TermQuery(new Term("text", "l:nehmen")),
                        10).totalHits);

        // TextIndex
        // All docs containing "s:den"
        assertEquals(2,
                searcher.search(new TermQuery(new Term("text", "s:den")),
                        10).totalHits);

        /*
        assertEquals(3,
              searcher.search(
                new TermQuery(
                  new Term("text", "T")
            ), 10
          ).totalHits
            );
        */

        // BooleanQuery
        // All docs containing "s:den" and "l:sie"
        TermQuery s_den = new TermQuery(new Term("text", "s:den"));
        TermQuery l_sie = new TermQuery(new Term("text", "l:sie"));
        BooleanQuery bool = new BooleanQuery();
        bool.add(s_den, BooleanClause.Occur.MUST);
        bool.add(l_sie, BooleanClause.Occur.MUST);

        assertEquals(1, searcher.search(bool, 10).totalHits);

        // BooleanQuery
        // All docs containing "s:den" or "l:sie"
        bool = new BooleanQuery();
        bool.add(s_den, BooleanClause.Occur.SHOULD);
        bool.add(l_sie, BooleanClause.Occur.SHOULD);
        assertEquals(2, searcher.search(bool, 10).totalHits);

        // RegexpQuery
        // All docs containing ".{4}en" (liefen und Hunden)
        RegexpQuery srquery = new RegexpQuery(new Term("text", "s:.{4}en"));
        assertEquals(2, searcher.search(srquery, 10).totalHits);

        // RegexpQuery
        // All docs containing "E." (Er) (2x)
        srquery = new RegexpQuery(new Term("text", "s:E."));
        assertEquals(2, searcher.search(srquery, 10).totalHits);

        SpanRegexQueryWrapper ssrquery = new SpanRegexQueryWrapper("text",
                "s:E.");
        assertEquals(2, searcher.search(ssrquery.toQuery(), 10).totalHits);

        // RegexpQuery
        // All docs containing "E." (er) (0x)
        srquery = new RegexpQuery(new Term("text", "s:e."));
        assertEquals(0, searcher.search(srquery, 10).totalHits);

        ssrquery = new SpanRegexQueryWrapper("text", "s:e.");
        assertEquals(0, searcher.search(ssrquery.toQuery(), 10).totalHits);

        // RegexpQuery
        // All docs containing "E."/i ([Ee]r) (2x)
        srquery = new RegexpQuery(new Term("text", "i:e."));
        assertEquals(2, searcher.search(srquery, 10).totalHits);

        ssrquery = new SpanRegexQueryWrapper("text", "s:e.", true);
        assertEquals("SpanMultiTermQueryWrapper(text:/i:e./)",
                ssrquery.toQuery().toString());
        assertEquals(2, searcher.search(ssrquery.toQuery(), 10).totalHits);

        // All docs containing "ng"/x (Angst) (2x)
        srquery = new RegexpQuery(new Term("text", "s:.*ng.*"));
        assertEquals(2, searcher.search(srquery, 10).totalHits);

        // Check http://comments.gmane.org/gmane.comp.jakarta.lucene.user/52283
        // for Carstens question on wildcards
		// Wildcardquery
        // All docs containing ".{4}en" (liefen und Hunden)
        WildcardQuery swquery = new WildcardQuery(new Term("text", "s:*ng*"));
		assertEquals("text:s:*ng*", swquery.toString());
		assertEquals(2, searcher.search(swquery, 10).totalHits);

        // [base=angst]
        SpanTermQuery stq = new SpanTermQuery(new Term("text", "l:angst"));
        assertEquals(2, searcher.search(srquery, 10).totalHits);

        // vor Angst
        // [orth=vor][orth=Angst]
        SpanNearQuery snquery = new SpanNearQuery(
                new SpanQuery[] { new SpanTermQuery(new Term("text", "s:vor")),
                        new SpanTermQuery(new Term("text", "s:Angst")) },
                1, true);
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        // Spannearquery [p:VVFIN][]{,5}[m:nom:sg:fem]
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanTermQuery(new Term("text", "p:VVFIN")),
                        new SpanSegmentQueryWrapper("text", "m:c:nom", "m:n:sg",
                                "m:g:fem").toQuery() },
                5,     // slop
                true   // inOrder
            // Possible: CollectPayloads
        );
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        // Spannearquery [p:VVFIN][m:acc:sg:masc]
        snquery = new SpanNearQuery(new SpanQuery[] { new SpanTermQuery(
                new Term("text", "p:VVFIN")),
                new SpanNearQuery(
                        new SpanQuery[] {
                                new SpanTermQuery(new Term("text", "m:c:acc")),
                                new SpanNearQuery(
                                        new SpanQuery[] {
                                                new SpanTermQuery(new Term(
                                                        "text", "m:n:sg")),
                                                new SpanTermQuery(new Term(
                                                        "text", "m:g:masc")) },
                                        -1, false) },
                        -1,     // slop
                        false   // inOrder
                // Possible: CollectPayloads
                )
                // new SpanTermQuery(new Term("text", "m:-acc:--sg:masc"))
        }, 0,     // slop
                true   // inOrder
            // Possible: CollectPayloads
        );
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        // Spannearquery [p:VVFIN|m:3:sg:past:ind]
        // Exact match!
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanTermQuery(new Term("text", "p:VVFIN")),
                        new SpanNearQuery(new SpanQuery[] {
                                new SpanTermQuery(new Term("text", "m:p:3")),
                                new SpanNearQuery(new SpanQuery[] {
                                        new SpanTermQuery(
                                                new Term("text", "m:n:sg")),
                                        new SpanNearQuery(
                                                new SpanQuery[] {
                                                        new SpanTermQuery(
                                                                new Term("text",
                                                                        "m:t:past")),
                                                        new SpanTermQuery(
                                                                new Term("text",
                                                                        "m:m:ind")), },
                                                -1, false) },
                                        -1, false) },
                                -1, false) },
                // new SpanTermQuery(new Term("text", "m:---3:--sg:past:-ind"))
                -1,     // slop
                false   // inOrder
        // Possible: CollectPayloads
        );
        assertEquals(2, searcher.search(snquery, 10).totalHits);

        // To make sure, this is not equal:
        // Spannearquery [p:VVFIN & m:3:sg:past:ind]
        // Exact match!
        // Maybe it IS equal
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanTermQuery(new Term("text", "p:VVFIN")),
                        new SpanTermQuery(new Term("text", "m:p:3")),
                        new SpanTermQuery(new Term("text", "m:n:sg")),
                        new SpanTermQuery(new Term("text", "m:t:past")),
                        new SpanTermQuery(new Term("text", "m:m:ind")), },
                -1,     // slop
                false   // inOrder
        // Possible: CollectPayloads
        );
        assertNotEquals(2, searcher.search(snquery, 10).totalHits);
        // assertEquals(2, searcher.search(snquery, 10).totalHits);

        // Spannearquery [p:VVFIN & m:3:sg & past:ind]
        SpanSegmentQueryWrapper sniquery = new SpanSegmentQueryWrapper("text",
                "p:VVFIN", "m:p:3", "m:n:sg", "m:t:past", "m:m:ind");
        assertEquals(2, searcher.search(sniquery.toQuery(), 10).totalHits);

        // Todo:

        /*
        sniquery = new SpanSegmentQuery(
              "text",
          "p:VVFIN",
          "m:p:3",
          "m:n:sg",
          "m:t:past",
          "m:m:ind"
            );
        */

        // Spannearquery [p:VVFIN][]{,5}[m:nom:sg:fem]
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanTermQuery(new Term("text", "p:VVFIN")),
                        new SpanSegmentQueryWrapper("text", "m:c:nom", "m:n:sg",
                                "m:g:fem").toQuery() },
                5,     // slop
                true   // inOrder
            // Possible: CollectPayloads
        );
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        sniquery = new SpanSegmentQueryWrapper("text", "p:VVFIN", "m:p:3",
                "m:t:past", "m:m:ind", "m:n:sg");
        assertEquals(2, searcher.search(sniquery.toQuery(), 10).totalHits);

        // [p = VVFIN & m:p = 3 & m:t = past & m:n != pl] or
        // [p = VVFIN & m:p = 3 & m:t = past & !m:n = pl]
        // TODO: Problem: What should happen in case the category does not exist?
        // pssible solution: & ( m:n != pl & exists(m:n))
        sniquery = new SpanSegmentQueryWrapper("text", "p:VVFIN", "m:p:3",
                "m:t:past");
        SpanQuery snqquery = new SpanNotQuery(sniquery.toQuery(),
                new SpanTermQuery(new Term("text", "m:n:pl")));
        assertEquals(2, searcher.search(snqquery, 10).totalHits);

        // [p = NN & (m:c: = dat | m:c = acc)]
        snquery = new SpanNearQuery(
                new SpanQuery[] { new SpanTermQuery(new Term("text", "p:NN")),
                        new SpanOrQuery(
                                new SpanTermQuery(new Term("text", "m:c:nom")),
                                new SpanTermQuery(
                                        new Term("text", "m:c:acc"))) },
                -1, false);

        assertEquals(2, searcher.search(snqquery, 10).totalHits);

        // [p = NN & !(m:c: = nom | m:c = acc)]
        snqquery = new SpanNotQuery(new SpanTermQuery(new Term("text", "p:NN")),
                new SpanOrQuery(new SpanTermQuery(new Term("text", "m:c:nom")),
                        new SpanTermQuery(new Term("text", "m:c:acc"))));
        assertEquals(1, searcher.search(snqquery, 10).totalHits);

        // [p = NN & !(m:c = nom)]
        snqquery = new SpanNotQuery(new SpanTermQuery(new Term("text", "p:NN")),
                new SpanTermQuery(new Term("text", "m:c:nom")));
        assertEquals(3, searcher.search(snqquery, 10).totalHits);

        // [p=NN & !(m:c = acc)]
        snqquery = new SpanNotQuery(new SpanTermQuery(new Term("text", "p:NN")),
                new SpanTermQuery(new Term("text", "m:c:acc")));
        assertEquals(2, searcher.search(snqquery, 10).totalHits);

        // [p=PPER][][p=ART]
        snquery = new SpanNearQuery(
                new SpanQuery[] { new SpanTermQuery(new Term("text", "p:PPER")),
                        new SpanNearQuery(new SpanQuery[] {
                                new SpanTermQuery(new Term("text", "T")),
                                new SpanTermQuery(new Term("text", "p:ART")) },
                                0, true), },
                0, true);
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        // Todo:
        // [orth=się][]{2,4}[base=bać]
        // [orth=się][orth!="[.!?,:]"]{,5}[base=bać]|[base=bać][base="on|ja|ty|my|wy"]?[orth=się]
        // [pos=subst & orth="a.*"]{2}
        // [tag=subst:sg:nom:n]
        // [case==acc & case==gen] ??
        // [case~acc & case~gen]
        // [case~~acc]
        // [base=bać][orth!=się]+[orth=się] within s

        // [][][p:VAFIN] within s
        // [][p:VAFIN] within s

        // [][][p:VAFIN]
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanNearQuery(new SpanQuery[] {
                                new SpanTermQuery(new Term("text", "T")),
                                new SpanTermQuery(new Term("text", "T")) }, 0,
                                true),
                        new SpanTermQuery(new Term("text", "p:VAFIN")) },
                0, true);
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        /*
        http://stackoverflow.com/questions/1311199/finding-the-position-of-search-hits-from-lucene
        */

        StringBuilder payloadString = new StringBuilder();
        Map<Term, TermContext> termContexts = new HashMap<>();
        for (LeafReaderContext atomic : reader.leaves()) {
            Bits bitset = atomic.reader().getLiveDocs();
            //	    Spans spans = NearSpansOrdered();
            Spans spans = snquery.getSpans(atomic, bitset, termContexts);

            while (spans.next()) {
                int docid = atomic.docBase + spans.doc();
                if (spans.isPayloadAvailable()) {
                    for (byte[] payload : spans.getPayload()) {
                        /* retrieve payload for current matching span */
                        payloadString.append(new String(payload));
                        payloadString.append(" | ");
                    };
                };
            };
        };
        //	assertEquals(33, payloadString.length());
        assertEquals(0, payloadString.length());

        // [][][p:VAFIN]
        // without collecting payloads
        snquery = new SpanNearQuery(
                new SpanQuery[] {
                        new SpanNearQuery(new SpanQuery[] {
                                new SpanTermQuery(new Term("text", "T")),
                                new SpanTermQuery(new Term("text", "T")) }, 0,
                                true, false),
                        new SpanTermQuery(new Term("text", "p:VAFIN")) },
                0, true, false);
        assertEquals(1, searcher.search(snquery, 10).totalHits);

        payloadString = new StringBuilder();
        termContexts = new HashMap<>();
        for (LeafReaderContext atomic : reader.leaves()) {
            Bits bitset = atomic.reader().getLiveDocs();
            //	    Spans spans = NearSpansOrdered();
            Spans spans = snquery.getSpans(atomic, bitset, termContexts);

            while (spans.next()) {
                int docid = atomic.docBase + spans.doc();
                for (byte[] payload : spans.getPayload()) {
                    /* retrieve payload for current matching span */
                    payloadString.append(new String(payload));
                    payloadString.append(" | ");
                };
            };
        };
        assertEquals(0, payloadString.length());

        // [][][p:VAFIN] in s
        // ([e:s:<][]*[T] | [T & e:s:<]) [T] ([p:VAFIN & e:s:>] | [T][]*[e:s:>]

        /*

        SpanSegmentWithinQuery ssequery = new SpanSegmentWithinQuery(
            "text","s", new SpanSegmentSequenceQuery("text", "T", "T", "p:VAFIN")
            );
        assertEquals(0, searcher.search(ssequery.toQuery(), 10).totalHits);

        payloadString = new StringBuilder();
        termContexts = new HashMap<>();
        for (LeafReaderContext atomic : reader.leaves()) {
            Bits bitset = atomic.reader().getLiveDocs();
            // Spans spans = NearSpansOrdered();
            Spans spans = ssequery.toQuery().getSpans(atomic, bitset, termContexts);

            while (spans.next()) {
        	int docid = atomic.docBase + spans.doc();
        	for (byte[] payload : spans.getPayload()) {
        	/// retrieve payload for current matching span
        	    payloadString.append(new String(payload));
        	    payloadString.append(" | ");
        	};
            };
        };
        assertEquals(0, payloadString.length(), 1);

        ssequery = new SpanSegmentWithinQuery(
            "text","s", new SpanSegmentSequenceQuery("text", "T", "p:VAFIN")
            );

        assertEquals("for " + ssequery.toQuery(),
        	     1, searcher.search(ssequery.toQuery(), 10).totalHits);

        payloadString = new StringBuilder();
        termContexts = new HashMap<>();
        for (LeafReaderContext atomic : reader.leaves()) {
            Bits bitset = atomic.reader().getLiveDocs();
            // Spans spans = NearSpansOrdered();
            Spans spans = ssequery.toQuery().getSpans(atomic, bitset, termContexts);

            while (spans.next()) {
        	int docid = atomic.docBase + spans.doc();
        	for (byte[] payload : spans.getPayload()) {
        	    // retrieve payload for current matching span
        	    payloadString.append(new String(payload));
        	    payloadString.append(" | ");
        	};
        	fail("Doc: " + docid + " with " + spans.start() + "-" + spans.end() + " || " + payloadString.toString());
            };
        };
        assertEquals(20, payloadString.length());

        */

        // --------------------______>

        //	Spans spans = MultiSpansWrapper.wrap(searcher.getTopReaderContext(), ssequery.toQuery());
        /*
        TopDocs topDocs = is.search(snq, 1);
        Set<String> payloadSet = new HashSet<String>();
        for (int i = 0; i < topDocs.scoreDocs.length; i++) {
          while (spans.next()) {
            Collection<byte[]> payloads = spans.getPayload();

            for (final byte [] payload : payloads) {
              payloadSet.add(new String(payload, "UTF-8"));
            }
          }
        }
        */

        /*
        Alternativ:
        IndexReader reader = writer.getReader();
        writer.close();
        IndexSearcher searcher = newSearcher(reader);

        PayloadSpanUtil psu = new PayloadSpanUtil(searcher.getTopReaderContext());

        Collection<byte[]> payloads = psu.getPayloadsForQuery(new TermQuery(new Term(PayloadHelper.FIELD, "rr")));
        if(VERBOSE)
          System.out.println("Num payloads:" + payloads.size());
        for (final byte [] bytes : payloads) {
          if(VERBOSE)
            System.out.println(new String(bytes, "UTF-8"));
        }
        */

        /* new: */

        // PayloadHelper helper = new PayloadHelper();

        // Map<Term, TermContext> termContexts = new HashMap<>();
        //Spans spans;
        //spans = snquery.getSpans(searcher.getIndexReader());
        //    searcher = helper.setUp(similarity, 1000);
        /*
        IndexReader reader = search.getReader(querycontainer.getFoundry());
        Spans luceneSpans;
        Bits bitset = atomic.reader().getLiveDocs();
        for (byte[] payload : luceneSpans.getPayload())

        /* Iterate over all matching documents */
        /*
            while (luceneSpans.next() && total < config.getMaxhits()) {
        	Span matchSpan;
        	StringBuilder payloadString = new StringBuilder();
        	int docid = atomic.docBase + luceneSpans.doc();
        	String docname = search.retrieveDocname(docid,
        					querycontainer.getFoundry());
        					total++;

        	for (byte[] payload : luceneSpans.getPayload())
        */
        /* retrieve payload for current matching span */
        //				payloadString.append(new String(payload));

        /* create span containing result */
        /*
        		matchSpan = new Span(docname);
        		matchSpan.setIndexdocid(docid);
        		matchSpan.setLayer(querycontainer.getLayer());
        		matchSpan.storePayloads(payloadString.toString());
        		matchSpans.add(matchSpan);
        */
        /*
         * topdocs = searcher.search(new ConstantScoreQuery(corpusQ add
         * position to list of positions to be considered for later
         * searches
         */
        /*
        validValues.put(docname,
        		matchSpan.getPayload(config.getPrefix()));
        }
        */

        // Todo: API made by add() typisiert für queries, strings

        // SpanPayloadCheckQuery for sentences!

        /* Support regular expression in SpanSegmentQuery */
        // new Regexp();
        // new Term();

        /*
          Vielleicht: spanSegmentQuery(new Term(), new Wildcard(), new Regex());
         */

        // And Not ->
        //	SpanTermDiffQuery

        /*
        SpanNearQuery poquery = new SpanNearQuery(

        );
        */

        reader.close();

    };
};


text:
"""Constants for the Renault integration tests."""
from homeassistant.components.binary_sensor import BinarySensorDeviceClass
from homeassistant.components.renault.const import (
    CONF_KAMEREON_ACCOUNT_ID,
    CONF_LOCALE,
    DEVICE_CLASS_CHARGE_MODE,
    DEVICE_CLASS_CHARGE_STATE,
    DEVICE_CLASS_PLUG_STATE,
    DOMAIN,
)
from homeassistant.components.select.const import ATTR_OPTIONS
from homeassistant.components.sensor import (
    ATTR_STATE_CLASS,
    SensorDeviceClass,
    SensorStateClass,
)
from homeassistant.const import (
    ATTR_DEVICE_CLASS,
    ATTR_ENTITY_ID,
    ATTR_ICON,
    ATTR_IDENTIFIERS,
    ATTR_MANUFACTURER,
    ATTR_MODEL,
    ATTR_NAME,
    ATTR_STATE,
    ATTR_SW_VERSION,
    ATTR_UNIT_OF_MEASUREMENT,
    CONF_PASSWORD,
    CONF_USERNAME,
    ELECTRIC_CURRENT_AMPERE,
    ENERGY_KILO_WATT_HOUR,
    LENGTH_KILOMETERS,
    PERCENTAGE,
    POWER_KILO_WATT,
    STATE_NOT_HOME,
    STATE_OFF,
    STATE_ON,
    STATE_UNKNOWN,
    TEMP_CELSIUS,
    TIME_MINUTES,
    VOLUME_LITERS,
    Platform,
)

ATTR_DEFAULT_DISABLED = "default_disabled"
ATTR_UNIQUE_ID = "unique_id"

FIXED_ATTRIBUTES = (
    ATTR_DEVICE_CLASS,
    ATTR_OPTIONS,
    ATTR_STATE_CLASS,
    ATTR_UNIT_OF_MEASUREMENT,
)
DYNAMIC_ATTRIBUTES = (ATTR_ICON,)

ICON_FOR_EMPTY_VALUES = {
    "binary_sensor.reg_number_hvac": "mdi:fan-off",
    "select.reg_number_charge_mode": "mdi:calendar-remove",
    "sensor.reg_number_charge_state": "mdi:flash-off",
    "sensor.reg_number_plug_state": "mdi:power-plug-off",
}

MOCK_ACCOUNT_ID = "account_id_1"

# Mock config data to be used across multiple tests
MOCK_CONFIG = {
    CONF_USERNAME: "email@test.com",
    CONF_PASSWORD: "test",
    CONF_KAMEREON_ACCOUNT_ID: "account_id_1",
    CONF_LOCALE: "fr_FR",
}

MOCK_VEHICLES = {
    "zoe_40": {
        "expected_device": {
            ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")},
            ATTR_MANUFACTURER: "Renault",
            ATTR_MODEL: "Zoe",
            ATTR_NAME: "REG-NUMBER",
            ATTR_SW_VERSION: "X101VE",
        },
        "endpoints": {
            "battery_status": "battery_status_charging.json",
            "charge_mode": "charge_mode_always.json",
            "cockpit": "cockpit_ev.json",
            "hvac_status": "hvac_status.1.json",
        },
        Platform.BINARY_SENSOR: [
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.PLUG,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in",
                ATTR_STATE: STATE_ON,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_plugged_in",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.BATTERY_CHARGING,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_charging",
                ATTR_STATE: STATE_ON,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging",
            },
            {
                ATTR_ENTITY_ID: "binary_sensor.reg_number_hvac",
                ATTR_ICON: "mdi:fan-off",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_status",
            },
        ],
        Platform.BUTTON: [
            {
                ATTR_ENTITY_ID: "button.reg_number_start_air_conditioner",
                ATTR_ICON: "mdi:air-conditioner",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_air_conditioner",
            },
            {
                ATTR_ENTITY_ID: "button.reg_number_start_charge",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_charge",
            },
        ],
        Platform.DEVICE_TRACKER: [],
        Platform.SELECT: [
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
                ATTR_ENTITY_ID: "select.reg_number_charge_mode",
                ATTR_ICON: "mdi:calendar-remove",
                ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
                ATTR_STATE: "always",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode",
            },
        ],
        Platform.SENSOR: [
            {
                ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: "141",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.ENERGY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
                ATTR_STATE: "31",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy",
                ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.BATTERY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
                ATTR_STATE: "60",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level",
                ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity",
                ATTR_STATE: "2020-01-12T21:40:16+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_last_activity",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
                ATTR_STATE: "20",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature",
                ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
                ATTR_ICON: "mdi:flash",
                ATTR_STATE: "charge_in_progress",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_state",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.POWER,
                ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
                ATTR_STATE: "0.027",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power",
                ATTR_UNIT_OF_MEASUREMENT: POWER_KILO_WATT,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
                ATTR_ICON: "mdi:timer",
                ATTR_STATE: "145",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time",
                ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_mileage",
                ATTR_ICON: "mdi:sign-direction",
                ATTR_STATE: "49114",
                ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
                ATTR_ENTITY_ID: "sensor.reg_number_outside_temperature",
                ATTR_STATE: "8.0",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature",
                ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_hvac_soc_threshold",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_soc_threshold",
                ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_hvac_last_activity",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_last_activity",
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
                ATTR_ICON: "mdi:power-plug",
                ATTR_STATE: "plugged",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state_code",
            },
        ],
    },
    "zoe_50": {
        "expected_device": {
            ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777999")},
            ATTR_MANUFACTURER: "Renault",
            ATTR_MODEL: "Zoe",
            ATTR_NAME: "REG-NUMBER",
            ATTR_SW_VERSION: "X102VE",
        },
        "endpoints": {
            "battery_status": "battery_status_not_charging.json",
            "charge_mode": "charge_mode_schedule.json",
            "cockpit": "cockpit_ev.json",
            "hvac_status": "hvac_status.2.json",
            "location": "location.json",
            "lock_status": "lock_status.1.json",
            "res_state": "res_state.1.json",
        },
        Platform.BINARY_SENSOR: [
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.PLUG,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_plugged_in",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.BATTERY_CHARGING,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_charging",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging",
            },
            {
                ATTR_ENTITY_ID: "binary_sensor.reg_number_hvac",
                ATTR_ICON: "mdi:fan-off",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_lock_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_rear_left_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_rear_right_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_driver_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_passenger_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hatch_status",
            },
        ],
        Platform.BUTTON: [
            {
                ATTR_ENTITY_ID: "button.reg_number_start_air_conditioner",
                ATTR_ICON: "mdi:air-conditioner",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_air_conditioner",
            },
            {
                ATTR_ENTITY_ID: "button.reg_number_start_charge",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_start_charge",
            },
        ],
        Platform.DEVICE_TRACKER: [
            {
                ATTR_ENTITY_ID: "device_tracker.reg_number_location",
                ATTR_ICON: "mdi:car",
                ATTR_STATE: STATE_NOT_HOME,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_location",
            }
        ],
        Platform.SELECT: [
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
                ATTR_ENTITY_ID: "select.reg_number_charge_mode",
                ATTR_ICON: "mdi:calendar-clock",
                ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
                ATTR_STATE: "schedule_mode",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_mode",
            },
        ],
        Platform.SENSOR: [
            {
                ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: "128",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_autonomy",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.ENERGY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
                ATTR_STATE: "0",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_available_energy",
                ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.BATTERY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
                ATTR_STATE: "50",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_level",
                ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity",
                ATTR_STATE: "2020-11-17T08:06:48+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_last_activity",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_battery_temperature",
                ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
                ATTR_ICON: "mdi:flash-off",
                ATTR_STATE: "charge_error",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charge_state",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.CURRENT,
                ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_power",
                ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
                ATTR_ICON: "mdi:timer",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_charging_remaining_time",
                ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_mileage",
                ATTR_ICON: "mdi:sign-direction",
                ATTR_STATE: "49114",
                ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_mileage",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
                ATTR_ENTITY_ID: "sensor.reg_number_outside_temperature",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_outside_temperature",
                ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_hvac_soc_threshold",
                ATTR_STATE: "30.0",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_soc_threshold",
                ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_hvac_last_activity",
                ATTR_STATE: "2020-12-03T00:00:00+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_hvac_last_activity",
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
                ATTR_ICON: "mdi:power-plug-off",
                ATTR_STATE: "unplugged",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_plug_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity",
                ATTR_STATE: "2020-02-18T16:58:38+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_location_last_activity",
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start",
                ATTR_STATE: "Stopped, ready for RES",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code",
                ATTR_STATE: "10",
                ATTR_UNIQUE_ID: "vf1aaaaa555777999_res_state_code",
            },
        ],
    },
    "captur_phev": {
        "expected_device": {
            ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")},
            ATTR_MANUFACTURER: "Renault",
            ATTR_MODEL: "Captur ii",
            ATTR_NAME: "REG-NUMBER",
            ATTR_SW_VERSION: "XJB1SU",
        },
        "endpoints": {
            "battery_status": "battery_status_charging.json",
            "charge_mode": "charge_mode_always.json",
            "cockpit": "cockpit_fuel.json",
            "location": "location.json",
            "lock_status": "lock_status.1.json",
            "res_state": "res_state.1.json",
        },
        Platform.BINARY_SENSOR: [
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.PLUG,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_plugged_in",
                ATTR_STATE: STATE_ON,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_plugged_in",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.BATTERY_CHARGING,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_charging",
                ATTR_STATE: STATE_ON,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_lock_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_left_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_right_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_driver_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_passenger_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_hatch_status",
            },
        ],
        Platform.BUTTON: [
            {
                ATTR_ENTITY_ID: "button.reg_number_start_air_conditioner",
                ATTR_ICON: "mdi:air-conditioner",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_start_air_conditioner",
            },
            {
                ATTR_ENTITY_ID: "button.reg_number_start_charge",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_start_charge",
            },
        ],
        Platform.DEVICE_TRACKER: [
            {
                ATTR_ENTITY_ID: "device_tracker.reg_number_location",
                ATTR_ICON: "mdi:car",
                ATTR_STATE: STATE_NOT_HOME,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_location",
            }
        ],
        Platform.SELECT: [
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_MODE,
                ATTR_ENTITY_ID: "select.reg_number_charge_mode",
                ATTR_ICON: "mdi:calendar-remove",
                ATTR_OPTIONS: ["always", "always_charging", "schedule_mode"],
                ATTR_STATE: "always",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_charge_mode",
            },
        ],
        Platform.SENSOR: [
            {
                ATTR_ENTITY_ID: "sensor.reg_number_battery_autonomy",
                ATTR_ICON: "mdi:ev-station",
                ATTR_STATE: "141",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_autonomy",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.ENERGY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_available_energy",
                ATTR_STATE: "31",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_available_energy",
                ATTR_UNIT_OF_MEASUREMENT: ENERGY_KILO_WATT_HOUR,
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.BATTERY,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_level",
                ATTR_STATE: "60",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_level",
                ATTR_UNIT_OF_MEASUREMENT: PERCENTAGE,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_last_activity",
                ATTR_STATE: "2020-01-12T21:40:16+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_last_activity",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.TEMPERATURE,
                ATTR_ENTITY_ID: "sensor.reg_number_battery_temperature",
                ATTR_STATE: "20",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_battery_temperature",
                ATTR_UNIT_OF_MEASUREMENT: TEMP_CELSIUS,
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_CHARGE_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_charge_state",
                ATTR_ICON: "mdi:flash",
                ATTR_STATE: "charge_in_progress",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_charge_state",
            },
            {
                ATTR_DEVICE_CLASS: SensorDeviceClass.CURRENT,
                ATTR_ENTITY_ID: "sensor.reg_number_charging_power",
                ATTR_STATE: "27.0",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_power",
                ATTR_UNIT_OF_MEASUREMENT: ELECTRIC_CURRENT_AMPERE,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_charging_remaining_time",
                ATTR_ICON: "mdi:timer",
                ATTR_STATE: "145",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_charging_remaining_time",
                ATTR_UNIT_OF_MEASUREMENT: TIME_MINUTES,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy",
                ATTR_ICON: "mdi:gas-station",
                ATTR_STATE: "35",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity",
                ATTR_ICON: "mdi:fuel",
                ATTR_STATE: "3",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity",
                ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_mileage",
                ATTR_ICON: "mdi:sign-direction",
                ATTR_STATE: "5567",
                ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEVICE_CLASS: DEVICE_CLASS_PLUG_STATE,
                ATTR_ENTITY_ID: "sensor.reg_number_plug_state",
                ATTR_ICON: "mdi:power-plug",
                ATTR_STATE: "plugged",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_plug_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity",
                ATTR_STATE: "2020-02-18T16:58:38+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity",
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start",
                ATTR_STATE: "Stopped, ready for RES",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code",
                ATTR_STATE: "10",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state_code",
            },
        ],
    },
    "captur_fuel": {
        "expected_device": {
            ATTR_IDENTIFIERS: {(DOMAIN, "VF1AAAAA555777123")},
            ATTR_MANUFACTURER: "Renault",
            ATTR_MODEL: "Captur ii",
            ATTR_NAME: "REG-NUMBER",
            ATTR_SW_VERSION: "XJB1SU",
        },
        "endpoints": {
            "cockpit": "cockpit_fuel.json",
            "location": "location.json",
            "lock_status": "lock_status.1.json",
            "res_state": "res_state.1.json",
        },
        Platform.BINARY_SENSOR: [
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.LOCK,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_lock",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_lock_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_left_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_left_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_rear_right_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_rear_right_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_driver_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_driver_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_passenger_door",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_passenger_door_status",
            },
            {
                ATTR_DEVICE_CLASS: BinarySensorDeviceClass.DOOR,
                ATTR_ENTITY_ID: "binary_sensor.reg_number_hatch",
                ATTR_STATE: STATE_OFF,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_hatch_status",
            },
        ],
        Platform.BUTTON: [
            {
                ATTR_ENTITY_ID: "button.reg_number_start_air_conditioner",
                ATTR_ICON: "mdi:air-conditioner",
                ATTR_STATE: STATE_UNKNOWN,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_start_air_conditioner",
            },
        ],
        Platform.DEVICE_TRACKER: [
            {
                ATTR_ENTITY_ID: "device_tracker.reg_number_location",
                ATTR_ICON: "mdi:car",
                ATTR_STATE: STATE_NOT_HOME,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_location",
            }
        ],
        Platform.SELECT: [],
        Platform.SENSOR: [
            {
                ATTR_ENTITY_ID: "sensor.reg_number_fuel_autonomy",
                ATTR_ICON: "mdi:gas-station",
                ATTR_STATE: "35",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_autonomy",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_fuel_quantity",
                ATTR_ICON: "mdi:fuel",
                ATTR_STATE: "3",
                ATTR_STATE_CLASS: SensorStateClass.MEASUREMENT,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_fuel_quantity",
                ATTR_UNIT_OF_MEASUREMENT: VOLUME_LITERS,
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_mileage",
                ATTR_ICON: "mdi:sign-direction",
                ATTR_STATE: "5567",
                ATTR_STATE_CLASS: SensorStateClass.TOTAL_INCREASING,
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_mileage",
                ATTR_UNIT_OF_MEASUREMENT: LENGTH_KILOMETERS,
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_DEVICE_CLASS: SensorDeviceClass.TIMESTAMP,
                ATTR_ENTITY_ID: "sensor.reg_number_location_last_activity",
                ATTR_STATE: "2020-02-18T16:58:38+00:00",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_location_last_activity",
            },
            {
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start",
                ATTR_STATE: "Stopped, ready for RES",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state",
            },
            {
                ATTR_DEFAULT_DISABLED: True,
                ATTR_ENTITY_ID: "sensor.reg_number_remote_engine_start_code",
                ATTR_STATE: "10",
                ATTR_UNIQUE_ID: "vf1aaaaa555777123_res_state_code",
            },
        ],
    },
}

redpajama_set_name: RedPajamaGithub


text:
title: <init> -
---
//[kotlin-util](../../index.md)/[it.czerwinski.kotlin.util](../index.md)/[Failure](index.md)/[<init>](-init-.md)

# <init>
[Kotlin utilities]
Content
fun [<init>](-init-.md)(exception: [Throwable](https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-throwable/index.html))


text:
import { createElement } from "react";
import ControlModule, {
  Range,
  Select,
} from "../../../../components/organisms/ControlModule";

const SelectOscType = ({ defaultValue, onChange }) =>
  createElement(
    Select,
    {
      defaultValue,
      label: "Type",
      onChange,
    },
    createElement("option", { value: "sawtooth" }, "Sawtooth"),
    createElement("option", { value: "sine" }, "Sine"),
    createElement("option", { value: "square" }, "Square"),
    createElement("option", { value: "triangle" }, "Triangle")
  );

export default ({ detune, gain, id, pan, pitch, type, updateOsc }) =>
  createElement(
    ControlModule,
    { title: `Osc ${id + 1}` },
    createElement(SelectOscType, {
      defaultValue: type,
      onChange: ({ target: { value } }) => updateOsc("type", value),
    }),
    createElement(Range, {
      defaultValue: gain,
      label: "Gain",
      max: 2,
      onInput: (e) => updateOsc("gain", Number(e.target.value)),
    }),
    createElement(Range, {
      defaultValue: pan,
      label: "Pan",
      min: -1,
      onInput: (e) => updateOsc("pan", Number(e.target.value)),
    }),
    createElement(Range, {
      defaultValue: pitch,
      displayValue: pitch,
      label: "Pitch",
      max: 24,
      min: -24,
      onInput: (e) => updateOsc("pitch", Number(e.target.value)),
      step: 1,
    }),
    createElement(Range, {
      defaultValue: detune,
      displayValue: detune,
      label: "Detune",
      max: 50,
      min: -50,
      onInput: (e) => updateOsc("detune", Number(e.target.value)),
    })
  );


text:
using System;
using System.Collections.Generic;
using System.Data;
using System.Drawing;
using System.Text;
using Aspose.Cells;

namespace Memento.Component.Office.Excel
{
    /// <summary>
    /// Aspose.Cells 辅助类
    /// </summary>
    public partial class AsposeHelper
    {
        #region 成员变量

        private Workbook m_Workbook;        // 工作表
        private Worksheet m_Worksheet;      // 工作簿

        private Style m_HeaderCellStyle;    // 标题单元格样式
        private Style m_CommonCellStyle;    // 普通单元格样式
        private Style m_TextCellStyle;      // 文本单元格样式
        private Style m_NumericCellStyle;   // 数值单元格样式
        private Style m_DateTimeCellStyle;  // 时间单元格样式

        private Encoding m_Encoding;        // 编码格式

        #endregion

        #region 公开属性

        /// <summary>
        /// 根据列头名称获取列数据类型
        /// </summary>
        public Func<string, Type> GetColSettingByColName;

        #endregion

        #region 私有属性

        /// <summary>
        /// 标题单元格样式
        /// </summary>
        private Style HeaderCellStyle
        {
            get
            {
                if (m_HeaderCellStyle == null)
                {
                    m_HeaderCellStyle = CreateStyle();
                    m_HeaderCellStyle.IsTextWrapped = true;
                    m_HeaderCellStyle.HorizontalAlignment = TextAlignmentType.Center;
                    m_HeaderCellStyle.VerticalAlignment = TextAlignmentType.Center;
                    m_HeaderCellStyle.Borders.SetStyle(CellBorderType.Thin);
                    m_HeaderCellStyle.Borders.DiagonalStyle = CellBorderType.None;
                    m_HeaderCellStyle.Font.Name = "宋体";
                    m_HeaderCellStyle.Font.Size = 12;
                    m_HeaderCellStyle.Font.IsBold = true;
                }

                return m_HeaderCellStyle;
            }
        }

        /// <summary>
        /// 普通单元格样式
        /// </summary>
        private Style CommonCellStyle
        {
            get
            {
                if (m_CommonCellStyle == null)
                {
                    m_CommonCellStyle = CreateStyle();
                    m_CommonCellStyle.HorizontalAlignment = TextAlignmentType.Center;
                    m_CommonCellStyle.VerticalAlignment = TextAlignmentType.Center;
                    m_CommonCellStyle.Borders.DiagonalStyle = CellBorderType.None;
                    m_CommonCellStyle.Font.Name = "宋体";
                    m_CommonCellStyle.Font.Size = 10;
                    m_CommonCellStyle.Font.IsBold = false;
                    m_CommonCellStyle.Pattern = BackgroundType.None;
                }

                return m_CommonCellStyle;
            }
        }

        /// <summary>
        /// 文本单元格样式
        /// </summary>
        private Style TextCellStyle
        {
            get
            {
                if (m_TextCellStyle == null)
                {
                    m_TextCellStyle = CreateStyle();
                    m_TextCellStyle.Copy(CommonCellStyle);
                    m_TextCellStyle.HorizontalAlignment = TextAlignmentType.Left;
                }

                return m_TextCellStyle;
            }
        }

        /// <summary>
        /// 数值单元格样式
        /// </summary>
        private Style NumericCellStyle
        {
            get
            {
                if (m_NumericCellStyle == null)
                {
                    m_NumericCellStyle = CreateStyle();
                    m_NumericCellStyle.Copy(CommonCellStyle);
                    m_NumericCellStyle.HorizontalAlignment = TextAlignmentType.Right;
                }

                return m_NumericCellStyle;
            }
        }

        /// <summary>
        /// 时间单元格样式
        /// </summary>
        private Style DateTimeCellStyle
        {
            get
            {
                if (m_DateTimeCellStyle == null)
                {
                    m_DateTimeCellStyle = CreateStyle();
                    m_DateTimeCellStyle.Copy(CommonCellStyle);
                    m_DateTimeCellStyle.CultureCustom = "yyyy-mm-dd";
                    m_DateTimeCellStyle.Custom = "yyyy-mm-dd";
                }

                return m_DateTimeCellStyle;
            }
        }

        #endregion

        #region 构造函数

        /// <summary>
        /// Aspose.Cells 辅助类
        /// </summary>
        public AsposeHelper()
        {
            m_Encoding = Encoding.GetEncoding("gb2312");
        }

        /// <summary>
        /// 析构函数
        /// </summary>
        ~AsposeHelper()
        {
            Dispose();
        }

        #endregion

        #region 私有方法

        // 释放数据
        private void Dispose()
        {
            m_Workbook = null;
            m_Worksheet = null;
            GC.Collect();
            GC.WaitForFullGCComplete();
        }

        // 获取单元格数据类型
        private Type GetCellType(Cell cell)
        {
            Type result = typeof(string);
            Style style = cell.GetStyle();
            switch (cell.Type)
            {
                case CellValueType.IsBool:
                    result = typeof(bool);
                    break;
                case CellValueType.IsDateTime:
                    result = typeof(DateTime);
                    break;
                case CellValueType.IsError:
                    break;
                case CellValueType.IsNull:
                    break;
                case CellValueType.IsNumeric:
                    result = typeof(int);
                    if (cell.Value != null)
                    {
                        result = cell.Value.GetType();
                    }
                    break;
                case CellValueType.IsString:
                    break;
                case CellValueType.IsUnknown:
                    break;
                default:
                    break;
            }

            return result;
        }

        // 创建工作簿
        private void CreateWorksheet(DataTable dataTable, Dictionary<Tuple<int, int>, Color> markCells = null, List<int> exportColIndexList = null)
        {
            string sheetName = dataTable.TableName;
            if (string.IsNullOrEmpty(sheetName))
            {
                sheetName = "Sheet " + (m_Workbook.Worksheets.Count + 1);
            }
            Worksheet sheet = m_Workbook.Worksheets.Add(sheetName);
            CreateHeader(sheet, dataTable, exportColIndexList);
            CreateContentRows(ref sheet, dataTable, 1, markCells, exportColIndexList);
        }

        // 创建 Excel 表头
        private void CreateHeader(Worksheet sheet, DataTable dataTable, List<int> exportColIndexList = null)
        {
            Cells cells = sheet.Cells;
            if (exportColIndexList == null)
            {
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    DataColumn dataColumn = dataTable.Columns[i];
                    cells[0, i].PutValue(dataColumn.Caption);
                    cells[0, i].SetStyle(HeaderCellStyle);
                }
            }
            else
            {
                int col = 0;
                foreach (int i in exportColIndexList)
                {
                    DataColumn dataColumn = dataTable.Columns[i];
                    cells[0, col].PutValue(dataColumn.Caption);
                    cells[0, col].SetStyle(HeaderCellStyle);
                    col++;
                }
            }
            sheet.AutoFitRow(0);
            sheet.FreezePanes(0, 0, 1, exportColIndexList.Count);
        }

        // 创建内容数据行
        private void CreateContentRows(ref Worksheet sheet, DataTable dataTable, int startRowIndex, Dictionary<Tuple<int, int>, Color> markCells = null, List<int> exportColIndexList = null)
        {
            int sheetCount = 0;
            int rowIndex = 0;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (startRowIndex == ExcelCommon.MaxRowsCount2007)// 数据达到支持的最大行数时,另起一个Sheet存储数据
                {
                    sheetCount++;
                    sheet = m_Workbook.Worksheets.Add(sheet.Name + "(" + sheetCount + ")");
                    CreateHeader(sheet, dataTable, exportColIndexList);
                    startRowIndex = 1;
                }
                Row row = sheet.Cells.Rows[startRowIndex];
                CreateCell(sheet, row, dataRow, rowIndex, markCells, exportColIndexList);
                startRowIndex++;
                rowIndex++;
            }
        }

        private void ApplyStyle(Worksheet sheet)
        {

        }

        // 创建一行的单元格
        private void CreateCell(Worksheet sheet, Row row, DataRow dataRow, int rowIndex, Dictionary<Tuple<int, int>, Color> markCells = null, List<int> exportColIndexList = null)
        {
            if (exportColIndexList == null)// 完整导出
            {
                for (int colIndex = 0; colIndex < dataRow.ItemArray.Length; colIndex++)
                {
                    Cell cell = sheet.Cells[row.Index, colIndex];
                    cell.PutValue(dataRow[colIndex]);
                    TypeCode code = Type.GetTypeCode(dataRow[colIndex].GetType());
                    SetCellStyle(cell, code, rowIndex, colIndex, markCells);
                }
            }
            else// 导出指定列
            {
                int col = 0;
                foreach (int colIndex in exportColIndexList)
                {
                    Cell cell = sheet.Cells[row.Index, col];
                    cell.PutValue(dataRow[colIndex]);
                    TypeCode code = Type.GetTypeCode(dataRow[colIndex].GetType());
                    SetCellStyle(cell, code, rowIndex, colIndex, markCells);
                    col++;
                }
            }
        }

        // 获取单元格内容
        private object GetCellValue(Cell cell, Type targetType)
        {
            object result = null;
            if (cell == null)
                return result;

            if (cell.IsMerged)// 合并区域获取合并区域左上角第一个单元格内容
            {
                Range range = cell.GetMergedRange();
                cell = range[range.FirstRow, range.FirstColumn];
            }
            switch (cell.Type)
            {
                case CellValueType.IsUnknown:
                case CellValueType.IsError:
                case CellValueType.IsString:
                    if (string.IsNullOrEmpty(cell.StringValue) ||
                        cell.StringValue.Trim().Equals("null", StringComparison.CurrentCultureIgnoreCase))
                    {
                        result = "";
                    }
                    else
                    {
                        result = cell.StringValue.Trim();
                    }
                    break;
                case CellValueType.IsNumeric:
                    result = Convert.ChangeType(cell.Value, targetType);
                    break;
                case CellValueType.IsBool:
                    result = cell.BoolValue;
                    break;
                case CellValueType.IsDateTime:
                    if (targetType == typeof(DateTime))
                    {
                        result = cell.DateTimeValue;
                    }
                    else
                    {
                        result = cell.StringValue;
                    }
                    break;
                case CellValueType.IsNull:
                    result = "";
                    break;
            }

            return result;
        }

        // 获取数据类型对应默认的样式
        private Style GetCellDefaultStyle(Type dataType)
        {
            Style result = CommonCellStyle;
            TypeCode code = Type.GetTypeCode(dataType);
            switch (code)
            {
                case TypeCode.Empty:
                case TypeCode.DBNull:
                case TypeCode.Object:
                case TypeCode.Boolean:
                case TypeCode.String:
                    result.Copy(TextCellStyle);
                    break;
                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    result.Copy(NumericCellStyle);
                    break;
                case TypeCode.DateTime:
                    result.Copy(DateTimeCellStyle);
                    break;
            }

            return result;
        }

        // 设置单元格样式
        private void SetCellStyle(Cell cell, TypeCode code, int rowIndex, int colIndex, Dictionary<Tuple<int, int>, Color> markCells)
        {
            Style cellStyle = CommonCellStyle;
            switch (code)
            {
                case TypeCode.Char:
                case TypeCode.SByte:
                case TypeCode.Byte:
                case TypeCode.Int16:
                case TypeCode.UInt16:
                case TypeCode.Int32:
                case TypeCode.UInt32:
                case TypeCode.Int64:
                case TypeCode.UInt64:
                case TypeCode.Single:
                case TypeCode.Double:
                case TypeCode.Decimal:
                    cellStyle = NumericCellStyle;
                    break;
                case TypeCode.DateTime:
                    cellStyle = DateTimeCellStyle;
                    break;
                case TypeCode.String:
                case TypeCode.Empty:
                case TypeCode.DBNull:
                case TypeCode.Object:
                case TypeCode.Boolean:
                default:
                    cellStyle = TextCellStyle;
                    break;
            }
            if (markCells != null)
            {
                Tuple<int, int> location = new Tuple<int, int>(rowIndex, colIndex);
                if (markCells.ContainsKey(location))
                {
                    Style newStyle = CreateStyle();
                    newStyle.Copy(cellStyle);
                    newStyle.Pattern = BackgroundType.Solid;
                    newStyle.ForegroundColor = markCells[location];// 背景色
                    cellStyle = newStyle;
                }
            }
            cell.SetStyle(cellStyle);
        }

        // 创建样式
        private Style CreateStyle()
        {
            return m_Workbook.CreateStyle();
            // return m_Workbook.Styles[m_Workbook.Styles.Add()];
        }

        #endregion

        #region 创建工作簿

        // 创建工作簿
        private void CreateWorksheet(DataTable dataTable, List<AsposeColumn> exportColSetting)
        {
            string sheetName = dataTable.TableName;
            if (string.IsNullOrEmpty(sheetName))
            {
                sheetName = "Sheet " + (m_Workbook.Worksheets.Count + 1);
            }
            Worksheet sheet = m_Workbook.Worksheets.Add(sheetName);
            CreateHeader(sheet, dataTable, ref exportColSetting);
            CreateContentRows(ref sheet, dataTable, 1, exportColSetting);
        }

        // 创建 Excel 表头
        private void CreateHeader(Worksheet sheet, DataTable dataTable, ref List<AsposeColumn> exportColSetting)
        {
            Cells cells = sheet.Cells;
            if (exportColSetting == null)
            {
                exportColSetting = new List<AsposeColumn>();
                for (int i = 0; i < dataTable.Columns.Count; i++)
                {
                    DataColumn dataColumn = dataTable.Columns[i];
                    cells[0, i].PutValue(dataColumn.Caption);
                    cells[0, i].SetStyle(HeaderCellStyle);

                    exportColSetting.Add(new AsposeColumn() { DataColIndex = i, ExcelColIndex = i, DataType = dataColumn.DataType, CustomFilter = null });
                }
            }
            else
            {
                int col = 0;
                foreach (AsposeColumn item in exportColSetting)
                {
                    DataColumn dataColumn = dataTable.Columns[item.DataColIndex];
                    cells[0, col].PutValue(dataColumn.Caption);
                    cells[0, col].SetStyle(HeaderCellStyle);
                    item.ExcelColIndex = col;
                    item.DataType = dataColumn.DataType;

                    col++;
                }
            }
            // 列头行自动行高
            sheet.AutoFitRow(0);
            // 列头自动筛选
            string endColName = ExcelCommon.CreateExcelColName(exportColSetting.Count - 1);
            sheet.AutoFilter.Range = string.Format("A1:{0}1", endColName);
            // 固定列头行
            sheet.FreezePanes(1, 0, 1, exportColSetting.Count);
        }

        // 创建内容数据行
        private void CreateContentRows(ref Worksheet sheet, DataTable dataTable, int startRowIndex, List<AsposeColumn> exportColSetting)
        {
            int sheetCount = 0;
            int rowIndex = 0;
            foreach (DataRow dataRow in dataTable.Rows)
            {
                if (startRowIndex == ExcelCommon.MaxRowsCount2007)// 数据达到支持的最大行数时,另起一个Sheet存储数据
                {
                    sheetCount++;
                    sheet = m_Workbook.Worksheets.Add(sheet.Name + "(" + sheetCount + ")");
                    CreateHeader(sheet, dataTable, ref exportColSetting);
                    startRowIndex = 1;
                }
                Row row = sheet.Cells.Rows[startRowIndex];
                CreateCell(sheet, row.Index, dataRow, exportColSetting);
                startRowIndex++;
                rowIndex++;
            }
        }

        // 创建一行的单元格
        private void CreateCell(Worksheet sheet, int xlRowIndex, DataRow dataRow, List<AsposeColumn> exportColSetting)
        {
            foreach (AsposeColumn column in exportColSetting)
            {
                Cell cell = sheet.Cells[xlRowIndex, column.ExcelColIndex];
                object cellValue = dataRow[column.DataColIndex];
                Style cellStyle = GetCellDefaultStyle(column.DataType);

                // 应用自定义列
                if (column.CustomFilter != null)
                {
                    AsposeCellStyle customCellStyle = new AsposeCellStyle();
                    cellValue = column.CustomFilter(column.DataColIndex, dataRow, ref customCellStyle);
                    if (customCellStyle != null)
                    {
                        ApplyCellStyle(ref cellStyle, customCellStyle);
                    }
                }
                cell.SetStyle(cellStyle);
                cell.PutValue(cellValue);
            }
        }

        private void ApplyCellStyle(ref Style style, AsposeCellStyle cellStyle)
        {
            style.ForegroundColor = cellStyle.BackgroundColor;
            if (style.ForegroundColor != Color.Transparent)
            {
                style.Pattern = BackgroundType.Solid;
            }
            style.Font.Color = cellStyle.FontColor;
            if (cellStyle.FontSize > 0)
            {
                style.Font.Size = cellStyle.FontSize;
            }
            style.Font.IsBold = cellStyle.IsBold;
            if (!string.IsNullOrEmpty(cellStyle.FontName))
            {
                style.Font.Name = cellStyle.FontName;
            }
            style.HorizontalAlignment = (TextAlignmentType)cellStyle.HorizontalAlignment;
        }

        #endregion
    }
}


text:
package org.fest.assertions.api;

import static junit.framework.Assert.assertSame;
import static org.fest.assertions.test.DoubleArrayFactory.*;
import static org.mockito.Mockito.*;

import org.fest.assertions.internal.DoubleArrays;
import org.junit.*;

/**
 * Tests for <code>{@link DoubleArrayAssert#containsOnly(double...)}</code>.
 *
 * @author Alex Ruiz
 */
public class DoubleArrayAssert_containsOnly_Test {

  private DoubleArrays arrays;
  private DoubleArrayAssert assertions;

  @Before public void setUp() {
    arrays = mock(DoubleArrays.class);
    assertions = new DoubleArrayAssert(emptyArray());
    assertions.arrays = arrays;
  }

  @Test public void should_verify_that_actual_contains_given_values_only() {
    assertions.containsOnly(6d, 8d);
    verify(arrays).assertContainsOnly(assertions.info, assertions.actual, array(6d, 8d));
  }

  @Test public void should_return_this() {
    DoubleArrayAssert returned = assertions.containsOnly(8d);
    assertSame(assertions, returned);
  }
}


text:
<?php

/*
 * This file is part of the PHP CS utility.
 *
 * (c) Fabien Potencier <fabien@symfony.com>
 *
 * This source file is subject to the MIT license that is bundled
 * with this source code in the file LICENSE.
 */

namespace Symfony\CS\Fixer\Symfony;

use Symfony\CS\AbstractFixer;
use Symfony\CS\Tokenizer\Tokens;
use Symfony\CS\Utils;

/**
 * @author Ceeram <ceeram@cakephp.org>
 * @author Graham Campbell <graham@mineuk.com>
 */
class PhpdocIndentFixer extends AbstractFixer
{
    /**
     * {@inheritdoc}
     */
    public function fix(\SplFileInfo $file, $content)
    {
        $tokens = Tokens::fromCode($content);

        foreach ($tokens->findGivenKind(T_DOC_COMMENT) as $index => $token) {
            $nextIndex = $tokens->getNextMeaningfulToken($index);

            // skip if there is no next token or if next token is block end `}`
            if (null === $nextIndex || $tokens[$nextIndex]->equals('}')) {
                continue;
            }

            $prevToken = $tokens[$index - 1];

            // ignore inline docblocks
            if (
                $prevToken->isGivenKind(T_OPEN_TAG)
                || ($prevToken->isWhitespace(array('whitespaces' => " \t")) && !$tokens[$index - 2]->isGivenKind(T_OPEN_TAG))
                || $prevToken->equalsAny(array(';', '{'))
            ) {
                continue;
            }

            $indent = '';
            if ($tokens[$nextIndex - 1]->isWhitespace()) {
                $indent = Utils::calculateTrailingWhitespaceIndent($tokens[$nextIndex - 1]);
            }

            $prevToken->setContent($this->fixWhitespaceBefore($prevToken->getContent(), $indent));
            $token->setContent($this->fixDocBlock($token->getContent(), $indent));
        }

        return $tokens->generateCode();
    }

    /**
     * {@inheritdoc}
     */
    public function getDescription()
    {
        return 'Docblocks should have the same indentation as the documented subject.';
    }

    /**
     * {@inheritdoc}
     */
    public function getPriority()
    {
        /*
         * Should be run before all other docblock fixers apart from the
         * phpdoc_to_comment fixer to make sure all fixers apply correct
         * indentation to new code they add, and the phpdoc_params fixer only
         * works on correctly indented docblocks. We also need to be running
         * after the psr2 indentation fixer for obvious reasons.
         * comments.
         */
        return 20;
    }

    /**
     * Fix indentation of Docblock.
     *
     * @param string $content Docblock contents
     * @param string $indent  Indentation to apply
     *
     * @return string Dockblock contents including correct indentation
     */
    private function fixDocBlock($content, $indent)
    {
        return ltrim(preg_replace('/^[ \t]*/m', $indent.' ', $content));
    }

    /**
     * Fix whitespace before the Docblock.
     *
     * @param string $content Whitespace before Docblock
     * @param string $indent  Indentation of the documented subject
     *
     * @return string Whitespace including correct indentation for Dockblock after this whitespace
     */
    private function fixWhitespaceBefore($content, $indent)
    {
        return rtrim($content, " \t").$indent;
    }
}


text:
<?php

/**
 * @see Zend_Gdata_Feed
 */
require_once 'Zend/Gdata/Feed.php';

/**
 * Describes a Book Search collection feed
 *
 * @category   Zend
 * @package    Zend_Gdata
 * @subpackage Books
 * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
 * @license    http://framework.zend.com/license/new-bsd     New BSD License
 */
class Zend_Gdata_Books_CollectionFeed extends Zend_Gdata_Feed
{

    /**
     * Constructor for Zend_Gdata_Books_CollectionFeed which
     * Describes a Book Search collection feed
     *
     * @param DOMElement $element (optional) DOMElement from which this
     *          object should be constructed.
     */
    public function __construct($element = null)
    {
        $this->registerAllNamespaces(Zend_Gdata_Books::$namespaces);
        parent::__construct($element);
    }

    /**
     * The classname for individual feed elements.
     *
     * @var string
     */
    protected $_entryClassName = 'Zend_Gdata_Books_CollectionEntry';

}


text:
package org.pentaho.di.trans.steps.sapinput.mock;

import java.util.Collection;
import java.util.Vector;

import org.pentaho.di.core.database.DatabaseMeta;
import org.pentaho.di.core.database.SAPR3DatabaseMeta;
import org.pentaho.di.trans.steps.sapinput.sap.SAPConnection;
import org.pentaho.di.trans.steps.sapinput.sap.SAPException;
import org.pentaho.di.trans.steps.sapinput.sap.SAPField;
import org.pentaho.di.trans.steps.sapinput.sap.SAPFunction;
import org.pentaho.di.trans.steps.sapinput.sap.SAPFunctionSignature;
import org.pentaho.di.trans.steps.sapinput.sap.SAPResultSet;
import org.pentaho.di.trans.steps.sapinput.sap.SAPRow;

public class SAPConnectionMockTest {

  /**
   * How to use a SAPConnection
   *
   * @throws SAPException
   */
  public static void main( String[] args ) throws SAPException {

    // how to obtain a connection
    SAPConnection sc = SAPConnectionFactoryMock.create();

    // how to open a connection
    // @Matt:
    // please show us how to retrieve the connection params from the
    // pentaho environment
    DatabaseMeta cp = new DatabaseMeta( "SAP", "SAPR3", "Plugin", "192.168.9.50", null, null, "USER", "PASSWORT" );
    cp.getAttributes().setProperty( SAPR3DatabaseMeta.ATTRIBUTE_SAP_SYSTEM_NUMBER, "00" );
    cp.getAttributes().setProperty( SAPR3DatabaseMeta.ATTRIBUTE_SAP_CLIENT, "100" );
    cp.getAttributes().setProperty( SAPR3DatabaseMeta.ATTRIBUTE_SAP_LANGUAGE, "DE" );
    sc.open( cp );

    // how to query all functions
    System.out.println( "how to query all functions" );
    Collection<SAPFunction> csf1 = sc.getFunctions( "" );
    for ( SAPFunction sapFunction : csf1 ) {
      System.out.println( sapFunction );
    }
    System.out.println();

    // how to query functions
    System.out.println( "how to query functions" );
    Collection<SAPFunction> csf2 = sc.getFunctions( "1" );
    for ( SAPFunction sapFunction : csf2 ) {
      System.out.println( sapFunction );
    }
    System.out.println();

    // how to get a function
    System.out.println( "how to get a function" );
    SAPFunction sf = sc.getFunction( "SearchCustomer" );
    System.out.println( sf );
    System.out.println();

    // how to get function signature
    System.out.println( "how to get function signature" );
    SAPFunctionSignature sfs = sc.getFunctionSignature( sf );
    System.out.println( "input:" );
    for ( SAPField field : sfs.getInput() ) {
      System.out.println( field );
    }
    System.out.println( "output:" );
    for ( SAPField field : sfs.getOutput() ) {
      System.out.println( field );
    }
    System.out.println();

    // how to execute a function
    System.out.println( "how to execute a function" );
    Collection<SAPField> input = new Vector<SAPField>();
    input.add( new SAPField( "Name", "", "input_single", "Casters" ) );
    Collection<SAPField> output = new Vector<SAPField>();
    output.add( new SAPField( "Name", "", "output_single" ) );
    output.add( new SAPField( "Firstname", "", "output_single" ) );
    output.add( new SAPField( "Adress", "", "output_single" ) );
    output.add( new SAPField( "Zipcode", "", "output_single" ) );
    output.add( new SAPField( "CustomerGroup", "", "output_single" ) );
    SAPResultSet sfr = sc.executeFunctionUncursored( sf, input, output );
    for ( SAPRow row : sfr.getRows() ) {
      System.out.println( row );
    }
    System.out.println();

    // Close the connection
    //
    sc.close();
  }

}


text:
package com.sxt.inter;

import java.util.List;

import com.sxt.models.LdYingxiangProductDetail;

import java.util.Map;

public interface ILdYingxiangProductDetail {

	/**
	 * 添加一个盈享理财产品详情表,并且给它分配ID
	 * @param ldYingxiangProductDetail
	 * @return 影响行数
	 */
	public int insert(LdYingxiangProductDetail ldYingxiangProductDetail);

	/**
	 * 编辑盈享理财产品详情表
	 * @param ldYingxiangProductDetail
	 * @return 影响行数
	 */
	public int update(LdYingxiangProductDetail ldYingxiangProductDetail);

	/**
	 * 根据ID删除盈享理财产品详情表
	 * @param id
	 * @return 影响行数
	 */
	public int delete(Long id);

	/**
	 * 根据条件查询List盈享理财产品详情表
	 * @param maps
	 * @return
	 */
	public List<LdYingxiangProductDetail> queryLdYingxiangProductDetailList(Map<String, Object> params);

	/**
	 * 根据条件查询盈享理财产品详情表
	 * @param ldYingxiangProductDetail
	 * @return
	 */
	public LdYingxiangProductDetail queryLdYingxiangProductDetailByCondition(LdYingxiangProductDetail ldYingxiangProductDetail);

	/**
	 * 根据条件查询盈享理财产品详情表总个数
	 * @param ldYingxiangProductDetail
	 * @return
	 */
	public int queryLdYingxiangProductDetailCount(LdYingxiangProductDetail ldYingxiangProductDetail);

}


text:
//
//  shapes.js
//
//  Created by David Rowe on 14 May 2018.
//  Copyright 2018 High Fidelity, Inc.
//
//  Distributed under the Apache License, Version 2.0.
//  See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//

/* global document, EventBridge */

(function () {

    "use strict";

    var isActive = false;

    function onToggleActiveClick() {
        var SET_ACTIVE_MESSAGE = "setActive"; // EventBridge message.

        isActive = !isActive;

        // Notify main script. It closes the dialog.
        EventBridge.emitWebEvent(JSON.stringify({
            command: SET_ACTIVE_MESSAGE,
            value: isActive
        }));
    }

    function onLoad() {
        var ICON_DIV = "icon",
            LOGO_IMG = "logo",
            LOGO_IMG_ACTIVE = "../assets/shapes-a.svg",
            LOGO_IMG_INACTIVE = "../assets/shapes-i.svg",
            TOGGLE_ACTIVE_BUTTON_ID = "toggle-active",
            iconDiv,
            logoImg,
            toggleActiveButton;

        isActive = location.search.replace("?active=", "") === "true";

        iconDiv = document.getElementById(ICON_DIV);
        logoImg = document.getElementById(LOGO_IMG);
        toggleActiveButton = document.getElementById(TOGGLE_ACTIVE_BUTTON_ID);
        toggleActiveButton.addEventListener("click", onToggleActiveClick, true);
        iconDiv.className = isActive ? "on" : "off";
        logoImg.src = isActive ? LOGO_IMG_ACTIVE : LOGO_IMG_INACTIVE;
        toggleActiveButton.value = isActive ? "TURN OFF SHAPES" : "TURN ON SHAPES";
        toggleActiveButton.className = isActive ? "on" : "off";
    }

    onLoad();

}());