text:
package org.drools.compiler.integrationtests;

import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

import junit.framework.Assert;
import org.drools.compiler.CommonTestMethodBase;
import org.drools.compiler.lang.DrlDumper;
import org.drools.compiler.lang.api.DescrFactory;
import org.drools.compiler.lang.api.PackageDescrBuilder;
import org.drools.core.common.EventFactHandle;
import org.drools.core.common.InternalFactHandle;
import org.drools.core.io.impl.ByteArrayResource;
import org.junit.Test;
import org.kie.api.KieServices;
import org.kie.api.builder.KieBuilder;
import org.kie.api.builder.KieFileSystem;
import org.kie.api.builder.Message;
import org.kie.internal.KnowledgeBase;
import org.kie.internal.KnowledgeBaseFactory;
import org.kie.internal.builder.KnowledgeBuilder;
import org.kie.internal.builder.KnowledgeBuilderError;
import org.kie.internal.builder.KnowledgeBuilderErrors;
import org.kie.internal.builder.KnowledgeBuilderFactory;
import org.kie.api.definition.type.FactType;
import org.kie.internal.builder.KnowledgeBuilderResults;
import org.kie.internal.builder.ResultSeverity;
import org.kie.internal.io.ResourceFactory;
import org.kie.internal.runtime.StatefulKnowledgeSession;
import org.kie.api.io.ResourceType;
import org.kie.api.runtime.ClassObjectFilter;
import org.kie.api.runtime.rule.FactHandle;

/**
 * Test for declared bean Extension
 */
public class ExtendsTest extends CommonTestMethodBase {

    public StatefulKnowledgeSession genSession(String source) {
        return genSession(new String[] {source},0);
    }

    public StatefulKnowledgeSession genSession(String source, int numerrors)  {
        return genSession(new String[] {source},numerrors);
    }

    public StatefulKnowledgeSession genSession(String[] sources, int numerrors)  {
        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        for (String source : sources)
            kbuilder.add( ResourceFactory.newClassPathResource(source, getClass()), ResourceType.DRL );
        KnowledgeBuilderErrors errors = kbuilder.getErrors();
        if ( kbuilder.getErrors().size() > 0 ) {
            for ( KnowledgeBuilderError error : kbuilder.getErrors() ) {
                System.err.println( error );
            }
        }
        assertEquals(numerrors, errors.size() );

        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();

        kbase.addKnowledgePackages( kbuilder.getKnowledgePackages() );

        return createKnowledgeSession(kbase);

    }

    @Test
    public void testExtends() throws Exception {
        //Test Base Fact Type
        StatefulKnowledgeSession ksession = genSession("test_Extends.drl");

        FactType person = ksession.getKieBase().getFactType("defaultpkg","Person");
        FactType eqPair = ksession.getKieBase().getFactType("defaultpkg","EqualityPair");

        Object p = person.newInstance();
        assertNotNull(p);

        ksession.insert("Populate");
        ksession.fireAllRules();

        // A Rule will generate 3 Persons, one with default constructor, two with field constructor
        // and 3 Students, which extends Person. One with default, one with field constructor
        assertEquals(6, ksession.getObjects(new ClassObjectFilter(person.getFactClass())).size());
        assertEquals(1+4+1+4,ksession.getObjects(new ClassObjectFilter(eqPair.getFactClass())).size());
        ksession.dispose();
    }

    @Test
    public void testGeneratedMethods() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_Extends.drl");

        FactType student = ksession.getKieBase().getFactType("defaultpkg","Student");

        Constructor constructor = student.getFactClass().getConstructor(String.class,int.class,String.class);
        assertNotNull(constructor);
        Method equals = student.getFactClass().getMethod("equals",Object.class);
        assertNotNull(equals);

        Object s1 = constructor.newInstance("John",18,"Skool");
            assertNotNull(s1);
            assertEquals("Student( name=John, age=18, school=Skool )", s1.toString());

        Object s2 = constructor.newInstance("John",25,"Skool");
            assertNotNull(s2);
            assertEquals("Student( name=John, age=25, school=Skool )", s2.toString());
            assertEquals(s1.hashCode(),s2.hashCode());
            assertTrue((Boolean) equals.invoke(s1,s2));
            assertTrue(s1.equals(s2));

        Object s3 = constructor.newInstance("Mark",18,"Skool");
            assertNotNull(s3);
            assertEquals("Student( name=Mark, age=18, school=Skool )", s3.toString());

            assertNotSame(s1.hashCode(),s3.hashCode());
            assertNotSame(s2.hashCode(),s3.hashCode());
            assertFalse(s1.equals(s3));
            assertFalse(s2.equals(s3));

        Object s4 = constructor.newInstance("John",25,"AnotherSkool");
            assertNotNull(s4);
            assertEquals("Student( name=John, age=25, school=AnotherSkool )", s4.toString());

