text:
<Global.Microsoft.VisualBasic.CompilerServices.DesignerGenerated()> _
Partial Class Form1
    Inherits System.Windows.Forms.Form

    'Form overrides dispose to clean up the component list.
    <System.Diagnostics.DebuggerNonUserCode()> _
    Protected Overrides Sub Dispose(ByVal disposing As Boolean)
        Try
            If disposing AndAlso components IsNot Nothing Then
                components.Dispose()
            End If
        Finally
            MyBase.Dispose(disposing)
        End Try
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.
    'Do not modify it using the code editor.
    <System.Diagnostics.DebuggerStepThrough()> _
    Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(Form1))
        Me.GroupBox1 = New System.Windows.Forms.GroupBox()
        Me.btnBrowse = New System.Windows.Forms.Button()
        Me.txtFileLocation = New System.Windows.Forms.TextBox()
        Me.GroupBox2 = New System.Windows.Forms.GroupBox()
        Me.lnkCopySHA256 = New System.Windows.Forms.LinkLabel()
        Me.lnkCopySHA1 = New System.Windows.Forms.LinkLabel()
        Me.lnkCopyMD5 = New System.Windows.Forms.LinkLabel()
        Me.txtFileSHA256 = New System.Windows.Forms.TextBox()
        Me.Label3 = New System.Windows.Forms.Label()
        Me.txtFileSHA1 = New System.Windows.Forms.TextBox()
        Me.Label2 = New System.Windows.Forms.Label()
        Me.txtFileMD5 = New System.Windows.Forms.TextBox()
        Me.Label1 = New System.Windows.Forms.Label()
        Me.GroupBox3 = New System.Windows.Forms.GroupBox()
        Me.picFileCompareResult = New System.Windows.Forms.PictureBox()
        Me.lblFileCompareResult = New System.Windows.Forms.Label()
        Me.txtFileCompare = New System.Windows.Forms.TextBox()
        Me.Label4 = New System.Windows.Forms.Label()
        Me.btnFileCompare = New System.Windows.Forms.Button()
        Me.btnFileCalculateHash = New System.Windows.Forms.Button()
        Me.btnOptions = New System.Windows.Forms.Button()
        Me.btnAbout = New System.Windows.Forms.Button()
        Me.OpenFileDialog1 = New System.Windows.Forms.OpenFileDialog()
        Me.btnClear = New System.Windows.Forms.Button()
        Me.GroupBox1.SuspendLayout()
        Me.GroupBox2.SuspendLayout()
        Me.GroupBox3.SuspendLayout()
        CType(Me.picFileCompareResult, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'GroupBox1
        '
        Me.GroupBox1.Controls.Add(Me.btnBrowse)
        Me.GroupBox1.Controls.Add(Me.txtFileLocation)
        Me.GroupBox1.Location = New System.Drawing.Point(12, 12)
        Me.GroupBox1.Name = "GroupBox1"
        Me.GroupBox1.Size = New System.Drawing.Size(495, 59)
        Me.GroupBox1.TabIndex = 0
        Me.GroupBox1.TabStop = False
        Me.GroupBox1.Text = "File"
        '
        'btnBrowse
        '
        Me.btnBrowse.Location = New System.Drawing.Point(405, 18)
        Me.btnBrowse.Name = "btnBrowse"
        Me.btnBrowse.Size = New System.Drawing.Size(75, 23)
        Me.btnBrowse.TabIndex = 1
        Me.btnBrowse.Text = "Browse"
        Me.btnBrowse.UseVisualStyleBackColor = True
        '
        'txtFileLocation
        '
        Me.txtFileLocation.AllowDrop = True
        Me.txtFileLocation.Location = New System.Drawing.Point(20, 19)
        Me.txtFileLocation.Name = "txtFileLocation"
        Me.txtFileLocation.Size = New System.Drawing.Size(379, 20)
        Me.txtFileLocation.TabIndex = 0
        '
        'GroupBox2
        '
        Me.GroupBox2.Controls.Add(Me.lnkCopySHA256)
        Me.GroupBox2.Controls.Add(Me.lnkCopySHA1)
        Me.GroupBox2.Controls.Add(Me.lnkCopyMD5)
        Me.GroupBox2.Controls.Add(Me.txtFileSHA256)
        Me.GroupBox2.Controls.Add(Me.Label3)
        Me.GroupBox2.Controls.Add(Me.txtFileSHA1)
        Me.GroupBox2.Controls.Add(Me.Label2)
        Me.GroupBox2.Controls.Add(Me.txtFileMD5)
        Me.GroupBox2.Controls.Add(Me.Label1)
        Me.GroupBox2.Location = New System.Drawing.Point(12, 77)
        Me.GroupBox2.Name = "GroupBox2"
        Me.GroupBox2.Size = New System.Drawing.Size(495, 122)
        Me.GroupBox2.TabIndex = 1
        Me.GroupBox2.TabStop = False
        Me.GroupBox2.Text = "CheckSums"
        '
        'lnkCopySHA256
        '
        Me.lnkCopySHA256.AutoSize = True
        Me.lnkCopySHA256.Location = New System.Drawing.Point(406, 100)
        Me.lnkCopySHA256.Name = "lnkCopySHA256"
        Me.lnkCopySHA256.Size = New System.Drawing.Size(74, 13)
        Me.lnkCopySHA256.TabIndex = 2
        Me.lnkCopySHA256.TabStop = True
        Me.lnkCopySHA256.Text = "Copy SHA256"
        '
        'lnkCopySHA1
        '
        Me.lnkCopySHA1.AutoSize = True
        Me.lnkCopySHA1.Location = New System.Drawing.Point(245, 100)
        Me.lnkCopySHA1.Name = "lnkCopySHA1"
        Me.lnkCopySHA1.Size = New System.Drawing.Size(62, 13)
        Me.lnkCopySHA1.TabIndex = 2
        Me.lnkCopySHA1.TabStop = True
        Me.lnkCopySHA1.Text = "Copy SHA1"
        '
        'lnkCopyMD5
        '
        Me.lnkCopyMD5.AutoSize = True
        Me.lnkCopyMD5.Location = New System.Drawing.Point(70, 100)
        Me.lnkCopyMD5.Name = "lnkCopyMD5"
        Me.lnkCopyMD5.Size = New System.Drawing.Size(57, 13)
        Me.lnkCopyMD5.TabIndex = 2
        Me.lnkCopyMD5.TabStop = True
        Me.lnkCopyMD5.Text = "Copy MD5"
        '
        'txtFileSHA256
        '
        Me.txtFileSHA256.Location = New System.Drawing.Point(73, 73)
        Me.txtFileSHA256.Name = "txtFileSHA256"
        Me.txtFileSHA256.ReadOnly = True
        Me.txtFileSHA256.Size = New System.Drawing.Size(407, 20)
        Me.txtFileSHA256.TabIndex = 1
        '
        'Label3
        '
        Me.Label3.AutoSize = True
        Me.Label3.Location = New System.Drawing.Point(6, 77)
        Me.Label3.Name = "Label3"
        Me.Label3.Size = New System.Drawing.Size(50, 13)
        Me.Label3.TabIndex = 0
        Me.Label3.Text = "SHA256:"
        '
        'txtFileSHA1
        '
        Me.txtFileSHA1.Location = New System.Drawing.Point(73, 47)
        Me.txtFileSHA1.Name = "txtFileSHA1"
        Me.txtFileSHA1.ReadOnly = True
        Me.txtFileSHA1.Size = New System.Drawing.Size(407, 20)
        Me.txtFileSHA1.TabIndex = 1
        '
        'Label2
        '
        Me.Label2.AutoSize = True
        Me.Label2.Location = New System.Drawing.Point(6, 51)
        Me.Label2.Name = "Label2"
        Me.Label2.Size = New System.Drawing.Size(38, 13)
        Me.Label2.TabIndex = 0
        Me.Label2.Text = "SHA1:"
        '
        'txtFileMD5
        '
        Me.txtFileMD5.Location = New System.Drawing.Point(73, 21)
        Me.txtFileMD5.Name = "txtFileMD5"
        Me.txtFileMD5.ReadOnly = True
        Me.txtFileMD5.Size = New System.Drawing.Size(407, 20)
        Me.txtFileMD5.TabIndex = 1
        '
        'Label1
        '
        Me.Label1.AutoSize = True
        Me.Label1.Location = New System.Drawing.Point(6, 25)
        Me.Label1.Name = "Label1"
        Me.Label1.Size = New System.Drawing.Size(33, 13)
        Me.Label1.TabIndex = 0
        Me.Label1.Text = "MD5:"
        '
        'GroupBox3
        '
        Me.GroupBox3.Controls.Add(Me.picFileCompareResult)
        Me.GroupBox3.Controls.Add(Me.lblFileCompareResult)
        Me.GroupBox3.Controls.Add(Me.txtFileCompare)
        Me.GroupBox3.Controls.Add(Me.Label4)
        Me.GroupBox3.Location = New System.Drawing.Point(16, 205)
        Me.GroupBox3.Name = "GroupBox3"
        Me.GroupBox3.Size = New System.Drawing.Size(495, 100)
        Me.GroupBox3.TabIndex = 2
        Me.GroupBox3.TabStop = False
        Me.GroupBox3.Text = "Compare"
        '
        'picFileCompareResult
        '
        Me.picFileCompareResult.Image = Global.CheckSum.My.Resources.Resources.correct
        Me.picFileCompareResult.Location = New System.Drawing.Point(73, 44)
        Me.picFileCompareResult.Name = "picFileCompareResult"
        Me.picFileCompareResult.Size = New System.Drawing.Size(50, 50)
        Me.picFileCompareResult.TabIndex = 3
        Me.picFileCompareResult.TabStop = False
        '
        'lblFileCompareResult
        '
        Me.lblFileCompareResult.AutoSize = True
        Me.lblFileCompareResult.Font = New System.Drawing.Font("Microsoft Sans Serif", 12.0!, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, CType(0, Byte))
        Me.lblFileCompareResult.Location = New System.Drawing.Point(136, 59)
        Me.lblFileCompareResult.Name = "lblFileCompareResult"
        Me.lblFileCompareResult.Size = New System.Drawing.Size(35, 20)
        Me.lblFileCompareResult.TabIndex = 2
        Me.lblFileCompareResult.Text = "N/A"
        '
        'txtFileCompare
        '
        Me.txtFileCompare.Location = New System.Drawing.Point(73, 17)
        Me.txtFileCompare.Name = "txtFileCompare"
        Me.txtFileCompare.Size = New System.Drawing.Size(407, 20)
        Me.txtFileCompare.TabIndex = 1
        '
        'Label4
        '
        Me.Label4.AutoSize = True
        Me.Label4.Location = New System.Drawing.Point(7, 20)
        Me.Label4.Name = "Label4"
        Me.Label4.Size = New System.Drawing.Size(35, 13)
        Me.Label4.TabIndex = 0
        Me.Label4.Text = "Hash:"
        '
        'btnFileCompare
        '
        Me.btnFileCompare.Location = New System.Drawing.Point(517, 82)
        Me.btnFileCompare.Name = "btnFileCompare"
        Me.btnFileCompare.Size = New System.Drawing.Size(91, 23)
        Me.btnFileCompare.TabIndex = 3
        Me.btnFileCompare.Text = "Compare Hash"
        Me.btnFileCompare.UseVisualStyleBackColor = True
        '
        'btnFileCalculateHash
        '
        Me.btnFileCalculateHash.Location = New System.Drawing.Point(517, 16)
        Me.btnFileCalculateHash.Name = "btnFileCalculateHash"
        Me.btnFileCalculateHash.Size = New System.Drawing.Size(91, 23)
        Me.btnFileCalculateHash.TabIndex = 3
        Me.btnFileCalculateHash.Text = "Calculate Hash"
        Me.btnFileCalculateHash.UseVisualStyleBackColor = True
        '
        'btnOptions
        '
        Me.btnOptions.Location = New System.Drawing.Point(517, 214)
        Me.btnOptions.Name = "btnOptions"
        Me.btnOptions.Size = New System.Drawing.Size(91, 23)
        Me.btnOptions.TabIndex = 4
        Me.btnOptions.Text = "Options"
        Me.btnOptions.UseVisualStyleBackColor = True
        '
        'btnAbout
        '
        Me.btnAbout.Location = New System.Drawing.Point(517, 280)
        Me.btnAbout.Name = "btnAbout"
        Me.btnAbout.Size = New System.Drawing.Size(91, 23)
        Me.btnAbout.TabIndex = 4
        Me.btnAbout.Text = "About"
        Me.btnAbout.UseVisualStyleBackColor = True
        '
        'OpenFileDialog1
        '
        Me.OpenFileDialog1.DefaultExt = "*.*"
        Me.OpenFileDialog1.Filter = "All files (*.*)|*.*"
        Me.OpenFileDialog1.Title = "Select File"
        '
        'btnClear
        '
        Me.btnClear.Location = New System.Drawing.Point(518, 148)
        Me.btnClear.Name = "btnClear"
        Me.btnClear.Size = New System.Drawing.Size(91, 23)
        Me.btnClear.TabIndex = 3
        Me.btnClear.Text = "Clear"
        Me.btnClear.UseVisualStyleBackColor = True
        '
        'Form1
        '
        Me.AutoScaleDimensions = New System.Drawing.SizeF(6.0!, 13.0!)
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.ClientSize = New System.Drawing.Size(621, 313)
        Me.Controls.Add(Me.btnAbout)
        Me.Controls.Add(Me.btnOptions)
        Me.Controls.Add(Me.btnFileCalculateHash)
        Me.Controls.Add(Me.btnClear)
        Me.Controls.Add(Me.btnFileCompare)
        Me.Controls.Add(Me.GroupBox1)
        Me.Controls.Add(Me.GroupBox3)
        Me.Controls.Add(Me.GroupBox2)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.MaximizeBox = False
        Me.Name = "Form1"
        Me.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen
        Me.Text = "CheckSum"
        Me.GroupBox1.ResumeLayout(False)
        Me.GroupBox1.PerformLayout()
        Me.GroupBox2.ResumeLayout(False)
        Me.GroupBox2.PerformLayout()
        Me.GroupBox3.ResumeLayout(False)
        Me.GroupBox3.PerformLayout()
        CType(Me.picFileCompareResult, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub
    Friend WithEvents GroupBox2 As System.Windows.Forms.GroupBox
    Friend WithEvents txtFileSHA256 As System.Windows.Forms.TextBox
    Friend WithEvents Label3 As System.Windows.Forms.Label
    Friend WithEvents txtFileSHA1 As System.Windows.Forms.TextBox
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtFileMD5 As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents GroupBox1 As System.Windows.Forms.GroupBox
    Friend WithEvents btnBrowse As System.Windows.Forms.Button
    Friend WithEvents txtFileLocation As System.Windows.Forms.TextBox
    Friend WithEvents GroupBox3 As System.Windows.Forms.GroupBox
    Friend WithEvents picFileCompareResult As System.Windows.Forms.PictureBox
    Friend WithEvents lblFileCompareResult As System.Windows.Forms.Label
    Friend WithEvents txtFileCompare As System.Windows.Forms.TextBox
    Friend WithEvents Label4 As System.Windows.Forms.Label
    Friend WithEvents btnFileCompare As System.Windows.Forms.Button
    Friend WithEvents btnFileCalculateHash As System.Windows.Forms.Button
    Friend WithEvents btnOptions As System.Windows.Forms.Button
    Friend WithEvents btnAbout As System.Windows.Forms.Button
    Friend WithEvents OpenFileDialog1 As System.Windows.Forms.OpenFileDialog
    Friend WithEvents btnClear As System.Windows.Forms.Button
    Friend WithEvents lnkCopyMD5 As System.Windows.Forms.LinkLabel
    Friend WithEvents lnkCopySHA256 As System.Windows.Forms.LinkLabel
    Friend WithEvents lnkCopySHA1 As System.Windows.Forms.LinkLabel

End Class


text:
namespace service_manager {

extern COMPONENT_EXPORT(SERVICE_MANAGER_CPP) const base::Token
    kSystemInstanceGroup;

}  // namespace service_manager

#endif  // SERVICES_SERVICE_MANAGER_PUBLIC_CPP_CONSTANTS_H_

redpajama_set_name: RedPajamaGithub


text:
module CZMQ
  module FFI

    # sending and receiving strings
    class Zstr
      class DestroyedError < RuntimeError; end

      # Boilerplate for self pointer, initializer, and finalizer
      class << self
        alias :__new :new
      end
      def initialize ptr, finalize=true
        @ptr = ptr
        if @ptr.null?
          @ptr = nil # Remove null pointers so we don't have to test for them.
        elsif finalize
          @finalizer = self.class.send :create_finalizer_for, @ptr
          ObjectSpace.define_finalizer self, @finalizer
        end
      end
      def self.create_finalizer_for ptr
        Proc.new do
          "WARNING: "\
          "Objects of type #{self} cannot be destroyed implicitly. "\
          "Please call the correct destroy method with the relevant arguments."
        end
      end
      def null?
        !@ptr or ptr.null?
      end
      # Return internal pointer
      def __ptr
        raise DestroyedError unless @ptr
        @ptr
      end
      # So external Libraries can just pass the Object to a FFI function which expects a :pointer
      alias_method :to_ptr, :__ptr
      # Nullify internal pointer and return pointer pointer
      def __ptr_give_ref
        raise DestroyedError unless @ptr
        ptr_ptr = ::FFI::MemoryPointer.new :pointer
        ptr_ptr.write_pointer @ptr
        ObjectSpace.undefine_finalizer self if @finalizer
        @finalizer = nil
        @ptr = nil
        ptr_ptr
      end

      # Receive C string from socket. Caller must free returned string using
      # zstr_free(). Returns NULL if the context is being terminated or the
      # process was interrupted.
      def self.recv source
        result = ::CZMQ::FFI.zstr_recv source
        result
      end

      # Send a C string to a socket, as a frame. The string is sent without
      # trailing null byte; to read this you can use zstr_recv, or a similar
      # method that adds a null terminator on the received string. String
      # may be NULL, which is sent as "".
      def self.send dest, string
        string = String(string)
        result = ::CZMQ::FFI.zstr_send dest, string
        result
      end

      # Send a C string to a socket, as zstr_send(), with a MORE flag, so that
      # you can send further strings in the same multi-part message.
      def self.sendm dest, string
        string = String(string)
        result = ::CZMQ::FFI.zstr_sendm dest, string
        result
      end

      # Send a formatted string to a socket. Note that you should NOT use
      # user-supplied strings in the format (they may contain '%' which
      # will create security holes).
      def self.sendf dest, format, result
        format = String(format)
        result = ::CZMQ::FFI.zstr_sendf dest, format, result
        result
      end

      # Send a formatted string to a socket, as for zstr_sendf(), with a
      # MORE flag, so that you can send further strings in the same multi-part
      # message.
      def self.sendfm dest, format, result
        format = String(format)
        result = ::CZMQ::FFI.zstr_sendfm dest, format, result
        result
      end

      # Send a series of strings (until NULL) as multipart data
      # Returns 0 if the strings could be sent OK, or -1 on error.
      def self.sendx dest, string, result
        string = String(string)
        result = ::CZMQ::FFI.zstr_sendx dest, string, result
        result
      end

      # Receive a series of strings (until NULL) from multipart data.
      # Each string is allocated and filled with string data; if there
      # are not enough frames, unallocated strings are set to NULL.
      # Returns -1 if the message could not be read, else returns the
      # number of strings filled, zero or more. Free each returned string
      # using zstr_free(). If not enough strings are provided, remaining
      # multipart frames in the message are dropped.
      def self.recvx source, string_p, result
        result = ::CZMQ::FFI.zstr_recvx source, string_p, result
        result
      end

      # Free a provided string, and nullify the parent pointer. Safe to call on
      # a null pointer.
      def self.free string_p
        result = ::CZMQ::FFI.zstr_free string_p
        result
      end

      # Self test of this class
      def self.test verbose
        verbose = !(0==verbose||!verbose) # boolean
        result = ::CZMQ::FFI.zstr_test verbose
        result
      end
    end

  end
end

################################################################################
#  THIS FILE IS 100% GENERATED BY ZPROJECT; DO NOT EDIT EXCEPT EXPERIMENTALLY  #
#  Please refer to the README for information about making permanent changes.  #
################################################################################


text:
package org.kodejava.example.geom;

import javax.swing.*;
import java.awt.*;
import java.awt.geom.GeneralPath;

public class DrawGeneralPath extends JComponent {
    @Override
    public void paint(Graphics g) {
        Graphics2D g2 = (Graphics2D) g;

        g2.setStroke(new BasicStroke(4.0f));
        g2.setPaint(Color.GREEN);

        int[] xPoints = {10, 50, 100, 150, 200, 250, 300, 350};
        int[] yPoints = {10, 50,  10,  50,  10,  50,  10,  50};
        GeneralPath path = new GeneralPath(GeneralPath.WIND_EVEN_ODD,
            xPoints.length);

        // Adds point to the path by moving to the specified
        // coordinates.
        path.moveTo(xPoints[0], yPoints[0]);
        for (int i = 1; i < xPoints.length; i++) {
            // Adds a point to the path by drawing a straight
            // line from the current position to the specified
            // coordinates.
            path.lineTo(xPoints[i], yPoints[i]);
        }
        path.curveTo(150, 150, 300, 300, 50, 250);
        path.closePath();
        g2.draw(path);

        // Draw another path, a start
        g2.setPaint(Color.RED);
        g2.setStroke(new BasicStroke(2.0f));
        path = new GeneralPath(GeneralPath.WIND_NON_ZERO);
        path.moveTo(200, 50);
        path.lineTo(270, 300);
        path.lineTo(100, 120);
        path.lineTo(300, 120);
        path.lineTo(130, 300);
        path.closePath();
        g2.draw(path);

    }

    public static void main(String[] args) {
        JFrame frame = new JFrame("Draw GeneralPath Demo");
        frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
        frame.getContentPane().add(new DrawGeneralPath());
        frame.pack();
        frame.setSize(new Dimension(420, 400));
        frame.setVisible(true);
    }
}


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

<title>TestCompareParameterAveragingSparkVsSingleMachine</title>
<meta name="date" content="2016-09-19">
<link rel="stylesheet" type="text/css" href="../../../../../stylesheet.css" title="Style">

JavaScript is disabled on your browser.

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method

org.deeplearning4j.spark.impl.paramavg

Class TestCompareParameterAveragingSparkVsSingleMachine

java.lang.Object

org.deeplearning4j.spark.impl.paramavg.TestCompareParameterAveragingSparkVsSingleMachine

public class TestCompareParameterAveragingSparkVsSingleMachine
extends java.lang.Object

Created by Alex on 18/06/2016.

Constructor Summary

Constructors

Constructor and Description

TestCompareParameterAveragingSparkVsSingleMachine()

Method Summary

All Methods Instance Methods Concrete Methods

Modifier and Type
Method and Description

void
setUp()

void
testAverageEveryStep()

void
testAverageEveryStepCNN()

void
testAverageEveryStepGraph()

void
testAverageEveryStepGraphCNN()

void
testOneExecutor()

void
testOneExecutorGraph()

Methods inherited from class java.lang.Object

clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Detail

TestCompareParameterAveragingSparkVsSingleMachine

public TestCompareParameterAveragingSparkVsSingleMachine()

Method Detail

setUp

public void setUp()

testOneExecutor

public void testOneExecutor()

testOneExecutorGraph

public void testOneExecutorGraph()

testAverageEveryStep

public void testAverageEveryStep()

testAverageEveryStepCNN

public void testAverageEveryStepCNN()

testAverageEveryStepGraph

public void testAverageEveryStepGraph()

testAverageEveryStepGraphCNN

public void testAverageEveryStepGraphCNN()

Skip navigation links

Overview

Package

Class

Tree

Deprecated

Index

Help

Prev Class

Next Class

Frames

No Frames

All Classes

Summary:

Nested |

Field |

Constr |

Method

Detail:

Field |

Constr |

Method


text:
package com.yqclouds.commerce.core.order.order.model;

import com.yqclouds.commerce.core.product.enums.Unit;
import com.yqclouds.commerce.core.product.model.Product;
import org.springframework.data.jpa.domain.AbstractPersistable;

import javax.persistence.Entity;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "CMC_ORDER_ENTRY")
public class OrderEntry extends AbstractPersistable<Long> {
    private Integer entryNumber;

    private Product product;

    private Long quantity;

    private Double basePrice;

    private Double totalPrice;

    private Unit unit = Unit.NONE;

    @ManyToOne(optional = false)
    private Order order;

    public Integer getEntryNumber() {
        return entryNumber;
    }

    public void setEntryNumber(Integer entryNumber) {
        this.entryNumber = entryNumber;
    }

    public Product getProduct() {
        return product;
    }

    public void setProduct(Product product) {
        this.product = product;
    }

    public Long getQuantity() {
        return quantity;
    }

    public void setQuantity(Long quantity) {
        this.quantity = quantity;
    }

    public Double getBasePrice() {
        return basePrice;
    }

    public void setBasePrice(Double basePrice) {
        this.basePrice = basePrice;
    }

    public Double getTotalPrice() {
        return totalPrice;
    }

    public void setTotalPrice(Double totalPrice) {
        this.totalPrice = totalPrice;
    }

    public Unit getUnit() {
        return unit;
    }

    public void setUnit(Unit unit) {
        this.unit = unit;
    }

    public Order getOrder() {
        return order;
    }

    public void setOrder(Order order) {
        this.order = order;
    }
}


text:
import chai from 'chai';
import sinon from 'sinon';
import sinonChai from 'sinon-chai';
import jsdom from 'jsdom-global';
import MockStorage from 'mock-localstorage';
import { afterEach, beforeEach, describe, it } from 'mocha';
import Oauth2 from '../src/authorization/oauth2.js';

const expect = chai.expect;
chai.use(sinonChai);
let oauthInstance;

describe('oauth2', function() {
    beforeEach(function() {
        global.cleanup = jsdom();
        global.localStorage = new MockStorage();

        let options = {
            appId: 'fakeAppId',
            redirectURI: 'fakeURI'
        };
        oauthInstance = new Oauth2(options);

        sinon.spy(oauthInstance, '_loginRedirect');
    });

    afterEach(() => {
        global.cleanup();
    });

    describe('#login', function() {
        it('should bulid a URL with provided app id and redirect uri', function() {
            oauthInstance.login();

            expect(oauthInstance._loginRedirect).to.have.been.calledWith('https://api.relayr.io/oauth2/auth?client_id=fakeAppId&redirect_uri=fakeURI&response_type=token&scope=access-own-user-info+configure-devices');
        });

        it('should build a URL with configured input ', function() {
            oauthInstance.appId = 'new-fake-app-id';
            oauthInstance.login();

            expect(oauthInstance._loginRedirect).to.have.been.calledWith('https://api.relayr.io/oauth2/auth?client_id=new-fake-app-id&redirect_uri=fakeURI&response_type=token&scope=access-own-user-info+configure-devices');
        });

        it('should throw an error if no redirect uri was provided', function() {
            oauthInstance.redirectURI = null;
            const fn = function() {
                oauthInstance.login();
            };
            expect(fn).to.throw(Error);
        });

        it('should throw an error if no app id was provided', function() {
            oauthInstance.appId = null;
            const fn = function() {
                oauthInstance.login();
            };
            expect(fn).to.throw(Error);
        });

        it('should have a response type token', function() {
            oauthInstance.appId = null;
            const fn = function() {
                oauthInstance.login();
            };
            expect(fn).to.throw(Error);
        });

        describe('and it should persist credentials', function() {
            beforeEach(function() {
                let options = {
                    appId: 'fakeAppId',
                    redirectURI: 'fakeURI',
                    persist: true
                };
                oauthInstance = new Oauth2(options);

                sinon.spy(oauthInstance, '_loginRedirect');
            });

            it('should not redirect if access token is present', function() {
                localStorage.setItem('relayr_access_token', 'FAKE_ACCESS_TOKEN');

                oauthInstance.login();

                expect(oauthInstance._loginRedirect).not.to.have.been.called;
            });

            it('should fetch token from localStorage', function() {
                localStorage.setItem('relayr_access_token', 'FAKE_ACCESS_TOKEN');

                oauthInstance.login();

                expect(oauthInstance.token).to.equal('FAKE_ACCESS_TOKEN');
            });

            it('should redirect if access token is not present', function() {
                localStorage.removeItem('relayr_access_token');

                oauthInstance.login();

                expect(oauthInstance._loginRedirect).to.have.been.called;
            });
        });
    });

    describe('#_loginRedirect', function() {
        beforeEach(function() {
            let options = {
                appId: 'fakeAppId',
                redirectURI: 'fakeURI',
                persist: true
            };

            oauthInstance = new Oauth2(options);
            sinon.spy(oauthInstance, '_loginRedirect');
        });

        it('should build the redirect from the appID and redirect URI', function() {
            //do we need this?
            let uri = 'https://api.relayr.io/oauth2/auth?client_id=fakeAppId&redirect_uri=fakeURI&response_type=token&scope=access-own-user-info+configure-devices';
            oauthInstance._loginRedirect(uri);
            expect(oauthInstance._loginRedirect).to.have.been.calledWith('https://api.relayr.io/oauth2/auth?client_id=fakeAppId&redirect_uri=fakeURI&response_type=token&scope=access-own-user-info+configure-devices');
        });
    });

    describe('#_parseToken', function() {
        it('should return token provided in URL as a query paramter', function() {
            oauthInstance._parseToken('example.com/oauth#access_token=A_FAKE_TOKEN&token_type=Bearer');
            expect(oauthInstance.token).to.equal('Bearer A_FAKE_TOKEN');
        });

        it('should throw an error when the URL is emptys', function() {
            const fn = function() {
                oauthInstance._parseToken('');
            };
            expect(fn).to.throw(Error);
        });

        it('should throw an error when no query parameter is provided', function() {
            const fn = function() {
                oauthInstance._parseToken('example.com/oauth#');
            };
            expect(fn).to.throw(Error);
        });

        it('should throw an error when no access token is provided', function() {
            const fn = function() {
                oauthInstance._parseToken('example.com/oauth#BLABLA');
            };
            expect(fn).to.throw(Error);
        });

        describe('and it should persist credentials', function() {
            it('should persist the access token in local storage as well', function() {

            });
        });
    });

    describe('#setToken', function() {
        beforeEach(function() {
            let options = {
                appId: 'fakeAppId',
                redirectURI: 'fakeURI',
                persist: true
            };
            oauthInstance = new Oauth2(options);
            oauthInstance.token = 'A_FAKE_TOKEN';
        });

        it('should save token to local storage', function() {
            oauthInstance.setToken();

            expect(localStorage.getItem('relayr_access_token')).to.equal('A_FAKE_TOKEN');
        });

    });

    describe('#logout', function() {
        beforeEach(function() {
            let options = {
                appId: 'fakeAppId',
                redirectURI: 'fakeURI',
                persist: true
            };
            oauthInstance = new Oauth2(options);
            oauthInstance.token = 'A_FAKE_TOKEN';

            localStorage.setItem('relayr_access_token', oauthInstance.token);
        });

        it('should remove the token from local storage', function() {
            oauthInstance.logout();
            expect(localStorage.getItem('relayr_access_token')).to.be.undefined;
        });
    });

});


text:
namespace SilverNeedle.Serialization
{
    using System;
    public class EntityNotFoundException : Exception
    {
        public EntityNotFoundException()
        {
        }

        public EntityNotFoundException(string message)
            : base(message)
        {
        }

        public EntityNotFoundException(string message, Exception inner)
            : base(message, inner)
        {
        }
    }
}


text:
from .nominal_behavior import NominalBehavior
from .store_flight_data import StoreFlightData


text:
package com.jcabi.github;

import com.jcabi.github.mock.MkGithub;
import com.jcabi.http.Request;
import com.jcabi.http.mock.MkAnswer;
import com.jcabi.http.mock.MkContainer;
import com.jcabi.http.mock.MkGrizzlyContainer;
import com.jcabi.http.request.ApacheRequest;
import java.net.HttpURLConnection;
import javax.json.Json;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.junit.Test;

/**
 * Test case for {@link RtReference}.
 *
 * @author Mihai Andronache (amihaiemil@gmail.com)
 * @version $Id$
 * @checkstyle MultipleStringLiterals (500 lines)
 */
public final class RtReferenceTest {

    /**
     * RtReference should be able to execute patch.
     * @throws Exception - If something goes wrong.
     */
    @Test
    public void patchesContent() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"ref\":\"refs/heads/featureA\"}"
            )
        ).start();
        final Reference reference = new RtReference(
            new ApacheRequest(container.home()),
            new MkGithub().randomRepo(),
            "refs/heads/featureA"
        );
        try {
            reference.patch(
                Json.createObjectBuilder().add("sha", "abcdef12345")
                .add("force", "false").build()
            );
            MatcherAssert.assertThat(
                container.take().method(),
                Matchers.equalTo(Request.PATCH)
            );
        } finally {
            container.stop();
        }
    }

    /**
     * RtReference should be able to fetch its json.
     * @throws Exception - if something goes wrong.
     */
    @Test
    public void fetchesContent() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"ref\":\"refs/heads/featureB\"}"
            )
        ).start();
        final Reference reference = new RtReference(
            new ApacheRequest(container.home()),
            new MkGithub().randomRepo(),
            "refs/heads/featureB"
        );
        try {
            MatcherAssert.assertThat(
                reference.json().getString("ref"),
                Matchers.is("refs/heads/featureB")
            );
        } finally {
            container.stop();
        }
    }

    /**
     * RtReference should be able to return its ref.
     * @throws Exception - If something goes wrong.
     */
    @Test
    public void returnsRef() throws Exception {
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"ref\":\"refs/heads/featureC\"}"
            )
        ).start();
        final Reference reference = new RtReference(
            new ApacheRequest(container.home()),
            new MkGithub().randomRepo(),
            "refs/heads/featureC"
        );
        try {
            MatcherAssert.assertThat(
                reference.ref(),
                Matchers.is("refs/heads/featureC")
            );
        } finally {
            container.stop();
        }
    }

    /**
     * RtReference should be able to return its owner repo.
     * @throws Exception - If something goes wrong.
     */
    @Test
    public void returnsOwner() throws Exception {
        final Repo owner = new MkGithub().randomRepo();
        final MkContainer container = new MkGrizzlyContainer().next(
            new MkAnswer.Simple(
                HttpURLConnection.HTTP_OK,
                "{\"ref\":\"refs/heads/featureD\"}"
            )
        ).start();
        final Reference reference = new RtReference(
            new ApacheRequest(container.home()), owner, "refs/heads/featureD"
        );
        try {
            MatcherAssert.assertThat(
                reference.repo(),
                Matchers.is(owner)
            );
        } finally {
            container.stop();
        }
    }
}


