From 03a7b52a8e607ac631336fe267b0d5804d11494f Mon Sep 17 00:00:00 2001 From: gomeow Date: Fri, 12 Apr 2013 10:54:25 -0700 Subject: [PATCH] drtshock loves formatting, so I may as well --- .../com/drtshock/playervaults/Listeners.java | 8 +- .../java/com/drtshock/playervaults/Main.java | 8 +- .../playervaults/commands/Commands.java | 2 +- .../playervaults/commands/Feedback.java | 3 +- .../commands/VaultOperations.java | 21 +- .../playervaults/util/DropOnDeath.java | 3 +- .../playervaults/util/EconomyOperations.java | 8 +- .../drtshock/playervaults/util/Metrics.java | 87 ++-- .../playervaults/util/Serialization.java | 29 +- .../drtshock/playervaults/util/Updater.java | 31 +- .../playervaults/util/VaultManager.java | 5 +- src/main/java/org/json/CDL.java | 95 ++-- src/main/java/org/json/Cookie.java | 86 ++-- src/main/java/org/json/CookieList.java | 53 +- src/main/java/org/json/HTTP.java | 50 +- src/main/java/org/json/HTTPTokener.java | 55 +- src/main/java/org/json/JSONArray.java | 193 +++---- src/main/java/org/json/JSONObject.java | 477 ++++++++---------- src/main/java/org/json/JSONString.java | 1 + src/main/java/org/json/JSONStringer.java | 42 +- src/main/java/org/json/JSONTokener.java | 127 ++--- src/main/java/org/json/JSONWriter.java | 86 ++-- 22 files changed, 677 insertions(+), 793 deletions(-) diff --git a/src/main/java/com/drtshock/playervaults/Listeners.java b/src/main/java/com/drtshock/playervaults/Listeners.java index e7c9a76..2fe59e5 100644 --- a/src/main/java/com/drtshock/playervaults/Listeners.java +++ b/src/main/java/com/drtshock/playervaults/Listeners.java @@ -46,7 +46,7 @@ public class Listeners implements Listener { VaultViewInfo info = Commands.inVault.get(p.getName()); try { vm.saveVault(inv, info.getHolder(), info.getNumber()); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } Commands.inVault.remove(p.getName()); @@ -83,7 +83,7 @@ public class Listeners implements Listener { } } - @EventHandler + @EventHandler public void onClose(InventoryCloseEvent event) { HumanEntity he = event.getPlayer(); if(he instanceof Player) { @@ -108,7 +108,7 @@ public class Listeners implements Listener { * Different inventories that * we don't want the player to open. */ - if(block.getType() == Material.CHEST + if(block.getType() == Material.CHEST || block.getType() == Material.ENDER_CHEST || block.getType() == Material.FURNACE || block.getType() == Material.BURNING_FURNACE @@ -127,7 +127,7 @@ public class Listeners implements Listener { public void onInteractEntity(PlayerInteractEntityEvent event) { Player player = event.getPlayer(); EntityType type = event.getRightClicked().getType(); - if((type == EntityType.VILLAGER||type==EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) { + if((type == EntityType.VILLAGER || type == EntityType.MINECART) && Commands.inVault.containsKey(player.getName())) { event.setCancelled(true); } } diff --git a/src/main/java/com/drtshock/playervaults/Main.java b/src/main/java/com/drtshock/playervaults/Main.java index 293b075..89e0fbf 100644 --- a/src/main/java/com/drtshock/playervaults/Main.java +++ b/src/main/java/com/drtshock/playervaults/Main.java @@ -46,7 +46,7 @@ public class Main extends JavaPlugin { update = true; name = u.getNewVersion(); } - } catch (Exception e) { + } catch(Exception e) { log.log(Level.WARNING, "PlayerVaults: Failed to check for updates."); log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow."); e.printStackTrace(); @@ -72,7 +72,7 @@ public class Main extends JavaPlugin { try { Metrics metrics = new Metrics(this); metrics.start(); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } @@ -119,7 +119,7 @@ public class Main extends JavaPlugin { setInConfig("drop-on-death.inventories", dropInvs, conf); try { conf.save(configFile); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } @@ -141,7 +141,7 @@ public class Main extends JavaPlugin { Lang.setFile(defConfig); return defConfig; } - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); // So they notice log.severe("[PlayerVaults] Couldn't create language file."); log.severe("[PlayerVaults] This is a fatal error. Now disabling"); diff --git a/src/main/java/com/drtshock/playervaults/commands/Commands.java b/src/main/java/com/drtshock/playervaults/commands/Commands.java index 7174908..01f62e9 100644 --- a/src/main/java/com/drtshock/playervaults/commands/Commands.java +++ b/src/main/java/com/drtshock/playervaults/commands/Commands.java @@ -57,7 +57,7 @@ public class Commands implements CommandExecutor { if(sender.hasPermission("playervaults.workbench")) { if(sender instanceof Player) { Inventory workbench = Bukkit.createInventory(null, InventoryType.WORKBENCH); - ((Player)sender).openInventory(workbench); + ((Player) sender).openInventory(workbench); sender.sendMessage(Lang.TITLE.toString() + Lang.OPEN_WORKBENCH); } else { sender.sendMessage(Lang.TITLE.toString() + Lang.PLAYER_ONLY); diff --git a/src/main/java/com/drtshock/playervaults/commands/Feedback.java b/src/main/java/com/drtshock/playervaults/commands/Feedback.java index 2731a14..fddd0b7 100644 --- a/src/main/java/com/drtshock/playervaults/commands/Feedback.java +++ b/src/main/java/com/drtshock/playervaults/commands/Feedback.java @@ -4,12 +4,11 @@ import org.bukkit.command.CommandSender; import com.drtshock.playervaults.util.Lang; - public class Feedback { public enum Type { OPEN, DELETE, - WORKBENCH, //For later versions + WORKBENCH, // For later versions FURNACE; } diff --git a/src/main/java/com/drtshock/playervaults/commands/VaultOperations.java b/src/main/java/com/drtshock/playervaults/commands/VaultOperations.java index 02018cd..71e768e 100644 --- a/src/main/java/com/drtshock/playervaults/commands/VaultOperations.java +++ b/src/main/java/com/drtshock/playervaults/commands/VaultOperations.java @@ -16,10 +16,9 @@ public class VaultOperations { private static Main plugin; private static VaultManager vm = new VaultManager(plugin); - public static boolean checkPerms(CommandSender cs, int number) { if(cs.hasPermission("playervaults.amount." + String.valueOf(number))) return true; - for(int x = number; x <= 99;x++) { + for(int x = number; x <= 99; x++) { if(cs.hasPermission("playervaults.amount." + String.valueOf(x))) return true; } return false; @@ -39,8 +38,7 @@ public class VaultOperations { number = Integer.parseInt(arg); if(number == 0) return false; - } - catch(NumberFormatException nfe) { + } catch(NumberFormatException nfe) { sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); return false; } @@ -78,8 +76,7 @@ public class VaultOperations { number = Integer.parseInt(arg); if(number == 0) return false; - } - catch(NumberFormatException nfe) { + } catch(NumberFormatException nfe) { sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); } vm.loadVault(sender, user, number); @@ -109,8 +106,7 @@ public class VaultOperations { if(number == 0) sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); return; - } - catch(NumberFormatException nfe) { + } catch(NumberFormatException nfe) { sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); } try { @@ -118,11 +114,11 @@ public class VaultOperations { vm.deleteVault(sender, sender.getName(), number); return; } - } catch (IOException e) { + } catch(IOException e) { sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR); } } else { - sender.sendMessage(Lang.TITLE.toString()+ Lang.MUST_BE_NUMBER); + sender.sendMessage(Lang.TITLE.toString() + Lang.MUST_BE_NUMBER); } } @@ -143,13 +139,12 @@ public class VaultOperations { sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); return; } - } - catch(NumberFormatException nfe) { + } catch(NumberFormatException nfe) { sender.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.MUST_BE_NUMBER); } try { vm.deleteVault(sender, user, number); - } catch (IOException e) { + } catch(IOException e) { sender.sendMessage(Lang.TITLE.toString() + Lang.DELETE_VAULT_ERROR); } } else { diff --git a/src/main/java/com/drtshock/playervaults/util/DropOnDeath.java b/src/main/java/com/drtshock/playervaults/util/DropOnDeath.java index a1f2aae..e69da70 100644 --- a/src/main/java/com/drtshock/playervaults/util/DropOnDeath.java +++ b/src/main/java/com/drtshock/playervaults/util/DropOnDeath.java @@ -10,6 +10,7 @@ import com.drtshock.playervaults.Main; public class DropOnDeath { public static Main plugin; + public DropOnDeath(Main instance) { DropOnDeath.plugin = instance; } @@ -26,7 +27,7 @@ public class DropOnDeath { for(int count = 1; count <= Main.inventoriesToDrop; count++) { Inventory inv = vm.getVault(player, count); ItemStack[] stack = inv.getContents(); - for(ItemStack is : stack) { + for(ItemStack is:stack) { loc.getWorld().dropItemNaturally(loc, is); } } diff --git a/src/main/java/com/drtshock/playervaults/util/EconomyOperations.java b/src/main/java/com/drtshock/playervaults/util/EconomyOperations.java index 81216b3..a8db09a 100644 --- a/src/main/java/com/drtshock/playervaults/util/EconomyOperations.java +++ b/src/main/java/com/drtshock/playervaults/util/EconomyOperations.java @@ -25,6 +25,7 @@ public class EconomyOperations { configFile = new File(plugin.getDataFolder(), "config.yml"); bukkitConfig.load(configFile); } + /** * Have a player pay to open a vault. * Returns true if successful. Otherwise false. @@ -32,7 +33,7 @@ public class EconomyOperations { * @return transaction success */ public static boolean payToOpen(Player player) { - if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault) + if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault) return true; double cost = bukkitConfig.getDouble("economy.cost-to-open", 10); @@ -44,6 +45,7 @@ public class EconomyOperations { return false; } + /** * Have a player pay to create a vault. * Returns true if successful. Otherwise false. @@ -51,7 +53,7 @@ public class EconomyOperations { * @return transaction success */ public static boolean payToCreate(Player player) { - if(!bukkitConfig.getBoolean("economy.enabled") || /*player.hasPermission("playervaults.free") || */!Main.useVault) + if(!bukkitConfig.getBoolean("economy.enabled") || player.hasPermission("playervaults.free") || !Main.useVault) return true; double cost = bukkitConfig.getDouble("economy.cost-to-create", 100); @@ -79,7 +81,7 @@ public class EconomyOperations { File file = new File(directory + File.separator + name.toLowerCase() + ".yml"); YamlConfiguration playerFile = YamlConfiguration.loadConfiguration(file); if(file.exists()) { - if(playerFile.getString("vault"+number) == null) { + if(playerFile.getString("vault" + number) == null) { player.sendMessage(Lang.TITLE.toString() + ChatColor.RED + Lang.VAULT_DOES_NOT_EXIST); return false; } diff --git a/src/main/java/com/drtshock/playervaults/util/Metrics.java b/src/main/java/com/drtshock/playervaults/util/Metrics.java index fb9d3ec..cb55c8f 100644 --- a/src/main/java/com/drtshock/playervaults/util/Metrics.java +++ b/src/main/java/com/drtshock/playervaults/util/Metrics.java @@ -2,17 +2,17 @@ package com.drtshock.playervaults.util; /* * Copyright 2011 Tyler Blair. All rights reserved. - * + * * Redistribution and use in source and binary forms, with or without modification, are * permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, this list of - * conditions and the following disclaimer. - * - * 2. Redistributions in binary form must reproduce the above copyright notice, this list - * of conditions and the following disclaimer in the documentation and/or other materials - * provided with the distribution. - * + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ''AS IS'' AND ANY EXPRESS OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR @@ -22,7 +22,7 @@ package com.drtshock.playervaults.util; * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - * + * * The views and conclusions contained in the software and documentation are those of the * authors and contributors and should not be interpreted as representing official policies, * either expressed or implied, of anybody else. @@ -134,7 +134,7 @@ public class Metrics { private volatile int taskId = -1; public Metrics(final Plugin plugin) throws IOException { - if (plugin == null) { + if(plugin == null) { throw new IllegalArgumentException("Plugin cannot be null"); } @@ -149,7 +149,7 @@ public class Metrics { configuration.addDefault("guid", UUID.randomUUID().toString()); // Do we need to create the file? - if (configuration.get("guid", null) == null) { + if(configuration.get("guid", null) == null) { configuration.options().header("http://mcstats.org").copyDefaults(true); configuration.save(configurationFile); } @@ -166,7 +166,7 @@ public class Metrics { * @return Graph object created. Will never return NULL under normal circumstances unless bad parameters are given */ public Graph createGraph(final String name) { - if (name == null) { + if(name == null) { throw new IllegalArgumentException("Graph name cannot be null"); } @@ -186,7 +186,7 @@ public class Metrics { * @param graph The name of the graph */ public void addGraph(final Graph graph) { - if (graph == null) { + if(graph == null) { throw new IllegalArgumentException("Graph cannot be null"); } @@ -199,7 +199,7 @@ public class Metrics { * @param plotter The plotter to use to plot custom data */ public void addCustomData(final Plotter plotter) { - if (plotter == null) { + if(plotter == null) { throw new IllegalArgumentException("Plotter cannot be null"); } @@ -221,12 +221,12 @@ public class Metrics { public boolean start() { synchronized (optOutLock) { // Did we opt out? - if (isOptOut()) { + if(isOptOut()) { return false; } // Is metrics already running? - if (taskId >= 0) { + if(taskId >= 0) { return true; } @@ -239,18 +239,20 @@ public class Metrics { try { // This has to be synchronized or it can collide with the disable method. synchronized (optOutLock) { - // Disable Task, if it is running and the server owner decided to opt-out - if (isOptOut() && taskId > 0) { + // Disable Task, if it is running and the server owner decided to + // opt-out + if(isOptOut() && taskId > 0) { plugin.getServer().getScheduler().cancelTask(taskId); taskId = -1; // Tell all plotters to stop gathering information. - for (Graph graph : graphs){ + for(Graph graph:graphs) { graph.onOptOut(); } } } - // We use the inverse of firstPost because if it is the first time we are posting, + // We use the inverse of firstPost because if it is the first time we are + // posting, // it is not a interval ping, so it evaluates to FALSE // Each time thereafter it will evaluate to TRUE, i.e PING! postPlugin(!firstPost); @@ -258,7 +260,7 @@ public class Metrics { // After the first post we set firstPost to false // Each post thereafter will be a ping firstPost = false; - } catch (IOException e) { + } catch(IOException e) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + e.getMessage()); } } @@ -274,14 +276,14 @@ public class Metrics { * @return true if metrics should be opted out of it */ public boolean isOptOut() { - synchronized(optOutLock) { + synchronized (optOutLock) { try { // Reload the metrics file configuration.load(getConfigFile()); - } catch (IOException ex) { + } catch(IOException ex) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); return true; - } catch (InvalidConfigurationException ex) { + } catch(InvalidConfigurationException ex) { Bukkit.getLogger().log(Level.INFO, "[Metrics] " + ex.getMessage()); return true; } @@ -298,13 +300,13 @@ public class Metrics { // This has to be synchronized or it can collide with the check in the task. synchronized (optOutLock) { // Check if the server owner has already set opt-out, if not, set it. - if (isOptOut()) { + if(isOptOut()) { configuration.set("opt-out", false); configuration.save(configurationFile); } // Enable Task, if it is not running - if (taskId < 0) { + if(taskId < 0) { start(); } } @@ -319,13 +321,13 @@ public class Metrics { // This has to be synchronized or it can collide with the check in the task. synchronized (optOutLock) { // Check if the server owner has already set opt-out, if not, set it. - if (!isOptOut()) { + if(!isOptOut()) { configuration.set("opt-out", true); configuration.save(configurationFile); } // Disable Task, if it is running - if (taskId > 0) { + if(taskId > 0) { this.plugin.getServer().getScheduler().cancelTask(taskId); taskId = -1; } @@ -338,7 +340,8 @@ public class Metrics { * @return the File object for the config file */ public File getConfigFile() { - // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins to use + // I believe the easiest way to get the base folder (e.g craftbukkit set via -P) for plugins + // to use // is to abuse the plugin object we already have // plugin.getDataFolder() => base/plugins/PluginA/ // pluginsFolder => base/plugins/ @@ -353,7 +356,8 @@ public class Metrics { * Generic method that posts a plugin to the metrics website */ private void postPlugin(final boolean isPing) throws IOException { - // The plugin's description file containg all of the plugin data such as name, version, author, etc + // The plugin's description file containg all of the plugin data such as name, version, + // author, etc final PluginDescriptionFile description = plugin.getDescription(); // Construct the post data @@ -365,7 +369,7 @@ public class Metrics { encodeDataPair(data, "revision", String.valueOf(REVISION)); // If we're pinging, append it - if (isPing) { + if(isPing) { encodeDataPair(data, "ping", "true"); } @@ -377,7 +381,7 @@ public class Metrics { while (iter.hasNext()) { final Graph graph = iter.next(); - for (Plotter plotter : graph.getPlotters()) { + for(Plotter plotter:graph.getPlotters()) { // The key name to send to the metrics server // The format is C-GRAPHNAME-PLOTTERNAME where separator - is defined at the top // Legacy (R4) submitters use the format Custom%s, or CustomPLOTTERNAME @@ -401,7 +405,7 @@ public class Metrics { // Mineshafter creates a socks proxy, so we can safely bypass it // It does not reroute POST requests so we need to go around it - if (isMineshafterPresent()) { + if(isMineshafterPresent()) { connection = url.openConnection(Proxy.NO_PROXY); } else { connection = url.openConnection(); @@ -422,18 +426,18 @@ public class Metrics { writer.close(); reader.close(); - if (response == null || response.startsWith("ERR")) { - throw new IOException(response); //Throw the exception + if(response == null || response.startsWith("ERR")) { + throw new IOException(response); // Throw the exception } else { // Is this the first update this hour? - if (response.contains("OK This is your first update this hour")) { + if(response.contains("OK This is your first update this hour")) { synchronized (graphs) { final Iterator iter = graphs.iterator(); while (iter.hasNext()) { final Graph graph = iter.next(); - for (Plotter plotter : graph.getPlotters()) { + for(Plotter plotter:graph.getPlotters()) { plotter.reset(); } } @@ -451,7 +455,7 @@ public class Metrics { try { Class.forName("mineshafter.MineServer"); return true; - } catch (Exception e) { + } catch(Exception e) { return false; } } @@ -546,7 +550,7 @@ public class Metrics { @Override public boolean equals(final Object object) { - if (!(object instanceof Graph)) { + if(!(object instanceof Graph)) { return false; } @@ -620,7 +624,7 @@ public class Metrics { @Override public boolean equals(final Object object) { - if (!(object instanceof Plotter)) { + if(!(object instanceof Plotter)) { return false; } @@ -631,4 +635,3 @@ public class Metrics { } } - diff --git a/src/main/java/com/drtshock/playervaults/util/Serialization.java b/src/main/java/com/drtshock/playervaults/util/Serialization.java index 4a27c8d..5d9d8b0 100644 --- a/src/main/java/com/drtshock/playervaults/util/Serialization.java +++ b/src/main/java/com/drtshock/playervaults/util/Serialization.java @@ -33,12 +33,13 @@ public class Serialization { } return map; } + private static Object fromJson(Object json) throws JSONException { - if (json == JSONObject.NULL) { + if(json == JSONObject.NULL) { return null; - } else if (json instanceof JSONObject) { + } else if(json instanceof JSONObject) { return toMap((JSONObject) json); - } else if (json instanceof JSONArray) { + } else if(json instanceof JSONArray) { return toList((JSONArray) json); } else { return json; @@ -47,7 +48,7 @@ public class Serialization { public static List toList(JSONArray array) throws JSONException { List list = new ArrayList(); - for (int i = 0; i < array.length(); i++) { + for(int i = 0; i < array.length(); i++) { list.add(fromJson(array.get(i))); } return list; @@ -81,7 +82,7 @@ public class Serialization { try { ItemStack item = (ItemStack) deserialize(toMap(new JSONObject(piece))); contents.add(item); - } catch (JSONException e) { + } catch(JSONException e) { e.printStackTrace(); } } @@ -95,17 +96,18 @@ public class Serialization { public static Map serialize(ConfigurationSerializable cs) { Map serialized = recreateMap(cs.serialize()); - for (Entry entry : serialized.entrySet()) { - if (entry.getValue() instanceof ConfigurationSerializable) { - entry.setValue(serialize((ConfigurationSerializable)entry.getValue())); + for(Entry entry:serialized.entrySet()) { + if(entry.getValue() instanceof ConfigurationSerializable) { + entry.setValue(serialize((ConfigurationSerializable) entry.getValue())); } } serialized.put(ConfigurationSerialization.SERIALIZED_TYPE_KEY, ConfigurationSerialization.getAlias(cs.getClass())); return serialized; } + public static Map recreateMap(Map original) { Map map = new HashMap(); - for (Entry entry : original.entrySet()) { + for(Entry entry:original.entrySet()) { map.put(entry.getKey(), entry.getValue()); } return map; @@ -113,10 +115,11 @@ public class Serialization { @SuppressWarnings({ "unchecked", "rawtypes" }) public static ConfigurationSerializable deserialize(Map map) { - for (Entry entry : map.entrySet()) { - // Check if any of its sub-maps are ConfigurationSerializable. They need to be done first. - if (entry.getValue() instanceof Map && ((Map)entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { - entry.setValue(deserialize((Map)entry.getValue())); + for(Entry entry:map.entrySet()) { + // Check if any of its sub-maps are ConfigurationSerializable. They need to be done + // first. + if(entry.getValue() instanceof Map && ((Map) entry.getValue()).containsKey(ConfigurationSerialization.SERIALIZED_TYPE_KEY)) { + entry.setValue(deserialize((Map) entry.getValue())); } } return ConfigurationSerialization.deserializeObject(map); diff --git a/src/main/java/com/drtshock/playervaults/util/Updater.java b/src/main/java/com/drtshock/playervaults/util/Updater.java index 98dfaba..5aa75f8 100644 --- a/src/main/java/com/drtshock/playervaults/util/Updater.java +++ b/src/main/java/com/drtshock/playervaults/util/Updater.java @@ -28,7 +28,7 @@ public class Updater extends Main { } try { langConf.save(super.getLangFile()); - } catch (IOException e) { + } catch(IOException e) { log.log(Level.WARNING, "PlayerVaults: Failed to save lang.yml."); log.log(Level.WARNING, "PlayerVaults: Report this stack trace to drtshock and gomeow."); e.printStackTrace(); @@ -40,34 +40,47 @@ public class Updater extends Main { public String getNewVersion() { return this.newVersion; } + public boolean getUpdate() throws Exception { String version = this.version; URL url = new URL("http://dev.bukkit.org/server-mods/playervaults/files.rss"); InputStreamReader isr = null; try { isr = new InputStreamReader(url.openStream()); - } - catch(UnknownHostException e) { - return false; //Cannot connect + } catch(UnknownHostException e) { + return false; // Cannot connect } BufferedReader in = new BufferedReader(isr); String line; int lineNum = 0; - while((line = in.readLine()) != null) { + while ((line = in.readLine()) != null) { if(line.length() != line.replace("", "").length()) { - line = line.replaceAll("<title>", "").replaceAll("", "").replaceAll(" ", "").substring(1); //Substring 1 for me, takes off the beginning v on my file name "v1.3.2" + line = line.replaceAll("", "").replaceAll("", "").replaceAll(" ", "").substring(1); // Substring + // 1 + // for + // me, + // takes + // off + // the + // beginning + // v + // on + // my + // file + // name + // "v1.3.2" if(lineNum == 1) { this.newVersion = line; Integer newVer = Integer.parseInt(line.replace(".", "")); Integer oldVer = Integer.parseInt(version.replace(".", "")); if(oldVer < newVer) { - return true; //They are using an old version + return true; // They are using an old version } else if(oldVer > newVer) { - return false; //They are using a FUTURE version! + return false; // They are using a FUTURE version! } else { - return false; //They are up to date! + return false; // They are up to date! } } lineNum = lineNum + 1; diff --git a/src/main/java/com/drtshock/playervaults/util/VaultManager.java b/src/main/java/com/drtshock/playervaults/util/VaultManager.java index cc838f2..3cd19da 100644 --- a/src/main/java/com/drtshock/playervaults/util/VaultManager.java +++ b/src/main/java/com/drtshock/playervaults/util/VaultManager.java @@ -18,6 +18,7 @@ import com.drtshock.playervaults.Main; public class VaultManager { public Main plugin; + public VaultManager(Main instance) { this.plugin = instance; } @@ -128,7 +129,7 @@ public class VaultManager { if(!file.exists()) { try { file.createNewFile(); - } catch (IOException e) { + } catch(IOException e) { e.printStackTrace(); } } @@ -144,7 +145,7 @@ public class VaultManager { */ public void saveFile(String name, YamlConfiguration yaml) throws IOException { File file = new File(directory + File.separator + name.toLowerCase() + ".yml"); - if (file.exists()) { + if(file.exists()) { file.renameTo(new File(directory + File.separator + "backups" + File.separator + name.toLowerCase() + ".yml")); } yaml.save(file); diff --git a/src/main/java/org/json/CDL.java b/src/main/java/org/json/CDL.java index ffe344e..e7da4df 100644 --- a/src/main/java/org/json/CDL.java +++ b/src/main/java/org/json/CDL.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ /** @@ -66,12 +66,12 @@ public class CDL { case '\'': q = c; sb = new StringBuffer(); - for (;;) { + for(;;) { c = x.next(); - if (c == q) { + if(c == q) { break; } - if (c == 0 || c == '\n' || c == '\r') { + if(c == 0 || c == '\n' || c == '\r') { throw x.syntaxError("Missing close quote '" + q + "'."); } sb.append(c); @@ -94,24 +94,24 @@ public class CDL { */ public static JSONArray rowToJSONArray(JSONTokener x) throws JSONException { JSONArray ja = new JSONArray(); - for (;;) { + for(;;) { String value = getValue(x); char c = x.next(); - if (value == null || + if(value == null || (ja.length() == 0 && value.length() == 0 && c != ',')) { return null; } ja.put(value); - for (;;) { - if (c == ',') { + for(;;) { + if(c == ',') { break; } - if (c != ' ') { - if (c == '\n' || c == '\r' || c == 0) { + if(c != ' ') { + if(c == '\n' || c == '\r' || c == 0) { return ja; } throw x.syntaxError("Bad character '" + c + "' (" + - (int)c + ")."); + (int) c + ")."); } c = x.next(); } @@ -131,7 +131,7 @@ public class CDL { public static JSONObject rowToJSONObject(JSONArray names, JSONTokener x) throws JSONException { JSONArray ja = rowToJSONArray(x); - return ja != null ? ja.toJSONObject(names) : null; + return ja != null ? ja.toJSONObject(names) : null; } /** @@ -143,21 +143,21 @@ public class CDL { */ public static String rowToString(JSONArray ja) { StringBuffer sb = new StringBuffer(); - for (int i = 0; i < ja.length(); i += 1) { - if (i > 0) { + for(int i = 0; i < ja.length(); i += 1) { + if(i > 0) { sb.append(','); } Object object = ja.opt(i); - if (object != null) { + if(object != null) { String string = object.toString(); - if (string.length() > 0 && (string.indexOf(',') >= 0 || + if(string.length() > 0 && (string.indexOf(',') >= 0 || string.indexOf('\n') >= 0 || string.indexOf('\r') >= 0 || string.indexOf(0) >= 0 || string.charAt(0) == '"')) { sb.append('"'); int length = string.length(); - for (int j = 0; j < length; j += 1) { + for(int j = 0; j < length; j += 1) { char c = string.charAt(j); - if (c >= ' ' && c != '"') { + if(c >= ' ' && c != '"') { sb.append(c); } } @@ -216,24 +216,23 @@ public class CDL { */ public static JSONArray toJSONArray(JSONArray names, JSONTokener x) throws JSONException { - if (names == null || names.length() == 0) { + if(names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); - for (;;) { + for(;;) { JSONObject jo = rowToJSONObject(names, x); - if (jo == null) { + if(jo == null) { break; } ja.put(jo); } - if (ja.length() == 0) { + if(ja.length() == 0) { return null; } return ja; } - /** * Produce a comma delimited text from a JSONArray of JSONObjects. The * first row will be a list of names obtained by inspecting the first @@ -244,9 +243,9 @@ public class CDL { */ public static String toString(JSONArray ja) throws JSONException { JSONObject jo = ja.optJSONObject(0); - if (jo != null) { + if(jo != null) { JSONArray names = jo.names(); - if (names != null) { + if(names != null) { return rowToString(names) + toString(names, ja); } } @@ -264,13 +263,13 @@ public class CDL { */ public static String toString(JSONArray names, JSONArray ja) throws JSONException { - if (names == null || names.length() == 0) { + if(names == null || names.length() == 0) { return null; } StringBuffer sb = new StringBuffer(); - for (int i = 0; i < ja.length(); i += 1) { + for(int i = 0; i < ja.length(); i += 1) { JSONObject jo = ja.optJSONObject(i); - if (jo != null) { + if(jo != null) { sb.append(rowToString(jo.toJSONArray(names))); } } diff --git a/src/main/java/org/json/Cookie.java b/src/main/java/org/json/Cookie.java index f93199b..893bd0d 100644 --- a/src/main/java/org/json/Cookie.java +++ b/src/main/java/org/json/Cookie.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ /** @@ -45,16 +45,16 @@ public class Cookie { * @return The escaped result. */ public static String escape(String string) { - char c; - String s = string.trim(); + char c; + String s = string.trim(); StringBuffer sb = new StringBuffer(); - int length = s.length(); - for (int i = 0; i < length; i += 1) { + int length = s.length(); + for(int i = 0; i < length; i += 1) { c = s.charAt(i); - if (c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { + if(c < ' ' || c == '+' || c == '%' || c == '=' || c == ';') { sb.append('%'); - sb.append(Character.forDigit((char)((c >>> 4) & 0x0f), 16)); - sb.append(Character.forDigit((char)(c & 0x0f), 16)); + sb.append(Character.forDigit((char) ((c >>> 4) & 0x0f), 16)); + sb.append(Character.forDigit((char) (c & 0x0f), 16)); } else { sb.append(c); } @@ -62,7 +62,6 @@ public class Cookie { return sb.toString(); } - /** * Convert a cookie specification string into a JSONObject. The string * will contain a name value pair separated by '='. The name and the value @@ -79,9 +78,9 @@ public class Cookie { * @throws JSONException */ public static JSONObject toJSONObject(String string) throws JSONException { - String name; - JSONObject jo = new JSONObject(); - Object value; + String name; + JSONObject jo = new JSONObject(); + Object value; JSONTokener x = new JSONTokener(string); jo.put("name", x.nextTo('=')); x.next('='); @@ -89,8 +88,8 @@ public class Cookie { x.next(); while (x.more()) { name = unescape(x.nextTo("=;")); - if (x.next() != '=') { - if (name.equals("secure")) { + if(x.next() != '=') { + if(name.equals("secure")) { value = Boolean.TRUE; } else { throw x.syntaxError("Missing '=' in cookie parameter."); @@ -104,7 +103,6 @@ public class Cookie { return jo; } - /** * Convert a JSONObject into a cookie specification string. The JSONObject * must contain "name" and "value" members. @@ -121,19 +119,19 @@ public class Cookie { sb.append(escape(jo.getString("name"))); sb.append("="); sb.append(escape(jo.getString("value"))); - if (jo.has("expires")) { + if(jo.has("expires")) { sb.append(";expires="); sb.append(jo.getString("expires")); } - if (jo.has("domain")) { + if(jo.has("domain")) { sb.append(";domain="); sb.append(escape(jo.getString("domain"))); } - if (jo.has("path")) { + if(jo.has("path")) { sb.append(";path="); sb.append(escape(jo.getString("path"))); } - if (jo.optBoolean("secure")) { + if(jo.optBoolean("secure")) { sb.append(";secure"); } return sb.toString(); @@ -150,15 +148,15 @@ public class Cookie { public static String unescape(String string) { int length = string.length(); StringBuffer sb = new StringBuffer(); - for (int i = 0; i < length; ++i) { + for(int i = 0; i < length; ++i) { char c = string.charAt(i); - if (c == '+') { + if(c == '+') { c = ' '; - } else if (c == '%' && i + 2 < length) { + } else if(c == '%' && i + 2 < length) { int d = JSONTokener.dehexchar(string.charAt(i + 1)); int e = JSONTokener.dehexchar(string.charAt(i + 2)); - if (d >= 0 && e >= 0) { - c = (char)(d * 16 + e); + if(d >= 0 && e >= 0) { + c = (char) (d * 16 + e); i += 2; } } diff --git a/src/main/java/org/json/CookieList.java b/src/main/java/org/json/CookieList.java index 897690b..11670e1 100644 --- a/src/main/java/org/json/CookieList.java +++ b/src/main/java/org/json/CookieList.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ import java.util.Iterator; @@ -58,7 +58,6 @@ public class CookieList { return jo; } - /** * Convert a JSONObject into a cookie list. A cookie list is a sequence * of name/value pairs. The names are separated from the values by '='. @@ -69,14 +68,14 @@ public class CookieList { * @throws JSONException */ public static String toString(JSONObject jo) throws JSONException { - boolean b = false; - Iterator keys = jo.keys(); - String string; + boolean b = false; + Iterator keys = jo.keys(); + String string; StringBuffer sb = new StringBuffer(); while (keys.hasNext()) { string = keys.next().toString(); - if (!jo.isNull(string)) { - if (b) { + if(!jo.isNull(string)) { + if(b) { sb.append(';'); } sb.append(Cookie.escape(string)); diff --git a/src/main/java/org/json/HTTP.java b/src/main/java/org/json/HTTP.java index 528f6aa..619036f 100644 --- a/src/main/java/org/json/HTTP.java +++ b/src/main/java/org/json/HTTP.java @@ -1,27 +1,27 @@ package org.json; /* - Copyright (c) 2002 JSON.org - - Permission is hereby granted, free of charge, to any person obtaining a copy - of this software and associated documentation files (the "Software"), to deal - in the Software without restriction, including without limitation the rights - to use, copy, modify, merge, publish, distribute, sublicense, and/or sell - copies of the Software, and to permit persons to whom the Software is - furnished to do so, subject to the following conditions: - - The above copyright notice and this permission notice shall be included in all - copies or substantial portions of the Software. - - The Software shall be used for Good, not Evil. - - THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR - IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, - FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE - AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER - LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, - OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE - SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ import java.util.Iterator; @@ -93,7 +93,7 @@ public class HTTP { String token; token = x.nextToken(); - if (token.toUpperCase().startsWith("HTTP")) { + if(token.toUpperCase().startsWith("HTTP")) { // Response @@ -156,13 +156,13 @@ public class HTTP { Iterator keys = jo.keys(); String string; StringBuffer sb = new StringBuffer(); - if (jo.has("Status-Code") && jo.has("Reason-Phrase")) { + if(jo.has("Status-Code") && jo.has("Reason-Phrase")) { sb.append(jo.getString("HTTP-Version")); sb.append(' '); sb.append(jo.getString("Status-Code")); sb.append(' '); sb.append(jo.getString("Reason-Phrase")); - } else if (jo.has("Method") && jo.has("Request-URI")) { + } else if(jo.has("Method") && jo.has("Request-URI")) { sb.append(jo.getString("Method")); sb.append(' '); sb.append('"'); @@ -176,7 +176,7 @@ public class HTTP { sb.append(CRLF); while (keys.hasNext()) { string = keys.next().toString(); - if (!"HTTP-Version".equals(string) && !"Status-Code".equals(string) + if(!"HTTP-Version".equals(string) && !"Status-Code".equals(string) && !"Reason-Phrase".equals(string) && !"Method".equals(string) && !"Request-URI".equals(string) && !jo.isNull(string)) { diff --git a/src/main/java/org/json/HTTPTokener.java b/src/main/java/org/json/HTTPTokener.java index 5253485..f5ab59b 100644 --- a/src/main/java/org/json/HTTPTokener.java +++ b/src/main/java/org/json/HTTPTokener.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ /** @@ -40,7 +40,6 @@ public class HTTPTokener extends JSONTokener { super(string); } - /** * Get the next token or string. This is used in parsing HTTP headers. * @throws JSONException @@ -53,21 +52,21 @@ public class HTTPTokener extends JSONTokener { do { c = next(); } while (Character.isWhitespace(c)); - if (c == '"' || c == '\'') { + if(c == '"' || c == '\'') { q = c; - for (;;) { + for(;;) { c = next(); - if (c < ' ') { + if(c < ' ') { throw syntaxError("Unterminated string."); } - if (c == q) { + if(c == q) { return sb.toString(); } sb.append(c); } } - for (;;) { - if (c == 0 || Character.isWhitespace(c)) { + for(;;) { + if(c == 0 || Character.isWhitespace(c)) { return sb.toString(); } sb.append(c); diff --git a/src/main/java/org/json/JSONArray.java b/src/main/java/org/json/JSONArray.java index 1e47c56..f0897e9 100644 --- a/src/main/java/org/json/JSONArray.java +++ b/src/main/java/org/json/JSONArray.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ import java.io.IOException; @@ -81,13 +81,11 @@ import java.util.Map; */ public class JSONArray { - /** * The arrayList where the JSONArray's properties are kept. */ private final ArrayList myArrayList; - /** * Construct an empty JSONArray. */ @@ -102,13 +100,13 @@ public class JSONArray { */ public JSONArray(JSONTokener x) throws JSONException { this(); - if (x.nextClean() != '[') { + if(x.nextClean() != '[') { throw x.syntaxError("A JSONArray text must start with '['"); } - if (x.nextClean() != ']') { + if(x.nextClean() != ']') { x.back(); - for (;;) { - if (x.nextClean() == ',') { + for(;;) { + if(x.nextClean() == ',') { x.back(); this.myArrayList.add(JSONObject.NULL); } else { @@ -118,7 +116,7 @@ public class JSONArray { switch (x.nextClean()) { case ';': case ',': - if (x.nextClean() == ']') { + if(x.nextClean() == ']') { return; } x.back(); @@ -132,7 +130,6 @@ public class JSONArray { } } - /** * Construct a JSONArray from a source JSON text. * @param source A string that begins with @@ -144,14 +141,13 @@ public class JSONArray { this(new JSONTokener(source)); } - /** * Construct a JSONArray from a Collection. * @param collection A Collection. */ public JSONArray(Collection collection) { this.myArrayList = new ArrayList(); - if (collection != null) { + if(collection != null) { Iterator iter = collection.iterator(); while (iter.hasNext()) { this.myArrayList.add(JSONObject.wrap(iter.next())); @@ -159,16 +155,15 @@ public class JSONArray { } } - /** * Construct a JSONArray from an array * @throws JSONException If not an array. */ public JSONArray(Object array) throws JSONException { this(); - if (array.getClass().isArray()) { + if(array.getClass().isArray()) { int length = Array.getLength(array); - for (int i = 0; i < length; i += 1) { + for(int i = 0; i < length; i += 1) { this.put(JSONObject.wrap(Array.get(array, i))); } } else { @@ -177,7 +172,6 @@ public class JSONArray { } } - /** * Get the object value associated with an index. * @param index @@ -187,13 +181,12 @@ public class JSONArray { */ public Object get(int index) throws JSONException { Object object = this.opt(index); - if (object == null) { + if(object == null) { throw new JSONException("JSONArray[" + index + "] not found."); } return object; } - /** * Get the boolean value associated with an index. * The string values "true" and "false" are converted to boolean. @@ -205,19 +198,18 @@ public class JSONArray { */ public boolean getBoolean(int index) throws JSONException { Object object = this.get(index); - if (object.equals(Boolean.FALSE) || + if(object.equals(Boolean.FALSE) || (object instanceof String && - ((String)object).equalsIgnoreCase("false"))) { + ((String) object).equalsIgnoreCase("false"))) { return false; - } else if (object.equals(Boolean.TRUE) || + } else if(object.equals(Boolean.TRUE) || (object instanceof String && - ((String)object).equalsIgnoreCase("true"))) { + ((String) object).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONArray[" + index + "] is not a boolean."); } - /** * Get the double value associated with an index. * @@ -230,15 +222,14 @@ public class JSONArray { Object object = this.get(index); try { return object instanceof Number - ? ((Number)object).doubleValue() - : Double.parseDouble((String)object); - } catch (Exception e) { + ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch(Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } - /** * Get the int value associated with an index. * @@ -250,15 +241,14 @@ public class JSONArray { Object object = this.get(index); try { return object instanceof Number - ? ((Number)object).intValue() - : Integer.parseInt((String)object); - } catch (Exception e) { + ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch(Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } - /** * Get the JSONArray associated with an index. * @param index The index must be between 0 and length() - 1. @@ -268,14 +258,13 @@ public class JSONArray { */ public JSONArray getJSONArray(int index) throws JSONException { Object object = this.get(index); - if (object instanceof JSONArray) { - return (JSONArray)object; + if(object instanceof JSONArray) { + return (JSONArray) object; } throw new JSONException("JSONArray[" + index + "] is not a JSONArray."); } - /** * Get the JSONObject associated with an index. * @param index subscript @@ -285,14 +274,13 @@ public class JSONArray { */ public JSONObject getJSONObject(int index) throws JSONException { Object object = this.get(index); - if (object instanceof JSONObject) { - return (JSONObject)object; + if(object instanceof JSONObject) { + return (JSONObject) object; } throw new JSONException("JSONArray[" + index + "] is not a JSONObject."); } - /** * Get the long value associated with an index. * @@ -305,15 +293,14 @@ public class JSONArray { Object object = this.get(index); try { return object instanceof Number - ? ((Number)object).longValue() - : Long.parseLong((String)object); - } catch (Exception e) { + ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch(Exception e) { throw new JSONException("JSONArray[" + index + "] is not a number."); } } - /** * Get the string associated with an index. * @param index The index must be between 0 and length() - 1. @@ -322,13 +309,12 @@ public class JSONArray { */ public String getString(int index) throws JSONException { Object object = this.get(index); - if (object instanceof String) { - return (String)object; + if(object instanceof String) { + return (String) object; } throw new JSONException("JSONArray[" + index + "] not a string."); } - /** * Determine if the value is null. * @param index The index must be between 0 and length() - 1. @@ -338,7 +324,6 @@ public class JSONArray { return JSONObject.NULL.equals(this.opt(index)); } - /** * Make a string from the contents of this JSONArray. The * separator string is inserted between each element. @@ -351,8 +336,8 @@ public class JSONArray { int len = this.length(); StringBuffer sb = new StringBuffer(); - for (int i = 0; i < len; i += 1) { - if (i > 0) { + for(int i = 0; i < len; i += 1) { + if(i > 0) { sb.append(separator); } sb.append(JSONObject.valueToString(this.myArrayList.get(i))); @@ -360,7 +345,6 @@ public class JSONArray { return sb.toString(); } - /** * Get the number of elements in the JSONArray, included nulls. * @@ -370,7 +354,6 @@ public class JSONArray { return this.myArrayList.size(); } - /** * Get the optional object value associated with an index. * @param index The index must be between 0 and length() - 1. @@ -380,10 +363,9 @@ public class JSONArray { public Object opt(int index) { return (index < 0 || index >= this.length()) ? null - : this.myArrayList.get(index); + : this.myArrayList.get(index); } - /** * Get the optional boolean value associated with an index. * It returns false if there is no value at that index, @@ -392,11 +374,10 @@ public class JSONArray { * @param index The index must be between 0 and length() - 1. * @return The truth. */ - public boolean optBoolean(int index) { + public boolean optBoolean(int index) { return this.optBoolean(index, false); } - /** * Get the optional boolean value associated with an index. * It returns the defaultValue if there is no value at that index or if @@ -406,15 +387,14 @@ public class JSONArray { * @param defaultValue A boolean default. * @return The truth. */ - public boolean optBoolean(int index, boolean defaultValue) { + public boolean optBoolean(int index, boolean defaultValue) { try { return this.getBoolean(index); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get the optional double value associated with an index. * NaN is returned if there is no value for the index, @@ -427,7 +407,6 @@ public class JSONArray { return this.optDouble(index, Double.NaN); } - /** * Get the optional double value associated with an index. * The defaultValue is returned if there is no value for the index, @@ -440,12 +419,11 @@ public class JSONArray { public double optDouble(int index, double defaultValue) { try { return this.getDouble(index); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get the optional int value associated with an index. * Zero is returned if there is no value for the index, @@ -458,7 +436,6 @@ public class JSONArray { return this.optInt(index, 0); } - /** * Get the optional int value associated with an index. * The defaultValue is returned if there is no value for the index, @@ -470,12 +447,11 @@ public class JSONArray { public int optInt(int index, int defaultValue) { try { return this.getInt(index); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get the optional JSONArray associated with an index. * @param index subscript @@ -484,10 +460,9 @@ public class JSONArray { */ public JSONArray optJSONArray(int index) { Object o = this.opt(index); - return o instanceof JSONArray ? (JSONArray)o : null; + return o instanceof JSONArray ? (JSONArray) o : null; } - /** * Get the optional JSONObject associated with an index. * Null is returned if the key is not found, or null if the index has @@ -498,10 +473,9 @@ public class JSONArray { */ public JSONObject optJSONObject(int index) { Object o = this.opt(index); - return o instanceof JSONObject ? (JSONObject)o : null; + return o instanceof JSONObject ? (JSONObject) o : null; } - /** * Get the optional long value associated with an index. * Zero is returned if there is no value for the index, @@ -514,7 +488,6 @@ public class JSONArray { return this.optLong(index, 0); } - /** * Get the optional long value associated with an index. * The defaultValue is returned if there is no value for the index, @@ -526,12 +499,11 @@ public class JSONArray { public long optLong(int index, long defaultValue) { try { return this.getLong(index); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get the optional string value associated with an index. It returns an * empty string if there is no value at that index. If the value @@ -544,7 +516,6 @@ public class JSONArray { return this.optString(index, ""); } - /** * Get the optional string associated with an index. * The defaultValue is returned if the key is not found. @@ -557,10 +528,9 @@ public class JSONArray { Object object = this.opt(index); return JSONObject.NULL.equals(object) ? defaultValue - : object.toString(); + : object.toString(); } - /** * Append a boolean value. This increases the array's length by one. * @@ -572,7 +542,6 @@ public class JSONArray { return this; } - /** * Put a value in the JSONArray, where the value will be a * JSONArray which is produced from a Collection. @@ -584,7 +553,6 @@ public class JSONArray { return this; } - /** * Append a double value. This increases the array's length by one. * @@ -599,7 +567,6 @@ public class JSONArray { return this; } - /** * Append an int value. This increases the array's length by one. * @@ -611,7 +578,6 @@ public class JSONArray { return this; } - /** * Append an long value. This increases the array's length by one. * @@ -623,7 +589,6 @@ public class JSONArray { return this; } - /** * Put a value in the JSONArray, where the value will be a * JSONObject which is produced from a Map. @@ -635,7 +600,6 @@ public class JSONArray { return this; } - /** * Append an object value. This increases the array's length by one. * @param value An object value. The value should be a @@ -648,7 +612,6 @@ public class JSONArray { return this; } - /** * Put or replace a boolean value in the JSONArray. If the index is greater * than the length of the JSONArray, then null elements will be added as @@ -663,7 +626,6 @@ public class JSONArray { return this; } - /** * Put a value in the JSONArray, where the value will be a * JSONArray which is produced from a Collection. @@ -678,7 +640,6 @@ public class JSONArray { return this; } - /** * Put or replace a double value. If the index is greater than the length of * the JSONArray, then null elements will be added as necessary to pad @@ -694,7 +655,6 @@ public class JSONArray { return this; } - /** * Put or replace an int value. If the index is greater than the length of * the JSONArray, then null elements will be added as necessary to pad @@ -709,7 +669,6 @@ public class JSONArray { return this; } - /** * Put or replace a long value. If the index is greater than the length of * the JSONArray, then null elements will be added as necessary to pad @@ -724,7 +683,6 @@ public class JSONArray { return this; } - /** * Put a value in the JSONArray, where the value will be a * JSONObject that is produced from a Map. @@ -739,7 +697,6 @@ public class JSONArray { return this; } - /** * Put or replace an object value in the JSONArray. If the index is greater * than the length of the JSONArray, then null elements will be added as @@ -754,10 +711,10 @@ public class JSONArray { */ public JSONArray put(int index, Object value) throws JSONException { JSONObject.testValidity(value); - if (index < 0) { + if(index < 0) { throw new JSONException("JSONArray[" + index + "] not found."); } - if (index < this.length()) { + if(index < this.length()) { this.myArrayList.set(index, value); } else { while (index != this.length()) { @@ -768,7 +725,6 @@ public class JSONArray { return this; } - /** * Remove an index and close the hole. * @param index The index of the element to be removed. @@ -781,7 +737,6 @@ public class JSONArray { return o; } - /** * Produce a JSONObject by combining a JSONArray of names with the values * of this JSONArray. @@ -792,17 +747,16 @@ public class JSONArray { * @throws JSONException If any of the names are null. */ public JSONObject toJSONObject(JSONArray names) throws JSONException { - if (names == null || names.length() == 0 || this.length() == 0) { + if(names == null || names.length() == 0 || this.length() == 0) { return null; } JSONObject jo = new JSONObject(); - for (int i = 0; i < names.length(); i += 1) { + for(int i = 0; i < names.length(); i += 1) { jo.put(names.getString(i), this.opt(i)); } return jo; } - /** * Make a JSON text of this JSONArray. For compactness, no * unnecessary whitespace is added. If it is not possible to produce a @@ -817,12 +771,11 @@ public class JSONArray { public String toString() { try { return this.toString(0); - } catch (Exception e) { + } catch(Exception e) { return null; } } - /** * Make a prettyprinted JSON text of this JSONArray. * Warning: This method assumes that the data structure is acyclical. @@ -874,17 +827,17 @@ public class JSONArray { int length = this.length(); writer.write('['); - if (length == 1) { + if(length == 1) { JSONObject.writeValue(writer, this.myArrayList.get(0), indentFactor, indent); - } else if (length != 0) { + } else if(length != 0) { final int newindent = indent + indentFactor; - for (int i = 0; i < length; i += 1) { - if (commanate) { + for(int i = 0; i < length; i += 1) { + if(commanate) { writer.write(','); } - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write('\n'); } JSONObject.indent(writer, newindent); @@ -892,14 +845,14 @@ public class JSONArray { indentFactor, newindent); commanate = true; } - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write('\n'); } JSONObject.indent(writer, indent); } writer.write(']'); return writer; - } catch (IOException e) { + } catch(IOException e) { throw new JSONException(e); } } diff --git a/src/main/java/org/json/JSONObject.java b/src/main/java/org/json/JSONObject.java index 89b3e70..0b40983 100644 --- a/src/main/java/org/json/JSONObject.java +++ b/src/main/java/org/json/JSONObject.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ import java.io.IOException; @@ -142,13 +142,11 @@ public class JSONObject { } } - /** * The map where the JSONObject's properties are kept. */ private final Map map; - /** * It is sometimes more convenient and less ambiguous to have a * NULL object than to use Java's null value. @@ -157,7 +155,6 @@ public class JSONObject { */ public static final Object NULL = new Null(); - /** * Construct an empty JSONObject. */ @@ -165,7 +162,6 @@ public class JSONObject { this.map = new HashMap(); } - /** * Construct a JSONObject from a subset of another JSONObject. * An array of strings is used to identify the keys that should be copied. @@ -177,15 +173,14 @@ public class JSONObject { */ public JSONObject(JSONObject jo, String[] names) { this(); - for (int i = 0; i < names.length; i += 1) { + for(int i = 0; i < names.length; i += 1) { try { this.putOnce(names[i], jo.opt(names[i])); - } catch (Exception ignore) { + } catch(Exception ignore) { } } } - /** * Construct a JSONObject from a JSONTokener. * @param x A JSONTokener object containing the source string. @@ -197,10 +192,10 @@ public class JSONObject { char c; String key; - if (x.nextClean() != '{') { + if(x.nextClean() != '{') { throw x.syntaxError("A JSONObject text must begin with '{'"); } - for (;;) { + for(;;) { c = x.nextClean(); switch (c) { case 0: @@ -215,11 +210,11 @@ public class JSONObject { // The key is followed by ':'. We will also tolerate '=' or '=>'. c = x.nextClean(); - if (c == '=') { - if (x.next() != '>') { + if(c == '=') { + if(x.next() != '>') { x.back(); } - } else if (c != ':') { + } else if(c != ':') { throw x.syntaxError("Expected a ':' after a key"); } this.putOnce(key, x.nextValue()); @@ -229,7 +224,7 @@ public class JSONObject { switch (x.nextClean()) { case ';': case ',': - if (x.nextClean() == '}') { + if(x.nextClean() == '}') { return; } x.back(); @@ -242,7 +237,6 @@ public class JSONObject { } } - /** * Construct a JSONObject from a Map. * @@ -252,19 +246,18 @@ public class JSONObject { */ public JSONObject(Map map) { this.map = new HashMap(); - if (map != null) { + if(map != null) { Iterator i = map.entrySet().iterator(); while (i.hasNext()) { - Map.Entry e = (Map.Entry)i.next(); + Map.Entry e = (Map.Entry) i.next(); Object value = e.getValue(); - if (value != null) { + if(value != null) { this.map.put(e.getKey(), wrap(value)); } } } } - /** * Construct a JSONObject from an Object using bean getters. * It reflects on all of the public methods of the object. @@ -289,7 +282,6 @@ public class JSONObject { this.populateMap(bean); } - /** * Construct a JSONObject from an Object, using reflection to find the * public members. The resulting JSONObject's keys will be the strings @@ -304,16 +296,15 @@ public class JSONObject { public JSONObject(Object object, String names[]) { this(); Class c = object.getClass(); - for (int i = 0; i < names.length; i += 1) { + for(int i = 0; i < names.length; i += 1) { String name = names[i]; try { this.putOpt(name, c.getField(name).get(object)); - } catch (Exception ignore) { + } catch(Exception ignore) { } } } - /** * Construct a JSONObject from a source JSON text string. * This is the most commonly used JSONObject constructor. @@ -327,7 +318,6 @@ public class JSONObject { this(new JSONTokener(source)); } - /** * Construct a JSONObject from a ResourceBundle. * @param baseName The ResourceBundle base name. @@ -344,30 +334,29 @@ public class JSONObject { Enumeration keys = bundle.getKeys(); while (keys.hasMoreElements()) { Object key = keys.nextElement(); - if (key instanceof String) { + if(key instanceof String) { // Go through the path, ensuring that there is a nested JSONObject for each // segment except the last. Add the value using the last segment's name into // the deepest nested JSONObject. - String[] path = ((String)key).split("\\."); + String[] path = ((String) key).split("\\."); int last = path.length - 1; JSONObject target = this; - for (int i = 0; i < last; i += 1) { + for(int i = 0; i < last; i += 1) { String segment = path[i]; JSONObject nextTarget = target.optJSONObject(segment); - if (nextTarget == null) { + if(nextTarget == null) { nextTarget = new JSONObject(); target.put(segment, nextTarget); } target = nextTarget; } - target.put(path[last], bundle.getString((String)key)); + target.put(path[last], bundle.getString((String) key)); } } } - /** * Accumulate values under a key. It is similar to the put method except * that if there is already an object stored under the key then a @@ -390,19 +379,18 @@ public class JSONObject { ) throws JSONException { testValidity(value); Object object = this.opt(key); - if (object == null) { + if(object == null) { this.put(key, value instanceof JSONArray ? new JSONArray().put(value) - : value); - } else if (object instanceof JSONArray) { - ((JSONArray)object).put(value); + : value); + } else if(object instanceof JSONArray) { + ((JSONArray) object).put(value); } else { this.put(key, new JSONArray().put(object).put(value)); } return this; } - /** * Append values to the array under a key. If the key does not exist in the * JSONObject, then the key is put in the JSONObject with its value being a @@ -417,10 +405,10 @@ public class JSONObject { public JSONObject append(String key, Object value) throws JSONException { testValidity(value); Object object = this.opt(key); - if (object == null) { + if(object == null) { this.put(key, new JSONArray().put(value)); - } else if (object instanceof JSONArray) { - this.put(key, ((JSONArray)object).put(value)); + } else if(object instanceof JSONArray) { + this.put(key, ((JSONArray) object).put(value)); } else { throw new JSONException("JSONObject[" + key + "] is not a JSONArray."); @@ -428,7 +416,6 @@ public class JSONObject { return this; } - /** * Produce a string from a double. The string "null" will be returned if * the number is not finite. @@ -436,26 +423,25 @@ public class JSONObject { * @return A String. */ public static String doubleToString(double d) { - if (Double.isInfinite(d) || Double.isNaN(d)) { + if(Double.isInfinite(d) || Double.isNaN(d)) { return "null"; } // Shave off trailing zeros and decimal point, if possible. String string = Double.toString(d); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && + if(string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { while (string.endsWith("0")) { string = string.substring(0, string.length() - 1); } - if (string.endsWith(".")) { + if(string.endsWith(".")) { string = string.substring(0, string.length() - 1); } } return string; } - /** * Get the value object associated with a key. * @@ -464,18 +450,17 @@ public class JSONObject { * @throws JSONException if the key is not found. */ public Object get(String key) throws JSONException { - if (key == null) { + if(key == null) { throw new JSONException("Null key."); } Object object = this.opt(key); - if (object == null) { + if(object == null) { throw new JSONException("JSONObject[" + quote(key) + "] not found."); } return object; } - /** * Get the boolean value associated with a key. * @@ -486,20 +471,19 @@ public class JSONObject { */ public boolean getBoolean(String key) throws JSONException { Object object = this.get(key); - if (object.equals(Boolean.FALSE) || + if(object.equals(Boolean.FALSE) || (object instanceof String && - ((String)object).equalsIgnoreCase("false"))) { + ((String) object).equalsIgnoreCase("false"))) { return false; - } else if (object.equals(Boolean.TRUE) || + } else if(object.equals(Boolean.TRUE) || (object instanceof String && - ((String)object).equalsIgnoreCase("true"))) { + ((String) object).equalsIgnoreCase("true"))) { return true; } throw new JSONException("JSONObject[" + quote(key) + "] is not a Boolean."); } - /** * Get the double value associated with a key. * @param key A key string. @@ -511,15 +495,14 @@ public class JSONObject { Object object = this.get(key); try { return object instanceof Number - ? ((Number)object).doubleValue() - : Double.parseDouble((String)object); - } catch (Exception e) { + ? ((Number) object).doubleValue() + : Double.parseDouble((String) object); + } catch(Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a number."); } } - /** * Get the int value associated with a key. * @@ -532,15 +515,14 @@ public class JSONObject { Object object = this.get(key); try { return object instanceof Number - ? ((Number)object).intValue() - : Integer.parseInt((String)object); - } catch (Exception e) { + ? ((Number) object).intValue() + : Integer.parseInt((String) object); + } catch(Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not an int."); } } - /** * Get the JSONArray value associated with a key. * @@ -551,14 +533,13 @@ public class JSONObject { */ public JSONArray getJSONArray(String key) throws JSONException { Object object = this.get(key); - if (object instanceof JSONArray) { - return (JSONArray)object; + if(object instanceof JSONArray) { + return (JSONArray) object; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONArray."); } - /** * Get the JSONObject value associated with a key. * @@ -569,14 +550,13 @@ public class JSONObject { */ public JSONObject getJSONObject(String key) throws JSONException { Object object = this.get(key); - if (object instanceof JSONObject) { - return (JSONObject)object; + if(object instanceof JSONObject) { + return (JSONObject) object; } throw new JSONException("JSONObject[" + quote(key) + "] is not a JSONObject."); } - /** * Get the long value associated with a key. * @@ -589,15 +569,14 @@ public class JSONObject { Object object = this.get(key); try { return object instanceof Number - ? ((Number)object).longValue() - : Long.parseLong((String)object); - } catch (Exception e) { + ? ((Number) object).longValue() + : Long.parseLong((String) object); + } catch(Exception e) { throw new JSONException("JSONObject[" + quote(key) + "] is not a long."); } } - /** * Get an array of field names from a JSONObject. * @@ -605,43 +584,41 @@ public class JSONObject { */ public static String[] getNames(JSONObject jo) { int length = jo.length(); - if (length == 0) { + if(length == 0) { return null; } Iterator iterator = jo.keys(); String[] names = new String[length]; int i = 0; while (iterator.hasNext()) { - names[i] = (String)iterator.next(); + names[i] = (String) iterator.next(); i += 1; } return names; } - /** * Get an array of field names from an Object. * * @return An array of field names, or null if there are no names. */ public static String[] getNames(Object object) { - if (object == null) { + if(object == null) { return null; } Class klass = object.getClass(); Field[] fields = klass.getFields(); int length = fields.length; - if (length == 0) { + if(length == 0) { return null; } String[] names = new String[length]; - for (int i = 0; i < length; i += 1) { + for(int i = 0; i < length; i += 1) { names[i] = fields[i].getName(); } return names; } - /** * Get the string associated with a key. * @@ -651,14 +628,13 @@ public class JSONObject { */ public String getString(String key) throws JSONException { Object object = this.get(key); - if (object instanceof String) { - return (String)object; + if(object instanceof String) { + return (String) object; } throw new JSONException("JSONObject[" + quote(key) + "] not a string."); } - /** * Determine if the JSONObject contains a specific key. * @param key A key string. @@ -668,7 +644,6 @@ public class JSONObject { return this.map.containsKey(key); } - /** * Increment a property of a JSONObject. If there is no such property, * create one with a value of 1. If there is such a property, and if @@ -680,23 +655,22 @@ public class JSONObject { */ public JSONObject increment(String key) throws JSONException { Object value = this.opt(key); - if (value == null) { + if(value == null) { this.put(key, 1); - } else if (value instanceof Integer) { - this.put(key, ((Integer)value).intValue() + 1); - } else if (value instanceof Long) { - this.put(key, ((Long)value).longValue() + 1); - } else if (value instanceof Double) { - this.put(key, ((Double)value).doubleValue() + 1); - } else if (value instanceof Float) { - this.put(key, ((Float)value).floatValue() + 1); + } else if(value instanceof Integer) { + this.put(key, ((Integer) value).intValue() + 1); + } else if(value instanceof Long) { + this.put(key, ((Long) value).longValue() + 1); + } else if(value instanceof Double) { + this.put(key, ((Double) value).doubleValue() + 1); + } else if(value instanceof Float) { + this.put(key, ((Float) value).floatValue() + 1); } else { throw new JSONException("Unable to increment [" + quote(key) + "]."); } return this; } - /** * Determine if the value associated with the key is null or if there is * no value. @@ -708,7 +682,6 @@ public class JSONObject { return JSONObject.NULL.equals(this.opt(key)); } - /** * Get an enumeration of the keys of the JSONObject. * @@ -718,7 +691,6 @@ public class JSONObject { return this.keySet().iterator(); } - /** * Get a set of keys of the JSONObject. * @@ -728,7 +700,6 @@ public class JSONObject { return this.map.keySet(); } - /** * Get the number of keys stored in the JSONObject. * @@ -738,7 +709,6 @@ public class JSONObject { return this.map.size(); } - /** * Produce a JSONArray containing the names of the elements of this * JSONObject. @@ -747,7 +717,7 @@ public class JSONObject { */ public JSONArray names() { JSONArray ja = new JSONArray(); - Iterator keys = this.keys(); + Iterator keys = this.keys(); while (keys.hasNext()) { ja.put(keys.next()); } @@ -762,7 +732,7 @@ public class JSONObject { */ public static String numberToString(Number number) throws JSONException { - if (number == null) { + if(number == null) { throw new JSONException("Null pointer"); } testValidity(number); @@ -770,19 +740,18 @@ public class JSONObject { // Shave off trailing zeros and decimal point, if possible. String string = number.toString(); - if (string.indexOf('.') > 0 && string.indexOf('e') < 0 && + if(string.indexOf('.') > 0 && string.indexOf('e') < 0 && string.indexOf('E') < 0) { while (string.endsWith("0")) { string = string.substring(0, string.length() - 1); } - if (string.endsWith(".")) { + if(string.endsWith(".")) { string = string.substring(0, string.length() - 1); } } return string; } - /** * Get an optional value associated with a key. * @param key A key string. @@ -792,7 +761,6 @@ public class JSONObject { return key == null ? null : this.map.get(key); } - /** * Get an optional boolean associated with a key. * It returns false if there is no such key, or if the value is not @@ -805,7 +773,6 @@ public class JSONObject { return this.optBoolean(key, false); } - /** * Get an optional boolean associated with a key. * It returns the defaultValue if there is no such key, or if it is not @@ -818,12 +785,11 @@ public class JSONObject { public boolean optBoolean(String key, boolean defaultValue) { try { return this.getBoolean(key); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get an optional double associated with a key, * or NaN if there is no such key or if its value is not a number. @@ -837,7 +803,6 @@ public class JSONObject { return this.optDouble(key, Double.NaN); } - /** * Get an optional double associated with a key, or the * defaultValue if there is no such key or if its value is not a number. @@ -851,12 +816,11 @@ public class JSONObject { public double optDouble(String key, double defaultValue) { try { return this.getDouble(key); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get an optional int value associated with a key, * or zero if there is no such key or if the value is not a number. @@ -870,7 +834,6 @@ public class JSONObject { return this.optInt(key, 0); } - /** * Get an optional int value associated with a key, * or the default if there is no such key or if the value is not a number. @@ -884,12 +847,11 @@ public class JSONObject { public int optInt(String key, int defaultValue) { try { return this.getInt(key); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get an optional JSONArray associated with a key. * It returns null if there is no such key, or if its value is not a @@ -900,10 +862,9 @@ public class JSONObject { */ public JSONArray optJSONArray(String key) { Object o = this.opt(key); - return o instanceof JSONArray ? (JSONArray)o : null; + return o instanceof JSONArray ? (JSONArray) o : null; } - /** * Get an optional JSONObject associated with a key. * It returns null if there is no such key, or if its value is not a @@ -914,10 +875,9 @@ public class JSONObject { */ public JSONObject optJSONObject(String key) { Object object = this.opt(key); - return object instanceof JSONObject ? (JSONObject)object : null; + return object instanceof JSONObject ? (JSONObject) object : null; } - /** * Get an optional long value associated with a key, * or zero if there is no such key or if the value is not a number. @@ -931,7 +891,6 @@ public class JSONObject { return this.optLong(key, 0); } - /** * Get an optional long value associated with a key, * or the default if there is no such key or if the value is not a number. @@ -945,12 +904,11 @@ public class JSONObject { public long optLong(String key, long defaultValue) { try { return this.getLong(key); - } catch (Exception e) { + } catch(Exception e) { return defaultValue; } } - /** * Get an optional string associated with a key. * It returns an empty string if there is no such key. If the value is not @@ -963,7 +921,6 @@ public class JSONObject { return this.optString(key, ""); } - /** * Get an optional string associated with a key. * It returns the defaultValue if there is no such key. @@ -977,7 +934,6 @@ public class JSONObject { return NULL.equals(object) ? defaultValue : object.toString(); } - private void populateMap(Object bean) { Class klass = bean.getClass(); @@ -987,45 +943,44 @@ public class JSONObject { Method[] methods = includeSuperClass ? klass.getMethods() - : klass.getDeclaredMethods(); - for (int i = 0; i < methods.length; i += 1) { - try { - Method method = methods[i]; - if (Modifier.isPublic(method.getModifiers())) { - String name = method.getName(); - String key = ""; - if (name.startsWith("get")) { - if ("getClass".equals(name) || - "getDeclaringClass".equals(name)) { - key = ""; - } else { - key = name.substring(3); - } - } else if (name.startsWith("is")) { - key = name.substring(2); - } - if (key.length() > 0 && - Character.isUpperCase(key.charAt(0)) && - method.getParameterTypes().length == 0) { - if (key.length() == 1) { - key = key.toLowerCase(); - } else if (!Character.isUpperCase(key.charAt(1))) { - key = key.substring(0, 1).toLowerCase() + - key.substring(1); - } - - Object result = method.invoke(bean, (Object[])null); - if (result != null) { - this.map.put(key, wrap(result)); - } - } + : klass.getDeclaredMethods(); + for(int i = 0; i < methods.length; i += 1) { + try { + Method method = methods[i]; + if(Modifier.isPublic(method.getModifiers())) { + String name = method.getName(); + String key = ""; + if(name.startsWith("get")) { + if("getClass".equals(name) || + "getDeclaringClass".equals(name)) { + key = ""; + } else { + key = name.substring(3); + } + } else if(name.startsWith("is")) { + key = name.substring(2); + } + if(key.length() > 0 && + Character.isUpperCase(key.charAt(0)) && + method.getParameterTypes().length == 0) { + if(key.length() == 1) { + key = key.toLowerCase(); + } else if(!Character.isUpperCase(key.charAt(1))) { + key = key.substring(0, 1).toLowerCase() + + key.substring(1); + } + + Object result = method.invoke(bean, (Object[]) null); + if(result != null) { + this.map.put(key, wrap(result)); } - } catch (Exception ignore) { } } + } catch(Exception ignore) { + } + } } - /** * Put a key/boolean pair in the JSONObject. * @@ -1039,7 +994,6 @@ public class JSONObject { return this; } - /** * Put a key/value pair in the JSONObject, where the value will be a * JSONArray which is produced from a Collection. @@ -1053,7 +1007,6 @@ public class JSONObject { return this; } - /** * Put a key/double pair in the JSONObject. * @@ -1067,7 +1020,6 @@ public class JSONObject { return this; } - /** * Put a key/int pair in the JSONObject. * @@ -1081,7 +1033,6 @@ public class JSONObject { return this; } - /** * Put a key/long pair in the JSONObject. * @@ -1095,7 +1046,6 @@ public class JSONObject { return this; } - /** * Put a key/value pair in the JSONObject, where the value will be a * JSONObject which is produced from a Map. @@ -1109,7 +1059,6 @@ public class JSONObject { return this; } - /** * Put a key/value pair in the JSONObject. If the value is null, * then the key will be removed from the JSONObject if it is present. @@ -1123,14 +1072,14 @@ public class JSONObject { */ public JSONObject put(String key, Object value) throws JSONException { String pooled; - if (key == null) { + if(key == null) { throw new JSONException("Null key."); } - if (value != null) { + if(value != null) { testValidity(value); - pooled = (String)keyPool.get(key); - if (pooled == null) { - if (keyPool.size() >= keyPoolSize) { + pooled = (String) keyPool.get(key); + if(pooled == null) { + if(keyPool.size() >= keyPoolSize) { keyPool = new HashMap(keyPoolSize); } keyPool.put(key, key); @@ -1144,7 +1093,6 @@ public class JSONObject { return this; } - /** * Put a key/value pair in the JSONObject, but only if the key and the * value are both non-null, and only if there is not already a member @@ -1155,8 +1103,8 @@ public class JSONObject { * @throws JSONException if the key is a duplicate */ public JSONObject putOnce(String key, Object value) throws JSONException { - if (key != null && value != null) { - if (this.opt(key) != null) { + if(key != null && value != null) { + if(this.opt(key) != null) { throw new JSONException("Duplicate key \"" + key + "\""); } this.put(key, value); @@ -1164,7 +1112,6 @@ public class JSONObject { return this; } - /** * Put a key/value pair in the JSONObject, but only if the * key and the value are both non-null. @@ -1176,13 +1123,12 @@ public class JSONObject { * @throws JSONException If the value is a non-finite number. */ public JSONObject putOpt(String key, Object value) throws JSONException { - if (key != null && value != null) { + if(key != null && value != null) { this.put(key, value); } return this; } - /** * Produce a string in double quotes with backslash sequences in all the * right places. A backslash will be inserted within = '\u0080' && c < '\u00a0') + if(c < ' ' || (c >= '\u0080' && c < '\u00a0') || (c >= '\u2000' && c < '\u2100')) { w.write("\\u"); hhhh = Integer.toHexString(c); @@ -1280,16 +1226,16 @@ public class JSONObject { */ public static Object stringToValue(String string) { Double d; - if (string.equals("")) { + if(string.equals("")) { return string; } - if (string.equalsIgnoreCase("true")) { + if(string.equalsIgnoreCase("true")) { return Boolean.TRUE; } - if (string.equalsIgnoreCase("false")) { + if(string.equalsIgnoreCase("false")) { return Boolean.FALSE; } - if (string.equalsIgnoreCase("null")) { + if(string.equalsIgnoreCase("null")) { return JSONObject.NULL; } @@ -1302,43 +1248,42 @@ public class JSONObject { */ char b = string.charAt(0); - if ((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { + if((b >= '0' && b <= '9') || b == '.' || b == '-' || b == '+') { try { - if (string.indexOf('.') > -1 || + if(string.indexOf('.') > -1 || string.indexOf('e') > -1 || string.indexOf('E') > -1) { d = Double.valueOf(string); - if (!d.isInfinite() && !d.isNaN()) { + if(!d.isInfinite() && !d.isNaN()) { return d; } } else { Long myLong = new Long(string); - if (myLong.longValue() == myLong.intValue()) { + if(myLong.longValue() == myLong.intValue()) { return new Integer(myLong.intValue()); } else { return myLong; } } - } catch (Exception ignore) { + } catch(Exception ignore) { } } return string; } - /** * Throw an exception if the object is a NaN or infinite number. * @param o The object to test. * @throws JSONException If o is a non-finite number. */ public static void testValidity(Object o) throws JSONException { - if (o != null) { - if (o instanceof Double) { - if (((Double)o).isInfinite() || ((Double)o).isNaN()) { + if(o != null) { + if(o instanceof Double) { + if(((Double) o).isInfinite() || ((Double) o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers."); } - } else if (o instanceof Float) { - if (((Float)o).isInfinite() || ((Float)o).isNaN()) { + } else if(o instanceof Float) { + if(((Float) o).isInfinite() || ((Float) o).isNaN()) { throw new JSONException( "JSON does not allow non-finite numbers."); } @@ -1346,7 +1291,6 @@ public class JSONObject { } } - /** * Produce a JSONArray containing the values of the members of this * JSONObject. @@ -1356,11 +1300,11 @@ public class JSONObject { * @throws JSONException If any of the values are non-finite numbers. */ public JSONArray toJSONArray(JSONArray names) throws JSONException { - if (names == null || names.length() == 0) { + if(names == null || names.length() == 0) { return null; } JSONArray ja = new JSONArray(); - for (int i = 0; i < names.length(); i += 1) { + for(int i = 0; i < names.length(); i += 1) { ja.put(this.opt(names.getString(i))); } return ja; @@ -1381,12 +1325,11 @@ public class JSONObject { public String toString() { try { return this.toString(0); - } catch (Exception e) { + } catch(Exception e) { return null; } } - /** * Make a prettyprinted JSON text of this JSONObject. *

@@ -1428,35 +1371,35 @@ public class JSONObject { * @throws JSONException If the value is or contains an invalid number. */ public static String valueToString(Object value) throws JSONException { - if (value == null || value.equals(null)) { + if(value == null || value.equals(null)) { return "null"; } - if (value instanceof JSONString) { + if(value instanceof JSONString) { Object object; try { - object = ((JSONString)value).toJSONString(); - } catch (Exception e) { + object = ((JSONString) value).toJSONString(); + } catch(Exception e) { throw new JSONException(e); } - if (object instanceof String) { - return (String)object; + if(object instanceof String) { + return (String) object; } throw new JSONException("Bad value from toJSONString: " + object); } - if (value instanceof Number) { + if(value instanceof Number) { return numberToString((Number) value); } - if (value instanceof Boolean || value instanceof JSONObject || + if(value instanceof Boolean || value instanceof JSONObject || value instanceof JSONArray) { return value.toString(); } - if (value instanceof Map) { - return new JSONObject((Map)value).toString(); + if(value instanceof Map) { + return new JSONObject((Map) value).toString(); } - if (value instanceof Collection) { - return new JSONArray((Collection)value).toString(); + if(value instanceof Collection) { + return new JSONArray((Collection) value).toString(); } - if (value.getClass().isArray()) { + if(value.getClass().isArray()) { return new JSONArray(value).toString(); } return quote(value.toString()); @@ -1476,46 +1419,43 @@ public class JSONObject { */ public static Object wrap(Object object) { try { - if (object == null) { + if(object == null) { return NULL; } - if (object instanceof JSONObject || object instanceof JSONArray || - NULL.equals(object) || object instanceof JSONString || - object instanceof Byte || object instanceof Character || - object instanceof Short || object instanceof Integer || - object instanceof Long || object instanceof Boolean || - object instanceof Float || object instanceof Double || + if(object instanceof JSONObject || object instanceof JSONArray || + NULL.equals(object) || object instanceof JSONString || + object instanceof Byte || object instanceof Character || + object instanceof Short || object instanceof Integer || + object instanceof Long || object instanceof Boolean || + object instanceof Float || object instanceof Double || object instanceof String) { return object; } - if (object instanceof Collection) { - return new JSONArray((Collection)object); + if(object instanceof Collection) { + return new JSONArray((Collection) object); } - if (object.getClass().isArray()) { + if(object.getClass().isArray()) { return new JSONArray(object); } - if (object instanceof Map) { - return new JSONObject((Map)object); + if(object instanceof Map) { + return new JSONObject((Map) object); } Package objectPackage = object.getClass().getPackage(); String objectPackageName = objectPackage != null ? objectPackage.getName() - : ""; - if ( - objectPackageName.startsWith("java.") || - objectPackageName.startsWith("javax.") || - object.getClass().getClassLoader() == null - ) { - return object.toString(); - } - return new JSONObject(object); + : ""; + if(objectPackageName.startsWith("java.") || + objectPackageName.startsWith("javax.") || + object.getClass().getClassLoader() == null) { + return object.toString(); + } + return new JSONObject(object); } catch(Exception exception) { return null; } } - /** * Write the contents of the JSONObject as JSON text to a writer. * For compactness, no whitespace is added. @@ -1529,31 +1469,30 @@ public class JSONObject { return this.write(writer, 0, 0); } - static final Writer writeValue(Writer writer, Object value, int indentFactor, int indent) throws JSONException, IOException { - if (value == null || value.equals(null)) { + if(value == null || value.equals(null)) { writer.write("null"); - } else if (value instanceof JSONObject) { + } else if(value instanceof JSONObject) { ((JSONObject) value).write(writer, indentFactor, indent); - } else if (value instanceof JSONArray) { + } else if(value instanceof JSONArray) { ((JSONArray) value).write(writer, indentFactor, indent); - } else if (value instanceof Map) { + } else if(value instanceof Map) { new JSONObject((Map) value).write(writer, indentFactor, indent); - } else if (value instanceof Collection) { + } else if(value instanceof Collection) { new JSONArray((Collection) value).write(writer, indentFactor, indent); - } else if (value.getClass().isArray()) { + } else if(value.getClass().isArray()) { new JSONArray(value).write(writer, indentFactor, indent); - } else if (value instanceof Number) { + } else if(value instanceof Number) { writer.write(numberToString((Number) value)); - } else if (value instanceof Boolean) { + } else if(value instanceof Boolean) { writer.write(value.toString()); - } else if (value instanceof JSONString) { + } else if(value instanceof JSONString) { Object o; try { o = ((JSONString) value).toJSONString(); - } catch (Exception e) { + } catch(Exception e) { throw new JSONException(e); } writer.write(o != null ? o.toString() : quote(value.toString())); @@ -1564,7 +1503,7 @@ public class JSONObject { } static final void indent(Writer writer, int indent) throws IOException { - for (int i = 0; i < indent; i += 1) { + for(int i = 0; i < indent; i += 1) { writer.write(' '); } } @@ -1586,42 +1525,42 @@ public class JSONObject { Iterator keys = this.keys(); writer.write('{'); - if (length == 1) { + if(length == 1) { Object key = keys.next(); writer.write(quote(key.toString())); writer.write(':'); - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write(' '); } writeValue(writer, this.map.get(key), indentFactor, indent); - } else if (length != 0) { + } else if(length != 0) { final int newindent = indent + indentFactor; while (keys.hasNext()) { Object key = keys.next(); - if (commanate) { + if(commanate) { writer.write(','); } - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write('\n'); } indent(writer, newindent); writer.write(quote(key.toString())); writer.write(':'); - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write(' '); } writeValue(writer, this.map.get(key), indentFactor, newindent); commanate = true; } - if (indentFactor > 0) { + if(indentFactor > 0) { writer.write('\n'); } indent(writer, indent); } writer.write('}'); return writer; - } catch (IOException exception) { + } catch(IOException exception) { throw new JSONException(exception); } } diff --git a/src/main/java/org/json/JSONString.java b/src/main/java/org/json/JSONString.java index 1f2d77d..1564788 100644 --- a/src/main/java/org/json/JSONString.java +++ b/src/main/java/org/json/JSONString.java @@ -1,4 +1,5 @@ package org.json; + /** * The JSONString interface allows a toJSONString() * method so that a class can change the behavior of diff --git a/src/main/java/org/json/JSONStringer.java b/src/main/java/org/json/JSONStringer.java index 844e71f..b4f6170 100644 --- a/src/main/java/org/json/JSONStringer.java +++ b/src/main/java/org/json/JSONStringer.java @@ -1,27 +1,27 @@ package org.json; /* -Copyright (c) 2006 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2006 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ import java.io.StringWriter; diff --git a/src/main/java/org/json/JSONTokener.java b/src/main/java/org/json/JSONTokener.java index 095b165..1ad0a2d 100644 --- a/src/main/java/org/json/JSONTokener.java +++ b/src/main/java/org/json/JSONTokener.java @@ -8,27 +8,27 @@ import java.io.Reader; import java.io.StringReader; /* -Copyright (c) 2002 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2002 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ /** @@ -40,15 +40,14 @@ SOFTWARE. */ public class JSONTokener { - private long character; + private long character; private boolean eof; - private long index; - private long line; - private char previous; - private Reader reader; + private long index; + private long line; + private char previous; + private Reader reader; private boolean usePrevious; - /** * Construct a JSONTokener from a Reader. * @@ -57,7 +56,7 @@ public class JSONTokener { public JSONTokener(Reader reader) { this.reader = reader.markSupported() ? reader - : new BufferedReader(reader); + : new BufferedReader(reader); this.eof = false; this.usePrevious = false; this.previous = 0; @@ -66,7 +65,6 @@ public class JSONTokener { this.line = 1; } - /** * Construct a JSONTokener from an InputStream. */ @@ -74,7 +72,6 @@ public class JSONTokener { this(new InputStreamReader(inputStream)); } - /** * Construct a JSONTokener from a string. * @@ -84,14 +81,13 @@ public class JSONTokener { this(new StringReader(s)); } - /** * Back up one character. This provides a sort of lookahead capability, * so that you can test for a digit or letter before attempting to parse * the next number or identifier. */ public void back() throws JSONException { - if (this.usePrevious || this.index <= 0) { + if(this.usePrevious || this.index <= 0) { throw new JSONException("Stepping back two steps is not supported"); } this.index -= 1; @@ -100,7 +96,6 @@ public class JSONTokener { this.eof = false; } - /** * Get the hex value of a character (base16). * @param c A character between '0' and '9' or between 'A' and 'F' or @@ -108,13 +103,13 @@ public class JSONTokener { * @return An int between 0 and 15, or -1 if c was not a hex digit. */ public static int dehexchar(char c) { - if (c >= '0' && c <= '9') { + if(c >= '0' && c <= '9') { return c - '0'; } - if (c >= 'A' && c <= 'F') { + if(c >= 'A' && c <= 'F') { return c - ('A' - 10); } - if (c >= 'a' && c <= 'f') { + if(c >= 'a' && c <= 'f') { return c - ('a' - 10); } return -1; @@ -124,7 +119,6 @@ public class JSONTokener { return this.eof && !this.usePrevious; } - /** * Determine if the source string still contains characters that next() * can consume. @@ -132,14 +126,13 @@ public class JSONTokener { */ public boolean more() throws JSONException { this.next(); - if (this.end()) { + if(this.end()) { return false; } this.back(); return true; } - /** * Get the next character in the source string. * @@ -147,26 +140,26 @@ public class JSONTokener { */ public char next() throws JSONException { int c; - if (this.usePrevious) { + if(this.usePrevious) { this.usePrevious = false; c = this.previous; } else { try { c = this.reader.read(); - } catch (IOException exception) { + } catch(IOException exception) { throw new JSONException(exception); } - if (c <= 0) { // End of stream + if(c <= 0) { // End of stream this.eof = true; c = 0; } } this.index += 1; - if (this.previous == '\r') { + if(this.previous == '\r') { this.line += 1; this.character = c == '\n' ? 0 : 1; - } else if (c == '\n') { + } else if(c == '\n') { this.line += 1; this.character = 0; } else { @@ -176,7 +169,6 @@ public class JSONTokener { return this.previous; } - /** * Consume the next character, and check that it matches a specified * character. @@ -186,14 +178,13 @@ public class JSONTokener { */ public char next(char c) throws JSONException { char n = this.next(); - if (n != c) { + if(n != c) { throw this.syntaxError("Expected '" + c + "' and instead saw '" + n + "'"); } return n; } - /** * Get the next n characters. * @@ -204,7 +195,7 @@ public class JSONTokener { * n characters remaining in the source string. */ public String next(int n) throws JSONException { - if (n == 0) { + if(n == 0) { return ""; } @@ -213,7 +204,7 @@ public class JSONTokener { while (pos < n) { chars[pos] = this.next(); - if (this.end()) { + if(this.end()) { throw this.syntaxError("Substring bounds error"); } pos += 1; @@ -221,22 +212,20 @@ public class JSONTokener { return new String(chars); } - /** * Get the next char in the string, skipping whitespace. * @throws JSONException * @return A character, or 0 if there are no more characters. */ public char nextClean() throws JSONException { - for (;;) { + for(;;) { char c = this.next(); - if (c == 0 || c > ' ') { + if(c == 0 || c > ' ') { return c; } } } - /** * Return the characters up to the next close quote character. * Backslash processing is done. The formal JSON format does not @@ -251,7 +240,7 @@ public class JSONTokener { public String nextString(char quote) throws JSONException { char c; StringBuffer sb = new StringBuffer(); - for (;;) { + for(;;) { c = this.next(); switch (c) { case 0: @@ -277,7 +266,7 @@ public class JSONTokener { sb.append('\r'); break; case 'u': - sb.append((char)Integer.parseInt(this.next(4), 16)); + sb.append((char) Integer.parseInt(this.next(4), 16)); break; case '"': case '\'': @@ -290,7 +279,7 @@ public class JSONTokener { } break; default: - if (c == quote) { + if(c == quote) { return sb.toString(); } sb.append(c); @@ -298,7 +287,6 @@ public class JSONTokener { } } - /** * Get the text up but not including the specified character or the * end of line, whichever comes first. @@ -307,10 +295,10 @@ public class JSONTokener { */ public String nextTo(char delimiter) throws JSONException { StringBuffer sb = new StringBuffer(); - for (;;) { + for(;;) { char c = this.next(); - if (c == delimiter || c == 0 || c == '\n' || c == '\r') { - if (c != 0) { + if(c == delimiter || c == 0 || c == '\n' || c == '\r') { + if(c != 0) { this.back(); } return sb.toString().trim(); @@ -319,7 +307,6 @@ public class JSONTokener { } } - /** * Get the text up but not including one of the specified delimiter * characters or the end of line, whichever comes first. @@ -329,11 +316,11 @@ public class JSONTokener { public String nextTo(String delimiters) throws JSONException { char c; StringBuffer sb = new StringBuffer(); - for (;;) { + for(;;) { c = this.next(); - if (delimiters.indexOf(c) >= 0 || c == 0 || + if(delimiters.indexOf(c) >= 0 || c == 0 || c == '\n' || c == '\r') { - if (c != 0) { + if(c != 0) { this.back(); } return sb.toString().trim(); @@ -342,7 +329,6 @@ public class JSONTokener { } } - /** * Get the next value. The value can be a Boolean, Double, Integer, * JSONArray, JSONObject, Long, or String, or the JSONObject.NULL object. @@ -370,7 +356,7 @@ public class JSONTokener { * Handle unquoted text. This could be the values true, false, or * null, or it can be a number. An implementation (such as this one) * is allowed to also accept non-standard forms. - * + * * Accumulate characters until we reach the end of the text or a * formatting character. */ @@ -383,13 +369,12 @@ public class JSONTokener { this.back(); string = sb.toString().trim(); - if ("".equals(string)) { + if("".equals(string)) { throw this.syntaxError("Missing value"); } return JSONObject.stringToValue(string); } - /** * Skip characters until the next character is the requested character. * If the requested character is not found, no characters are skipped. @@ -406,7 +391,7 @@ public class JSONTokener { this.reader.mark(1000000); do { c = this.next(); - if (c == 0) { + if(c == 0) { this.reader.reset(); this.index = startIndex; this.character = startCharacter; @@ -414,7 +399,7 @@ public class JSONTokener { return c; } } while (c != to); - } catch (IOException exc) { + } catch(IOException exc) { throw new JSONException(exc); } @@ -422,7 +407,6 @@ public class JSONTokener { return c; } - /** * Make a JSONException to signal a syntax error. * @@ -433,7 +417,6 @@ public class JSONTokener { return new JSONException(message + this.toString()); } - /** * Make a printable string of this JSONTokener. * diff --git a/src/main/java/org/json/JSONWriter.java b/src/main/java/org/json/JSONWriter.java index 2c28ac4..b413ff6 100644 --- a/src/main/java/org/json/JSONWriter.java +++ b/src/main/java/org/json/JSONWriter.java @@ -4,27 +4,27 @@ import java.io.IOException; import java.io.Writer; /* -Copyright (c) 2006 JSON.org - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -The Software shall be used for Good, not Evil. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. + * Copyright (c) 2006 JSON.org + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * The Software shall be used for Good, not Evil. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. */ /** @@ -108,19 +108,19 @@ public class JSONWriter { * @throws JSONException If the value is out of sequence. */ private JSONWriter append(String string) throws JSONException { - if (string == null) { + if(string == null) { throw new JSONException("Null pointer"); } - if (this.mode == 'o' || this.mode == 'a') { + if(this.mode == 'o' || this.mode == 'a') { try { - if (this.comma && this.mode == 'a') { + if(this.comma && this.mode == 'a') { this.writer.write(','); } this.writer.write(string); - } catch (IOException e) { + } catch(IOException e) { throw new JSONException(e); } - if (this.mode == 'o') { + if(this.mode == 'o') { this.mode = 'k'; } this.comma = true; @@ -139,7 +139,7 @@ public class JSONWriter { * outermost array or object). */ public JSONWriter array() throws JSONException { - if (this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { + if(this.mode == 'i' || this.mode == 'o' || this.mode == 'a') { this.push(null); this.append("["); this.comma = false; @@ -156,15 +156,15 @@ public class JSONWriter { * @throws JSONException If unbalanced. */ private JSONWriter end(char mode, char c) throws JSONException { - if (this.mode != mode) { + if(this.mode != mode) { throw new JSONException(mode == 'a' ? "Misplaced endArray." - : "Misplaced endObject."); + : "Misplaced endObject."); } this.pop(mode); try { this.writer.write(c); - } catch (IOException e) { + } catch(IOException e) { throw new JSONException(e); } this.comma = true; @@ -200,13 +200,13 @@ public class JSONWriter { * do not belong in arrays or if the key is null. */ public JSONWriter key(String string) throws JSONException { - if (string == null) { + if(string == null) { throw new JSONException("Null key."); } - if (this.mode == 'k') { + if(this.mode == 'k') { try { this.stack[this.top - 1].putOnce(string, Boolean.TRUE); - if (this.comma) { + if(this.comma) { this.writer.write(','); } this.writer.write(JSONObject.quote(string)); @@ -214,14 +214,13 @@ public class JSONWriter { this.comma = false; this.mode = 'o'; return this; - } catch (IOException e) { + } catch(IOException e) { throw new JSONException(e); } } throw new JSONException("Misplaced key."); } - /** * Begin appending a new object. All keys and values until the balancing * endObject will be appended to this object. The @@ -232,10 +231,10 @@ public class JSONWriter { * outermost array or object). */ public JSONWriter object() throws JSONException { - if (this.mode == 'i') { + if(this.mode == 'i') { this.mode = 'o'; } - if (this.mode == 'o' || this.mode == 'a') { + if(this.mode == 'o' || this.mode == 'a') { this.append("{"); this.push(new JSONObject()); this.comma = false; @@ -245,26 +244,25 @@ public class JSONWriter { } - /** * Pop an array or object scope. * @param c The scope to close. * @throws JSONException If nesting is wrong. */ private void pop(char c) throws JSONException { - if (this.top <= 0) { + if(this.top <= 0) { throw new JSONException("Nesting error."); } char m = this.stack[this.top - 1] == null ? 'a' : 'k'; - if (m != c) { + if(m != c) { throw new JSONException("Nesting error."); } this.top -= 1; this.mode = this.top == 0 ? 'd' - : this.stack[this.top - 1] == null + : this.stack[this.top - 1] == null ? 'a' - : 'k'; + : 'k'; } /** @@ -273,7 +271,7 @@ public class JSONWriter { * @throws JSONException If nesting is too deep. */ private void push(JSONObject jo) throws JSONException { - if (this.top >= maxdepth) { + if(this.top >= maxdepth) { throw new JSONException("Nesting too deep."); } this.stack[this.top] = jo; @@ -281,7 +279,6 @@ public class JSONWriter { this.top += 1; } - /** * Append either the value true or the value * false. @@ -313,7 +310,6 @@ public class JSONWriter { return this.append(Long.toString(l)); } - /** * Append an object value. * @param object The object to append. It can be null, or a Boolean, Number,