private static void spawnFireworks(Player player) { int power = (int) (Math.random() * 3) + 1; int type = (int) (Math.random() * 5) + 1; Type typen = Type.BALL; if (type == 1) typen = Type.BALL; if (type == 2) typen = Type.BALL_LARGE; if (type == 3) typen = Type.BURST; if (type == 4) typen = Type.CREEPER; if (type == 5) typen = Type.STAR; Firework fireworks = (Firework) player.getWorld().spawnEntity(player.getLocation(), EntityType.FIREWORK); FireworkMeta fireworkmeta = fireworks.getFireworkMeta(); FireworkEffect effect = FireworkEffect.builder() .flicker(Misc.getRandom().nextBoolean()) .withColor(colorchoose()) .withFade(colorchoose()) .with(typen) .trail(Misc.getRandom().nextBoolean()) .build(); fireworkmeta.addEffect(effect); fireworkmeta.setPower(power); fireworks.setFireworkMeta(fireworkmeta); }
public boolean equals(Object o) { if (!(o instanceof UserInfo)) return false; UserInfo that = (UserInfo) o; return Misc.equals(this.realm, that.realm) && Misc.equals(this.userId, that.userId) && Misc.equals(this.password, that.password); }
private static List<Color> colorchoose() { // Thanks Zomis and Tejpbit for the help with this function! int numberofcolors = Misc.getRandom().nextInt(17) + 1; List<Color> allcolors = new ArrayList<Color>(); allcolors.add(Color.AQUA); allcolors.add(Color.BLACK); allcolors.add(Color.BLUE); allcolors.add(Color.FUCHSIA); allcolors.add(Color.GRAY); allcolors.add(Color.GREEN); allcolors.add(Color.LIME); allcolors.add(Color.MAROON); allcolors.add(Color.NAVY); allcolors.add(Color.OLIVE); allcolors.add(Color.ORANGE); allcolors.add(Color.PURPLE); allcolors.add(Color.RED); allcolors.add(Color.SILVER); allcolors.add(Color.TEAL); allcolors.add(Color.WHITE); allcolors.add(Color.YELLOW); List<Color> choosencolors = new ArrayList<Color>(); for (int i = 0; i < numberofcolors; i++) { choosencolors.add(allcolors.remove(Misc.getRandom().nextInt(allcolors.size()))); } return choosencolors; }
@Test public void apps_projavascript_sun() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/projavascript/sun/08-sun.html"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_paint() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/paint/index.html", "test/apps/paint/paint.js"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_minesweeper() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/minesweeper/minesweeper.html"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_mceditor_full() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/mceditor/full.html", "test/apps/mceditor/tiny_mce_src.js"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_jscrypto_encrypt_from_form() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/jscrypto/encrypt_from_form.html", "test/apps/jscrypto/jscrypto.js"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_solitaire() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/solitaire/spider.html"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_simplecalc() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = {"test/apps/simplecalc/math2.html"}; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void apps_samegame() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = { "test/apps/samegame/index.html", "test/apps/samegame/header.js", "test/apps/samegame/main.js" }; Misc.run(args); Misc.checkSystemOutput(); }
/** * Check for equality * * @param object the object in question * @return true if they are equal */ public boolean equals(Object object) { if (!object.getClass().equals(getClass())) { return false; } RaobDataSource that = (RaobDataSource) object; if (file != null) { return Misc.equals(this.file, that.file); } return Misc.equals(raobDataSet, that.raobDataSet); }
@Test public void exceptionInBody() { Misc.init(); Misc.runSource( "var v = true;", "for(var p in {'a': 'a'}){", " v = false;", " FAIL;", "}", "TAJS_assert(v);"); }
/** This method will process each argument and assign new varibles */ public void processArgs(String[] args) { File file = null; Pattern pat = Pattern.compile("-[a-z]"); for (int i = 0; i < args.length; i++) { String lcArg = args[i].toLowerCase(); Matcher mat = pat.matcher(lcArg); if (mat.matches()) { char test = args[i].charAt(1); try { switch (test) { case 'f': file = new File(args[i + 1]); i++; break; case 'v': genomeVersion = args[i + 1]; i++; break; case 's': sumScores = true; break; case 't': threshold = Float.parseFloat(args[++i]); break; case 'h': printDocs(); System.exit(0); default: Misc.printExit("\nError, unknown option! " + mat.group()); } } catch (Exception e) { System.out.print("\nSorry, something doesn't look right with this parameter: -" + test); System.out.println(); System.exit(0); } } } if (file == null || file.exists() == false) Misc.printErrAndExit("Problem finding your bed files!\n"); // pull files File[][] tot = new File[3][]; tot[0] = IO.extractFiles(file, ".bed"); tot[1] = IO.extractFiles(file, ".bed.zip"); tot[2] = IO.extractFiles(file, ".bed.gz"); bedFiles = IO.collapseFileArray(tot); if (bedFiles == null || bedFiles.length == 0) Misc.printErrAndExit("Problem finding your xxx.bed(.zip/.gz OK) files!\n"); // genome version if (genomeVersion == null) Misc.printErrAndExit( "Please enter a genome version (e.g. H_sapiens_Mar_2006, see http://genome.ucsc.edu/FAQ/FAQreleases\n"); }
@Test public void regression_NullPointerException() { Misc.init(); Misc.runSource( "", "function merge(root){", " for ( var i = 0; i < arguments.length; i++ )", " for ( var key in arguments[i] )", " root[key] = arguments[i][key];", "}", "merge({p: 'p'}, {q: 'q'});"); }
@Test public void apps_projavascript_gallery() throws Exception { Misc.init(); Misc.captureSystemOutput(); String[] args = { "test/apps/projavascript/gallery/index.html", "test/apps/projavascript/gallery/library.js", "test/apps/projavascript/gallery/gallery.js" }; Misc.run(args); Misc.checkSystemOutput(); }
@Test public void noProperties() { Misc.init(); Misc.runSource( "", "var x;", "for(var p in {}){", "}", "TAJS_assert(x, 'isNotUndef', false);", "TAJS_dumpValue('OK');", ""); }
@Test public void twoPropertiesConflict1() { Misc.init(); Misc.runSource( "", "var x = '';", "for(var p in {a: 'a', b: 'b'}){", " x += p;", "}", "TAJS_assert(x, 'isMaybeStrIdentifierParts');", "TAJS_dumpValue('OK');", ""); }
@Test public void catching() { Misc.init(); Misc.runSource( "", "try {", " for(var p in {a: 'a'}){", " throw 42;", " }", "}catch(e){", "}", ""); }
private int signConverter(Player player, Block block) { Sign sign = (Sign) block.getState(); String[] lines = sign.getLines(); if (!lines[1].startsWith("/")) return 0; lines[1] = lines[1].replaceFirst("/", ""); String cmd[] = Misc.concatCmd(lines); cmd[1] = Misc.insertAll(cmd[1], player, block); return executor(player, block, cmd, false, false, false); }
/** This method will process each argument and assign new varibles */ public void processArgs(String[] args) { Pattern pat = Pattern.compile("-[a-z]"); File dir = null; for (int i = 0; i < args.length; i++) { String lcArg = args[i].toLowerCase(); Matcher mat = pat.matcher(lcArg); if (mat.matches()) { char test = args[i].charAt(1); try { switch (test) { case 'f': dir = new File(args[i + 1]); i++; break; case 'v': genomeVersion = args[i + 1]; i++; break; case 's': strand = args[++i]; break; case 't': stairStep = true; break; case 'h': printDocs(); System.exit(0); default: Misc.printExit("\nError: unknown option! " + mat.group()); } } catch (Exception e) { Misc.printExit( "\nSorry, something doesn't look right with this parameter: -" + test + "\n"); } } } if (dir == null || dir.canRead() == false) Misc.printExit("\nError: cannot find or read your sgr file/ directory.\n"); File[][] tot = new File[3][]; tot[0] = IO.extractFiles(dir, ".sgr"); tot[1] = IO.extractFiles(dir, ".sgr.zip"); tot[2] = IO.extractFiles(dir, ".sgr.gz"); sgrFiles = IO.collapseFileArray(tot); if (sgrFiles == null || sgrFiles.length == 0) Misc.printExit("\nError: cannot find your xxx.sgr.zip file(s)"); if (genomeVersion == null) Misc.printExit( "\nError: you must supply a genome version. Goto http://genome.ucsc.edu/cgi-" + "bin/hgGateway load your organism to find the associated genome version.\n"); }
/** Test the Misc.decodeLatLon method. */ @Test public void testMakeUnique() { List<Integer> listDup = Arrays.asList(1, 3, 4, 5, 1); List<Integer> listUnique = Misc.makeUnique(listDup); String error = "Misc.makeUnique not working"; assertEquals(error, listUnique.size(), 4); listDup = Arrays.asList(1, 3, null, 5, 1); listUnique = Misc.makeUnique(listDup); assertEquals(error, listUnique.size(), 4); listUnique = Misc.makeUnique(Collections.<Integer>emptyList()); assertEquals(error, listUnique.size(), 0); }
@Test public void returningValue() { Misc.init(); Misc.runSource( "", "var v = (function(){", " for(var p in {a: 'a'}){", " return 42;", " }", "})();", "TAJS_assert(v, 'isMaybeSingleNum');", "TAJS_assert(v, 'isMaybeUndef');", ""); }
@Test public void concatenateIdentifierString() { // should not crash Misc.init(); Misc.runSource( "", "var s = 'a';", "for(var p in {b: 'b', c: 'c'}){", " s += p;", "}", "TAJS_assert(s, 'isMaybeStrIdentifierParts');", // optimal precision would give // StrIdentifier ""); }
@Test public void oneProperty() { Misc.init(); Misc.runSource( "", "var x;", "for(var p in {a: 'a'}){", " x = p;", "}", "TAJS_assert(x, 'isMaybeSingleStr');", "TAJS_assert(x, 'isMaybeUndef');", "TAJS_dumpValue('OK');", ""); }
@Test public void twoPropertiesConflict3() { Misc.init(); Misc.runSource( "", "var x = 0;", "var o = {a: 1, b: 2};", "for(var p in o){", " x += o[p];", "}", "TAJS_assert(x, 'isMaybeNumUInt');", "TAJS_dumpValue('OK');", ""); }
@Test public void readingPropertiesFromOutSideLoop_bug() { Misc.init(); Misc.runSource( "", "var o = { u: Math.random() };", "for(var p in {a: 'a'}){", " if(o.u){", " break;", " }", "}", "TAJS_dumpValue('OK');", ""); }
/** Create singleton template for use with dictionary values */ public ST createSingleton(Token templateToken) { String template; if (templateToken.getType() == GroupParser.BIGSTRING) { template = Misc.strip(templateToken.getText(), 2); } else { template = Misc.strip(templateToken.getText(), 1); } CompiledST impl = compile(getFileName(), null, null, template, templateToken); ST st = createStringTemplateInternally(impl); st.groupThatCreatedThisInstance = this; st.impl.hasFormalArgs = false; st.impl.name = ST.UNKNOWN_NAME; st.impl.defineImplicitlyDefinedTemplates(this); return st; }
@Test public void functionWithForInAndLazyPropagationRecovery() { // should not crash Misc.init(); Misc.runSource( "", "var o1 = {};", "function f(o2) {", " for (var name in o2) {", " o1.p = o2[name]", " }", "}", "f({a: 'a'});", ""); }
@Test public void unorderedForInImplementation_withLazyPropagation() { Misc.init(); Misc.captureSystemOutput(); Misc.runSourceWithNamedFile( "unorderedForInImplementation_withLazyPropagation.js", "var o1 = {x: 'A', y: 'A'};", "var o2 = {};", "for(var p in o1){", " o2[p] = o1[p];", " TAJS_dumpObject(o2);", "}", "TAJS_dumpObject(o2);"); Misc.checkSystemOutput(); }