text:
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package App;

/**
 *
 * @author Felipe Rubin
 */

//import ConnectionProperties;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ServerConnect {
    private Connection connection = null;
    private ConnectionProperties cprop;

    public ServerConnect(){

    }

    public ConnectionProperties getConnectionProp() {
        return cprop;
    }

    public void setConnectionProp(ConnectionProperties cprop){
        this.cprop = cprop;
    }

    public void setConnection(Connection connection){

        this.connection = connection;
    }

    public void initConnection(){
        getConnection();
    }

    public Connection getConnection() {
        connection = getConnectionMySQL(cprop);
        return connection;
    }

    public ServerConnect(ConnectionProperties cprop) {
        this.cprop = cprop;

    }

    public static Connection getConnectionMySQL(ConnectionProperties cprop) {

        Connection connection = null;

        try{

            String driverName = "com.mysql.jdbc.Driver";
            Class.forName(driverName);
            connection = DriverManager.getConnection(cprop.getUrl(), cprop.getUser(), cprop.getPass());

            if(connection != null){
              return connection;
            }else{return null;}
        }catch (ClassNotFoundException | SQLException e) {//Driver nao encontrado
            System.out.println("WTF\n"+e.getMessage() + "\nWTF");
            return null;
        }
    }

    public static boolean CloseConnection(Connection c) {

        try {
            c.close();
            return true;
        } catch (SQLException e) {
            return false;
        }
    }

    public ResultSet QueryEndereco(){
        Statement st = null;
        String sql;

        try{
            st = connection.createStatement();
            sql = "SELECT * FROM Endereco";
            ResultSet rs = st.executeQuery(sql);
            return rs;
        }catch (SQLException ex){
            Logger.getLogger(ServerConnect.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public ResultSet QueryPedido(){
        Statement st = null;
        String sql;

        try{
            st = connection.createStatement();
            sql = "SELECT * FROM Pedido";
            ResultSet rs = st.executeQuery(sql);
            return rs;
        }catch (SQLException ex){
            Logger.getLogger(ServerConnect.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }
        public ResultSet QueryProfile(){
        Statement st = null;
        String sql;

        try{
            st = connection.createStatement();
            sql = "SELECT * FROM Profile";
            ResultSet rs = st.executeQuery(sql);
            return rs;
        }catch (SQLException ex){
            Logger.getLogger(ServerConnect.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public ResultSet QueryGeneric(String sql){ //Generica requer input da Sql

        Statement st = null;
        if(connection == null) System.out.println("ta null");
        try{
            st = connection.createStatement();
            ResultSet rs = st.executeQuery(sql);
            return rs;
        }catch (SQLException ex){
            Logger.getLogger(ServerConnect.class.getName()).log(Level.SEVERE, null, ex);
            return null;
        }
    }

    public void insertQuery(String sql){
        Statement st = null;
        try{
            st = connection.createStatement();
            st.executeUpdate(sql);
        }catch(Exception e){
            System.out.println(e.getMessage());
        }

    }
}


text:
local self = {}
mUI.XML = self

local TOKENIZER = {
    IDLE = 0,
    IDENTIFIER = 1,
    CARRIAGERETURN = 2,
    QUOTED_SINGLE = 3,
    QUOTED_DOUBLE = 4,
    ESCAPED = 5
}

function self:Tokenize(str)
    local mode = TOKENIZER.IDLE
    local tokens = {}
    local line,col = 1,0
    local tempBuffer1
    local tempBuffer2

    local escapeSequences = {
        nbsp = " ",
        lt = "<",
        gt = ">",
        amp = "&",
        quot = "\"",
        apos = "'",
        nl = "\n" -- because
    }

    for char in str:gmatch("(.)") do
        col = col + 1
        ::parser::
        if mode == TOKENIZER.IDLE then
            if char == "\n" then
                tokens[#tokens + 1] = {
                    type = "NewLine",
                    data = char,
                    line = line,
                    col = col
                }
                line = line + 1
                col = 0
            elseif char == "\r" then
                tokens[#tokens + 1] = {
                    type = "NewLine",
                    data = char,
                    line = line,
                    col = col
                }
                mode = TOKENIZER.CARRIAGERETURN
            elseif char == "<" then
                tokens[#tokens + 1] = {
                    type = "TagOpen",
                    data = char,
                    line = line,
                    col = col
                }
            elseif char == " " then
                if tokens[#tokens].type == "Whitespace" then
                    tokens[#tokens].data = tokens[#tokens].data..char
                else
                    tokens[#tokens + 1] = {
                        type = "Whitespace",
                        data = char,
                        line = line,
                        col = col
                    }
                end
            elseif char == "\t" then
                if tokens[#tokens].type == "Tab" then
                    tokens[#tokens].data = tokens[#tokens].data..char
                else
                    tokens[#tokens + 1] = {
                        type = "Tab",
                        data = char,
                        line = line,
                        col = col
                    }
                end
            elseif char == ">" then
                tokens[#tokens + 1] = {
                    type = "TagClose",
                    data = char,
                    line = line,
                    col = col
                }
            elseif char == "/" then
                tokens[#tokens + 1] = {
                    type = "Slash",
                    data = char,
                    line = line,
                    col = col
                }
            elseif char == "=" then
                tokens[#tokens + 1] = {
                    type = "Equals",
                    data = char,
                    line = line,
                    col = col
                }
            elseif char == "\"" then
                tokens[#tokens + 1] = {
                    type = "Quote",
                    data = char,
                    line = line,
                    col = col
                }
                tokens[#tokens + 1] = {
                    type = "Text",
                    data = "",
                    line = line,
                    col = col
                }
                mode = TOKENIZER.QUOTED_DOUBLE
            elseif char == "'" then
                tokens[#tokens + 1] = {
                    type = "Quote",
                    data = char,
                    line = line,
                    col = col
                }
                tokens[#tokens + 1] = {
                    type = "Text",
                    data = "",
                    line = line,
                    col = col
                }
                mode = TOKENIZER.QUOTED_SINGLE
            elseif char == "&" then
                if not (tokens[#tokens] and tokens[#tokens].type == "Identifier") then
                    tokens[#tokens + 1] = {
                        type = "Identifier",
                        data = "",
                        line = line,
                        col = col
                    }
                end
                tempBuffer1 = ""
                tempBuffer2 = mode
                mode = TOKENIZER.ESCAPED
            elseif char:match("[^<>\r\n =]") then
                tokens[#tokens + 1] = {
                    type = "Identifier",
                    data = char,
                    line = line,
                    col = col
                }
                mode = TOKENIZER.IDENTIFIER
            else
                error("Unexpected character: "..char.." at line "..line.." col "..col)
            end
        elseif mode == TOKENIZER.IDENTIFIER then
            if char:match("[^<>\r\n =]") then
                tokens[#tokens].data = tokens[#tokens].data..char
            else
                mode = TOKENIZER.IDLE
                goto parser
            end
        elseif mode == TOKENIZER.CARRIAGERETURN then
            if char == "\n" then
                tokens[#tokens].data = tokens[#tokens].data..char
                mode = TOKENIZER.IDLE
                line = line + 1
                col = 0
            else
                error("Malformed carriage return at line "..line.." col "..col)
            end
        elseif (mode == TOKENIZER.QUOTED_SINGLE) then
            if char:match("[^'\r\n&]") then
                tokens[#tokens].data = tokens[#tokens].data..char
            elseif char == "&" then
                tempBuffer1 = ""
                tempBuffer2 = mode
                mode = TOKENIZER.ESCAPED
            elseif char == "'" then
                tokens[#tokens + 1] = {
                    type = "Quote",
                    data = char,
                    line = line,
                    col = col
                }
                mode = TOKENIZER.IDLE
            else
                error("Malformed quoted text at line "..line.." col "..col)
            end
        elseif (mode == TOKENIZER.QUOTED_DOUBLE) then
            if char:match("[^\"\r\n&]") then
                tokens[#tokens].data = tokens[#tokens].data..char
            elseif char == "&" then
                tempBuffer1 = ""
                tempBuffer2 = mode
                mode = TOKENIZER.ESCAPED
            elseif char == "\"" then
                tokens[#tokens + 1] = {
                    type = "Quote",
                    data = char,
                    line = line,
                    col = col
                }
                mode = TOKENIZER.IDLE
            else
                error("Malformed quoted text at line "..line.." col "..col)
            end
        elseif (mode == TOKENIZER.ESCAPED) then
            if char == ";" then
                if tempBuffer1:sub(1,1) == "#" then
                    if tempBuffer1:sub(2,2) == "x" then
                        if tonumber(tempBuffer1:sub(3,-1) or "",16) then
                            tokens[#tokens].data = tokens[#tokens].data..string.char(tonumber(tempBuffer1:sub(3,-1),16))
                            mode = tempBuffer2
                        else
                            error("Invalid numeric hex escape sequence at line "..line.." col "..col)
                        end
                    elseif tonumber(tempBuffer1:sub(2,-1) or "") then
                        tokens[#tokens].data = tokens[#tokens].data..string.char(tonumber(tempBuffer1:sub(2,-1)))
                        mode = tempBuffer2
                    else
                        error("Invalid numeric escape sequence at line "..line.." col "..col)
                    end
                elseif escapeSequences[tempBuffer1] then
                    tokens[#tokens].data = tokens[#tokens].data..escapeSequences[tempBuffer1]
                    mode = tempBuffer2
                else
                    error("Invalid escape sequence \"&"..tempBuffer1..";\" at line "..line.." col "..col)
                end
            elseif tokens[#tokens - 1].data == char then
                error("Unterminated escape sequence at line "..line.." col "..col)
            else
                tempBuffer1 = tempBuffer1..char
            end
        end
    end

    if mode ~= TOKENIZER.IDLE then
        error("Unexpected EOF!")
    end

    return tokens
end

local PARSER = {
    IDLE = 0,
    TAG_NEED_IDENT = 1,
    TAG_NEED_CLOSE = 2,
    IDENT_NEED_EQUALS = 3,
    IDENT_NEED_QUOTE = 4,
    IDENT_NEED_DEFINE = 5,
    IDENT_NEED_QUOTE_CLOSE = 6,
    TAG_CLOSE_IDENT = 7,
    TAG_NEED_CLOSE_ONLY = 8
}

self.Parsers = {}
function self.Parsers.Whitespace()end
function self.Parsers.NewLine(parser,token)
    parser.currentNode.text = parser.currentNode.text:sub(1,-1-#token.data)
end
function self.Parsers.Tab(parser,token)
    parser.currentNode.text = parser.currentNode.text:sub(1,-1-#token.data)
end

function self.Parsers.TagOpen(parser,token)
    assert(parser.mode == PARSER.IDLE,"Unexpected tag opening at line "..token.line.." col "..token.col.."!")
    parser.mode = PARSER.TAG_NEED_IDENT

    parser.isInBody = false
    parser.tempBuffer1 = parser:newChild(token)
end

function self.Parsers.Slash(parser,token)
    if parser.isInBody then return end
    assert((parser.mode == PARSER.TAG_NEED_IDENT) or (parser.mode == PARSER.TAG_NEED_CLOSE),"Unexpected slash at line "..token.line.." col "..token.col.."!")

    if parser.mode == PARSER.TAG_NEED_CLOSE then
        parser.tempBuffer1._id = parser.currentNode._id.."."..parser.tempBuffer1.identifier..(#parser.currentNode.children+1)
        parser:pushChild(parser.tempBuffer1)
        parser.tempBuffer1 = nil
        parser.mode = PARSER.TAG_NEED_CLOSE_ONLY
    else
        parser.tempBuffer1 = nil
        parser.mode = PARSER.TAG_CLOSE_IDENT
    end
end

function self.Parsers.Identifier(parser,token)
    if parser.mode == PARSER.TAG_NEED_IDENT then
        parser.mode = PARSER.TAG_NEED_CLOSE

        parser.tempBuffer1.identifier = token.data
    elseif parser.mode == PARSER.TAG_NEED_CLOSE then
        assert(token.data:match("[A-Za-z0-9%-]"),"Token contains non alphanumeric symbols!")
        parser.tempBuffer2 = token.data
        parser.mode = PARSER.IDENT_NEED_EQUALS
    elseif parser.mode == PARSER.TAG_CLOSE_IDENT then
        assert(parser.currentNode.identifier == token.data,"Tag "..token.data.." was unexpectedly closed at line "..token.line.." col "..token.col.."!")
        parser.mode = PARSER.TAG_NEED_CLOSE_ONLY
    elseif parser.mode == PARSER.IDLE then

    else
        error("Unexpected identifier at line "..token.line.." col "..token.col.."!")
    end
end

function self.Parsers.Equals(parser,token)
    if parser.isInBody then return end
    assert(parser.mode == PARSER.IDENT_NEED_EQUALS,"Unexpected '=' at line "..token.line.." col "..token.col.."!")
    parser.mode = PARSER.IDENT_NEED_QUOTE
end

function self.Parsers.Text(parser,token)
    assert(parser.mode == PARSER.IDENT_NEED_DEFINE,"Unexpected text at line "..token.line.." col "..token.col.."!")
    parser.mode = PARSER.IDENT_NEED_QUOTE_CLOSE

    parser.tempBuffer1.attributes[parser.tempBuffer2] = token.data
    parser.tempBuffer2 = nil
end

function self.Parsers.Quote(parser,token)
    if parser.mode == PARSER.IDENT_NEED_QUOTE then
        parser.mode = PARSER.IDENT_NEED_DEFINE
    elseif parser.mode == PARSER.IDENT_NEED_QUOTE_CLOSE then
        parser.mode = PARSER.TAG_NEED_CLOSE
    else
        error("Unexpected quote at line "..token.line.." col "..token.col.."!")
    end
end

function self.Parsers.TagClose(parser,token)
    assert((parser.mode == PARSER.TAG_NEED_CLOSE) or (parser.mode == PARSER.TAG_NEED_CLOSE_ONLY),"Unexpected tag closing at line "..token.line.." col "..token.col.."!")

    if parser.mode == PARSER.TAG_NEED_CLOSE_ONLY then
        parser:popChild()
    else
        parser.tempBuffer1._id = parser.currentNode._id.."."..parser.tempBuffer1.identifier..(#parser.currentNode.children+1)
        parser:pushChild(parser.tempBuffer1)
        parser.tempBuffer1 = nil
    end
    parser.isInBody = true
    parser.mode = PARSER.IDLE
end

function self:ParseTokens(tokens)
    local parser = {}
    parser.tempBuffer1 = nil -- for reference
    parser.tempBuffer2 = nil
    parser.mode = PARSER.IDLE
    parser.idx = 1

    function parser:advanceIdx()
        self.idx = self.idx + 1
    end

    function parser:getRelativeToken(relative)
        return tokens[self.idx + relative]
    end

    function parser:expect(type)
        return self:getRelativeToken(1) and (self:getRelativeToken(1).type == type)
    end

    function parser:is(type)
        return self:getRelativeToken(0) and (self:getRelativeToken(0).type == type)
    end

    function parser:newChild(token)
        local child = {
            text = "",
            children = {},
            attributes = {},
            parent = self.currentNode,
            identifier = "",
            token = token
        }
        return child
    end

    function parser:pushChild(child)
        self.currentNode.children[#self.currentNode.children+1] = child
        self.currentNode = child or self.currentNode
    end

    function parser:popChild()
        self.currentNode = self.currentNode.parent or self.currentNode
    end

    function parser:updateText(child,text)
        if self.isInBody and not self:is "TagOpen" then
            child.text = child.text..text
        end
    end

    parser.AST = {
        text = "",
        children = {},
        attributes = {},
        parent = false,
        identifier = "main",
        _id = "main",
        token = false
    }
    parser.isInBody = true
    parser.currentNode = parser.AST

    for _,token in ipairs(tokens) do
        parser:updateText(parser.currentNode,token.data)
        self.Parsers[token.type](parser,token)

        parser:advanceIdx()
    end

    if parser.mode ~= PARSER.IDLE then
        error("Unexpected EOF!")
    end

    if parser.currentNode ~= parser.AST then
        error("Tag "..parser.currentNode.identifier.." was not closed! (line "..parser.currentNode.token.line.." col "..parser.currentNode.token.col..")")
    end

    return parser.AST
end

function self:Parse(xml)
    return self:ParseTokens(self:Tokenize(xml))
end


text:
{% extends "partials/base.html" %}

{% block content %}

Map Editor

Start editing your maps right now. Sign up to get most of the application.

    View gallery »

{% endblock %}