text:
<法規>
<法規性質>命令</法規性質>
<英文法規名稱>Regulations for Testing Body and Certification Body Management of Information and Communications Equipment Used by Critical Telecommunications Infrastructure</英文法規名稱>
<中文法規名稱>關鍵電信基礎設施資通設備測試機構及驗證機構管理辦法</中文法規名稱>
<法規網址>https://law.moj.gov.tw/Eng/LawClass/LawAll.aspx?pcode=K0060158</法規網址>
<最新英文異動日期>20210129</最新英文異動日期>
<廢止註記>
</廢止註記>
<附件>
  <檔案>
    <檔案名稱><![CDATA[Attachment 1 Critical Telecommunications Infrastructure Information and Communications Equipment Certification Body Application Form.pdf]]></檔案名稱>
    <下載網址>https://law.moj.gov.tw/Eng/LawClass/LawGetFile.ashx?FileId=0000006575</下載網址>
  </檔案>
  <檔案>
    <檔案名稱><![CDATA[Attachment 2 Accreditation Certificate for Certification Body of Information and Communications Equipment used by Critical Telecommunications Infrastructure.pdf]]></檔案名稱>
    <下載網址>https://law.moj.gov.tw/Eng/LawClass/LawGetFile.ashx?FileId=0000006576</下載網址>
  </檔案>
