forked from google/blockly
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathjava_compressed.js
119 lines (117 loc) · 68.8 KB
/
java_compressed.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
// Do not edit this file; automatically generated by build.py.
'use strict';
// Copyright 2012 Google Inc. Apache License 2.0
Blockly.Java=new Blockly.Generator("Java");Blockly.Java.addReservedWords("abstract,assert,boolean,break,case,catch,class,const,continue,default,do,double,else,enum,extends,final,finally,float,for,goto,if,implements,import,instanceof,int,interface,long,native,new,package,private,protected,public,return,short,static,strictfp,super,switch,synchronized,this,throw,throws,transient,try,void,volatile,while,false,null,true,abs,divmod,input,open,staticmethod,all,enumerate,int,ord,str,any,eval,isinstance,pow,sum,basestring,execfile,issubclass,print,super,bin,file,iter,property,tuple,bool,filter,len,range,type,bytearray,float,list,raw_input,unichr,callable,format,locals,reduce,unicode,chr,frozenset,long,reload,vars,classmethod,getattr,map,repr,xrange,cmp,globals,max,reversed,zip,compile,hasattr,memoryview,round,__import__,complex,hash,min,set,apply,delattr,help,next,setattr,buffer,dict,hex,object,slice,coerce,dir,id,oct,sorted,intern,equal");
Blockly.Java.ORDER_ATOMIC=0;Blockly.Java.ORDER_COLLECTION=1;Blockly.Java.ORDER_STRING_CONVERSION=1;Blockly.Java.ORDER_MEMBER=2;Blockly.Java.ORDER_FUNCTION_CALL=2;Blockly.Java.ORDER_POSTFIX=3;Blockly.Java.ORDER_EXPONENTIATION=3;Blockly.Java.ORDER_LOGICAL_NOT=3;Blockly.Java.ORDER_UNARY_SIGN=4;Blockly.Java.ORDER_MULTIPLICATIVE=5;Blockly.Java.ORDER_ADDITIVE=6;Blockly.Java.ORDER_BITWISE_SHIFT=7;Blockly.Java.ORDER_RELATIONAL=8;Blockly.Java.ORDER_EQUALITY=9;Blockly.Java.ORDER_BITWISE_AND=10;
Blockly.Java.ORDER_BITWISE_XOR=11;Blockly.Java.ORDER_BITWISE_OR=12;Blockly.Java.ORDER_LOGICAL_AND=13;Blockly.Java.ORDER_LOGICAL_OR=14;Blockly.Java.ORDER_CONDITIONAL=15;Blockly.Java.ORDER_ASSIGNMENT=16;Blockly.Java.ORDER_NONE=99;Blockly.Java.PASS=" {}\n";Blockly.Java.POSTFIX="";Blockly.Java.INDENT=" ";Blockly.Java.EXTRAINDENT="";Blockly.Java.variableTypes_={};Blockly.Java.blocklyTypes_={};Blockly.Java.AppName_="myApp";Blockly.Java.Package_="demo";Blockly.Java.Baseclass_="";
Blockly.Java.needImports_=[];Blockly.Java.Interfaces_=[];Blockly.Java.ExtraImports_=null;Blockly.Java.INLINEVARCLASS=!0;Blockly.Java.classes_=[];Blockly.Java.globals_={};Blockly.Java.targetType_=null;Blockly.Java.fileHeader='/*\n * Copyright (c) 2015, <<Your Name>>\n * All rights reserved.\n *\n * Redistribution and use in source and binary forms, with or without\n * modification, are permitted provided that the following conditions are met:\n *\n * * Redistributions of source code must retain the above copyright notice, this\n * list of conditions and the following disclaimer.\n * * Redistributions in binary form must reproduce the above copyright notice,\n * this list of conditions and the following disclaimer in the documentation\n * and/or other materials provided with the distribution.\n *\n * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"\n * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE\n * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE\n * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE\n * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR\n * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF\n * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS\n * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN\n * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)\n * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE\n * POSSIBILITY OF SUCH DAMAGE.\n */\n';
Blockly.Java.setAppName=function(a){a&&""!==a||(a="MyApp");this.AppName_=a};Blockly.Java.getAppName=function(){return Blockly.Java.variableDB_.getName(this.AppName_,"CLASS")};Blockly.Java.setPackage=function(a){a&&""!==a||(a="demo");this.Package_=a};Blockly.Java.forceUpdate=function(a){if(a.getDescendants)a=a.getDescendants();else if(a.getAllBlocks)a=a.getAllBlocks();else throw"Not Block or Workspace: "+a;for(var b=0;b<a.length;b++)if(a[b].onchange)a[b].onchange()};Blockly.Java.getPackage=function(){return this.Package_};
Blockly.Java.setBaseclass=function(a){this.Baseclass_=a};Blockly.Java.getBaseclass=function(){var a=this.Baseclass_;""!=a&&(a=Blockly.Java.variableDB_.getName(a,"CLASS"));return a};Blockly.Java.addInterface=function(a){goog.array.contains(this.Interfaces_,a)||this.Interfaces_.push(a)};Blockly.Java.getInterfaces=function(){return 0===this.Interfaces_.length?null:this.Interfaces_};
Blockly.Java.setGlobalVar=function(a,b,c){null!=Blockly.Variables.getLocalContext(a,b)||"undefined"!==typeof this.globals_[b]&&null!==this.globals_[b]||(this.globals_[b]=c)};Blockly.Java.GetVariableType=function(a){a=this.variableTypes_[a];a||(a="Var",Blockly.Java.provideVarClass());return a};Blockly.Java.GetBlocklyType=function(a){return this.blocklyTypes_[a]};Blockly.Java.addImport=function(a){a="import "+a+";";this.imports_[a]=a};
Blockly.Java.getImports=function(){if(this.ExtraImports_)for(var a=0;a<this.ExtraImports_.length;a++)this.addImport(this.ExtraImports_[a]);a=goog.object.getValues(this.imports_);goog.array.sort(a);return a.join("\n")};Blockly.Java.setExtraImports=function(a){this.ExtraImports_=a};Blockly.Java.setVarClassInline=function(a){this.INLINEVARCLASS=a};Blockly.Java.getClasses=function(){var a="",b;for(b in this.classes_)a+=this.classes_[b];a&&(a+="\n\n");return a};
Blockly.Java.setExtraClass=function(a,b){this.classes_[a]=b.join("\n")+"\n"};Blockly.Java.workspaceToCode_=Blockly.Java.workspaceToCode;
Blockly.Java.workspaceToCode=function(a,b){this.setAppName(a.options.appTitle);this.forceUpdate(a);var c=this.workspaceToCode_(a,b),d=this.fileHeader+"package "+this.getPackage()+";\n\n"+this.getImports()+"\n\npublic class "+this.getAppName(),e=this.getBaseclass();""!=e&&(d+=" extends "+e);if(e=this.getInterfaces())for(var g=" implements ",f=0;f<e.length;f++)d+=g+e[f],g=", ";return d+=" {\n\n"+c+"\n}\n\n"+this.getClasses()};
Blockly.Java.getValueType=function(a,b){var c=a.getInputTargetBlock(b);return c?c.outputConnection.check_:""};
Blockly.Java.provideVarClass=function(){this.INLINEVARCLASS?(Blockly.Java.addImport("java.text.DecimalFormat"),Blockly.Java.addImport("java.text.NumberFormat"),Blockly.Java.addImport("java.lang.Math"),Blockly.Java.addImport("java.util.Arrays"),Blockly.Java.addImport("java.util.Collections"),Blockly.Java.addImport("java.util.LinkedList"),Blockly.Java.addImport("java.util.List"),Blockly.Java.addImport("java.util.HashMap"),Blockly.Java.addImport("java.util.Map"),Blockly.Java.addImport("java.util.Objects"),
this.classes_.Var='/**\n *\n * @author bmoon\n */\nfinal class Var implements Comparable {\n\n public enum Type {\n\n STRING, INT, DOUBLE, LIST, NULL, UNKNOWN\n };\n\n private Type _type;\n private Object _object;\n private static final NumberFormat _formatter = new DecimalFormat("#.#####");\n\n /**\n * Construct a Var with an UNKNOWN type\n *\n */\n public Var() {\n _type = Type.UNKNOWN;\n } // end var\n\n /**\n * Construct a Var and assign its contained object to that specified.\n *\n * @param object The value to set this object to\n */\n public Var(Object object) {\n setObject(object);\n } // end var\n\n /**\n * Construct a Var from a given Var\n *\n * @param var var to construct this one from\n */\n public Var(Var var) {\n setObject(var.getObject());\n } // end var\n\n /**\n * Static constructor to make a var from some value.\n *\n * @param val some value to construct a var around\n * @return the Var object\n */\n public static Var valueOf(Object val) {\n return new Var(val);\n } // end valueOf\n\n /**\n * Get the type of the underlying object\n *\n * @return Will return the object\'s type as defined by Type\n */\n public Type getType() {\n return _type;\n } // end getType\n\n /**\n * Get the contained object\n *\n * @return the object\n */\n public Object getObject() {\n return _object;\n } // end getObject\n\n /**\n * Clone Object\n *\n * @return a new object equal to this one\n */\n public Object cloneObject() {\n Var tempVar = new Var(this);\n return tempVar.getObject();\n } // end cloneObject\n\n /**\n * Get object as an int. Does not make sense for a "LIST" type object\n *\n * @return an integer whose value equals this object\n */\n public int getObjectAsInt() {\n switch (getType()) {\n case STRING:\n return Integer.parseInt((String) getObject());\n case INT:\n return (int) getObject();\n case DOUBLE:\n return new Double((double) getObject()).intValue();\n case LIST:\n // has no meaning\n break;\n default:\n // has no meaning\n break;\n }\n return 0;\n } // end getObjectAsInt\n\n /**\n * Get object as a double. Does not make sense for a "LIST" type object.\n *\n * @return a double whose value equals this object\n */\n public double getObjectAsDouble() {\n switch (getType()) {\n case STRING:\n return Double.parseDouble((String) getObject());\n case INT:\n return new Integer((int) getObject()).doubleValue();\n case DOUBLE:\n return (double) getObject();\n case LIST:\n // has no meaning\n break;\n default:\n // has no meaning\n break;\n }\n return 0.0;\n } // end get object as double\n\n /**\n * Get object as a string.\n *\n * @return The string value of the object. Note that for lists, this is a\n * comma separated list of the form {x,y,z,...}\n */\n public String getObjectAsString() {\n return this.toString();\n } // end gotObjectAsString\n\n /**\n * Get the object as a list.\n *\n * @return a LinkedList whose elements are of type Var\n */\n public LinkedList<Var> getObjectAsList() {\n return (LinkedList<Var>) getObject();\n } // end getObjectAsList\n\n /**\n * If this object is a linked list, then calling this method will return the\n * Var at the index indicated\n *\n * @param index the index of the Var to read (0 based)\n * @return the Var at that index\n */\n public Var get(int index) {\n return ((LinkedList<Var>) getObject()).get(index);\n } // end get\n\n /**\n * If this object is a linked list, then calling this method will return the\n * size of the linked list.\n *\n * @return size of list\n */\n public int size() {\n return ((LinkedList<Var>) getObject()).size();\n } // end size\n\n /**\n * Set the value of of a list at the index specified. Note that this is only\n * value if this object is a list and also note that index must be in\n * bounds.\n *\n * @param index the index into which the Var will be inserted\n * @param var the var to insert\n */\n public void set(int index, Var var) {\n ((LinkedList<Var>) getObject()).add(index, var);\n } // end set\n\n /**\n * Add all values from one List to another. Both lists are Var objects that\n * contain linked lists.\n *\n * @param var The list to add\n */\n public void addAll(Var var) {\n ((LinkedList<Var>) getObject()).addAll(var.getObjectAsList());\n } // end addAll\n\n /**\n * Set the value of the underlying object. Note that the type of Var will be\n * determined when setObject is called.\n *\n * @param val the value to set this Var to\n */\n public void setObject(Object val) {\n this._object = val;\n inferType();\n // make sure each element of List is Var if type is list\n if (_type.equals(Var.Type.LIST)) {\n LinkedList<Var> myList = new LinkedList<>();\n for (Object obj : this.getObjectAsList()) {\n myList.add(new Var(obj));\n }\n this._object = myList;\n }\n } // end setObject\n\n /**\n * Add a new member to a Var that contains a list. If the Var current is not\n * of type "LIST", then this Var will be converted to a list, its current\n * value will then be stored as the first member and this new member added\n * to it.\n *\n * @param member The new member to add to the list\n */\n public void add(Var member) {\n if (_type.equals(Var.Type.LIST)) {\n // already a list\n ((LinkedList<Var>) _object).add(member);\n } else {\n // not current a list, change it\n LinkedList<Var> temp = new LinkedList<>();\n temp.add(new Var(member));\n setObject(temp);\n }\n } // end add\n\n /**\n * Increment Object by some value.\n *\n * @param inc The value to increment by\n */\n public void incrementObject(double inc) {\n switch (getType()) {\n case STRING:\n // has no meaning\n break;\n case INT:\n this.setObject((double) (this.getObjectAsInt() + inc));\n break;\n case DOUBLE:\n this.setObject((double) (this.getObjectAsDouble() + inc));\n break;\n case LIST:\n for (Var myVar : this.getObjectAsList()) {\n myVar.incrementObject(inc);\n }\n break;\n default:\n // has no meaning\n break;\n } // end switch\n } // end incrementObject\n\n /**\n * Increment Object by some value\n *\n * @param inc The value to increment by\n */\n public void incrementObject(int inc) {\n switch (getType()) {\n case STRING:\n // has no meaning\n break;\n case INT:\n this.setObject((int) (this.getObjectAsInt() + inc));\n break;\n case DOUBLE:\n this.setObject((double) (this.getObjectAsDouble() + inc));\n break;\n case LIST:\n for (Var myVar : this.getObjectAsList()) {\n myVar.incrementObject(inc);\n }\n break;\n default:\n // has no meaning\n break;\n }// end switch\n } // end incrementObject\n\n @Override\n public int hashCode() {\n int hash = 5;\n hash = 43 * hash + Objects.hashCode(this._type);\n hash = 43 * hash + Objects.hashCode(this._object);\n return hash;\n }\n\n /**\n * Test to see if this object equals another one. This is done by converting\n * both objects to strings and then doing a string compare.\n *\n * @param obj\n * @return\n */\n @Override\n public boolean equals(Object obj) {\n final Var other = Var.valueOf(obj);\n if (getType() == Var.Type.NULL || other.getType() == Var.Type.NULL) {\n return getType().equals(other.getType());\n }\n return this.toString().equals(other.toString());\n } // end equals\n\n /**\n * Check to see if this Var is less than some other var.\n *\n * @param var the var to compare to\n * @return true if it is less than\n */\n public boolean lessThan(Var var) {\n switch (getType()) {\n case STRING:\n return this.getObjectAsString().compareTo(var.getObjectAsString()) < 0;\n case INT:\n return this.getObjectAsInt() < var.getObjectAsDouble();\n case DOUBLE:\n return this.getObjectAsDouble() < var.getObjectAsDouble();\n case LIST:\n if (size() != var.size()) {\n return false;\n }\n if (!var.getType().equals(Var.Type.LIST)) {\n return false;\n }\n int index = 0;\n for (Var myVar : this.getObjectAsList()) {\n if (!myVar.lessThan(var.get(index))) {\n return false;\n }\n }\n return true;\n default:\n return false;\n }// end switch\n } // end less than\n\n /**\n * Check to see if this var is less than or equal to some other var\n *\n * @param var the var to compare to\n * @return true if this is less than or equal to var\n */\n public boolean lessThanOrEqual(Var var) {\n switch (getType()) {\n case STRING:\n return this.getObjectAsString().compareTo(var.getObjectAsString()) <= 0;\n case INT:\n return this.getObjectAsInt() <= var.getObjectAsDouble();\n case DOUBLE:\n return this.getObjectAsDouble() <= var.getObjectAsDouble();\n case LIST:\n if (size() != var.size()) {\n return false;\n }\n if (!var.getType().equals(Var.Type.LIST)) {\n return false;\n }\n int index = 0;\n for (Var myVar : this.getObjectAsList()) {\n if (!myVar.lessThanOrEqual(var.get(index))) {\n return false;\n }\n }\n return true;\n case NULL:\n return (var.getType() == Var.Type.NULL);\n default:\n return false;\n }// end switch\n } // end lessThanOrEqual\n\n /**\n * Check to see if this var is greater than a given var.\n *\n * @param var the var to compare to.\n * @return true if this object is grater than the given var\n */\n public boolean greaterThan(Var var) {\n return var.lessThan(this);\n } // end greaterThan\n\n /**\n * Check to see if this var is greater than or equal to a given var\n *\n * @param var the var to compare to\n * @return true if this var is greater than or equal to the given var\n */\n public boolean greaterThanOrEqual(Var var) {\n return var.lessThanOrEqual(this);\n } // end greaterThanOrEqual\n\n /**\n * Compare this object\'s value to another\n *\n * @param val the object to compare to\n * @return the value 0 if this is equal to the argument; a value less than 0\n * if this is numerically less than the argument; and a value greater than 0\n * if this is numerically greater than the argument (signed comparison).\n */\n @Override\n public int compareTo(Object val) {\n // only instantiate if val is not instance of Var\n Var var;\n if (val instanceof Var) {\n var = (Var) val;\n } else {\n var = new Var(val);\n }\n switch (getType()) {\n case STRING:\n return this.getObjectAsString().compareTo(var.getObjectAsString());\n case INT:\n if (var.getType().equals(Var.Type.INT)) {\n return ((Integer) this.getObjectAsInt()).compareTo(var.getObjectAsInt());\n } else {\n return ((Double) this.getObjectAsDouble()).compareTo(var.getObjectAsDouble());\n }\n case DOUBLE:\n return ((Double) this.getObjectAsDouble()).compareTo(var.getObjectAsDouble());\n case LIST:\n // doesn\'t make sense\n return Integer.MAX_VALUE;\n default:\n // doesn\'t make sense\n return Integer.MAX_VALUE;\n }// end switch\n } // end compareTo\n\n /**\n * Convert this Var to a string format.\n *\n * @return the string format of this var\n */\n @Override\n public String toString() {\n switch (getType()) {\n case STRING:\n return getObject().toString();\n case INT:\n Integer i = (int) getObject();\n return i.toString();\n case DOUBLE:\n Double d = (double) _object;\n return _formatter.format(d);\n case LIST:\n LinkedList<Var> ll = (LinkedList) getObject();\n StringBuilder sb = new StringBuilder();\n boolean first = true;\n for (Var v : ll) {\n if (first) {\n first = false;\n sb.append("{");\n } else {\n sb.append(", ");\n }\n sb.append(v.toString());\n } // end for each Var\n sb.append("}");\n return sb.toString();\n case NULL:\n return null;\n default:\n return getObject().toString();\n }// end switch\n } // end toString\n\n /**\n * Internal method for inferring the "object type" of this object. When it\n * is done, it sets the private member value of _type. This will be\n * referenced later on when various method calls are made on this object.\n */\n private void inferType() {\n if (_object == null) {\n _type = Type.NULL;\n } else if (_object instanceof Var) {\n Var oldObj = (Var)_object;\n _type = oldObj.getType();\n _object = oldObj.getObject();\n } else if (_object instanceof String) {\n _type = Type.STRING;\n } else {\n // must be a number or a list\n // try to see if its a double\n try {\n Double d = (double) _object;\n // it was a double, so keep going\n _type = Type.DOUBLE;\n } catch (Exception ex) {\n // not a double, see if it is an integer\n try {\n Integer i = (int) _object;\n // it was an integer\n _type = Type.INT;\n } catch (Exception ex2) {\n // not a double or integer, might be an array\n if (_object instanceof LinkedList) {\n _type = Type.LIST;\n } else if (_object instanceof List) {\n _type = Type.LIST;\n _object = new LinkedList<>((List) _object);\n } else {\n _type = Type.UNKNOWN;\n }\n } // end not an integer\n } // end not a double\n } // end else not a string\n } // end inferType\n\n static double math_sum(Var myList) {\n double sum = 0;\n LinkedList<Var> ll = myList.getObjectAsList();\n for (Var var : ll) {\n sum += var.getObjectAsDouble();\n }\n return sum;\n }\n\n static double math_min(Var myList) {\n double min = Double.MAX_VALUE;\n double d;\n LinkedList<Var> ll = myList.getObjectAsList();\n for (Var var : ll) {\n d = var.getObjectAsDouble();\n if (d < min) {\n min = d;\n }\n }\n return min;\n }\n\n static double math_max(Var myList) {\n double max = Double.MIN_VALUE;\n double d;\n LinkedList<Var> ll = myList.getObjectAsList();\n for (Var var : ll) {\n d = var.getObjectAsDouble();\n if (d > max) {\n max = d;\n }\n }\n return max;\n }\n\n static double math_mean(Var myList) {\n return Var.math_sum(myList) / myList.size();\n }\n\n static double math_median(Var myList) {\n LinkedList<Var> ll = myList.getObjectAsList();\n Collections.sort(ll);\n int length = myList.size();\n int middle = length / 2;\n if (length % 2 == 1) {\n return ll.get(middle).getObjectAsDouble();\n } else {\n double d1 = ll.get(middle - 1).getObjectAsDouble();\n double d2 = ll.get(middle).getObjectAsDouble();\n return (d1 + d2) / 2.0;\n }\n }\n\n static Var math_modes(Var myList) {\n final Var modes = new Var();\n final Map<Double, Double> countMap = new HashMap<Double, Double>();\n double max = -1;\n double d;\n LinkedList<Var> ll = myList.getObjectAsList();\n for (Var var : ll) {\n d = var.getObjectAsDouble();\n double count = 0;\n if (countMap.containsKey(d)) {\n count = countMap.get(d) + 1;\n } else {\n count = 1;\n }\n countMap.put(d, count);\n if (count > max) {\n max = count;\n }\n }\n for (final Map.Entry<Double, Double> tuple : countMap.entrySet()) {\n if (tuple.getValue() == max) {\n modes.add(Var.valueOf(tuple.getKey().doubleValue()));\n }\n }\n return modes;\n }\n\n static double math_standard_deviation(Var myList) {\n double mean = math_mean(myList);\n double size = myList.size();\n double temp = 0;\n double d;\n LinkedList<Var> ll = myList.getObjectAsList();\n for (Var var : ll) {\n d = var.getObjectAsDouble();\n temp += (mean - d) * (mean - d);\n }\n double variance = temp / size;\n return Math.sqrt(variance);\n }\n\n}\n'):
Blockly.Java.addImport("com.extreme.platform.application.Var")};Blockly.Java.typeMapping={Object:"Object",Array:"LinkedList",Map:"HashMap",Var:"Var",Boolean:"Boolean",String:"String",Colour:"String",Number:"double"};Blockly.Java.subtypeMapping={Object:"Object",Array:"LinkedList",Map:"HashMap",Var:"Var",Boolean:"Boolean",String:"String",Colour:"String",Number:"Double"};
Blockly.Java.mapType=function(a){var b=function(a,c){c&&0!==c.length||(console.log("Empty type. Using Var"),c=["Var"]);var g=c.shift(),f=g;a[f]?f=a[f]:Blockly.Blocks[f]&&Blockly.Blocks[f].GBPClass?f=Blockly.Blocks[f].GBPClass:Blockly.VariableTypeEquivalence[f]||(console.log("Unknown type for "+g+" using Var for "+f),f="Var");"Var"===f&&Blockly.Java.provideVarClass();0<c.length&&(g=b(Blockly.Java.subtypeMapping,c),f+="<"+g+">");return f},c=null;a&&(c=a.split(":"));return b(this.typeMapping,c)};
Blockly.Java.setTargetType=function(a){var b=this.targetType_;this.targetType_=a;return b};Blockly.Java.getTargetType=function(a){return this.targetType_};Blockly.Java.computeJavaType=function(a){a=Blockly.Variables.Intersection(a,a);a=Blockly.Variables.resolveTypes(a);return Blockly.Java.mapType(a)};
Blockly.Java.init=function(a,b){this.definitions_=Object.create(null);this.functionNames_=Object.create(null);this.imports_=Object.create(null);this.classes_=Object.create(null);this.globals_=Object.create(null);for(var c=0;c<this.needImports_.length;c++)this.addImport(this.needImports_[c]);this.variableDB_?this.variableDB_.reset():this.variableDB_=new Blockly.Names(this.RESERVED_WORDS_);Blockly.VariableTypeEquivalence.Colour=["String"];c=Blockly.Variables.allVariables(a);this.blocklyTypes_=Blockly.Variables.allVariablesTypes(a);
for(var d in this.blocklyTypes_)c.push(d);for(d=0;d<c.length;d++){var e=c[d];this.variableTypes_[e]=this.mapType(this.blocklyTypes_[e])}};
Blockly.Java.finish=function(a){var b=[[],[]],c;for(c in this.definitions_)if("variables"!==c){var d=this.definitions_[c],e=1;if("function"!==typeof d){var g=d.split(" ",3);goog.array.contains(g,"static")&&(e=0)}b[e].push(c)}c="";for(d in this.globals_){e="";g=this.GetVariableType(d);null!=this.globals_[d]&&""!==this.globals_[d]?e=" = "+this.globals_[d]:"Var"===g?e=" = new Var(0)":"Boolean"===g?e=" = false":"String"===g&&(e=' = ""');var f=Blockly.Java.variableDB_.getName(d,Blockly.Variables.NAME_TYPE);
c+="protected "+g+" "+f+e+";\n"}for(e=0;2>e;e++)for(g=b[e].sort(),f=0;f<g.length;f++){d=this.definitions_[g[f]];"function"===typeof d&&(d=d.call(this));var h="",l=d.split("(",2);if(2<=l.length&&-1===l[0].indexOf(";")){var h="/**\n * Description goes here\n",m=" *\n",k=l[0],k=k.split(" "),n=k[k.length-2],k=l[1],k=k.split(")",1),k=k[0].trim();if(""!==k)for(l=k.split(","),k=0;k<l.length;k++)var p=l[k].split(" "),h=h+(m+" * @param "+p[p.length-1]+"\n"),m="";"void"!==n&&"public"!==n&&(h+=m+" * @return "+
n+"\n");h+=" */\n"}c+=h+d+"\n\n"}delete Blockly.Java.definitions_;delete Blockly.Java.functionNames_;Blockly.Java.variableDB_.reset();return c.replace(/\n\n+/g,"\n\n").replace(/\n*$/,"\n\n\n")+a};Blockly.Java.scrubNakedValue=function(a){return a+";\n"};Blockly.Java.quote_=function(a){return goog.string.quote(a)};
Blockly.Java.toStringCode=function(a,b){var c=a.getInputTargetBlock(b);if(!c)return"";var d=Blockly.Java.valueToCode(a,b,Blockly.Java.ORDER_NONE),d=d.trim();""!==d&&'"'!==d.charAt(0)&&("variables_get"===c.type&&"Var"===Blockly.Java.GetVariableType(c.procedurePrefix_+c.getFieldValue("VAR"))?d+=".toString()":Blockly.isNumber(d)?d='"'+d+'"':"variables_get"!==c.type&&"Var"===Blockly.Java.GetVariableType(d)?d+=".toString()":(this.addImport("java.text.DecimalFormat"),this.addImport("java.text.NumberFormat"),
d=this.provideFunction_("blocklyToString",["public static String blocklyToString(Object object) {"," String result;"," if (object instanceof String) {"," result = (String) object;"," } else {"," // must be a number"," // might be a double"," try {"," Double d = (double) object;"," // it was a double, so keep going",' NumberFormat formatter = new DecimalFormat("#.#####");'," result = formatter.format(d);",""," } catch (Exception ex) {",
" // not a double, see if it is an integer"," try {"," Integer i = (int) object;"," // format should be number with a decimal point"," result = i.toString();"," } catch (Exception ex2) {"," // not a double or integer",' result = "UNKNOWN";'," }"," }"," }",""," return result;","}"])+"("+d+")"));return d};
Blockly.Java.scrub_=function(a,b,c){var d="";if(!a.outputConnection||!a.outputConnection.targetConnection){var e=a.getCommentText();e&&(d+=this.prefixLines(e,"// ")+"\n");for(var g=0;g<a.inputList.length;g++)a.inputList[g].type==Blockly.INPUT_VALUE&&(e=a.inputList[g].connection.targetBlock())&&(e=this.allNestedComments(e))&&(d+=this.prefixLines(e,"// "))}g=this.POSTFIX;this.POSTFIX="";e=this.EXTRAINDENT;this.EXTRAINDENT="";a=a.nextConnection&&a.nextConnection.targetBlock();c=this.blockToCode(a,c);
""!=e&&(c=this.prefixLines(c,e));return d+b+c+g};Blockly.Java.colour={};Blockly.Java.colour_picker=function(a){return['"'+a.getFieldValue("COLOUR")+'"',Blockly.Java.ORDER_ATOMIC]};Blockly.Java.colour_random=function(a){Blockly.Java.addImport("java.util.Random");return[Blockly.Java.provideFunction_("colour_random",["public static String "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"() {"," double num = Math.floor(Math.random() * Math.pow(2, 24));",' return String.format("#%06x", (int)num);',"}"])+"()",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.colour_rgb=function(a){var b=Blockly.Java.provideFunction_("colour_rgb",["public static String "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(double r, double g, double b) {"," r = Math.round(Math.max(Math.min(r, 100), 0) * 2.55);"," g = Math.round(Math.max(Math.min(g, 100), 0) * 2.55);"," b = Math.round(Math.max(Math.min(b, 100), 0) * 2.55);",' return String.format("#%02x%02x%02x", (int)r, (int)g, (int)b);',"}"]),c=Blockly.Java.valueToCode(a,"RED",Blockly.Java.ORDER_NONE)||0,d=Blockly.Java.valueToCode(a,
"GREEN",Blockly.Java.ORDER_NONE)||0;a=Blockly.Java.valueToCode(a,"BLUE",Blockly.Java.ORDER_NONE)||0;return[b+"("+c+", "+d+", "+a+")",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.colour_blend=function(a){var b=Blockly.Java.provideFunction_("colour_blend",["public static String "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(String c1, String c2, double ratio) {"," int r = 0;"," int g = 0;"," int b = 0;"," try {"," ratio = Math.max(Math.min(ratio, 1), 0);"," int r1 = Integer.parseInt(c1.substring(1, 3), 16);"," int g1 = Integer.parseInt(c1.substring(3, 5), 16);"," int b1 = Integer.parseInt(c1.substring(5, 7), 16);"," int r2 = Integer.parseInt(c2.substring(1, 3), 16);",
" int g2 = Integer.parseInt(c2.substring(3, 5), 16);"," int b2 = Integer.parseInt(c2.substring(5, 7), 16);"," r = (int)Math.round(r1 * (1 - ratio) + r2 * ratio);"," g = (int)Math.round(g1 * (1 - ratio) + g2 * ratio);"," b = (int)Math.round(b1 * (1 - ratio) + b2 * ratio);"," } catch (Exception ex) {"," }",' return String.format("#%02x%02x%02x", r, g, b);',"}"]),c=Blockly.Java.valueToCode(a,"COLOUR1",Blockly.Java.ORDER_NONE)||'"#000000"',d=Blockly.Java.valueToCode(a,"COLOUR2",Blockly.Java.ORDER_NONE)||
'"#000000"';a=Blockly.Java.valueToCode(a,"RATIO",Blockly.Java.ORDER_NONE)||0;return[b+"("+c+", "+d+", "+a+")",Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.lists={};Blockly.Java.lists_create_empty=function(a){Blockly.Java.addImport("java.util.LinkedList");return["new LinkedList()",Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.lists_create_with=function(a){var b=Array(a.itemCount_),c=a.getOutput();c.length||(c=["Array"]);var c=Blockly.Variables.Intersection(c,c),d=Blockly.Variables.resolveTypes(c),c=null;d&&0<d.indexOf(":")&&(c=d.substring(d.indexOf(":")+1),c=Blockly.Java.mapType(c));"double"===c&&(c="Double");for(var d=Blockly.Java.setTargetType(c),e=0;e<a.itemCount_;e++)b[e]=Blockly.Java.valueToCode(a,"ADD"+e,Blockly.Java.ORDER_NONE)||"null","Var"===c&&(b[e]="Var.valueOf("+b[e]+")");Blockly.Java.setTargetType(d);
Blockly.Java.addImport("java.util.Arrays");Blockly.Java.addImport("java.util.LinkedList");b="new LinkedList<>(Arrays.asList("+b.join(", ")+"))";return[b,Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.lists_repeat=function(a){var b=Blockly.Java.valueToCode(a,"ITEM",Blockly.Java.ORDER_NONE)||"None";a=Blockly.Java.valueToCode(a,"NUM",Blockly.Java.ORDER_MULTIPLICATIVE)||"0";Blockly.Java.addImport("java.util.LinkedList");return[Blockly.Java.provideFunction_("lists_repeat",["public static LinkedList "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(Object item, int torepeat) {"," LinkedList<Object> result = new LinkedList<>();"," for(int x = 0; x < torepeat; x++) {"," result.add(item);",
" }"," return result;","}"])+"("+b+","+a+")",Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.lists_length=function(a){a=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"[]";".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14)+".getObjectAsList()");return[a+".size()",Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.lists_isEmpty=function(a){return[(Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"[]")+".size() == 0",Blockly.Java.ORDER_LOGICAL_NOT]};
Blockly.Java.lists_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"indexOf":"lastIndexOf",c=Blockly.Java.valueToCode(a,"FIND",Blockly.Java.ORDER_NONE)||"[]";a=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_MEMBER)||"''";".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14)+".getObjectAsList()");return[a+"."+b+"("+c+") + 1",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.lists_getIndex=function(a){var b=a.getFieldValue("MODE")||"GET",c=a.getFieldValue("WHERE")||"FROM_START",d=Blockly.Java.valueToCode(a,"AT",Blockly.Java.ORDER_UNARY_SIGN)||"1";a=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_MEMBER)||"[]";".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14)+".getObjectAsList()");if("FIRST"==c){if("GET"==b)return[a+".getFirst()",Blockly.Java.ORDER_MEMBER];c=a+".removeFirst()";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==
b)return c+";\n"}else if("LAST"==c){if("GET"==b)return[a+".getLast()",Blockly.Java.ORDER_MEMBER];c=a+".removeLast()";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+";\n"}else if("FROM_START"==c){d=Blockly.isNumber(d)?parseInt(d,10)-1:"("+d+" - 1)";if("GET"==b)return[a+".get((int)"+d+")",Blockly.Java.ORDER_MEMBER];c=a+".remove((int)"+d+")";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+";\n"}else if("FROM_END"==c){if("GET"==
b)return[a+".get("+a+".size() - (int)"+d+")",Blockly.Java.ORDER_MEMBER];c=a+".remove("+a+".size() - (int)"+d+")";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+";\n"}else if("RANDOM"==c){Blockly.Java.addImport("java.lang.Math");if("GET"==b)return[a+".get((int)(Math.random() * "+a+".size()))",Blockly.Java.ORDER_FUNCTION_CALL];Blockly.Java.addImport("java.util.LinkedList");c=Blockly.Java.provideFunction_("lists_remove_random_item",["public static Object "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+
"(LinkedList myList) {"," int x = (int)(Math.random() * myList.size());"," return myList.remove(x);","}"])+"("+a+")";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+";\n"}throw"Unhandled combination (lists_getIndex).";};
Blockly.Java.lists_setIndex=function(a){var b=Blockly.Java.valueToCode(a,"LIST",Blockly.Java.ORDER_MEMBER)||"[]",c=a.getFieldValue("MODE")||"GET",d=a.getFieldValue("WHERE")||"FROM_START",e=Blockly.Java.valueToCode(a,"AT",Blockly.Java.ORDER_NONE)||"1";a=Blockly.Java.valueToCode(a,"TO",Blockly.Java.ORDER_NONE)||"None";".cloneObject()"===b.slice(-14)&&(b=b.slice(0,-14)+".getObjectAsList()");if("FIRST"==d){if("SET"==c)return b+".set(0, "+a+");\n";if("INSERT"==c)return b+".addFirst("+a+");\n"}else if("LAST"==
d){if("SET"==c)return b+".set("+b+".size()-1, "+a+");\n";if("INSERT"==c)return b+".add("+a+");\n"}else if("FROM_START"==d){e=Blockly.isNumber(e)?parseInt(e,10)-1:"((int)"+e+" - 1)";if("SET"==c)return b+".set("+e+", "+a+");\n";if("INSERT"==c)return b+".add("+e+", "+a+");\n"}else if("FROM_END"==d){e=Blockly.isNumber(e)?parseInt(e,10):"((int)"+e+")";if("SET"==c)return b+".set("+b+".size() -"+e+", "+a+");\n";if("INSERT"==c)return b+".add("+b+".size() -"+e+", "+a+");\n"}else if("RANDOM"==d){Blockly.Java.addImport("java.util.Random");
b.match(/^\w+$/)?d="":(d=Blockly.Java.variableDB_.getDistinctName("tmp_list",Blockly.Variables.NAME_TYPE),e=d+" = "+b+"\n",b=d,d=e);e=Blockly.Java.variableDB_.getDistinctName("tmp_x",Blockly.Variables.NAME_TYPE);d+="int "+e+" = (int)(Math.random() * "+b+".size());\n";if("SET"==c)return d+(b+".set("+e+", "+a+");\n");if("INSERT"==c)return d+=b+".add("+e+", "+a+");\n"}throw"Unhandled combination (lists_setIndex).";};
Blockly.Java.lists_getSublist=function(a){var b=Blockly.Java.valueToCode(a,"LIST",Blockly.Java.ORDER_MEMBER)||"[]",c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2"),e=Blockly.Java.valueToCode(a,"AT1",Blockly.Java.ORDER_ADDITIVE)||"1";a=Blockly.Java.valueToCode(a,"AT2",Blockly.Java.ORDER_ADDITIVE)||"1";".cloneObject()"===b.slice(-14)&&(b=b.slice(0,-14)+".getObjectAsList()");"FIRST"==c||"FROM_START"==c&&"1"==e?e="0":"FROM_START"==c?e=Blockly.isNumber(e)?parseInt(e,10)-1:"((int)"+e+" - 1)":"FROM_END"==
c&&(e=Blockly.isNumber(e)?parseInt(e,10):"((int)"+e+")",e=b+".size() - "+e);"LAST"==d||"FROM_END"==d&&"1"==a?a=b+".size()-1":"FROM_START"==d?a=Blockly.isNumber(a)?parseInt(a,10)-1:"((int)"+a+"-1)":"FROM_END"==d&&(Blockly.isNumber(a)?(a=parseInt(a,10),a=b+".size() - "+a):a=b+".size() - ((int)"+a+"-1)");Blockly.Java.addImport("java.util.LinkedList");return[Blockly.Java.provideFunction_("lists_sublist",["public static LinkedList "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List list, int startIndex, int endIndex) {",
" LinkedList<Object> result = new LinkedList<>();"," int sizeList = list.size();"," for(int x = startIndex; x <= endIndex && x < sizeList; x++) {"," result.add(list.get(x));"," }"," return result;","}"])+"("+b+", "+e+", "+a+")",Blockly.Java.ORDER_MEMBER]};
Blockly.Java.lists_split=function(a){var b=a.getFieldValue("MODE");if("SPLIT"==b)b=Blockly.Java.valueToCode(a,"INPUT",Blockly.Java.ORDER_MEMBER)||"''",a=Blockly.Java.valueToCode(a,"DELIM",Blockly.Java.ORDER_NONE),Blockly.Java.addImport("java.util.LinkedList"),a="new LinkedList(Arrays.asList("+b+".split("+a+")))";else if("JOIN"==b)b=Blockly.Java.valueToCode(a,"INPUT",Blockly.Java.ORDER_NONE)||"[]",a=Blockly.Java.valueToCode(a,"DELIM",Blockly.Java.ORDER_MEMBER)||"''",".cloneObject()"===b.slice(-14)&&
(b=b.slice(0,-14)+".getObjectAsList()"),Blockly.Java.addImport("java.lang.StringBuilder"),Blockly.Java.provideVarClass(),a=Blockly.Java.provideFunction_("lists_join",["public static String "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List list, String separator) {"," StringBuilder result = new StringBuilder();",' String extra = "";'," for (Object elem : list) {"," result.append(extra);"," result.append(new Var(elem).getObjectAsString());"," extra = separator;"," }"," return result.toString();",
"}"])+"("+b+", "+a+")";else throw"Unknown mode: "+b;return[a,Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.logic={};
Blockly.Java.controls_if=function(a){for(var b=0,c=Blockly.Java.valueToCode(a,"IF"+b,Blockly.Java.ORDER_NONE)||"false",d=Blockly.Java.statementToCode(a,"DO"+b)||Blockly.Java.PASS,e="if ("+c+") {\n"+d,b=1;b<=a.elseifCount_;b++)c=Blockly.Java.valueToCode(a,"IF"+b,Blockly.Java.ORDER_NONE)||"false",d=Blockly.Java.statementToCode(a,"DO"+b)||Blockly.Java.PASS,e+="} else if ("+c+") {\n"+d;a.elseCount_&&(d=Blockly.Java.statementToCode(a,"ELSE")||Blockly.Java.PASS,e+="} else {\n"+d);return e+"}\n"};
Blockly.Java.logic_compare=function(a){var b={"":"","!":"!","<":">","<=":">=",">":"<",">=":"<="},c={EQ:"",NEQ:"!",LT:"<",LTE:"<=",GT:">",GTE:">="}[a.getFieldValue("OP")];Blockly.Java.getValueType(a,"A");Blockly.Java.getValueType(a,"B");var d=Blockly.Java.valueToCode(a,"A",Blockly.Java.ORDER_RELATIONAL);a=Blockly.Java.valueToCode(a,"B",Blockly.Java.ORDER_RELATIONAL);".cloneObject()"===d.slice(-14)?(d=d.slice(0,-14),".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14))):".cloneObject()"===a.slice(-14)&&
(c=b[c],b=d,d=a.slice(0,-14),a=b);d?(d="Var.valueOf("+d+")",Blockly.Java.provideVarClass()):d='""';a||(a='""');return[""===c||"!"===c?c+d+".equals("+a+")":d+".compareTo("+a+") "+c+" 0",Blockly.Java.ORDER_RELATIONAL]};
Blockly.Java.logic_operation=function(a){var b="AND"==a.getFieldValue("OP")?" && ":" || ",c="and"==b?Blockly.Java.ORDER_LOGICAL_AND:Blockly.Java.ORDER_LOGICAL_OR,d=Blockly.Java.valueToCode(a,"A",c);a=Blockly.Java.valueToCode(a,"B",c);if(d||a){var e=" && "==b?"true":"false";d||(d=e);a||(a=e)}else a=d="false";return[d+b+a,c]};Blockly.Java.logic_negate=function(a){return["!("+(Blockly.Java.valueToCode(a,"BOOL",Blockly.Java.ORDER_LOGICAL_NOT)||"true")+")",Blockly.Java.ORDER_LOGICAL_NOT]};
Blockly.Java.logic_boolean=function(a){return["TRUE"==a.getFieldValue("BOOL")?"true":"false",Blockly.Java.ORDER_ATOMIC]};Blockly.Java.logic_null=function(a){return["null",Blockly.Java.ORDER_ATOMIC]};Blockly.Java.logic_ternary=function(a){var b=Blockly.Java.valueToCode(a,"IF",Blockly.Java.ORDER_CONDITIONAL)||"false",c=Blockly.Java.valueToCode(a,"THEN",Blockly.Java.ORDER_CONDITIONAL)||"null";a=Blockly.Java.valueToCode(a,"ELSE",Blockly.Java.ORDER_CONDITIONAL)||"null";return[b+" ? "+c+" : "+a,Blockly.Java.ORDER_CONDITIONAL]};Blockly.Java.loops={};
Blockly.Java.controls_repeat_ext=function(a){var b=a.getField("TIMES")?String(Number(a.getFieldValue("TIMES"))):Blockly.Java.valueToCode(a,"TIMES",Blockly.Java.ORDER_ASSIGNMENT)||"0",c=Blockly.Java.statementToCode(a,"DO"),c=Blockly.Java.addLoopTrap(c,a.id);a="";var d=Blockly.Java.variableDB_.getDistinctName("count",Blockly.Variables.NAME_TYPE),e=b;b.match(/^\w+$/)||Blockly.isNumber(b)||(e=Blockly.Java.variableDB_.getDistinctName("repeat_end",Blockly.Variables.NAME_TYPE),a+="int "+e+" = int("+b+");\n");
return a+="for (int "+d+" = 0; "+d+" < "+b+";"+d+"++) {\n"+Blockly.Java.INDENT+c+"} // end for\n"};Blockly.Java.controls_repeat=Blockly.Java.controls_repeat_ext;
Blockly.Java.controls_whileUntil=function(a){var b="UNTIL"==a.getFieldValue("MODE"),c=Blockly.Java.valueToCode(a,"BOOL",b?Blockly.Java.ORDER_LOGICAL_NOT:Blockly.Java.ORDER_NONE)||"false",d=Blockly.Java.statementToCode(a,"DO"),d=Blockly.Java.addLoopTrap(d,a.id)||Blockly.Java.PASS;if(b&&"true"===c||!b&&"false"===c)a=Blockly.Java.variableDB_.getDistinctName(c,Blockly.Variables.NAME_TYPE),Blockly.Java.stashStatement("boolean "+a+" = "+c+";\n"),c=a;b&&(c="!"+c);return"while ("+c+") {\n"+d+"} // end while\n"};
Blockly.Java.controls_for=function(a){var b=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);Blockly.Java.GetVariableType(a.getFieldValue("VAR"));var c=Blockly.Java.valueToCode(a,"FROM",Blockly.Java.ORDER_NONE)||"0",d=Blockly.Java.valueToCode(a,"TO",Blockly.Java.ORDER_NONE)||"0",e=Blockly.Java.valueToCode(a,"BY",Blockly.Java.ORDER_NONE)||"1",g=Blockly.Java.statementToCode(a,"DO"),g=Blockly.Java.addLoopTrap(g,a.id)||Blockly.Java.PASS;a=Blockly.Java.GetVariableType(a.getFieldValue("VAR"));
var f="";if(Blockly.isNumber(c)&&Blockly.isNumber(d)&&Blockly.isNumber(e)){var c=parseFloat(c),d=parseFloat(d),e=Math.abs(parseFloat(e)),h="<=",l="++";c>d&&(h=">=",e=-e);"Var"===a?f="for ("+b+".setObject("+c+"); "+b+".getObjectAsDouble() "+h+d+"; "+b+".incrementObject("+e+")) ":(0>e?l=" -= "+Math.abs(e):1!=e&&(l=" += "+e),f+="for ("+b+" = "+c+"; "+b+h+d+"; "+b+l+")")}else h=c,c.match(/^\w+$/)||Blockly.isNumber(c)||(h=Blockly.Java.variableDB_.getDistinctName(b+"_start",Blockly.Variables.NAME_TYPE),
f+="double "+h+" = "+c+";\n"),c=d,d.match(/^\w+$/)||Blockly.isNumber(d)||(c=Blockly.Java.variableDB_.getDistinctName(b+"_end",Blockly.Variables.NAME_TYPE),f+="double "+c+" = "+d+";\n"),d=Blockly.Java.variableDB_.getDistinctName(b+"_inc",Blockly.Variables.NAME_TYPE),f+="double "+d+" = ",f=Blockly.isNumber(e)?f+(Math.abs(e)+";\n"):f+("Math.abs("+e+");\n"),f=f+("if ("+h+" > "+c+") {\n")+(Blockly.Java.INDENT+d+" = -"+d+";\n"),f+="}\n",f="Var"===a?f+("for ("+b+".setObject("+h+");\n"+Blockly.Java.INDENT+
d+" >= 0 ? "+b+".getObjectAsDouble() <= "+c+" : "+b+".getObjectAsDouble() >= "+c+";\n"+b+".incrementObject("+d+")) "):f+("for ("+b+" = "+h+";\n"+Blockly.Java.INDENT+d+" >= 0 ? "+b+" <= "+c+" : "+b+" >= "+c+";\n"+Blockly.Java.INDENT+b+" += "+d+")");return f+=" {\n"+g+"} // end for\n"};
Blockly.Java.controls_forEach=function(a){var b=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Java.GetVariableType(a.getFieldValue("VAR")),d=Blockly.Java.valueToCode(a,"LIST",Blockly.Java.ORDER_RELATIONAL)||"[]",e=Blockly.Java.statementToCode(a,"DO"),e=Blockly.Java.addLoopTrap(e,a.id)||Blockly.Java.PASS;a="";"Var"===c?(c=Blockly.Java.variableDB_.getDistinctName("it",Blockly.Variables.NAME_TYPE),b=b+".setObject("+c+".next())",Blockly.Java.addImport("java.util.Iterator"),
a="for (Iterator "+c+" = "+d+".iterator(); "+c+".hasNext();) {\n"+Blockly.Java.INDENT+b+";\n"):a="for ("+c+" "+b+" :"+d+") {\n";return a+(e+"} // end for\n")};Blockly.Java.controls_flow_statements=function(a){switch(a.getFieldValue("FLOW")){case "BREAK":return"break;\n";case "CONTINUE":return"continue;\n"}throw"Unknown flow statement.";};Blockly.Java.maps={};Blockly.Java.maps_create_empty=function(a){return["new HashMap()",Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.maps_create_with=function(a){var b=Blockly.Java.variableDB_.getDistinctName("hashMap",Blockly.Variables.NAME_TYPE),c="HashMap "+b+" = new HashMap();\n";Blockly.Java.addImport("java.util.HashMap");Blockly.Java.stashStatement(c);for(var d=0;d<a.itemCount_;d++){var e="ADD"+d;if(c=a.getInputTargetBlock(e))if("maps_create"===c.type)e=Blockly.Java.valueToCode(c,"VAL",Blockly.Java.ORDER_NONE)||"null",c=Blockly.Java.valueToCode(c,"KEY",Blockly.Java.ORDER_NONE)||'""',c=b+".put("+c+", "+e+");\n",
Blockly.Java.stashStatement(c);else if(c=Blockly.Java.valueToCode(a,e,Blockly.Java.ORDER_NONE))c=b+".putAll("+c+");\n",Blockly.Java.stashStatement(c)}return[b,Blockly.Java.ORDER_ATOMIC]};Blockly.Java.maps_length=function(a){a=Blockly.Java.valueToCode(a,"MAP",Blockly.Java.ORDER_NONE)||"new HashMap()";".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14)+".getObjectAsList()");return[a+".size()",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.maps_isempty=function(a){a=Blockly.Java.valueToCode(a,"MAP",Blockly.Java.ORDER_NONE)||"";var b=a+".size() == 0";""===a&&(b="true");return[b,Blockly.Java.ORDER_LOGICAL_NOT]};
Blockly.Java.maps_create=function(a){var b=Blockly.Java.valueToCode(a,"VAL",Blockly.Java.ORDER_NONE)||"null";a=Blockly.Java.valueToCode(a,"KEY",Blockly.Java.ORDER_NONE)||'""';var c=Blockly.Java.variableDB_.getDistinctName("hashMap",Blockly.Variables.NAME_TYPE);Blockly.Java.stashStatement("HashMap "+c+" = new HashMap();\n"+c+".put("+a+", "+b+");\n");return[c,Blockly.Java.ORDER_LOGICAL_NOT]};
Blockly.Java.maps_getIndex=function(a){var b=a.getFieldValue("MODE")||"GET",c=Blockly.Java.valueToCode(a,"KEY",Blockly.Java.ORDER_NONE)||'""';a=Blockly.Java.valueToCode(a,"MAP",Blockly.Java.ORDER_MEMBER)||"";".cloneObject()"===a.slice(-14)&&(a=a.slice(0,-14)+".getObjectAsMap()");if("GET"==b)return[a+".get("+c+")",Blockly.Java.ORDER_MEMBER];c=a+".remove("+c+")";if("GET_REMOVE"==b)return[c,Blockly.Java.ORDER_FUNCTION_CALL];if("REMOVE"==b)return c+";\n";throw"Unhandled combination (maps_getIndex).";
};Blockly.Java.maps_setIndex=function(a){var b=Blockly.Java.valueToCode(a,"MAP",Blockly.Java.ORDER_MEMBER)||"new HashMap()",c=Blockly.Java.valueToCode(a,"VAL",Blockly.Java.ORDER_NONE)||"null";a=Blockly.Java.valueToCode(a,"KEY",Blockly.Java.ORDER_NONE)||'""';return b+".put("+a+", "+c+");\n"};Blockly.Java.maps_keys=function(a){return[(Blockly.Java.valueToCode(a,"MAP",Blockly.Java.ORDER_NONE)||"new HashMap()")+".keySet()",Blockly.Java.ORDER_LOGICAL_NOT]};Blockly.Java.controls_forEachKey=Blockly.Java.controls_forEach;Blockly.Java.math={};Blockly.Java.addReservedWords("math,random");Blockly.Java.math_number=function(a){a=""+parseFloat(a.getFieldValue("NUM"));"Double"===Blockly.Java.getTargetType()&&0>a.indexOf(".")&&(a+=".0");return[a,0>a?Blockly.Java.ORDER_UNARY_SIGN:Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.math_arithmetic=function(a){var b={ADD:[" + ",Blockly.Java.ORDER_ADDITIVE],MINUS:[" - ",Blockly.Java.ORDER_ADDITIVE],MULTIPLY:[" * ",Blockly.Java.ORDER_MULTIPLICATIVE],DIVIDE:[" / ",Blockly.Java.ORDER_MULTIPLICATIVE],POWER:[" ** ",Blockly.Java.ORDER_EXPONENTIATION]}[a.getFieldValue("OP")],c=b[0],b=b[1],d=Blockly.Java.valueToCode(a,"A",b)||"0";a=Blockly.Java.valueToCode(a,"B",b)||"0";var e="";" ** "===c?(Blockly.Java.addImport("java.lang.Math"),e="Math.pow("+d+", "+a+")"):e=d+c+a;return[e,
b]};
Blockly.Java.math_single=function(a){var b=a.getFieldValue("OP"),c;if("NEG"==b)return c=Blockly.Java.valueToCode(a,"NUM",Blockly.Java.ORDER_UNARY_SIGN)||"0",["-"+c,Blockly.Java.ORDER_UNARY_SIGN];Blockly.Java.addImport("java.lang.Math");a="SIN"==b||"COS"==b||"TAN"==b?Blockly.Java.valueToCode(a,"NUM",Blockly.Java.ORDER_MULTIPLICATIVE)||"0":Blockly.Java.valueToCode(a,"NUM",Blockly.Java.ORDER_NONE)||"0";switch(b){case "ABS":c="Math.abs("+a+")";break;case "ROOT":c="Math.sqrt("+a+")";break;case "LN":c="Math.log("+
a+")";break;case "LOG10":c="Math.log10("+a+")";break;case "EXP":c="Math.exp("+a+")";break;case "POW10":c="Math.pow(10,"+a+")";break;case "ROUND":c="Math.round("+a+")";break;case "ROUNDUP":c="Math.ceil("+a+")";break;case "ROUNDDOWN":c="Math.floor("+a+")";break;case "SIN":c="Math.sin("+a+" / 180.0 * Math.PI)";break;case "COS":c="Math.cos("+a+" / 180.0 * Math.PI)";break;case "TAN":c="Math.tan("+a+" / 180.0 * Math.PI)"}if(c)return[c,Blockly.Java.ORDER_FUNCTION_CALL];switch(b){case "ASIN":c="Math.asin("+
a+") / Math.PI * 180";break;case "ACOS":c="Math.acos("+a+") / Math.PI * 180";break;case "ATAN":c="Math.atan("+a+") / Math.PI * 180";break;default:throw"Unknown math operator: "+b;}return[c,Blockly.Java.ORDER_MULTIPLICATIVE]};
Blockly.Java.math_constant=function(a){var b={PI:["Math.PI",Blockly.Java.ORDER_MEMBER],E:["Math.E",Blockly.Java.ORDER_MEMBER],GOLDEN_RATIO:["(1 + Math.sqrt(5)) / 2",Blockly.Java.ORDER_MULTIPLICATIVE],SQRT2:["Math.sqrt(2)",Blockly.Java.ORDER_MEMBER],SQRT1_2:["Math.sqrt(1.0 / 2)",Blockly.Java.ORDER_MEMBER],INFINITY:["Double.POSITIVE_INFINITY",Blockly.Java.ORDER_ATOMIC]};a=a.getFieldValue("CONSTANT");"INFINITY"!=a&&Blockly.Java.addImport("java.lang.Math");return b[a]};
Blockly.Java.math_number_property=function(a){var b=Blockly.Java.valueToCode(a,"NUMBER_TO_CHECK",Blockly.Java.ORDER_MULTIPLICATIVE)||"0",c=a.getFieldValue("PROPERTY"),d;if("PRIME"==c)return Blockly.Java.addImport("java.lang.Math"),d=Blockly.Java.provideFunction_("math_isPrime",["public static boolean "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(Object d) {"," // https://en.wikipedia.org/wiki/Primality_test#Naive_methods"," // If n is not a number but a string, try parsing it."," double n;"," if (d instanceof Double) {",
" n = (Double)d;"," } else if (d instanceof Integer) {"," n = (Integer)d;"," } else {"," return false;"," }"," if (n == 2 || n == 3) {"," return true;"," }"," // False if n is negative, is 1, or not whole, or if n is divisible by 2 or 3."," if ((n <= 1) || (n % 1 != 0) || (n % 2 == 0) || (n % 3 == 0)) {"," return false;"," }"," // Check all the numbers of form 6k +/- 1, up to sqrt(n)."," for (int x = 6; x <= Math.sqrt(n) + 1; x += 6) {"," if (n % (x - 1) == 0 || n % (x + 1) == 0) {",
" return false;"," }"," }"," return true;","}"])+"("+b+")",[d,Blockly.Java.ORDER_FUNCTION_CALL];switch(c){case "EVEN":d=b+" % 2 == 0";break;case "ODD":d=b+" % 2 == 1";break;case "WHOLE":d=b+" % 1 == 0";break;case "POSITIVE":d=b+" > 0";break;case "NEGATIVE":d=b+" < 0";break;case "DIVISIBLE_BY":a=Blockly.Java.valueToCode(a,"DIVISOR",Blockly.Java.ORDER_MULTIPLICATIVE);if(!a||"0"==a)return["False",Blockly.Java.ORDER_ATOMIC];d=b+" % "+a+" == 0"}return[d,Blockly.Java.ORDER_RELATIONAL]};
Blockly.Java.math_change=function(a){var b=Blockly.Java.valueToCode(a,"DELTA",Blockly.Java.ORDER_ADDITIVE)||"0";a=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);return a+" = "+a+" + "+b+";\n"};Blockly.Java.math_round=Blockly.Java.math_single;Blockly.Java.math_trig=Blockly.Java.math_single;
Blockly.Java.math_on_list=function(a){var b=a.getFieldValue("OP"),c=Blockly.Java.valueToCode(a,"LIST",Blockly.Java.ORDER_NONE)||"[]";switch(b){case "SUM":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_sum",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," return Var.math_sum(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "MIN":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_min",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+
"(List myList) {"," return Var.math_min(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "MAX":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_max",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," return Var.math_max(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "AVERAGE":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_mean",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {",
" return Var.math_mean(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "MEDIAN":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_median",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," return Var.math_median(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "MODE":Blockly.Java.provideVarClass();Blockly.Java.addImport("java.util.LinkedList");b=Blockly.Java.provideFunction_("math_modes",["public static LinkedList "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+
"(List myList) {"," return Var.math_modes(Var.valueOf(myList)).getObjectAsList();","}"]);a=b+"("+c+")";break;case "STD_DEV":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_standard_deviation",["public static double "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List myList) {"," return Var.math_standard_deviation(Var.valueOf(myList));","}"]);a=b+"("+c+")";break;case "RANDOM":Blockly.Java.provideVarClass();b=Blockly.Java.provideFunction_("math_random_list",["public static Object "+
Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(List list) {"," int x = (int)(Math.floor(Math.random() * list.size()));"," return list.get(x);","}"]);c=Blockly.Java.valueToCode(a,"LIST",Blockly.Java.ORDER_NONE)||"[]";a=b+"("+c+")";break;default:throw"Unknown operator: "+b;}return[a,Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.math_modulo=function(a){var b=Blockly.Java.valueToCode(a,"DIVIDEND",Blockly.Java.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Java.valueToCode(a,"DIVISOR",Blockly.Java.ORDER_MULTIPLICATIVE)||"0";return[b+" % "+a,Blockly.Java.ORDER_MULTIPLICATIVE]};
Blockly.Java.math_format_as_decimal=function(a){var b=Blockly.Java.valueToCode(a,"NUM",Blockly.Java.ORDER_MULTIPLICATIVE)||"0";a=Blockly.Java.valueToCode(a,"PLACES",Blockly.Java.ORDER_MULTIPLICATIVE)||"0";return['new DecimalFormat("#.'+Array(++a).join("0")+'").format('+b+")",Blockly.Java.ORDER_MULTIPLICATIVE]};
Blockly.Java.math_constrain=function(a){Blockly.Java.addImport("java.lang.Math");var b=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"0",c=Blockly.Java.valueToCode(a,"LOW",Blockly.Java.ORDER_NONE)||"0";a=Blockly.Java.valueToCode(a,"HIGH",Blockly.Java.ORDER_NONE)||"float('inf')";return["Math.min(Math.max("+b+", "+c+"), "+a+")",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.math_random_int=function(a){Blockly.Java.addImport("java.lang.Math");var b=Blockly.Java.valueToCode(a,"FROM",Blockly.Java.ORDER_NONE)||"0";a=Blockly.Java.valueToCode(a,"TO",Blockly.Java.ORDER_NONE)||"0";return[Blockly.Java.provideFunction_("math_random_int",["public static int "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(int a, int b) {"," if (a > b) {"," // Swap a and b to ensure a is smaller."," int c = a;"," a = b;"," b = c;"," }"," return (int)Math.floor(Math.random() * (b - a + 1) + a);",
"}"])+"("+b+", "+a+")",Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.math_random_float=function(a){Blockly.Java.addImport("java.lang.Math");return["Math.random()",Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.procedures={};
Blockly.Java.procedures_defreturn=function(a){var b=a.getFieldValue("NAME"),c=Blockly.Java.variableDB_.getName(b,Blockly.Procedures.NAME_TYPE),d=Blockly.Java.statementToCode(a,"STACK");Blockly.Java.STATEMENT_PREFIX&&(d=Blockly.Java.prefixLines(Blockly.Java.STATEMENT_PREFIX.replace(/%1/g,"'"+a.id+"'"),Blockly.Java.INDENT)+d);Blockly.Java.INFINITE_LOOP_TRAP&&(d=Blockly.Java.INFINITE_LOOP_TRAP.replace(/%1/g,'"'+a.id+'"')+d);var e="void";this.hasReturnValue_&&(e=Blockly.Java.GetVariableType(b+"."));var g=
Blockly.Java.valueToCode(a,"RETURN",Blockly.Java.ORDER_NONE)||"";g?g="Var"===e?" return Var.valueOf("+g+");\n":" return "+g+";\n":d||(d=Blockly.Java.PASS);for(var f=[],h=0;h<a.arguments_.length;h++){var l=Blockly.Java.GetVariableType(b+"."+a.arguments_[h].name);f[h]=l+" "+Blockly.Java.variableDB_.getName(a.arguments_[h].name,Blockly.Variables.NAME_TYPE)}b="public "+e+" "+c+"("+f.join(", ")+"){\n"+d+g+"}";b=Blockly.Java.scrub_(a,b);Blockly.Java.definitions_[c]=b;return null};
Blockly.Java.procedures_defnoreturn=Blockly.Java.procedures_defreturn;Blockly.Java.procedures_callreturn=function(a){for(var b=Blockly.Java.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Java.valueToCode(a,"ARG"+d,Blockly.Java.ORDER_NONE)||"null";return[b+"("+c.join(", ")+")",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.procedures_callnoreturn=function(a){for(var b=Blockly.Java.variableDB_.getName(a.getFieldValue("NAME"),Blockly.Procedures.NAME_TYPE),c=[],d=0;d<a.arguments_.length;d++)c[d]=Blockly.Java.valueToCode(a,"ARG"+d,Blockly.Java.ORDER_NONE)||"null";return b+"("+c.join(", ")+");\n"};
Blockly.Java.procedures_ifreturn=function(a){var b="if ("+(Blockly.Java.valueToCode(a,"CONDITION",Blockly.Java.ORDER_NONE)||"False")+"){\n";a.hasReturnValue_?(a=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"None",b+=" return "+a+";\n}"):b+=" return;\n}";return b};Blockly.Java.texts={};Blockly.Java.text=function(a){return[Blockly.Java.quote_(a.getFieldValue("TEXT")),Blockly.Java.ORDER_ATOMIC]};Blockly.Java.text_join=function(a){for(var b="",c="",d=0;d<a.itemCount_;d++){var e=Blockly.Java.toStringCode(a,"ADD"+d);e&&(b+=c+e,c=" + ")}""===b&&(b='""');return[b,Blockly.Java.ORDER_ADDITIVE]};
Blockly.Java.text_append=function(a){var b=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),c=Blockly.Java.toStringCode(a,"TEXT")||'""',d=b+" = ",e="";"Var"===Blockly.Java.GetVariableType(a.getFieldValue("VAR"))&&(b="new Var("+b+".getObjectAsString()",e=")");return d+(b+" + "+c+e+";\n")};Blockly.Java.text_length=function(a){return[(Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||'""')+".length()",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.text_isEmpty=function(a){return[(Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||'""')+".isEmpty()",Blockly.Java.ORDER_LOGICAL_NOT]};Blockly.Java.text_indexOf=function(a){var b="FIRST"==a.getFieldValue("END")?"indexOf":"lastIndexOf",c=Blockly.Java.valueToCode(a,"FIND",Blockly.Java.ORDER_NONE)||'""';return[(Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_MEMBER)||'""')+"."+b+"("+c+") + 1",Blockly.Java.ORDER_MEMBER]};
Blockly.Java.text_charAt=function(a){var b=a.getFieldValue("WHERE")||"FROM_START",c=Blockly.Java.valueToCode(a,"AT",Blockly.Java.ORDER_UNARY_SIGN)||"1";a=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_MEMBER)||'""';switch(b){case "FIRST":return[a+".substring(0,1)",Blockly.Java.ORDER_MEMBER];case "LAST":return[a+".substring("+a+".length()-1)",Blockly.Java.ORDER_MEMBER];case "FROM_START":return Blockly.isNumber(c)?(b=parseInt(c,10),c=b-1):(c="(int)"+c+" - 1",b="(int)"+c),[a+".substring("+c+","+
b+")",Blockly.Java.ORDER_MEMBER];case "FROM_END":return Blockly.isNumber(c)?(b=parseInt(c,10),c=a+".length()-"+b,b=a+".length()-"+(b-1)):(b=a+".length()-(int)"+c,c=a+".length()-((int)"+c+"-1)"),[a+".substring("+c+","+b+")",Blockly.Java.ORDER_MEMBER];case "RANDOM":return Blockly.Java.addImport("java.lang.Math"),c=Blockly.Java.provideFunction_("text_random_letter",["public static int "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(String text) {"," int x = (int)(Math.random() * text.length());"," return text.charAt(x);",
"}"])+"("+a+")",[c,Blockly.Java.ORDER_FUNCTION_CALL]}throw"Unhandled option (text_charAt).";};
Blockly.Java.text_getSubstring=function(a){var b=Blockly.Java.valueToCode(a,"STRING",Blockly.Java.ORDER_MEMBER)||'""',c=a.getFieldValue("WHERE1"),d=a.getFieldValue("WHERE2"),e=Blockly.Java.valueToCode(a,"AT1",Blockly.Java.ORDER_ADDITIVE)||"1";a=Blockly.Java.valueToCode(a,"AT2",Blockly.Java.ORDER_ADDITIVE)||"1";"FIRST"==c||"FROM_START"==c&&"1"==e?e="0":"FROM_START"==c?e=Blockly.isNumber(e)?parseInt(e,10)-1:"((int)"+e+" - 1)":"FROM_END"==c&&(e=Blockly.isNumber(e)?b+".length() -"+parseInt(e,10):b+".length() - ((int)"+
e+")");"LAST"==d||"FROM_END"==d&&"1"==a?a="":"FROM_START"==d?a=Blockly.isNumber(a)?parseInt(a,10):"((int)"+a+")":"FROM_END"==d&&(Blockly.isNumber(a)?(a=parseInt(a,10)-1,a=0==a?"":b+".length() -"+a):a=b+".length() - ((int)"+a+"-1)");""!==a&&(a=", "+a);return[b+".substring("+e+a+")",Blockly.Java.ORDER_MEMBER]};
Blockly.Java.text_changeCase=function(a){var b={UPPERCASE:".toUpperCase()",LOWERCASE:".toLowerCase()",TITLECASE:"TITLECASE"}[a.getFieldValue("CASE")];a=Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_MEMBER)||'""';var c="";"TITLECASE"===b?(Blockly.Java.addImport("java.lang.StringBuilder"),c=Blockly.Java.provideFunction_("toTitleCase",["public static String "+Blockly.Java.FUNCTION_NAME_PLACEHOLDER_+"(String input) {"," StringBuilder titleCase = new StringBuilder();"," boolean nextTitleCase = true;",
""," for (char c : input.toLowerCase().toCharArray()) {"," if (Character.isSpaceChar(c)) {"," nextTitleCase = true;"," } else if (nextTitleCase) {"," c = Character.toTitleCase(c);"," nextTitleCase = false;"," }",""," titleCase.append(c);"," }",""," return titleCase.toString();","}"])+"("+a+")"):c=a+b;return[c,Blockly.Java.ORDER_MEMBER]};
Blockly.Java.text_trim=function(a){var b={LEFT:'.replaceAll("^\\\\s+", "")',RIGHT:'.replaceAll("\\\\s+$", "")',BOTH:".trim()"}[a.getFieldValue("MODE")];return[(Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_MEMBER)||'""')+b,Blockly.Java.ORDER_MEMBER]};Blockly.Java.text_print=function(a){return"System.out.println("+(Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_NONE)||'""')+".toString());\n"};
Blockly.Java.text_printf=function(a){return"System.out.println("+(Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_NONE)||'""')+".toString());\n"};Blockly.Java.text_printf=function(a){for(var b="System.out.format("+(Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_NONE)||'""'),c=0;c<a.itemCount_;c++){var d=Blockly.Java.toStringCode(a,"ADD"+c);d&&(b+=", "+d)}return b+");\n"};
Blockly.Java.text_sprintf=function(a){var b=Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_NONE)||'""';if(0==a.itemCount_)return[b,Blockly.Java.ORDER_ATOMIC];for(var b="String.format("+b,c=0;c<a.itemCount_;c++){var d=Blockly.Java.toStringCode(a,"ADD"+c);d&&(b+=", "+d)}return[b+")",Blockly.Java.ORDER_FUNCTION_CALL]};
Blockly.Java.text_prompt_ext=function(a){var b="window.prompt("+(a.getField("TEXT")?Blockly.Java.quote_(a.getFieldValue("TEXT")):Blockly.Java.valueToCode(a,"TEXT",Blockly.Java.ORDER_NONE)||"''")+")";"NUMBER"==a.getFieldValue("TYPE")&&(b="parseFloat("+b+")");return[b,Blockly.Java.ORDER_FUNCTION_CALL]};Blockly.Java.text_prompt=Blockly.Java.text_prompt_ext;Blockly.Java.text_comment=function(a){return"/*\n"+(a.getFieldValue("COMMENT")||"")+"\n*/\n"};
Blockly.Java.text_code_insert=function(a){var b="";"Java"==(a.getFieldValue("TYPE")||"")&&(a=a.getFieldValue("CODE")||"",b="//Arbitrary Java code insert block",b=""!=a?b+"\n"+(a+"\n"):b+" is empty\n");return b};Blockly.Java.variables={};Blockly.Java.variables_get=function(a){Blockly.Java.setGlobalVar(a,a.getFieldValue("VAR"),null);var b=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);"Var"===Blockly.Java.GetVariableType(this.procedurePrefix_+a.getFieldValue("VAR"))&&(b+=".cloneObject()");return[b,Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.variables_set=function(a){Blockly.Java.setGlobalVar(a,a.getFieldValue("VAR"),null);var b=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"0",c=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE),d=Blockly.Java.getValueType(a,"VALUE"),e=Blockly.Java.GetBlocklyType(a.getFieldValue("VAR")),g=!1;d&&goog.array.contains(d,e)&&(g=!0);"String"!==e||g||(b=Blockly.Java.toStringCode(a,"VALUE"));return c="Var"===Blockly.Java.GetVariableType(this.procedurePrefix_+
a.getFieldValue("VAR"))?c+(".setObject("+b+");\n"):c+(" = "+b+";\n")};
Blockly.Java.hash_variables_get=function(a){var b=a.getFieldValue("VAR");Blockly.Java.setGlobalVar(a,b,null);var c=Blockly.Java.GetVariableType(this.procedurePrefix_+b),b=Blockly.Java.variableDB_.getName(b,Blockly.Variables.NAME_TYPE),b=Blockly.VariableTypeEquivalence[c]?b+("."+a.getFieldValue("HASHKEY")):b+(".get("+a.getFieldValue("HASHKEY")+")");(a=a.getParent())&&(c=a.getVars)&&(a=c.call(a))&&a.length&&(goog.array.contains(a,"String")?b+=".getObjectAsString()":goog.array.contains(a,"List")&&(b+=
".getObjectAsList()"));return[b,Blockly.Java.ORDER_ATOMIC]};Blockly.Java.hash_parmvariables_get=function(a){Blockly.Java.setGlobalVar(a,a.getFieldValue("VAR"),null);var b="getString",c=a.getParent();if(c){var d=c.getVars;if(d)for(c=d.call(c),d=0;d<c.length;d++){var e=c[d];e&&(e=Blockly.Java.GetVariableType(e),"Array"===e?b="get":"Object"===e&&(b="get"))}}return[(Blockly.Java.valueToCode(a,"VAR",Blockly.Java.ORDER_NONE)||"0")+"."+b+"("+Blockly.Java.quote_(a.getFieldValue("HASHKEY"))+")",Blockly.Java.ORDER_ATOMIC]};
Blockly.Java.hash_variables_set=function(a){Blockly.Java.setGlobalVar(a,a.getFieldValue("VAR"),null);var b=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"0";return Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE)+"{"+a.getFieldValue("HASHKEY")+"} = "+b+";\n"};
Blockly.Java.initialize_variable=function(a){var b=Blockly.Java.valueToCode(a,"VALUE",Blockly.Java.ORDER_NONE)||"0";if(""!=a.procedurePrefix_){var c=Blockly.Java.GetVariableType(a.procedurePrefix_+a.getFieldValue("VAR"));"LinkedList"===c&&Blockly.Java.addImport("java.util.LinkedList");a=Blockly.Java.variableDB_.getName(a.getFieldValue("VAR"),Blockly.Variables.NAME_TYPE);return c+" "+a+" = "+b+";\n"}Blockly.Java.setGlobalVar(a,a.getFieldValue("VAR"),b);return""};