            assertNotSame(s1.hashCode(),s4.hashCode());
            assertNotSame(s2.hashCode(),s4.hashCode());
            assertNotSame(s3.hashCode(),s4.hashCode());
            assertFalse(s1.equals(s4));
            assertFalse(s2.equals(s4));
            assertFalse(s3.equals(s4));
        ksession.dispose();
    }

    @Test
    public void testDeepExt() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_Extends.drl");
        FactType LTstudent = ksession.getKieBase().getFactType("defaultpkg","LongTermStudent");

        Constructor constructor = LTstudent.getFactClass().getConstructor(String.class,int.class,String.class,String.class,int.class);
        assertNotNull(constructor);

        Object ls1 = constructor.newInstance("John",18,"Skool","C1245",4);
        Object ls2 = constructor.newInstance("John",33,"Skool","C1421",4);

        assertEquals(ls1,ls2);

        ksession.dispose();
    }

     @Test
    public void testIllegalExtendsLegacy() throws Exception {
        //Test Base Fact Type
        genSession("test_ExtLegacyIllegal.drl",7);

    }

    @Test
    public void testExtendsLegacy() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_ExtLegacy.drl",0);

        FactType leg = ksession.getKieBase().getFactType("org.drools.compiler","BetterLegacy");
        assertNotNull(leg);

        Object b = leg.newInstance();

        assertEquals(3.3,leg.get(b,"doubleField"));
        assertNull(leg.get(b,"objField"));
        assertEquals(245,leg.get(b,"intField"));
        assertEquals("XX",leg.get(b,"strField"));
        assertEquals(true,leg.get(b,"prop"));
        assertEquals("Hello",leg.get(b,"oneMoreField"));

        System.out.println(b);

    }

    @Test
     public void testExtendsAcrossFiles() throws Exception {
        StatefulKnowledgeSession ksession = genSession(new String[] {"test_Ext1.drl","test_Ext2.drl","test_Ext3.drl","test_Ext4.drl"} ,0);

        FactType person = ksession.getKieBase().getFactType("org.drools.compiler.ext.test","Person");
            assertNotNull(person);
        FactType student = ksession.getKieBase().getFactType("org.drools.compiler.ext.test","Student");
            assertNotNull(student);

        FactType worker = ksession.getKieBase().getFactType("org.drools.compiler.anothertest","Worker");
            assertNotNull(worker);

        FactType ltss = ksession.getKieBase().getFactType("defaultpkg","SubLTStudent");
            assertNotNull(ltss);

        Constructor ctor = worker.getFactClass().getConstructor(String.class,int.class,String.class, double.class, int.class);
            assertNotNull(ctor);

        Object w = ctor.newInstance("Adam",20,"Carpenter",150.0,40);
        System.out.println(w);
            assertEquals("Adam",worker.get(w,"name"));

        ksession.fireAllRules();
    }

    @Test
     public void testFieldInit() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_ExtFieldInit.drl");
        FactType test = ksession.getKieBase().getFactType("org.drools.compiler", "MyBean3");

        Object x = test.newInstance();
        assertNotNull(x);

        assertEquals(12,test.get(x,"fieldint"));
        assertEquals("xyz",test.get(x,"fieldstr"));
        assertEquals(3.23,test.get(x,"fielddbl"));
        assertEquals(0,test.get(x,"field0"));
        assertEquals(0.0f,test.get(x,"field1"));
        assertEquals(1.2f,test.get(x,"fieldflt"));
        short sht = 2;
        assertEquals(sht,test.get(x,"fieldsht"));
        assertEquals(0,test.get(x,"field2"));
        byte byt = 1;
        assertEquals(byt,test.get(x,"fieldbyt"));
        assertEquals(true,test.get(x,"fieldbln"));
        assertEquals('x',test.get(x,"fieldchr"));
        assertEquals(9999L,test.get(x,"fieldlng"));

        System.out.println(x);

    }

    @Test
    public void testBoxedFieldInit() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_ExtFieldInit.drl");
        FactType test = ksession.getKieBase().getFactType("org.drools.compiler","MyBoxBean");

        Object x = test.newInstance();
        assertNotNull(x);

        assertEquals(12,test.get(x,"fieldint"));
        assertEquals(3.23,test.get(x,"fielddbl"));
        assertEquals(1.2f,test.get(x,"fieldflt"));
        short sht = 2;
        assertEquals(sht,test.get(x,"fieldsht"));
        byte byt = 1;
        assertEquals(byt,test.get(x,"fieldbyt"));
        assertEquals(true,test.get(x,"fieldbln"));
        assertEquals('x',test.get(x,"fieldchr"));
        assertEquals(9999L,test.get(x,"fieldlng"));

        System.out.println(x);

    }

    @Test
    public void testExpressionFieldInit() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_ExtFieldInit.drl");
        FactType test = ksession.getKieBase().getFactType("org.drools.compiler","MyBoxExpressionBean");

        Object x = test.newInstance();
        assertNotNull(x);

        assertEquals("foobar",test.get(x,"f0"));
        assertEquals(-32,test.get(x,"fieldint"));
        assertEquals(4.0,test.get(x,"fielddbl"));
        assertEquals(0.5f,test.get(x,"fieldflt"));
        short sht = 6;
        assertEquals(sht,test.get(x,"fieldsht"));
        byte byt = 2;
        assertEquals(byt,test.get(x,"fieldbyt"));
        assertEquals(true,test.get(x,"fieldbln"));
        assertEquals('x',test.get(x,"fieldchr"));
        assertEquals(9999L,test.get(x,"fieldlng"));

        System.out.println(x);

        FactType test2 = ksession.getKieBase().getFactType("org.drools.compiler","MySimpleExpressionBean");

        x = test2.newInstance();
        assertNotNull(x);

        assertEquals("foobar",test2.get(x,"f0"));
        assertEquals(-32,test2.get(x,"fieldint"));
        assertEquals(4.0,test2.get(x,"fielddbl"));
        assertEquals(0.5f,test2.get(x,"fieldflt"));
        sht = 6;
        assertEquals(sht,test2.get(x,"fieldsht"));
        byt = 2;
        assertEquals(byt,test2.get(x,"fieldbyt"));
        assertEquals(true,test2.get(x,"fieldbln"));
        assertEquals('x',test2.get(x,"fieldchr"));
        assertEquals(9999L,test2.get(x,"fieldlng"));

        System.out.println(x);

    }

    @Test
    public void testHierarchy() throws Exception {
        StatefulKnowledgeSession ksession = genSession("test_ExtHierarchy.drl");
        ksession.setGlobal("list",new LinkedList());

        ksession.fireAllRules();

        assertEquals(1, ((List) ksession.getGlobal("list")).size());

    }

    @Test
    public void testExtendOverride() {

        String drl = "package test.beans;\n" +
                "\n" +
                "import java.util.List;\n" +
                "import java.util.ArrayList;\n" +
                "\n" +
                "global List ans;" +
                "\n" +
                "\n" +
                "declare ArrayList\n" +
                "end\n" +
                "" +
                "declare Bean extends ArrayList\n" +
                "  fld : int = 4 \n" +
                "  myField : String = \"xxx\" \n" +
                "end\n" +
                "\n" +
                "declare Bean2 extends Bean\n" +
                "  moref : double\n" +
                "  myField : String\n" +
                "end\n" +

                "rule \"Init\"\n" +
                "when\n" +
                "then\n" +
                "  Bean b = new Bean2();\n" +
                "  ans.add(b);" +
                "  System.out.println(b);\t\n" +
                "end\n"
                ;

        KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kbuilder.add(new ByteArrayResource(drl.getBytes()), ResourceType.DRL);
        if (kbuilder.hasErrors()) {
            fail(kbuilder.getErrors().toString());
        }
        KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
        kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
        StatefulKnowledgeSession ksession = createKnowledgeSession(kbase);

        List out = new ArrayList();
        ksession.setGlobal("ans",out);

        ksession.fireAllRules();
        Object x = out.get(0);

        FactType type = kbase.getFactType("test.beans","Bean2");
        assertEquals(4, type.get( x, "fld") );
        assertEquals("xxx", type.get( x, "myField") );
        assertEquals(0.0, type.get( x, "moref") );

        assertTrue( x instanceof ArrayList );
    }

    @Test
    public void testRedefineDefaults() throws Exception {
        //Test Base Fact Type
        StatefulKnowledgeSession ksession = genSession("test_Extends.drl");

        FactType person = ksession.getKieBase().getFactType("defaultpkg","Person");
        FactType student = ksession.getKieBase().getFactType("defaultpkg","Student");

        Object p = person.newInstance();
        Object s = student.newInstance();
        assertNotNull(p);
        assertNotNull(s);

        assertEquals( 99, person.get(p,"age") );
        assertEquals( 18, person.get(s,"age") );

        ksession.dispose();
    }

    @Test
    public void testExtendFromOtherPackage() throws Exception {

        String s1 = "package org.drools.compiler.test.pack1;\n" +
                "\n" +
                "declare Base\n" +
                "  id    : int\n" +
                "end\n" +
                "\n" +
                "declare Sub extends Base\n" +
                "  field : int\n" +
                "end\n";

        String s2 = "package org.drools.compiler.test.pack2;\n" +
                "\n" +
                "import org.drools.compiler.test.pack1.Base;\n" +
                "import org.drools.compiler.test.pack1.Sub;\n" +
                "\n" +
                "declare Sub end\n" +
                "\n" +
                "declare SubChild extends Sub\n" +
                "  field2 : int\n" +
                "end\n" +
                "\n" +
                "rule \"Init\"\n" +
                "when\n" +
                "then\n" +
                "  insert( new SubChild( 1, 2, 3 ) );\n" +
                "end\n" +
                "\n" +
                "rule \"Touch Base\"\n" +
                "when\n" +
                "  $b : Base()\n" +
                "then\n" +
                "  System.out.println( $b );\n" +
                "end \n" +
                "rule \"Touch Base 2\"\n" +
                "when\n" +
                "  $c : Sub()\n" +
                "then\n" +
                "  System.out.println( $c );\n" +
                "end";

        KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );

        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors().toString() );
            fail();
        }
        kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        KnowledgeBuilder kBuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder( kBase );
        kBuilder2.add( new ByteArrayResource( s2.getBytes() ), ResourceType.DRL );

        if ( kBuilder2.hasErrors() ) {
            System.err.println( kBuilder2.getErrors().toString() );
            fail();
        }
        kBase.addKnowledgePackages( kBuilder2.getKnowledgePackages() );

        StatefulKnowledgeSession kSession = kBase.newStatefulKnowledgeSession();

        assertEquals( 3, kSession.fireAllRules() );
    }

    @Test
    public void testInheritAnnotationsInOtherPackage() throws Exception {

        String s1 = "package org.drools.compiler.test.pack1;\n" +
                "global java.util.List list;" +
                "\n" +
                "declare Event\n" +
                "@role(event)" +
                "  id    : int\n" +
                "end\n" +
                "\n" +
                "rule \"X\"\n" +
                "when\n" +
                "  $s1 : Event()\n" +
                "then\n" +
                "  System.out.println( $s1 );\n" +
                "  list.add( $s1.getId() );\n " +
                "end";

        String s2 = "package org.drools.compiler.test.pack2;\n" +
                "\n" +
                "import org.drools.compiler.test.pack1.Event;\n" +
                "global java.util.List list;" +
                "\n" +
                "declare Event end\n" +
                "\n" +
                "declare SubEvent extends Event\n" +
                "end\n" +
                "\n" +
                "rule \"Init\"\n" +
                "when\n" +
                "then\n" +
                "  list.add( 0 );\n" +
                "  insert( new SubEvent( 1 ) );\n" +
                "  insert( new SubEvent( 2 ) );\n" +
                "end\n" +
                "\n" +
                "rule \"Seq\"\n" +
                "when\n" +
                "  $s1 : SubEvent( id == 1 )\n" +
                "  $s2 : SubEvent( id == 2, this after[0,10s] $s1 )\n" +
                "then\n" +
                "  list.add( 3 );\n" +
                "  System.out.println( $s1 + \" after \" + $s1 );\n" +
                "end \n" +
                "\n" +
                "rule \"Seq 2 \"\n" +
                "when\n" +
                "  $s1 : Event( id == 1 )\n" +
                "  $s2 : Event( id == 2, this after[0,10s] $s1 )\n" +
                "then\n" +
                "  list.add( 4 );\n" +
                "  System.out.println( $s1 + \" after II \" + $s1 );\n" +
                "end";

        KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(  );
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );

        if ( kBuilder.hasErrors() ) {
            fail( kBuilder.getErrors().toString() );
        }
        kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        KnowledgeBuilder kBuilder2 = KnowledgeBuilderFactory.newKnowledgeBuilder( kBase );
        kBuilder2.add( new ByteArrayResource( s2.getBytes() ), ResourceType.DRL );

        if ( kBuilder2.hasErrors() ) {
            fail( kBuilder2.getErrors().toString() );
        }
        kBase.addKnowledgePackages( kBuilder2.getKnowledgePackages() );

        StatefulKnowledgeSession kSession = kBase.newStatefulKnowledgeSession();
        List list = new ArrayList();
        kSession.setGlobal( "list", list );

        kSession.fireAllRules();

        for ( Object o : kSession.getObjects() ) {
            FactHandle h = kSession.getFactHandle( o );
            assertTrue( h instanceof EventFactHandle );
        }

        System.out.println( list );
        assertEquals( 5, list.size() );
        assertTrue( list.contains( 0 ) );
        assertTrue( list.contains( 1 ) );
        assertTrue( list.contains( 2 ) );
        assertTrue( list.contains( 3 ) );
        assertTrue( list.contains( 4 ) );

    }

    @Test
    public void testInheritFromClassWithDefaults() throws Exception {

        // car is a java class with attributes
        // brand (default ferrari)
        // expensive (default true)
        String s1 = "package org.drools.compiler;\n" +
                "global java.util.List list;\n" +
                "declare Car end\n" +
                "\n" +
                "declare MyCar extends Car \n" +
                " miles : int\n" +
                "end\n" +
                "\n" +
                "rule \"Init\"\n" +
                "when\n" +
                "then\n" +
                "  MyCar c = new MyCar();\n" +
                "  c.setMiles( 100 );" +
                "  insert( c );\n" +
                "end\n" +
                "rule \"Match\"\n" +
                "when\n" +
                "  MyCar( brand == \"ferrari\", expensive == true, $miles : miles ) " +
                "then\n" +
                "  list.add( $miles );\n" +
                "end";

        KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(  );
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            fail( kBuilder.getErrors().toString() );
        }
        kBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        StatefulKnowledgeSession kSession = kBase.newStatefulKnowledgeSession();
            List list = new ArrayList();
            kSession.setGlobal( "list", list );

        kSession.fireAllRules();
        assertEquals( 1, list.size() );
        assertTrue( list.contains( 100 ) );

    }

    @Test
    public void testExtendSelf() throws Exception {
        String s1 = "package org.drools;\n" +
                    "global java.util.List list;\n" +
                    "\n" +
                    "declare Bean extends Bean \n" +
                    " foo : int @key\n" +
                    "end\n";

        KnowledgeBase kBase = KnowledgeBaseFactory.newKnowledgeBase();

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );
        assertTrue( kBuilder.hasErrors() );
    }

    @Test
    public void testExtendCircular() throws Exception {
        String s1 = "package org.drools;\n" +
                    "global java.util.List list;\n" +
                    "\n" +
                    "declare Bean1 extends Bean2 \n" +
                    " foo : int @key\n" +
                    "end\n" +
                    "" +
                    "declare Bean2 extends Bean3 \n" +
                    " foo : int @key\n" +
                    "end\n" +
                    "" +
                    "declare Bean3 extends Bean1 \n" +
                    " foo : int @key\n" +
                    "end\n";

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );
        assertTrue( kBuilder.hasErrors() );

        System.out.println( kBuilder.getErrors() );
        assertTrue( kBuilder.getErrors().toString().contains( "circular" ) );
    }

    @Test
    public void testExtendsDump() {
        PackageDescrBuilder pkgd = DescrFactory.newPackage();
        pkgd.name( "org.test" )
            .newDeclare().type().name( "Foo" )
            .newField( "id" ).type( "int" ).end()
            .end()
            .newDeclare().type().name( "Bar" ).superType( "Foo" )
            .newField( "val" ).type( "int" ).initialValue( "42" ).end()
            .end();
        String drl = new DrlDumper().dump( pkgd.getDescr() );

        KnowledgeBase kb = loadKnowledgeBaseFromString( drl );

        FactType bar = kb.getFactType( "org.test", "Bar" );
        try {
            Object x = bar.newInstance();
            assertEquals( 42, bar.get( x, "val" ) );
            bar.set( x, "id", 1 );
            assertEquals( 1, bar.get( x, "id" ) );
        } catch ( Exception e ) {
            fail( e.getMessage() );
        }
    }

    @Test
    public void testMultipleInheritanceWithPosition1() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 //@position(0)\n" +
                " field1 : int = 101 //@position(1)\n" +
                " field2 : int = 102 //@position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 //@position(0)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 5, sw.getFields().size() );
        assertEquals( "field0", sw.getFields().get(0).getName() );
        assertEquals( "field1", sw.getFields().get(1).getName() );
        assertEquals( "mfield1", sw.getFields().get(2).getName() );
        assertEquals( "field2", sw.getFields().get(3).getName() );
        assertEquals( "mfield0", sw.getFields().get(4).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition2() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 //@position(0)\n" +
                " field1 : int = 101 //@position(1)\n" +
                " field2 : int = 102 //@position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 @position(0)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 5, sw.getFields().size() );
        assertEquals( "mfield0", sw.getFields().get(0).getName() );
        assertEquals( "field0", sw.getFields().get(1).getName() );
        assertEquals( "mfield1", sw.getFields().get(2).getName() );
        assertEquals( "field1", sw.getFields().get(3).getName() );
        assertEquals( "field2", sw.getFields().get(4).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition3() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 @position(0)\n" +
                " field1 : int = 101 @position(1)\n" +
                " field2 : int = 102 @position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 //@position(0)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 5, sw.getFields().size() );
        assertEquals( "field0", sw.getFields().get(0).getName() );
        assertEquals( "field2", sw.getFields().get(1).getName() );
        assertEquals( "field1", sw.getFields().get(2).getName() );
        assertEquals( "mfield1", sw.getFields().get(3).getName() );
        assertEquals( "mfield0", sw.getFields().get(4).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition4() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 @position(1)\n" +
                " field1 : int = 101 @position(0)\n" +
                " field2 : int = 102 @position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 @position(0)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 5, sw.getFields().size() );
        assertEquals( "field1", sw.getFields().get(0).getName() );
        assertEquals( "field2", sw.getFields().get(1).getName() );
        assertEquals( "mfield0", sw.getFields().get(2).getName() );
        assertEquals( "field0", sw.getFields().get(3).getName() );
        assertEquals( "mfield1", sw.getFields().get(4).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition5() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 @position(2)\n" +
                " field1 : int = 101 @position(1)\n" +
                " field2 : int = 102 @position(8)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 @position(7)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 5, sw.getFields().size() );
        assertEquals( "field1", sw.getFields().get(0).getName() );
        assertEquals( "field0", sw.getFields().get(1).getName() );
        assertEquals( "mfield1", sw.getFields().get(2).getName() );
        assertEquals( "mfield0", sw.getFields().get(3).getName() );
        assertEquals( "field2", sw.getFields().get(4).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition6() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 //@position(0)\n" +
                " field1 : int = 101 //@position(1)\n" +
                " field2 : int = 102 //@position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait SecPosTrait\n" +
                "@propertyReactive\n" +
                " field3 : int = 100 //@position(0)\n" +
                " field1 : int = 101 //@position(1)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait, SecPosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 //@position(0)\n" +
                " mfield1 : int = 201 //@position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 6, sw.getFields().size() );
        assertEquals( "field0", sw.getFields().get(0).getName() );
        assertEquals( "field1", sw.getFields().get(1).getName() );
        assertEquals( "field2", sw.getFields().get(2).getName() );
        assertEquals( "field3", sw.getFields().get(3).getName() );
        assertEquals( "mfield0", sw.getFields().get(4).getName() );
        assertEquals( "mfield1", sw.getFields().get(5).getName() );
    }

    @Test
    public void testMultipleInheritanceWithPosition7() throws Exception {
        // DROOLS-249
        String drl =
                "package org.drools.test\n" +
                "declare trait PosTrait\n" +
                "@propertyReactive\n" +
                " field0 : int = 100 @position(0)\n" +
                " field1 : int = 101 @position(1)\n" +
                " field2 : int = 102 @position(0)\n" +
                "end\n" +
                "\n" +
                "declare trait SecPosTrait\n" +
                "@propertyReactive\n" +
                " field3 : int = 100 @position(2)\n" +
                " field1 : int = 101 //@position(1)\n" +
                "end\n" +
                "\n" +
                "declare trait MultiInhPosTrait extends PosTrait, SecPosTrait\n" +
                "@propertyReactive\n" +
                " mfield0 : int = 200 @position(0)\n" +
                " mfield1 : int = 201 @position(2)\n" +
                "end";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder( );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        FactType sw = knowledgeBase.getFactType( "org.drools.test", "MultiInhPosTrait" );
        assertEquals( 6, sw.getFields().size() );
        assertEquals( "field0", sw.getFields().get(0).getName() );
        assertEquals( "field2", sw.getFields().get(1).getName() );
        assertEquals( "mfield0", sw.getFields().get(2).getName() );
        assertEquals( "field1", sw.getFields().get(3).getName() );
        assertEquals( "field3", sw.getFields().get(4).getName() );
        assertEquals( "mfield1", sw.getFields().get(5).getName() );
    }

    public static interface A {}

    public static interface B extends A {}

    public static interface C extends B {}

    public static class X implements C {
        private int x = 1;
        public int getX() { return x; }
    }

    @Test
    public void testDeclareInheritance() throws Exception {
        String s1 = "package org.drools;\n" +
                    "import org.drools.compiler.integrationtests.ExtendsTest.*;\n" +
                    "\n" +
                    "declare A \n" +
                    " @role( event )" +
                    " @typesafe( false )\n" +
                    "end\n" +
                    "" +
                    "declare C @role( event ) @typesafe( false ) end \n" +
                    "" +
                    "rule R \n" +
                    "when " +
                    "   $x : C( this.x == 1 ) \n" +
                    "then\n" +
                    "   System.out.println( $x ); \n" +
                    "end\n" +
                    "";

        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(  );
        kBuilder.add( new ByteArrayResource( s1.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertFalse( kBuilder.hasErrors() );

        KnowledgeBase knowledgeBase = KnowledgeBaseFactory.newKnowledgeBase();
        knowledgeBase.addKnowledgePackages( kBuilder.getKnowledgePackages() );

        StatefulKnowledgeSession knowledgeSession = knowledgeBase.newStatefulKnowledgeSession();
        FactHandle h = knowledgeSession.insert( new X() );

        assertTrue( ( (InternalFactHandle) h ).isEvent() );

    }

    @Test
    public void testDeclareExtendsMissingDeclareForParent() {
        String drl = "package org.drools.test; \n" +
                     "import org.drools.compiler.Person; \n" +
                     "declare Student extends Person end \n" +
                     "";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(  );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertTrue( kBuilder.hasErrors() );
        assertEquals( 1, kBuilder.getErrors().size() );
    }

    @Test
    public void testDeclareExtendsMissingDeclareForParentOuterPackaga() {
        String drl = "package org.drools.test; \n" +
                     "import org.drools.compiler.integrationtests.ExtendsTest.X; \n" +
                     "declare Student extends X end \n" +
                     "";
        KnowledgeBuilder kBuilder = KnowledgeBuilderFactory.newKnowledgeBuilder(  );
        kBuilder.add( new ByteArrayResource( drl.getBytes() ), ResourceType.DRL );
        if ( kBuilder.hasErrors() ) {
            System.err.println( kBuilder.getErrors() );
        }
        assertTrue( kBuilder.hasErrors() );
        assertEquals( 1, kBuilder.getErrors().size() );
    }

    @Test
    public void testDeclareExtendsWithFullyQualifiedName() {
        String drl = "package org.drools.extends.test; \n" +
                     "" +
                     "declare org.drools.extends.test.Foo end \n" +
                     "declare org.drools.extends.test.Bar extends org.drools.extends.test.Foo end \n" +
                     "";
        KieServices kieServices = KieServices.Factory.get();
        KieFileSystem kfs = kieServices.newKieFileSystem();
        kfs.write( kieServices.getResources().newByteArrayResource( drl.getBytes() )
                           .setSourcePath( "test.drl" )
                           .setResourceType( ResourceType.DRL ) );
        KieBuilder kieBuilder = kieServices.newKieBuilder( kfs );
        kieBuilder.buildAll();

        assertFalse( kieBuilder.getResults().hasMessages( Message.Level.ERROR ) );

    }

}


text:
module AuthNetReceiver
  class ProcessTransactionJob < ActiveJob::Base
    queue_as :default

    def perform(raw_transaction)
      raw_transaction.process!
    end

  end
end

redpajama_set_name: RedPajamaGithub


text:
"""This example displays the change logs of a specified advertiser object.

A similar pattern can be applied to get change logs for many other object
types.
"""

import argparse
import sys

from apiclient import sample_tools
from oauth2client import client

# Declare command-line flags.
argparser = argparse.ArgumentParser(add_help=False)
argparser.add_argument(
    'profile_id', type=int,
    help='The ID of the profile to look up change logs for')
argparser.add_argument(
    'advertiser_id', type=int,
    help='The ID of the advertiser to look up change logs for')

def main(argv):
  # Authenticate and construct service.
  service, flags = sample_tools.init(
      argv, 'dfareporting', 'v2.0', __doc__, __file__, parents=[argparser],
      scope=['https://www.googleapis.com/auth/dfareporting',
             'https://www.googleapis.com/auth/dfatrafficking'])

  profile_id = flags.profile_id
  advertiser_id = flags.advertiser_id

  try:
    # Construct the request.
    request = service.changeLogs().list(
        profileId=profile_id, objectIds=[advertiser_id],
        objectType='OBJECT_ADVERTISER')

    while True:
      # Execute request and print response.
      response = request.execute()

      for change_log in response['changeLogs']:
        print(
            '%s: Field "%s" from "%s" to "%s".' %
            (change_log['action'], change_log['fieldName'],
             change_log['oldValue'], change_log['newValue']))

      if response['changeLogs'] and response['nextPageToken']:
        request = service.changeLogs().list_next(request, response)
      else:
        break

  except client.AccessTokenRefreshError:
    print ('The credentials have been revoked or expired, please re-run the '
           'application to re-authorize')

if __name__ == '__main__':
  main(sys.argv)


text:
<?xml version='1.0' encoding='UTF-8'?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

          <title></title>
          <meta name="description" content="" />
          <meta name="keywords" content="" />
          <meta http-equiv="content-type" content="text/html; charset=UTF-8" />

      <link href="../lib/ref-index.css" media="screen" type="text/css" rel="stylesheet" />

data

MockRow Row SqlRow api Form AnyContentAsFormUrlEncoded Flash Headers Session FakeHeaders

databaseEvolutions

Evolutions

DataPart

MultipartFormData

dataParts

MultipartFormData

datasources

DBApi

date

SqlParser Forms HeaderNames

dateFormat

Formats

dateReads

DefaultReads

dateToStatement

ToStatement

dateWrites

DefaultWrites

DB

api db InconsistentDatabase InvalidDatabaseRevision

DBApi

db EvolutionsPlugin

dbConfig

BoneCPPlugin

DBPlugin

db

debug

LoggerLike

decode

Codec CookieBaker Cookies

decodeFromCookie

CookieBaker

decryptAES

Crypto

deepMerge

JsObject

default

controllers Forms TestBrowser

DEFAULT_MAX_TEXT_LENGTH

parse

DefaultApplication

api

DefaultContentTypeOfs

http

defaultContext

Execution Implicits

DefaultDateReads

DefaultReads

DefaultDateWrites

DefaultWrites

defaultField

helper FieldConstructor

defaultFieldConstructor

helper

DefaultFormat

json

DefaultGlobal

api

DefaultJodaDateReads

DefaultReads

DefaultJodaDateWrites

DefaultWrites

DefaultJodaLocalDateReads

DefaultReads

DefaultJodaLocalDateWrites

DefaultWrites

defaultLang

Lang

defaultParser

SimpleSql

DefaultReads

json

DefaultSqlDateReads

DefaultReads

defaultTypes

MimeTypes

DefaultWriteables

http

DefaultWrites

json

delegate

OpenIDServer

delete

WSRequestHolder Helpers

deserialize

CookieBaker Flash Session

Dev

Mode

discard

CookieBaker

DiscardingCookie

mvc

discardingCookies

AsyncResult PlainResult WithHeaders

discardingErrors

Form

doFilter

GlobalSettings WithFilters

domain

Cookie CookieBaker DiscardingCookie RequestHeader Session

Done

iteratee Step

doubleFormat

Formats

DoubleReads

DefaultReads

DoubleWrites

DefaultWrites

drop

Useful Enumeratee Traversable

dropInputIfNotReady

Concurrent

dropWhile

Enumeratee

duration

Cached


text:
#include "config.h"

#if ENABLE(SCRIPTED_SPEECH)

#include "SpeechGrammar.h"

#include "Document.h"

namespace WebCore {

PassRefPtr<SpeechGrammar> SpeechGrammar::create()
{
    return adoptRef(new SpeechGrammar);
}

PassRefPtr<SpeechGrammar> SpeechGrammar::create(const URL& src, double weight)
{
    return adoptRef(new SpeechGrammar(src, weight));
}

void SpeechGrammar::setSrc(ScriptExecutionContext* scriptExecutionContext, const String& src)
{
    Document* document = toDocument(scriptExecutionContext);
    m_src = document->completeURL(src);
}

SpeechGrammar::SpeechGrammar()
    : m_weight(1.0)
{
}

SpeechGrammar::SpeechGrammar(const URL& src, double weight)
    : m_src(src)
    , m_weight(weight)
{
}

} // namespace WebCore

#endif // ENABLE(SCRIPTED_SPEECH)


text:
import styled from 'styled-components';
import { getters as g } from './theme';

export default styled.div`
  background: ${g.bg};
  border-radius: ${g.border}px;
  box-shadow: ${g.boxShadow};
  box-sizing: border-box;
  display: flex;
  flex-grow: 1
  flex-direction: column;
  font-size: ${g.size}px;
  font-weight: 400;
  margin: 1em;
  min-height: 14em;
  min-width: 24em;
  overflow: hidden;
`;


text:
mvn clean install

java -Xms4096m -Xmx8192m -jar target/benchmarks.jar org.openjdk.jmh.bugreport.benchmark.ApplicationBenchmark


text:
package com.intellij.history.core.changes;

import com.intellij.history.core.Content;
import com.intellij.history.core.StreamUtil;
import com.intellij.util.SmartList;
import com.intellij.util.containers.ContainerUtil;
import org.jetbrains.annotations.Nullable;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class ChangeSet {
  private final long myId;
  @Nullable private String myName;
  private final long myTimestamp;
  private final List<Change> myChanges;

  public ChangeSet(long id, long timestamp) {
    myId = id;
    myTimestamp = timestamp;
    myChanges = new ArrayList<Change>();
  }

  public ChangeSet(DataInput in) throws IOException {
    myId = in.readLong();
    myName = StreamUtil.readStringOrNull(in);
    myTimestamp = in.readLong();

    int count = in.readInt();
    myChanges = new ArrayList<Change>(count);
    while (count-- > 0) {
      myChanges.add(StreamUtil.readChange(in));
    }
  }

  public void write(DataOutput out) throws IOException {
    out.writeLong(myId);
    StreamUtil.writeStringOrNull(out, myName);
    out.writeLong(myTimestamp);

    out.writeInt(myChanges.size());
    for (Change c : myChanges) {
      StreamUtil.writeChange(out, c);
    }
  }

  public void setName(@Nullable String name) {
    myName = name;
  }

  @Nullable
  public String getName() {
    return myName;
  }

  public long getTimestamp() {
    return myTimestamp;
  }

  @Nullable
  public String getLabel() {
    for (Change each : myChanges) {
      if (each instanceof PutLabelChange) {
       return ((PutLabelChange)each).getName();
      }
    }
    return null;
  }

  public int getLabelColor() {
    for (Change each : myChanges) {
      if (each instanceof PutSystemLabelChange) {
       return ((PutSystemLabelChange)each).getColor();
      }
    }
    return -1;
  }

  public void addChange(Change c) {
    myChanges.add(c);
  }

  public List<Change> getChanges() {
    return myChanges;
  }

  public boolean isEmpty() {
    return myChanges.isEmpty();
  }

  public boolean affectsPath(String paths) {
    for (Change c : myChanges) {
      if (c.affectsPath(paths)) return true;
    }
    return false;
  }

  public boolean isCreationalFor(String path) {
    for (Change c : myChanges) {
      if (c.isCreationalFor(path)) return true;
    }
    return false;
  }

  public List<Content> getContentsToPurge() {
    List<Content> result = new ArrayList<Content>();
    for (Change c : myChanges) {
      result.addAll(c.getContentsToPurge());
    }
    return result;
  }

  public boolean isContentChangeOnly() {
    return myChanges.size() == 1 && getFirstChange() instanceof ContentChange;
  }

  public boolean isLabelOnly() {
    return myChanges.size() == 1 && getFirstChange() instanceof PutLabelChange;
  }

  public Change getFirstChange() {
    return myChanges.get(0);
  }

  public Change getLastChange() {
    return myChanges.get(myChanges.size() - 1);
  }

  public List<String> getAffectedPaths() {
    List<String> result = new SmartList<String>();
    for (Change each : myChanges) {
      if (each instanceof StructuralChange) {
        result.add(((StructuralChange)each).getPath());
      }
    }
    return result;
  }

  public void accept(ChangeVisitor v) throws ChangeVisitor.StopVisitingException {
    v.begin(this);
    for (Change c : ContainerUtil.iterateBackward(myChanges)) {
      c.accept(v);
    }
    v.end(this);
  }

  public String toString() {
    return myChanges.toString();
  }

  public long getId() {
    return myId;
  }

  @Override
  public final boolean equals(Object o) {
    if (this == o) return true;
    if (o == null || getClass() != o.getClass()) return false;

    ChangeSet change = (ChangeSet)o;

    if (myId != change.myId) return false;

    return true;
  }

  @Override
  public final int hashCode() {
    return (int)(myId ^ (myId >>> 32));
  }
}


text:
<?xml version="1.0" encoding="UTF-8"?>
<root>
	<AnalogueModels>
		<AnalogueModel type="SimplePathlossModel">
	    	<parameter name="alpha" type="double" value="4.0"/>
	    	<parameter name="carrierFrequency" type="double" value="2.412e+9"/>
	    </AnalogueModel>
	</AnalogueModels>
	<Decider type="Decider80211">
		<!-- SNR threshold [NOT dB]-->
		<parameter name="threshold" type="double" value="0.12589254117942"/>
	</Decider>
</root>


text:
This repository replicates the figures from the 3rd edition of the book "Recursive Macroeconomic Theory" by Lars Ljunqvist and Thomas J. Sargent.

The code to create the figures is here, but you should consult the book for information on what is being described by the pictures.

The figures in the book are organized by chapter, section, and number. If you were looking for figure x.y.z then it would be found at the path `RMTFigs/Chapterx/Fig_x_y_z.py`.

Contributions are welcomed and encouraged. Submissions should be in Python and follow [this guide](http://quantecon.org/developer_resources.html).


text:
$(function()
{
$(window).off("mousedown", TouchNSwipe.preventDefault);
$(window).off("mousemove", TouchNSwipe.preventDefault);
});


text:
namespace atom {

namespace api {

SystemPreferences::SystemPreferences(v8::Isolate* isolate) {
  Init(isolate);
}

SystemPreferences::~SystemPreferences() {
}

#if defined(OS_WIN)
bool SystemPreferences::IsAeroGlassEnabled() {
  return ui::win::IsAeroGlassEnabled();
}
#endif

#if !defined(OS_MACOSX)
bool SystemPreferences::IsDarkMode() {
  return false;
}
#endif

// static
mate::Handle<SystemPreferences> SystemPreferences::Create(
    v8::Isolate* isolate) {
  return mate::CreateHandle(isolate, new SystemPreferences(isolate));
}

// static
void SystemPreferences::BuildPrototype(
    v8::Isolate* isolate, v8::Local<v8::ObjectTemplate> prototype) {
  mate::ObjectTemplateBuilder(isolate, prototype)
#if defined(OS_WIN)
      .SetMethod("isAeroGlassEnabled", &SystemPreferences::IsAeroGlassEnabled)
#elif defined(OS_MACOSX)
      .SetMethod("subscribeNotification",
                 &SystemPreferences::SubscribeNotification)
      .SetMethod("unsubscribeNotification",
                 &SystemPreferences::UnsubscribeNotification)
      .SetMethod("getUserDefault", &SystemPreferences::GetUserDefault)
#endif
      .SetMethod("isDarkMode", &SystemPreferences::IsDarkMode);
}

}  // namespace api

}  // namespace atom

namespace {

void Initialize(v8::Local<v8::Object> exports, v8::Local<v8::Value> unused,
                v8::Local<v8::Context> context, void* priv) {
  v8::Isolate* isolate = context->GetIsolate();
  mate::Dictionary dict(isolate, exports);
  dict.Set("systemPreferences", atom::api::SystemPreferences::Create(isolate));
}

}  // namespace

NODE_MODULE_CONTEXT_AWARE_BUILTIN(atom_browser_system_preferences, Initialize);


text:
import http = require('http');
import restify = require('restify');
import pipes = require('../src/pipes');
import pipelineConfig = require('./pipelineConfig');

var log = require('winston');
log.level = 'error';

var pipeline = pipes.createPipeline(pipelineConfig.pipelineConfigServerUrl.href);

var pipelineServer1 = pipeline.createServer(pipelineConfig.processJavascriptStage);
var pipelineServer2 = pipeline.createServer(pipelineConfig.processJavascriptStage);

function handler(pipeline: pipes.Pipeline, params: any, next: () => void) {

    log.info('Got process javascript request', params);

    if (!params.code) { next(); return; }

    var f = pipes.createFunction(params.code);
    delete params.code;

    if (!f) { next(); return; }

    ((pipeline: pipes.Pipeline, params: any, next: () => void) => {
        f(params, next);
    })(this.pipeline, params, next);
}

pipelineServer1.process('/pipeline/execute', (params, next) => {
    handler(this.pipeline, params, next);
});

pipelineServer2.process('/pipeline/execute', (params, next) => {
    handler(this.pipeline, params, next);
});

pipelineServer1.listen(pipelineConfig.processJavascriptPorts[0]);
log.info('Process Javascript Stage listening on ' + pipelineConfig.processJavascriptPorts[0]);

pipelineServer2.listen(pipelineConfig.processJavascriptPorts[1]);
log.info('Process Javascript Stage listening on ' + pipelineConfig.processJavascriptPorts[1]);

export var ready = true;

/*

// OLD code gen helpers

function escape(s) {
    return s
        .replace(/[\\]/g, '\\\\')
        .replace(/[\"]/g, '\\\"')
        .replace(/[\/]/g, '\\/')
        .replace(/[\b]/g, '\\b')
        .replace(/[\f]/g, '\\f')
        .replace(/[\n]/g, '\\n')
        .replace(/[\r]/g, '\\r')
        .replace(/[\t]/g, '\\t');
}

function stringify(s) {
    return '"' + escape(JSON.stringify(s)) + '"';
};

*/


text:
require 'fileutils'
require 'pathname'

def command(command, dir = '.')
    Dir.chdir(dir) do
        return `#{command}`.chomp
    end
end

AT_TOOLS_DIR = File.expand_path('~/.at-tools/')
AT_APPS_DIR = AT_TOOLS_BIN + '/apps'
AT_TOOLS_BIN = AT_TOOLS_DIR + '/bin'

puts "Making directories"
FileUtils.mkdir_p(AT_TOOLS_BIN)

puts "Linking programs"
FileUtils.ln_s(AT_APPS_DIR + '/cascader/bin/cascader',
               AT_TOOLS_BIN + '/cascader')

FileUtils.ln_s(AT_APPS_DIR + '/cascader-gui/bin/cascader-gui',
	       AT_TOOLS_BIN + '/cascader-gui')

FileUtils.ln_s(AT_APPS_DIR + '/print/bin/print',
               AT_TOOLS_BIN + '/print')

FileUtils.ln_s(AT_APPS_DIR + '/cen/bin/cen',
               AT_TOOLS_BIN + '/cen')

FileUtils.ln_s(AT_APPS_DIR + '/att/bin/att',
               AT_TOOLS_BIN + '/att')

puts "Updating PATH"
command('echo "PATH=$PATH:' + AT_TOOLS_BIN + '" >> ~/.bash_profile')
command('source ~/.bash_profile')