</附件>
<沿革內容><![CDATA[1.Promulgated on January 29,2021

]]></沿革內容>
<前言><![CDATA[]]></前言>
<法規內容>
  <條文>
    <條號>Article 1</條號>
    <條文內容><![CDATA[These Regulations are promulgated pursuant to Paragraph 2 and 3, Article 87 of the Telecommunications Management Act(hereinafter the "Act").]]></條文內容>
  </條文>
  <條文>
    <條號>Article 2</條號>
    <條文內容><![CDATA[The terms adopted in these Regulations are defined as follows:
1. Information and communications equipment used by critical telecommunications infrastructure(hereinafter the "Equipment"): The equipment regulated in Technical Specifications announced by the competent authority in accordance with the Paragraph 8, Article 42 of the Act.
2. Testing Body: The institution that performs testing of the Equipment in accordance with the Technical Specifications described in the preceding subparagraph.
3. Certification Body: The institution commissioned by the competent authority to perform certification of the Equipment.
The inspection items for the Equipment mentioned in Subparagraph 3 of the previous paragraph shall be announced by the competent authority.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 3</條號>
    <條文內容><![CDATA[The Testing Body shall be accredited by the Taiwan Accreditation Foundation(hereinafter the "Accreditation Organization")and shall be capable of undertaking the tests listed in Technical Specifications announced by the competent authority.
The Testing Body shall comply with the following requirements:
1. Shall be a domestic legal entity or institution established by law.
2. Compliance with CNS 17025 or ISO/IEC 17025 standards.
3. Shall not be engaged in the input, design, manufacturing or trading of the Equipment to be tested.
4. Include at least three professional and full-time personnel, consisting of one testing supervisor and two testing engineers.
The personnel mentioned in Subparagraph 4 of the previous paragraph shall comply with the following requirements:
1. The Testing Supervisor shall:
(1)Possess a bachelor's degree or above, majoring in information engineering, information management or relevant department from a domestic or foreign public or private college or university recognized by the Ministry of Education.
(2)Have at least five years of practical experience in cybersecurity related management or testing evaluation and understanding of regulations and technical specifications.
(3)Acquire CNS 17025 or ISO/IEC 17025 training certificate.
2. The Testing Engineer shall
(1)Possess a bachelor's degree or above, majoring in information engineering, information management or relevant department from a domestic or foreign public or private college or university recognized by the Ministry of Education.
(2)Have at least two years of practical experience in cybersecurity related testing evaluation.
(3)Acquire a certificate of attending ISO/IEC 15408 testing and evaluation training program at least 40 hours.
(4)Acquire a valid cybersecurity related professional license of Certified Ethical Hacker(CEH)or CompTIA Security+.
(5)Acquire one of the following valid professional licenses related to cybersecurity:
i.(ISC)2 Certified Information Systems Security Professional(CISSP).
ii. EC-Council Certified Security Analyst(ECSA).
iii. EC-Council Computer Hacking Forensic Investigator(CHFI).
iv. GIAC Penetration Tester(GPEN).
v.(ISC)2 Systems Security Certified Practitioner(SSCP).
vi. Offensive Security Certified Professional(OSCP).
After confirming the Testing Body meeting the requirements mentioned in the previous three paragraphs and accrediting the Testing Body, the Accreditation Organization shall submit the accreditation certificate of the Testing Body to the competent authority for reference.
In order to enforce the Technical Specifications announced by the competent authority, the Testing Body shall put in place the necessary testing equipment to perform testing work.
The competent authority may examine and audit relevant documents from the Testing Body and may also dispatch staff to the Testing Body to perform an onsite appraisal. The Testing Body shall not evade, interfere with or refuse such verification without justification.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 4</條號>
    <條文內容><![CDATA[In any of the following circumstances, the competent authority may order the Testing Body to undertake corrective action within a prescribed period and suspend its testing work. Testing work shall only be resumed after the completion of the corrective action has been confirmed by the competent authority:
1. Failure to comply with the requirements under Paragraph 2, Article 3.
2. Failure to perform testing work in accordance with the Technical Specifications applicable to the Equipment announced by the competent authority.
3. Refusal to provide relevant documents or refusal of on-site evaluation by the competent authority staff without justification.
4. Breach of CNS17025 or ISO/IEC 17025 standards as determined by the competent authority or Accreditation Organization.
The suspension period of testing work of the Testing Body in the previous paragraph shall be at least three months. The competent authority may also extend the period to one year depending on the gravity of the situation.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 5</條號>
    <條文內容><![CDATA[An applicant to become qualified as a certification body(hereinafter the Applicant)shall be:
1. Domestic legal entity or institution established in accordance with laws.
2. Does not engage in the input, design, manufacturing or trading of the Equipment to be certified.
3. Compliance with CNS 17065 or ISO/IEC 17065 standards.
4. Include at least two full-time certification personnel.
The certification personnel mentioned in Subparagraph 4 of the previous paragraph shall comply with the following requirements:
1. Possess a bachelor's degree or above, majoring in information engineering, information management or relevant department from a domestic or foreign public or private college or university recognized by the Ministry of Education.
2. Have at least five years of practical experience in cybersecurity related management or testing evaluation and understanding of regulations and technical specifications.
3. Acquisition of CNS 17065 or ISO/IEC 17065 training certificate.
4. Acquire one of the following valid professional licenses related to cybersecurity:
(1)(ISC)2 Certified Information Systems Security Professional(CISSP).
(2)EC-Council Certified Security Analyst(ECSA).
(3)EC-Council Computer Hacking Forensic Investigator(CHFI).
(4)GIAC Penetration Tester(GPEN).
(5)(ISC)2 Systems Security Certified Practitioner(SSCP).
(6)Offensive Security Certified Professional(OSCP).
5. No personnel shall also serve as personnel under Subparagraph 4, Paragraph 2, Article 3.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 6</條號>
    <條文內容><![CDATA[The Applicant shall submit the following documents with its application to the competent authority:
1. Critical Telecommunications Infrastructure Information and Communications Equipment Certification Body Application Form(as Attachment 1).
2. Photocopy of corporate or business registration documents.
3. Photocopy of CNS 17065 or ISO/IEC 17065 certificate acquired by the Applicant.
4. Basic information of certification personnel showing compliance with the qualifications as prescribed in Paragraph 2 of the preceding Article.
5. Organization chart and function introduction of the certification department.
6. Quality manual of the certification department.
7. A list of quality documents of the certification department.
8. Inspection procedure for the Equipment to be certified.
9. Other materials designated by the competent authority.
Where the Applicant fails to provide all of above-mentioned documents or the content of provided document is incomplete, corrections shall be made within the period prescribed by the competent authority. If the submitted documents remain incomplete or insufficient, the application will be rejected.
The period as described in the preceding paragraph shall not be longer than one month.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 7</條號>
    <條文內容><![CDATA[Where all documents submitted by the Applicant according to the preceding article are approved, the competent authority will conduct an on-site evaluation.
The said evaluation shall be conducted according to the following terms and conditions, and an evaluation report shall be provided accordingly:
1. CNS 17065 or ISO/IEC 17065 standards.
2. Technical Specifications applicable to the Equipment announced by the competent authority or national standards.
3. Other matters related to the on-site evaluation requested by the competent authority.
Where the on-site evaluation results indicate any non-conformity to the preceding paragraph, the competent authority shall list all of them and notify the Applicant to make corrections accordingly. The Applicant shall make corrections and submit an improvement report within the prescribed period. If not, the application will be rejected.
The period as prescribed in the preceding paragraph shall not exceed three months.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 8</條號>
    <條文內容><![CDATA[The Applicant shall carry out Equipment inspection work only after it passes the evaluation, signs a commissioned inspection contract for the Equipment with the appraisal(hereinafter the "Commissioned Inspection Contract")and after the acquires an accreditation certificate for Certification Body of Equipment(hereinafter the "Accreditation Certificate", as shown in Attachment 2)issued by the competent authority.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 9</條號>
    <條文內容><![CDATA[The Certification Body shall not refuse or make discrimination on any of application for Equipment inspection(hereinafter an "Inspection Case")without justification.
Certification Bodies and their certification personnel must not engage in any work related to assisting the manufacturer or adjusting the functions of the Equipment.
The Certification Body shall process Inspection Cases in the name of the Certification Body.
The testing reports for Inspection Cases under the previous paragraph shall be issued by a Testing Body that has been accredited by the Accreditation Organization.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 10</條號>
    <條文內容><![CDATA[The Certification Body shall process the  issuance, renewal, reissue, revocation or annulment of of inspection certificates of the Equipment(hereinafter the "Inspection Certificates"), rejection of inspection application or approval for change of the appearance of the approved Equipment, etc., according to the Technical Specifications for Security Testing of Information and Communication Equipment for Critical Telecommunications Infrastructure.
All information of each Inspection Case shall be reported to the competent agency within 10 days after the completion of the said work for reference.
The competent agency shall instruct the Certification Body to sample the Equipment of installers of critical telecommunications infrastructure when necessary. The Certification Body shall report results of all sampling cases to the competent authority within two months after the sampling day.
The Equipment to be inspected under the previous paragraph shall be provided by the installer of critical telecommunications infrastructure.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 11</條號>
    <條文內容><![CDATA[If the Certification Body submits an application to add an inspection item for certification of the Equipment, the application shall be submitted in accordance with Article 6 and the Accreditation Certificate shall be reissued. The validity of the new Accreditation Certificate shall be identical to the original certificate.
The competent authority may perform an on-site evaluation in accordance with Article 7 when it processes an application under the previous paragraph.
If there are any changes of the specifications in an Accreditation Certificate, other than adding item mentioned in the first paragraph, an application for reissue of the Accreditation Certificate shall be submitted to the competent authority within 15 days from the date of the change. The validity period of the new Accreditation Certificate shall be identical to the original certificate.
If any certification personnel of the Certification Body is absent or added, information about the personnel change shall be submitted to the competent authority for reference within 15 days from the date of change.
The competent authority may order the Certification Body to suspend relevant inspection work when the position of the certification personnel is vacant and leads to non-conformities as described in Subparagraph 4, Paragraph 1, Article 5. The Certification Body shall apply to the competent authority for resuming the conduction of certification by submitting the basic information of the certification personnel after above-mentioned vacancy has been filled.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 12</條號>
    <條文內容><![CDATA[The competent agency may dispatch personnel to the certification body for irregular inspections and the Certification Body must not refuse it.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 13</條號>
    <條文內容><![CDATA[The duration of Commissioned Inspection Contract shall be three years.
The Certification Body may apply for renewal within two months starting from three months prior to the expiry of the Commissioned Inspection Contract. The competent authority may undertake a review and evaluation as required in accordance with Articles 6 and 7.
The competent authority shall notify the Certification Body one month prior to the expiry of the Commissioned Inspection Contract that the Certification Body shall no longer accept Inspection Cases. The Certification Body shall complete all accepted Inspection Case within one month from the date of the notification.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 14</條號>
    <條文內容><![CDATA[The competent authority may terminate the Commissioned Inspection Contract in any of the following circumstances and order the Certification Body to return and annul its accreditation certificate:
1. Failure to comply with terms and conditions of Paragraph 1, Article 5.
2. Violation of Paragraph 2 of Article 9, Article 10, Article 11 or Article 16.
3. Where the Certification Body performs inspection activities beyond the scope of authority as prescribed in the Commissioned Inspection Contract or shows tardiness to perform the said activities.
4. Where the Certification Body refuses irregular inspections conducted by competent authority without any justifiable reason.
5. Violation of any legislation such as the Act, Administrative Procedure Act, Technical Specifications for Security Testing of Information and Communication Equipment for Critical Telecommunications Infrastructure or the Regulations.
6. Where the Certification Body rejects or makes discrimination on accepted Inspection Case without any justifiable reason.
7. Where the Inspection Certificate issued by the Certification Body contains false or incorrect information.
In the case of any event under Subparagraphs 1 to 4 of the previous paragraph, the competent authority may order the Certification Body to undertake corrective action within a prescribed period. Those who fail to make corrections within the prescribed deadline will be handled according to the preceding paragraph.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 15</條號>
    <條文內容><![CDATA[When a Commissioned Inspection Contract is terminated in accordance with the previous article, the Certification Body shall forward uncompleted Inspection Cases to the Certification Body designated by the competent authority.
The Certification Body shall forward complete information related to all Inspection Cases within 7 days from the end of the Commissioned Inspection Contract.
Certification Body that has the Commissioned Inspection Contract terminated due to circumstances described in the previous article must not become a Certification Body within one year after the termination of the said Contract.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 16</條號>
    <條文內容><![CDATA[The Certification Body shall establish an online application system within one year from the date of acquisition of the Accreditation Certificate described in Article 8 to accept applications of the inspection of Equipment.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 17</條號>
    <條文內容><![CDATA[The Certification Body shall charge an inspection fee from the applicant according to charging standards set by the competent authority, and transfer the entire amount to national treasury the next day. The competent authority will pay the outsourcing fee to the Certification Body according to the Commissioned Inspection Contract.]]></條文內容>
  </條文>
  <條文>
    <條號>Article 18</條號>
    <條文內容><![CDATA[These Regulations shall take effect upon the date of promulgation.]]></條文內容>
  </條文>
</法規內容>
</法規>


text:
package org.elasticsearch.action.support.broadcast;

import org.elasticsearch.action.ActionRequestBuilder;
import org.elasticsearch.action.support.IndicesOptions;
import org.elasticsearch.client.internal.InternalGenericClient;

/**
 */
public abstract class BroadcastOperationRequestBuilder<Request extends BroadcastOperationRequest<Request>, Response extends BroadcastOperationResponse, RequestBuilder extends BroadcastOperationRequestBuilder<Request, Response, RequestBuilder>>
        extends ActionRequestBuilder<Request, Response, RequestBuilder> {

    protected BroadcastOperationRequestBuilder(InternalGenericClient client, Request request) {
        super(client, request);
    }

    @SuppressWarnings("unchecked")
    public final RequestBuilder setIndices(String... indices) {
        request.indices(indices);
        return (RequestBuilder) this;
    }

    /**
     * Controls the operation threading model.
     */
    @SuppressWarnings("unchecked")
    public final RequestBuilder setOperationThreading(BroadcastOperationThreading operationThreading) {
        request.operationThreading(operationThreading);
        return (RequestBuilder) this;
    }

    /**
     * Controls the operation threading model.
     */
    @SuppressWarnings("unchecked")
    public RequestBuilder setOperationThreading(String operationThreading) {
        request.operationThreading(operationThreading);
        return (RequestBuilder) this;
    }

    @SuppressWarnings("unchecked")
    public final RequestBuilder setIndicesOptions(IndicesOptions indicesOptions) {
        request.indicesOptions(indicesOptions);
        return (RequestBuilder) this;
    }
}

redpajama_set_name: RedPajamaGithub


text:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VentaElectrodomesticos.Core.Model.Entities
{
    public class Provincia : IKeyValueEntity
    {
        public int Id { get; set; }
        public string Descripcion { get; set; }
    }
}


text:
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.wizzardo.tools.evaluation;

import com.wizzardo.tools.collections.CollectionTools;
import com.wizzardo.tools.misc.Unchecked;

import java.util.*;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author Moxa
 */
public class EvalTools {
    static final String CONSTRUCTOR = "%constructor%";
    static EvaluatingStrategy defaultEvaluatingStrategy;
    private static AtomicInteger variableCounter = new AtomicInteger();
    private static final Pattern CLEAN_CLASS = Pattern.compile("([a-z]+\\.)*(\\b[A-Z][a-zA-Z\\d]+)(\\.[A-Z][a-zA-Z\\d]+)*");
    private static final Pattern NEW = Pattern.compile("^new +" + CLEAN_CLASS.pattern());
    private static final Pattern CLASS = Pattern.compile("^" + CLEAN_CLASS.pattern());
    private static final Pattern CAST = Pattern.compile("^\\(" + CLEAN_CLASS.pattern() + "(\\<(\\s*" + CLEAN_CLASS.pattern() + "\\s*,*)+\\>)*" + "\\)");
    private static final Pattern FUNCTION = Pattern.compile("^([a-z_]+\\w*)\\(.+");
    private static final Pattern COMMA = Pattern.compile(",");
    private static final Pattern MAP_KEY_VALUE = Pattern.compile("[a-zA-Z\\d]+ *: *.+");
    private static final Pattern IF_FOR_WHILE = Pattern.compile("(if|for|while) *\\(");
    private static final Pattern LIST = Pattern.compile("^([a-z]+[a-zA-Z\\d]*)\\[");
    private static final Pattern VARIABLE = Pattern.compile("\\$([\\.a-z]+[\\.a-zA-Z]*)");
    private static final Pattern ACTIONS = Pattern.compile("\\+\\+|--|\\.\\.|\\?:|\\?\\.|\\*=|\\*(?!\\.)|/=?|\\+=?|-=?|:|<<|<=?|>=?|==?|%|!=?|\\?|&&?|\\|\\|?");
    private static final Pattern DEF = Pattern.compile("def +([a-z]+[a-zA-Z_\\d]*)$");
    private static final Pattern BRACKETS = Pattern.compile("[\\(\\)]");

    protected static int countOpenBrackets(String s, int from, int to) {
        int n = 0;
        for (int i = from; i < to; i++) {
            if (s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') {
                n++;
            } else if (s.charAt(i) == ')' || s.charAt(i) == ']' || s.charAt(i) == '}') {
                n--;
            }
        }
        return n;
    }

    protected static int findCloseBracket(String s, int from) {
        return findCloseBracket(s, from, s.length());
    }

    protected static int findCloseBracket(String s, int from, int to) {
        int n = 1;
        boolean inString = false;
        char quote = 0;
        int i;
        for (i = from; i < to && n > 0; i++) {
            if (!inString) {
                if ((s.charAt(i) == '\'' || s.charAt(i) == '\"') && (i == 0 || (i >= 1 && s.charAt(i - 1) != '\\'))) {
                    quote = s.charAt(i);
                    inString = true;
                    continue;
                }
                if (s.charAt(i) == '(' || s.charAt(i) == '[' || s.charAt(i) == '{') {
                    n++;
                } else if (s.charAt(i) == ')' || s.charAt(i) == ']' || s.charAt(i) == '}') {
                    n--;
                }
            } else if ((s.charAt(i) == quote) && i >= 1 && s.charAt(i - 1) != '\\') {
                inString = false;
            }
        }
        if (n == 0)
            return i - 1;
        else
            return -1;
    }

    protected static String getTempVariableName() {
        return "__tempVariable_" + variableCounter.incrementAndGet();
    }

    protected static boolean inString(String s, int from, int to) {
        boolean inString = false;
        char quote = 0;
        for (int i = from; i < to; i++) {
            if (!inString) {
                if ((s.charAt(i) == '\'' || s.charAt(i) == '\"') && (i == 0 || (i >= 1 && s.charAt(i - 1) != '\\'))) {
                    quote = s.charAt(i);
                    inString = true;
                }
            } else if ((s.charAt(i) == quote) && i >= 1 && s.charAt(i - 1) != '\\') {
                inString = false;
            }
        }
        return inString;
    }

    protected static LinkedList<String> getParts(String s) {
        LinkedList<String> l = new LinkedList<String>();
        boolean inString = false;
        char quote = 0;
        char[] chars = s.toCharArray();
        int from = 0;
        int brackets = 0;
        int squareBrackets = 0;
        int curlyBraces = 0;
        for (int i = 0; i < chars.length; i++) {
            if (!inString) {
                switch (chars[i]) {
                    case '"':
                    case '\'': {
                        quote = chars[i];
                        inString = true;
                        break;
                    }
                    case '(': {
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0 && i != from) {
                            l.add(trim(chars, from, i));
                            from = i;
                        }
                        brackets++;
                        break;
                    }
                    case '{': {
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0 && i != from) {
                            l.add(trim(chars, from, i));
                            from = i;
                        }
                        curlyBraces++;
                        break;
                    }
                    case '[': {
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0 && i != from) {
                            l.add(trim(chars, from, i));
                            from = i;
                        }
                        squareBrackets++;
                        break;
                    }
                    case ')': {
                        brackets--;
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0) {
                            l.add(trim(chars, from, i + 1));
                            from = i + 1;
                        }
                        break;
                    }
                    case '}': {
                        curlyBraces--;
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0) {
                            l.add(trim(chars, from, i + 1));
                            from = i + 1;
                        }
                        break;
                    }
                    case ']': {
                        squareBrackets--;
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0) {
                            l.add(trim(chars, from, i + 1));
                            from = i + 1;
                        }
                        break;
                    }
                    case '.': {
                        if (brackets == 0 && curlyBraces == 0 && squareBrackets == 0 && i != from) {
                            if (i > 0 && (chars[i - 1] == '*' || chars[i - 1] == '?'))
                                if (i - from == 1)
                                    continue;
                                else
                                    i--;

                            l.add(trim(chars, from, i));
                            from = i;
                        }
                        break;
                    }
                }
            } else if ((chars[i] == quote) && i > 1 && chars[i - 1] != '\\') {
                inString = false;
            }
        }
        if (from != chars.length) {
            l.add(trim(chars, from, chars.length));
        }
        return l;
    }

    private static String trim(char[] chars, int from, int to) {
        while (to > 0 && chars[to - 1] <= ' ') {
            to--;
        }
        return new String(chars, from, to - from);
    }

    public static enum EvaluatingStrategy {
        DEFAULT_JAVA, FLOAT, DOUBLE
    }

    public static void setDefaultEvaluatingStrategy(EvaluatingStrategy defaultEvaluatingStrategy) {
        EvalTools.defaultEvaluatingStrategy = defaultEvaluatingStrategy;
    }

    public static String trimBrackets(String s) {
        int db = s.indexOf("((");
        if (db != -1) {
            String t = s.substring(db + 2);
            Matcher m = BRACKETS.matcher(t);
            int brackets = 2;
            boolean innerBrackets = false;
            while (m.find()) {
                if (m.group().equals("(")) {
                    if (brackets < 2)
                        innerBrackets = true;
                    brackets++;
                } else if (m.group().equals(")")) {
                    brackets--;
                }
                if (!innerBrackets && brackets == 0 && m.start() > 0 && t.charAt(m.start() - 1) == ')') {
                    return trimBrackets(s.substring(0, db + 1) + t.substring(0, m.start() - 1) + t.substring(m.start()));
                }
            }
        }

        if (s.startsWith("(") && s.endsWith(")")) {
            Matcher m = BRACKETS.matcher(s);
            int brackets = 0;
            while (m.find()) {
                if (m.group().equals("(")) {
                    brackets++;
                } else if (m.group().equals(")")) {
                    brackets--;
                }
                if (brackets == 0 && m.end() != s.length()) {
                    return s;
                }
            }
            return s.substring(1, s.length() - 1);
        }
        return s;
    }

    private static boolean isMap(String s) {
        if (!s.startsWith("[") || !s.endsWith("]")) {
            return false;
        }
        boolean quotesSingle = false;
        boolean quotesDouble = false;
        int brackets = 0;
        for (int i = 1; i < s.length(); i++) {
            switch (s.charAt(i)) {
                case '\'':
                    if (!quotesDouble)
                        quotesSingle = !quotesSingle;
                    break;
                case '"':
                    if (!quotesSingle)
                        quotesDouble = !quotesDouble;
                    break;
                case '[': {
                    if (!quotesSingle && !quotesDouble)
                        brackets++;
                    break;
                }
                case ']': {
                    if (!quotesSingle && !quotesDouble)
                        brackets--;
                    break;
                }
                case ':':
                    if (!quotesSingle && !quotesDouble && brackets == 0) {
                        return true;
                    }
                    break;
            }
        }
        return false;
    }

    private static boolean isList(String s) {
        return s.startsWith("[") && s.endsWith("]");
    }

    private static boolean isClosure(String exp) {
        return exp.startsWith("{") && exp.endsWith("}");
    }

    static List<String> getBlocks(String exp) {
        return getBlocks(exp, false);
    }

    static class Statement {
        Type type = Type.BLOCK;
        String statement;
        String body;
        String optional;
        Statement bodyStatement;
        Statement optionalStatement;

        public Statement(String statement) {
            this.statement = statement;
        }

        public Statement() {
        }

        public Expression prepare(Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) {
            switch (type) {
                case IF: {
                    List<String> args = getBlocks(statement, true);
                    if (args.size() > 1)
                        throw new IllegalStateException("more then one statement in condition: " + statement);

                    AsBooleanExpression condition = new AsBooleanExpression(EvalTools.prepare(args.get(0), model, functions, imports));
                    Expression then = bodyStatement != null ? bodyStatement.prepare(model, functions, imports) : EvalTools.prepare(body, model, functions, imports);
                    Expression elseExpression = optionalStatement != null ? optionalStatement.prepare(model, functions, imports) : EvalTools.prepare(optional, model, functions, imports);
                    if (elseExpression == null)
                        return new IfExpression(condition, then);
                    else
                        return new IfExpression(condition, then, elseExpression);
                }
                default:
                    throw new IllegalStateException("not implemented yet");
            }
        }

        static enum Type {
            FOR, WHILE, IF, BLOCK;
        }
    }

    static List<Statement> getStatements(String s) {
        List<Statement> statements = new ArrayList<Statement>();
        Matcher m = IF_FOR_WHILE.matcher(s);
        int start = 0;
        int to = s.length();
        while (m.find(start)) {
            if (m.start() != start) {
                statements.add(new Statement(s.substring(start, m.start())));
            }

            Statement statement = new Statement();
            start = getBlock(s, m.start(), to, statement);

            statements.add(statement.bodyStatement);
        }
        if (start != to) {
            String sub = s.substring(start, to).trim();
            if (sub.length() > 0)
                statements.add(new Statement(sub));
        }
        return statements;
    }

    static int getBlock(String s, int from, int to, Statement statement) {
        Matcher m = IF_FOR_WHILE.matcher(s);
        int start = from;
        if (m.find(start)) {
            String before = s.substring(start, m.start()).trim();
            if (before.length() > 0) {
                return getStringBlock(s, from, to, statement);
            }
            if (m.start() >= to || m.end() >= to)
                return -1;

            int close = findCloseBracket(s, m.end());
            if (close < 0)
                throw new IllegalStateException("can't find closing bracket in expression: " + s);

            Statement inner = new Statement();

            if (statement.bodyStatement == null && statement.body == null)
                statement.bodyStatement = inner;
            else
                statement.optionalStatement = inner;

            inner.type = Statement.Type.valueOf(m.group(1).toUpperCase());
            inner.statement = s.substring(m.end(), close);

            char ch = 0;
            for (start = close + 1; start < to; start++) {
                ch = s.charAt(start);
                if (ch != ' ' && ch != '\n' && ch != '\t')
                    break;
            }
            if (start == to)
                throw new IllegalStateException("can't find block: " + s.substring(from, to));

            if (ch == '{') {
                start++;
                close = findCloseBracket(s, start, to);

                if (close < 0)
                    throw new IllegalStateException("can't find closing bracket in expression: " + s.substring(from, to));

                inner.body = s.substring(start, close);
                start = close + 1;

                if (inner.type == Statement.Type.IF)
                    return getElse(s, start, to, inner);
                return start;
            } else {
                start = getBlock(s, start, to, inner);

                if (inner.type == Statement.Type.IF)
                    return getElse(s, start, to, inner);
                return start;

            }
        } else {
            return getStringBlock(s, from, to, statement);
        }
    }

    static int getStringBlock(String s, int from, int to, Statement statement) {
        char last = 0, stringChar = 0;
        boolean inString = false;
        int brackets = 0;
        char c;
        for (int i = from; i < to; i++) {
            c = s.charAt(i);
            if (inString) {
                if (c == stringChar && last != '\\') {
                    inString = false;
                }
            } else {
                if (c == '(' || c == '[' || c == '{') {
                    brackets++;
                } else if (c == ')' || c == ']' || c == '}') {
                    brackets--;
                }

                if (brackets == 0) {
                    if (c == ';' || c == '\n') {
                        if (statement.bodyStatement == null && statement.body == null)
                            statement.body = s.substring(from, i).trim();
                        else
                            statement.optional = s.substring(from, i).trim();

                        return i + (c == ';' ? 1 : 0);
                    }
                    if (c == '"' || c == '\'') {
                        inString = true;
                    }
                }
            }
            last = c;
        }
        if (statement.bodyStatement == null && statement.body == null)
            statement.body = s.substring(from, to).trim();
        else
            statement.optional = s.substring(from, to).trim();
        return to;
    }

    static int getElse(String s, int from, int to, Statement statement) {
        int start = from;
        char ch;
        int close;
        for (; start < to; start++) {
            ch = s.charAt(start);
            if (ch != ' ' && ch != '\n' && ch != '\t')
                break;
        }

        if (!(start < to - 4 && s.startsWith("else", start)))
            return start;

        start += 4;
        ch = s.charAt(start);
        if (ch != ' ' && ch != '\n' && ch != '\t' && ch != '{' && ch != ';')
            return start - 4;

        for (; start < to; start++) {
            ch = s.charAt(start);
            if (ch != ' ' && ch != '\n' && ch != '\t')
                break;
        }

        if (start == to)
            throw new IllegalStateException("can't find block: " + s.substring(from, to));

        if (ch == '{') {
            start++;
            close = findCloseBracket(s, start, to);

            if (close < 0)
                throw new IllegalStateException("can't find closing bracket in expression: " + s.substring(from, to));

            statement.optional = s.substring(start, close);
            return close + 1;
        } else {
            return getBlock(s, start, to, statement);
        }
    }

    static List<String> getBlocks(String exp, boolean ignoreNewLine) {
        List<String> list = new ArrayList<String>();

        StringBuilder sb = new StringBuilder();
        char last = 0, stringChar = 0;
        boolean inString = false;
        int brackets = 0;
        for (char c : exp.toCharArray()) {
            if (inString) {
                if (c == stringChar && last != '\\') {
                    inString = false;
                }
            } else {
                if (c == '(' || c == '[' || c == '{') {
                    brackets++;
                } else if (c == ')' || c == ']' || c == '}') {
                    brackets--;
                }

                if (ignoreNewLine && c == '\n')
                    continue;

                if (brackets == 0) {
                    if (c == ';' || c == '\n') {
                        String value = cleanLine(sb.toString());
                        if (value.length() > 0)
                            list.add(value);
                        sb.setLength(0);
                        continue;
                    }
                    if (c == '"' || c == '\'') {
                        stringChar = c;
                        inString = true;
                    }
                }
            }
            last = c;
            sb.append(c);
        }
        String value = cleanLine(sb.toString());
        if (value.length() > 0)
            list.add(value);

        return list;
    }

    static String cleanLine(String line) {
        int comment = -1;
        while ((comment = line.indexOf("//", comment + 1)) != -1) {
            if (!inString(line, 0, comment)) {
                int end = line.indexOf("\n", comment);
                if (end == -1)
                    line = line.substring(0, comment);
                else
                    line = line.substring(0, comment) + line.substring(end);
            }
        }
        return line.trim();
    }

    public static Expression prepareTemplate(String exp) {
        return prepare(exp, null, null, null, true);
    }

    public static Expression prepare(String exp) {
        return prepare(exp, null);
    }

    public static Expression prepare(String exp, Map<String, Object> model) {
        return prepare(exp, model, null);
    }

    public static Expression prepare(String script, Map<String, Object> model, Map<String, UserFunction> functions) {
        List<String> imports = new ArrayList<String>();
        script = script.trim();
        int s, n;
        if (script.startsWith("package")) {
            n = script.indexOf("\n");
            s = script.indexOf(";");
            int to = Math.min(n == -1 ? script.length() : n, s == -1 ? script.length() : s);
            imports.add(script.substring(8, to).trim() + ".*");

            script = script.substring(to + 1).trim();
        }
        while (script.startsWith("import")) {
            n = script.indexOf("\n");
            s = script.indexOf(";");
            int to = Math.min(n == -1 ? script.length() : n, s == -1 ? script.length() : s);
            imports.add(script.substring(7, to).trim());

            script = script.substring(to + 1).trim();
        }
        return prepare(script, model, functions, imports, false);
    }

    public static Expression prepare(String exp, Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports) {
        return prepare(exp, model, functions, imports, false);
    }

    public static Expression prepare(String exp, Map<String, Object> model, Map<String, UserFunction> functions, List<String> imports, boolean isTemplate) {
//        System.out.println("try to prepare: " + exp);
        if (exp == null) {
            return null;
        }
        //remove comments
        int comment = -1;
        do {
            comment = exp.indexOf("/*", comment + 1);
            if (comment != -1 && !inString(exp, 0, comment)) {
                int commentEnd = exp.indexOf("*/", comment);
                if (commentEnd == -1)
                    throw new IllegalStateException("Cannot find end of comment block for exp '" + exp + "'");

                exp = exp.substring(0, comment) + exp.substring(commentEnd + 2);
            }
        } while (comment != -1);

        if (!isTemplate) {
            exp = exp.trim();
            String trimmed = trimBrackets(exp);
            while (trimmed != exp) {
                exp = trimmed;
                trimmed = trimBrackets(exp);
            }
            if (exp.length() == 0) {
                return null;
            }
        }

        if (isTemplate && exp.length() == 0)
            return new Expression.Holder("", true);

        if (model == null) {
            model = new HashMap<String, Object>();
        }

        if (functions == null) {
            functions = new HashMap<String, UserFunction>();
        }

        {
            if (!isTemplate && exp.startsWith("\"") && exp.endsWith("\"") && inString(exp, 0, exp.length() - 1)) {
                return prepare(exp.substring(1, exp.length() - 1), model, functions, imports, true);
            }

            if (isTemplate) {
                TemplateBuilder tb = new TemplateBuilder();
                Matcher m = VARIABLE.matcher(exp);
                int start = 0;
                int end = 0;
                while ((start = exp.indexOf("$", start)) != -1) {
                    if (start >= 0 && exp.charAt(start + 1) == '{') {
                        if (end != start)
                            tb.append(exp.substring(end, start));

                        end = findCloseBracket(exp, start + 2);
                        String sub = exp.substring(start + 2, end);
                        tb.append(prepare(sub, model, functions, imports, false));
                        end++;
                    } else {
                        if (m.find(start)) {
                            if (m.start() != end)
                                tb.append(exp.substring(end, m.start()));
                            String sub = m.group(1);
                            tb.append(prepare(sub, model, functions, imports, false));
                            end = m.end();
                        }
                    }
                    start = end;
                }
                if (end != exp.length())
                    tb.append(exp.substring(end, exp.length()));

                return tb;
            }
        }

        if (isClosure(exp)) {
            exp = exp.substring(1, exp.length() - 1).trim();
            ClosureExpression closure = new ClosureExpression();
            List<String> lines = getBlocks(exp);
            if (lines.isEmpty())
                return new ClosureHolder(closure);

            String firstLine = lines.get(0);
            firstLine = closure.parseArguments(firstLine);
            if (firstLine.length() == 0)
                lines.remove(0);
            else
                lines.set(0, firstLine);

            for (String s : lines) {
                if (isLineCommented(s))
                    continue;
                closure.add(prepare(s, model, functions, imports, isTemplate));
            }
            return new ClosureHolder(closure);
        }

        {
            List<Statement> statements = getStatements(exp);
            ClosureExpression closure = new ClosureExpression();
            for (Statement s : statements) {
                switch (s.type) {
                    case IF:
                    case FOR:
                    case WHILE:
                        closure.add(s.prepare(model, functions, imports));
                        break;

                    case BLOCK: {
                        List<String> lines = getBlocks(s.statement);
                        if (lines.size() > 1) {
                            ClosureExpression inner = new ClosureExpression();
                            for (String line : lines) {
                                if (isLineCommented(line))
                                    continue;
                                inner.add(prepare(line, model, functions, imports, isTemplate));
                            }
                            closure.add(inner);
                        } else if (statements.size() > 1 || !lines.get(0).equals(s.statement)) {
                            closure.add(prepare(lines.get(0), model, functions, imports, isTemplate));
                        }
                        break;
                    }

                    default:
                        throw new IllegalStateException("not implemented yet");
                }

            }
            if (!closure.isEmpty())
                return closure;
        }

        {
            if (exp.equals("null")) {
                return Expression.Holder.NULL;
            }
            Object obj = Expression.parse(exp);
            if (obj != null) {
                return new Expression.Holder(exp);
            }
            if (model.containsKey(exp)) {
                return new Expression.Holder(exp);
            }
            {
                Matcher m = DEF.matcher(exp);
                if (m.find()) {
                    model.put(m.group(1), null);
                    return new Expression.Holder(m.group(1));
                }
            }
        }

        {
            Matcher m = ACTIONS.matcher(exp);
            List<String> exps = new ArrayList<String>();
            List<Operation> operations = new ArrayList<Operation>();
            int last = 0;
            Operation operation = null;
            Expression lastExpressionHolder = null;
            boolean ternary = false;
            int ternaryInner = 0;
            while (m.find()) {
                if (ternary) {
                    if (m.group().equals("?")) {
                        ternaryInner++;
                        continue;
                    }
                    if (!m.group().equals(":")) {
                        continue;
                    }
                    if (ternaryInner > 0) {
                        ternaryInner--;
                        continue;
                    }
                }
                if ("?.".equals(m.group()))
                    continue;

//                System.out.println(m.group());
                if (countOpenBrackets(exp, last, m.start()) == 0 && !inString(exp, last, m.start())) {
                    exps.add(exp.substring(last, m.start()).trim());
//                    lastExpressionHolder = new ExpressionHolder(exp.substring(last, m.start()));
                    lastExpressionHolder = prepare(exp.substring(last, m.start()), model, functions, imports, isTemplate);
                    if (operation != null) {
                        //complete last operation
                        operation.end(m.start());
//                        operation.rightPart(new ExpressionHolder(exp.substring(last, operation.end())));
                        operation.rightPart(lastExpressionHolder);
                    }
                    operation = new Operation(lastExpressionHolder, Operator.get(m.group()), last, m.end());
                    operations.add(operation);
                    //add operation to list
                    last = m.end();
                    if (ternary) {
//                        lastExpressionHolder = new ExpressionHolder(exp.substring(last, exp.length()));
                        lastExpressionHolder = prepare(exp.substring(last, exp.length()), model, functions, imports, isTemplate);
                        operation.rightPart(lastExpressionHolder);
                        break;
                    }
                    if (m.group().equals("?")) {
                        ternary = true;
                    }
                }
            }
            if (operation != null) {
                if (last != exp.length()) {
                    exps.add(exp.substring(last).trim());
                    operation.end(exp.length());
//                    operation.rightPart(new ExpressionHolder(exp.substring(last)));
                    operation.rightPart(prepare(exp.substring(last), model, functions, imports, isTemplate));
                }

                Expression eh = null;
                while (operations.size() > 0) {
                    operation = null;
                    int n = 0;
                    for (int i = 0; i < operations.size(); i++) {
                        if (operation == null || operations.get(i).operator().priority > operation.operator().priority) {
                            operation = operations.get(i);
                            n = i;
                        }
                    }
                    if (operation.operator() == Operator.TERNARY) {
                        int ternaryIndex = n;
                        operation = null;
                        n = 0;
                        for (int i = 0; i < ternaryIndex; i++) {
                            if (operation == null || operations.get(i).operator().priority > operation.operator().priority) {
                                operation = operations.get(i);
                                n = i;
                            }
                        }
                        if (operation == null) {
                            operation = operations.get(0);
                        }
                    }

                    if (operation.operator() == Operator.TERNARY) {
                        operation.rightPart(operations.remove(n + 1));
                    }

                    //System.out.println("operation: " + operation);
                    if (n > 0) {
                        operations.get(n - 1).rightPart(operation);
                    }
                    if (n < operations.size() - 1) {
                        operations.get(n + 1).leftPart(operation);
                    }
                    eh = operations.remove(n);
                }
                return eh;
            }
        }

        {
            if (exp.equals("[]")) {
                return new Expression.CollectionExpression();
            }
            if (exp.equals("[:]")) {
                return new Expression.MapExpression();
            }
            if (isMap(exp)) {
                Map<String, Expression> map = new LinkedHashMap<String, Expression>();
                for (Map.Entry<String, String> entry : parseMap(exp).entrySet()) {
                    map.put(entry.getKey(), prepare(entry.getValue(), model, functions, imports, isTemplate));
                }
                return new Expression.MapExpression(map);
            }
            if (isList(exp)) {
                List<Expression> l = new ArrayList<Expression>();
                exp = exp.substring(1, exp.length() - 1);
                List<String> arr = parseArgs(exp);
                for (String anArr : arr) {
                    l.add(prepare(anArr, model, functions, imports, isTemplate));
                }
                return new Expression.CollectionExpression(l);
            }
        }

        Expression thatObject = null;
        String methodName = null;
        {
            Matcher m = NEW.matcher(exp);
            if (m.find()) {
                Class clazz = findClass(m.group().substring(4), imports);
                if (clazz != null) {
                    thatObject = new Expression.Holder(clazz);
                    exp = exp.substring(m.end());
                    methodName = CONSTRUCTOR;
                } else
                    Unchecked.rethrow(new ClassNotFoundException("Can not find class '" + m.group().substring(4) + "'"));
            }
        }

        if (thatObject == null) {
            Matcher m = LIST.matcher(exp);
            if (m.find()) {
                thatObject = new Expression.Holder(m.group(1));
                exp = exp.substring(m.group(1).length());
            }
        }

        if (thatObject == null) {
            String s = exp;
            Matcher m = CLASS.matcher(exp);
            while (m.find()) {
                String className;
                if (m.start(3) >= 0)
                    className = exp.substring(0, m.start(3)) + "$" + exp.substring(m.start(3) + 1, m.end(3));
                else
                    className = m.group();

                Class clazz = findClass(className, imports);
                if (clazz != null) {
                    thatObject = new Expression.Holder(clazz);
                    exp = exp.substring(m.end());
                    break;
                } else {
                    int i = s.lastIndexOf(".");
                    if (i > 0) {
                        s = s.substring(0, i);
                        m = CLASS.matcher(s);
                    }
                }
            }
        }

        if (thatObject == null) {
            Matcher m = CAST.matcher(exp);
            while (m.find()) {
                if (m.start(4) >= 0) {
                    //remove generics
                    exp = exp.substring(0, m.start(4)) + exp.substring(m.end(4));
                    m = CAST.matcher(exp);
                    continue;
                }
                String className = m.group();
                if (m.start(3) >= 0)
                    className = exp.substring(1, m.start(3)) + "$" + exp.substring(m.start(3) + 1, m.end(3));
                else
                    className = className.substring(1, className.length() - 1);
                Class clazz = findClass(className, imports);
                if (clazz != null) {
                    exp = exp.substring(m.end());
                    return new Expression.CastExpression(clazz, prepare(exp, model, functions, imports, isTemplate));
                }
            }
        }

        if (thatObject == null) {
            Matcher m = FUNCTION.matcher(exp);
            if (m.find()) {
//                System.out.println("find user function: " + m.group(1) + "\t from " + exp);
//                System.out.println("available functions: " + functions);
                String functionName = m.group(1);
                thatObject = new ClosureLookup(functionName, functions);
                exp = exp.substring(functionName.length());
            }
        }

        List<String> parts = getParts(exp);
        String last = null;
//        System.out.println(exp);
        while (!parts.isEmpty()) {
            String temp = parts.toString();
            if (temp.equals(last))
                throw new IllegalStateException("loop at " + exp + "\t\t" + parts);
            last = temp;

            if (thatObject == null && parts.size() == 1 && parts.get(0).equals(exp)) {
                thatObject = new Expression.Holder(parts.remove(0));
                continue;
            }
            if (thatObject == null) {
                thatObject = prepare(parts.remove(0), model, functions, imports, isTemplate);
                continue;
            }

            //.concat("ololo")
            if (parts.size() >= 2 && parts.get(0).startsWith(".")
                    && ((parts.get(1).startsWith("(") && parts.get(1).endsWith(")")) || (parts.get(1).startsWith("{") && parts.get(1).endsWith("}")))) {
                methodName = parts.remove(0).substring(1);
                Expression[] args = null;
                String argsRaw = trimBrackets(parts.remove(0));
                if (argsRaw.length() > 0) {
                    List<String> arr = parseArgs(argsRaw);
                    args = new Expression[arr.size()];
                    for (int i = 0; i < arr.size(); i++) {
                        args[i] = prepare(arr.get(i), model, functions, imports, isTemplate);
                    }
                }
                thatObject = new Function(thatObject, methodName, args);

                //?.concat("ololo")
            } else if (parts.size() >= 2 && parts.get(0).startsWith("?.")
                    && ((parts.get(1).startsWith("(") && parts.get(1).endsWith(")")) || (parts.get(1).startsWith("{") && parts.get(1).endsWith("}")))) {
                methodName = parts.remove(0).substring(2);
                Expression[] args = null;
                String argsRaw = trimBrackets(parts.remove(0));
                if (argsRaw.length() > 0) {
                    List<String> arr = parseArgs(argsRaw);
                    args = new Expression[arr.size()];
                    for (int i = 0; i < arr.size(); i++) {
                        args[i] = prepare(arr.get(i), model, functions, imports, isTemplate);
                    }
                }
                thatObject = new Function(thatObject, methodName, args, true);

                //*.concat("ololo")
            } else if (parts.size() >= 1 && parts.get(0).startsWith("*.")) {
                String var = getTempVariableName();
                Expression[] args = new Expression[1];
                methodName = parts.remove(0).substring(1);
                String argsRaw;
                if (parts.size() >= 1 && parts.get(0).startsWith("(") && parts.get(0).endsWith(")"))
                    argsRaw = parts.remove(0);
                else
                    argsRaw = "";

                args[0] = prepare("{" + var + " -> " + var + methodName + argsRaw + "}", model, functions, imports, isTemplate);
                thatObject = new Function(thatObject, "collect", args);

                //("ololo")
            } else if (parts.get(0).startsWith("(") && parts.get(0).endsWith(")")) {
                Expression[] args = null;
                String argsRaw = trimBrackets(parts.remove(0));
                if (argsRaw.length() > 0) {
                    List<String> arr = parseArgs(argsRaw);
                    args = new Expression[arr.size()];
                    for (int i = 0; i < arr.size(); i++) {
                        args[i] = prepare(arr.get(i), model, functions, imports, isTemplate);
                    }
                }
                if (thatObject instanceof UserFunction) {
                    UserFunction function = (UserFunction) thatObject;
                    function.setArgs(args);
                    function.setUserFunctions(functions);
                } else {
                    thatObject = new Function(thatObject, methodName, args);
                }

                //.x
            } else if (parts.get(0).startsWith(".")) {
                String field = parts.remove(0).substring(1);
                thatObject = new Function(thatObject, field);

                //?.x
            } else if (parts.get(0).startsWith("?.")) {
                String field = parts.remove(0).substring(2);
                thatObject = new Function(thatObject, field, true);

                //[0]
            } else if (parts.get(0).startsWith("[") && parts.get(0).endsWith("]")) {
                String argsRaw = parts.remove(0);
                argsRaw = argsRaw.substring(1, argsRaw.length() - 1);
                thatObject = new Operation(thatObject, prepare(argsRaw, model, functions, imports, isTemplate), Operator.GET);

                //execute closure
            } else if (parts.size() == 1) {
                Expression[] args = null;
                String argsRaw = trimBrackets(parts.remove(0));
                if (argsRaw.length() > 0) {
                    List<String> arr = parseArgs(argsRaw);
                    args = new Expression[arr.size()];
                    for (int i = 0; i < arr.size(); i++) {
                        args[i] = prepare(arr.get(i), model, functions, imports, isTemplate);
                    }
                }
                thatObject = new Function(thatObject, "execute", args);
            }
        }

        return thatObject;
    }

    protected static boolean isLineCommented(String s) {
        return s.startsWith("//");
    }

    private static Class findClass(String s) {
        return findClass(s, null);
    }

    private static Class findClass(String s, List<String> imports) {
        try {
            return ClassLoader.getSystemClassLoader().loadClass(s);
        } catch (ClassNotFoundException ignored) {
        }
        try {
            return ClassLoader.getSystemClassLoader().loadClass("java.lang." + s);
        } catch (ClassNotFoundException ignored) {
        }
        try {
            return ClassLoader.getSystemClassLoader().loadClass("java.util." + s);
        } catch (ClassNotFoundException ignored) {
        }
        if (imports != null) {
            for (String imp : imports) {
                if (imp.endsWith("." + s))
                    try {
                        return ClassLoader.getSystemClassLoader().loadClass(imp);
                    } catch (ClassNotFoundException ignored) {
                    }
                if (imp.endsWith(".*")) {
                    try {
                        return ClassLoader.getSystemClassLoader().loadClass(imp.substring(0, imp.length() - 1) + s);
                    } catch (ClassNotFoundException ignored) {
                    }
                }
            }
            if (s.contains("$")) {
                String mainClass = s.substring(0, s.indexOf('$'));
                String subClass = s.substring(s.indexOf('$') + 1);
                for (String imp : imports) {
                    if (imp.endsWith("." + mainClass))
                        try {
                            return ClassLoader.getSystemClassLoader().loadClass(imp + "$" + subClass);
                        } catch (ClassNotFoundException ignored) {
                        }
                }
            }
            if (s.contains(".")) {
                String mainClass = s.substring(0, s.indexOf('.'));
                String subClass = s.substring(s.indexOf('.') + 1);
                for (String imp : imports) {
                    if (imp.endsWith("." + mainClass))
                        try {
                            return ClassLoader.getSystemClassLoader().loadClass(imp + "$" + subClass);
                        } catch (ClassNotFoundException ignored) {
                        }
                }
            }
        }
        return null;
    }

    private static List<String> parseArgs(String argsRaw) {
        ArrayList<String> l = new ArrayList<String>();
        Matcher m = COMMA.matcher(argsRaw);
        int last = 0;
        while (m.find()) {
            if (countOpenBrackets(argsRaw, last, m.start()) == 0) {
                l.add(argsRaw.substring(last, m.start()).trim());
                last = m.end();
            }
        }
        if (last > 0) {
            l.add(argsRaw.substring(last).trim());
        } else if (last == 0 && argsRaw.length() > 0) {
            l.add(argsRaw.trim());
        }

        int mapStart = -1;
        int mapEnd = -1;
        while (mapStart == -1) {
            for (int i = 0; i < l.size(); i++) {
                String arg = l.get(i);
                if (MAP_KEY_VALUE.matcher(arg).matches()) {
                    if (mapStart == -1)
                        mapStart = mapEnd = i;
                    else
                        mapEnd = i;
                } else if (mapStart != -1)
                    break;
            }

            if (mapStart != -1) {
                StringBuilder sb = new StringBuilder("[");
                for (int i = mapStart; i <= mapEnd; i++) {
                    if (sb.length() > 1)
                        sb.append(", ");
                    sb.append(l.remove(mapStart));
                }
                sb.append("]");
                l.add(mapStart, sb.toString());
            } else
                break;

            //reset
            mapStart = -1;
            mapEnd = -1;
        }
        return l;
    }

    private static Map<String, String> parseMap(String s) {
        Map<String, String> m = new LinkedHashMap<String, String>();
        s = s.substring(1, s.length() - 1);
        boolean quotesSingle = false;
        boolean quotesDouble = false;
        StringBuilder sb = new StringBuilder();
        String key = null;
        boolean escape = false;
        int brackets = 0;
        for (int i = 0; i < s.length(); i++) {
            char ch = s.charAt(i);
            switch (ch) {
                case '\'':
                    sb.append(ch);
                    if (!quotesDouble && !escape)
                        quotesSingle = !quotesSingle;
                    escape = false;
                    break;
                case '"':
                    sb.append(ch);
                    if (!quotesSingle && !escape)
                        quotesDouble = !quotesDouble;
                    escape = false;
                    break;
                case '(':
                    if (!quotesSingle && !quotesDouble) {
                        brackets++;
                    }
                    sb.append(ch);
                    break;
                case '[':
                    if (!quotesSingle && !quotesDouble) {
                        brackets++;
                    }
                    sb.append(ch);
                    break;
                case ')':
                    if (!quotesSingle && !quotesDouble) {
                        brackets--;
                    }
                    sb.append(ch);
                    break;
                case ']':
                    if (!quotesSingle && !quotesDouble) {
                        brackets--;
                    }
                    sb.append(ch);
                    break;
                case ':':
                    if (brackets > 0) {
                        sb.append(ch);
                        break;
                    }
                    if (!quotesSingle && !quotesDouble) {
                        key = sb.toString().trim();
                        sb.setLength(0);
                    } else {
                        sb.append(ch);
                    }
                    break;
                case ',':
                    if (brackets > 0) {
                        sb.append(ch);
                        break;
                    }
                    if (!quotesSingle && !quotesDouble) {
                        String value = sb.toString().trim();
                        m.put(key, value);
                        key = null;
                        sb.setLength(0);
                    } else {
                        sb.append(ch);
                    }
                    break;
                case '\\':
                    escape = !escape;
                    if (!escape) {
                        sb.append(ch);
                    }
                    break;
                default:
                    sb.append(ch);
                    break;
            }
        }
        if (sb.length() > 0) {
            String value = sb.toString().trim();
            m.put(key, value);
        }
        return m;
    }

    @SuppressWarnings("unchecked")
    public static <T> T evaluate(String exp) {
//        System.out.println("evaluate: " + exp + "\t" + model);
        Expression ex = prepare(exp, null);
        return (T) ex.get(null);
    }

    @SuppressWarnings("unchecked")
    public static <T> T evaluate(String exp, Map<String, Object> model) {
//        System.out.println("evaluate: " + exp + "\t" + model);
        Expression ex = prepare(exp, model);
        return (T) ex.get(model);
    }

    @SuppressWarnings("unchecked")
    public static <T> T evaluate(String exp, Map<String, Object> model, Map<String, UserFunction> functions) {
//        System.out.println("evaluate: " + exp + "\t" + model);
        Expression ex = prepare(exp, model, functions);
        return (T) ex.get(model);
    }

    static {
        Function.setMethod(Collection.class, "collect", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                List l = new ArrayList();
                ClosureExpression closure = (ClosureExpression) args[0].get();
                Collection c = (Collection) it;
                for (Object ob : c) {
                    l.add(closure.get(model, ob));
                }
                return l;
            }
        });
        Function.setMethod(Collection.class, "find", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                for (Object ob : c) {
                    if ((Boolean) closure.get(model, ob)) {
                        return ob;
                    }
                }
                return null;
            }
        });
        Function.setMethod(Collection.class, "findAll", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                List l = new ArrayList();
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                for (Object ob : c) {
                    if ((Boolean) closure.get(model, ob)) {
                        l.add(ob);
                    }
                }
                return l;
            }
        });
        Function.setMethod(Collection.class, "findIndexOf", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                int i = 0;
                for (Object ob : c) {
                    if ((Boolean) closure.get(model, ob)) {
                        return i;
                    }
                    i++;
                }
                return -1;
            }
        });
        Function.setMethod(Collection.class, "each", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                for (Object ob : c) {
                    closure.get(model, ob);
                }
                return null;
            }
        });
        Function.setMethod(Collection.class, "eachWithIndex", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                int i = 0;
                for (Object ob : c) {
                    closure.get(model, ob, i++);
                }
                return null;
            }
        });
        Function.setMethod(Collection.class, "every", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                for (Object ob : c) {
                    if (!(Boolean) closure.get(model, ob))
                        return false;
                }
                return true;
            }
        });
        Function.setMethod(Collection.class, "any", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                Collection c = (Collection) it;
                ClosureExpression closure = (ClosureExpression) args[0].get();
                for (Object ob : c) {
                    if ((Boolean) closure.get(model, ob))
                        return true;
                }
                return false;
            }
        });
        Function.setMethod(Collection.class, "join", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {
            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                StringBuilder sb = new StringBuilder();
                Collection c = (Collection) it;
                Object separator = args[0].get(model);
                for (Object ob : c) {
                    if (sb.length() != 0) {
                        sb.append(separator);
                    }
                    sb.append(ob);
                }
                return sb.toString();
            }
        });

        Function.setMethod(Number.class, "multiply", new CollectionTools.Closure3<Object, Object, Map, Expression[]>() {

            @Override
            public Object execute(Object it, Map model, Expression[] args) {
                if (args.length != 1)
                    throw new MissingMethodException(it.getClass(), "multiply", args);

                return Operation.multiply(it, args[0].get(model));
            }
        });
    }
}


text:
using ConvNetSharp.Flow.Ops;
using ConvNetSharp.Volume;
using ConvNetSharp.Volume.Double;
using NUnit.Framework;

namespace ConvNetSharp.Flow.Tests
{
    [TestFixture]
    public class DoubleOpTests : OpTests<double>
    {
        public DoubleOpTests()
        {
            Op<double>.Count = 1;
            BuilderInstance<double>.Volume = new VolumeBuilder();
        }

        protected override Volume<double> NewVolume(double[] values, Shape shape)
        {
            return BuilderInstance.Volume.From(values, shape);
        }
    }
}


text:
<?php

use yii\helpers\Html;
use yii\widgets\ActiveForm;

/* @var $this yii\web\View */
/* @var $model content\models\Catalog */
/* @var $form yii\widgets\ActiveForm */
?>

    <?php $form = ActiveForm::begin(); ?>

    <?= $form->field($model, 'catalog_english')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'catalog_name')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'sort_num')->textInput(['maxlength' => true]) ?>

    <?= $form->field($model, 'status')->dropDownList([ 'Y' => 'Y', 'N' => 'N', ], ['prompt' => '']) ?>

        <?= Html::submitButton($model->isNewRecord ? Yii::t('app', 'Create') : Yii::t('app', 'Update'), ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?>

    <?php ActiveForm::end(); ?>