Example usage for java.lang Integer decode

List of usage examples for java.lang Integer decode

Introduction

In this page you can find the example usage for java.lang Integer decode.

Prototype

public static Integer decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into an Integer .

Usage

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a photo prompt and returns a PhotoPrompt object.
 * //from   ww w .j  a v a2 s .  co  m
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A PhotoPrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static PhotoPrompt processPhoto(final String id, final String condition, final String unit,
        final String text, final String explanationText, final boolean skippable, final String skipLabel,
        final String displayLabel, final String defaultValue, final Map<String, LabelValuePair> properties,
        final int index) throws DomainException {

    Integer maxDimension = null;
    try {
        LabelValuePair maxDimensionVlp = properties.get(PhotoPrompt.XML_KEY_MAXIMUM_DIMENSION);

        if (maxDimensionVlp != null) {
            maxDimension = Integer.decode(maxDimensionVlp.getLabel());
        }
    } catch (NumberFormatException e) {
        throw new DomainException(
                "The '" + PhotoPrompt.XML_KEY_MAXIMUM_DIMENSION + "' property is not an integer: " + id, e);
    }

    if (defaultValue != null) {
        throw new DomainException("Default values are not allowed for photo prompts: " + id);
    }

    return new PhotoPrompt(id, condition, unit, text, explanationText, skippable, skipLabel, displayLabel,
            maxDimension, index);
}

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a remote activity prompt and returns a RemoteActivityPrompt
 * object./*from w w w  .  j  a v a 2  s.c o  m*/
 * 
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A RemoteActivityPrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static RemoteActivityPrompt processRemoteActivity(final String id, final String condition,
        final String unit, final String text, final String explanationText, final boolean skippable,
        final String skipLabel, final String displayLabel, final String defaultValue,
        final Map<String, LabelValuePair> properties, final int index) throws DomainException {

    LabelValuePair packageVlp = properties.get(RemoteActivityPrompt.XML_KEY_PACKAGE);
    if (packageVlp == null) {
        throw new DomainException("Missing the '" + RemoteActivityPrompt.XML_KEY_PACKAGE + "' property: " + id);
    }
    String packagee = packageVlp.getLabel();

    LabelValuePair activityVlp = properties.get(RemoteActivityPrompt.XML_KEY_ACTIVITY);
    if (activityVlp == null) {
        throw new DomainException(
                "Missing the '" + RemoteActivityPrompt.XML_KEY_ACTIVITY + "' property: " + id);
    }
    String activity = activityVlp.getLabel();

    LabelValuePair actionVlp = properties.get(RemoteActivityPrompt.XML_KEY_ACTION);
    if (actionVlp == null) {
        throw new DomainException("Missing the '" + RemoteActivityPrompt.XML_KEY_ACTION + "' property: " + id);
    }
    String action = actionVlp.getLabel();

    LabelValuePair autolaunchVlp = properties.get(RemoteActivityPrompt.XML_KEY_AUTOLAUNCH);
    if (autolaunchVlp == null) {
        throw new DomainException("Missing the '" + RemoteActivityPrompt.XML_KEY_ACTION + "' property: " + id);
    }
    Boolean autolaunch = StringUtils.decodeBoolean(autolaunchVlp.getLabel());
    if (autolaunch == null) {
        throw new DomainException(
                "The property '" + RemoteActivityPrompt.XML_KEY_AUTOLAUNCH + "' is not a valid boolean: " + id);
    }

    int retries;
    try {
        LabelValuePair retriesVlp = properties.get(RemoteActivityPrompt.XML_KEY_RETRIES);
        if (retriesVlp == null) {
            throw new DomainException(
                    "Missing the '" + RemoteActivityPrompt.XML_KEY_RETRIES + "' property: " + id);
        }
        retries = Integer.decode(retriesVlp.getLabel());
    } catch (NumberFormatException e) {
        throw new DomainException(
                "The '" + RemoteActivityPrompt.XML_KEY_RETRIES + "' property is not an integer: " + id, e);
    }

    int minRuns;
    try {
        LabelValuePair minRunsVlp = properties.get(RemoteActivityPrompt.XML_KEY_MIN_RUNS);
        if (minRunsVlp == null) {
            throw new DomainException(
                    "Missing the '" + RemoteActivityPrompt.XML_KEY_MIN_RUNS + "' property: " + id);
        }
        minRuns = Integer.decode(minRunsVlp.getLabel());
    } catch (NumberFormatException e) {
        throw new DomainException(
                "The '" + RemoteActivityPrompt.XML_KEY_MIN_RUNS + "' property is not an integer: " + id, e);
    }

    String input = null;
    LabelValuePair inputVlp = properties.get(RemoteActivityPrompt.XML_KEY_INPUT);
    if (inputVlp != null) {
        input = inputVlp.getLabel();
    }

    if (defaultValue != null) {
        throw new DomainException("Default values aren't allowed for remote activity prompts: " + id);
    }

    return new RemoteActivityPrompt(id, condition, unit, text, explanationText, skippable, skipLabel,
            displayLabel, packagee, activity, action, autolaunch, retries, minRuns, input, index);
}

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a single choice prompt and returns a SingleChoicePrompt
 * object./* w  w w  .  j  a v  a  2  s . c om*/
 * 
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A SingleChoicePrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static SingleChoicePrompt processSingleChoice(final String id, final String condition,
        final String unit, final String text, final String explanationText, final boolean skippable,
        final String skipLabel, final String displayLabel, final String defaultValue,
        final Map<String, LabelValuePair> properties, final int index) throws DomainException {

    Map<Integer, LabelValuePair> choices = new HashMap<Integer, LabelValuePair>(properties.size());

    for (String key : properties.keySet()) {
        Integer keyInt;
        try {
            keyInt = Integer.decode(key);

            if (keyInt < 0) {
                throw new DomainException("The key value cannot be negative: " + id);
            }
        } catch (NumberFormatException e) {
            throw new DomainException("The key is not a valid integer: " + id, e);
        }

        choices.put(keyInt, properties.get(key));
    }

    Integer defaultKey = null;
    if (defaultValue != null) {
        try {
            defaultKey = Integer.decode(defaultValue);
        } catch (NumberFormatException e) {
            throw new DomainException("The default key is not an integer.");
        }
    }

    return new SingleChoicePrompt(id, condition, unit, text, explanationText, skippable, skipLabel,
            displayLabel, choices, defaultKey, index);
}

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a single choice custom prompt and returns a 
 * SingleChoiceCustomPrompt object./* w ww  .j  av  a 2 s. c om*/
 * 
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A SingleChoiceCustomPrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static SingleChoiceCustomPrompt processSingleChoiceCustom(final String id, final String condition,
        final String unit, final String text, final String explanationText, final boolean skippable,
        final String skipLabel, final String displayLabel, final String defaultValue,
        final Map<String, LabelValuePair> properties, final int index) throws DomainException {

    Map<Integer, LabelValuePair> choices = new HashMap<Integer, LabelValuePair>(properties.size());

    for (String key : properties.keySet()) {
        Integer keyInt;
        try {
            keyInt = Integer.decode(key);

            if (keyInt < 0) {
                throw new DomainException("The key value cannot be negative: " + id);
            }
        } catch (NumberFormatException e) {
            throw new DomainException("The key is not a valid integer: " + id, e);
        }

        choices.put(keyInt, properties.get(key));
    }

    Integer defaultKey = null;
    if (defaultValue != null) {
        try {
            defaultKey = Integer.decode(defaultValue);
        } catch (NumberFormatException e) {
            throw new DomainException("The default key is not an integer.");
        }
    }

    return new SingleChoiceCustomPrompt(id, condition, unit, text, explanationText, skippable, skipLabel,
            displayLabel, choices, new HashMap<Integer, LabelValuePair>(), defaultKey, index);
}

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a text prompt and returns a TextPrompt object.
 * //from  ww w  .j  a  v  a 2s. co  m
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A TextPrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static TextPrompt processText(final String id, final String condition, final String unit,
        final String text, final String explanationText, final boolean skippable, final String skipLabel,
        final String displayLabel, final String defaultValue, final Map<String, LabelValuePair> properties,
        final int index) throws DomainException {

    int min;
    try {
        LabelValuePair minVlp = properties.get(NumberPrompt.XML_KEY_MIN);

        if (minVlp == null) {
            throw new DomainException("Missing the '" + NumberPrompt.XML_KEY_MIN + "' property: " + id);
        }
        min = Integer.decode(minVlp.getLabel());
    } catch (NumberFormatException e) {
        throw new DomainException("The '" + NumberPrompt.XML_KEY_MIN + "' property is not an integer: " + id,
                e);
    }

    int max;
    try {
        LabelValuePair maxVlp = properties.get(NumberPrompt.XML_KEY_MAX);

        if (maxVlp == null) {
            throw new DomainException("Missing the '" + NumberPrompt.XML_KEY_MAX + "' property: " + id);
        }
        max = Integer.decode(maxVlp.getLabel());
    } catch (NumberFormatException e) {
        throw new DomainException("The '" + NumberPrompt.XML_KEY_MAX + "' property is not an integer: " + id,
                e);
    }

    return new TextPrompt(id, condition, unit, text, explanationText, skippable, skipLabel, displayLabel, min,
            max, defaultValue, index);
}

From source file:org.ohmage.domain.campaign.Campaign.java

/**
 * Processes a video prompt and returns a VideoPrompt object.
 * //  w ww. j av  a 2  s  . c  om
 * @param id The prompt's unique identifier.
 * 
 * @param condition The condition value.
 * 
 * @param unit The prompt's visualization unit.
 * 
 * @param text The prompt's text value.
 * 
 * @param explanationText The prompt's explanation text value.
 * 
 * @param skippable Whether or not this prompt is skippable.
 * 
 * @param skipLabel The label to show to skip this prompt.
 * 
 * @param displayLabel The label for this display type.
 * 
 * @param defaultValue The default value given in the XML.
 * 
 * @param properties The properties defined in the XML for this prompt.
 * 
 * @param index The index of this prompt in its collection of survey items.
 * 
 * @return A VideoPrompt object.
 * 
 * @throws DomainException Thrown if the required properties are missing or
 *                      if any of the parameters are invalid.
 */
private static VideoPrompt processVideo(final String id, final String condition, final String unit,
        final String text, final String explanationText, final boolean skippable, final String skipLabel,
        final String displayLabel, final String defaultValue, final Map<String, LabelValuePair> properties,
        final int index) throws DomainException {

    if (defaultValue != null) {
        throw new DomainException("Default values aren't allowed for video prompts: " + id);
    }

    Integer maxSeconds = null;
    try {
        LabelValuePair maxSecondsVlp = properties.get(VideoPrompt.XML_MAX_SECONDS);

        if (maxSecondsVlp != null) {
            maxSeconds = Integer.decode(maxSecondsVlp.getLabel());
        }
    } catch (NumberFormatException e) {
        throw new DomainException("The '" + VideoPrompt.XML_MAX_SECONDS + "' property is not an integer: " + id,
                e);
    }

    return new VideoPrompt(id, condition, unit, text, explanationText, skippable, skipLabel, displayLabel,
            maxSeconds, index);
}

From source file:pl.betoncraft.betonquest.config.ConfigUpdater.java

private void updateTo1_4() {
    Debug.broadcast("Started converting configuration files from v1.3 to v1.4!");
    instance.getConfig().set("autoupdate", "false");
    Debug.broadcast("Added AutoUpdate option to config. It's DISABLED by default!");
    Debug.broadcast("Moving conversation to separate files...");
    ConfigAccessor convOld = ch.getConfigs().get("conversations");
    Set<String> keys = convOld.getConfig().getKeys(false);
    File folder = new File(instance.getDataFolder(), "conversations");
    if (folder.exists() && folder.isDirectory())
        for (File file : folder.listFiles()) {
            file.delete();//from www. ja va  2 s. c  om
        }
    for (String convID : keys) {
        File convFile = new File(folder, convID + ".yml");
        Map<String, Object> convSection = convOld.getConfig().getConfigurationSection(convID).getValues(true);
        YamlConfiguration convNew = YamlConfiguration.loadConfiguration(convFile);
        for (String key : convSection.keySet()) {
            convNew.set(key, convSection.get(key));
        }
        try {
            convNew.save(convFile);
            Debug.broadcast("Conversation " + convID + " moved to it's own file!");
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    Debug.broadcast("All conversations moved, deleting old file.");
    new File(instance.getDataFolder(), "conversations.yml").delete();

    // updating items
    Debug.broadcast("Starting conversion of items...");
    // this map will contain all QuestItem objects extracted from
    // configs
    HashMap<String, QuestItem> items = new HashMap<>();
    // this is counter for a number in item names (in items.yml)
    int number = 0;
    // check every event
    for (String key : ch.getConfigs().get("events").getConfig().getKeys(false)) {
        String instructions = ch.getString("events." + key);
        String[] parts = instructions.split(" ");
        String type = parts[0];
        // if this event has items in it do the thing
        if (type.equals("give") || type.equals("take")) {
            // define all required variables
            String amount = "";
            String conditions = "";
            String material = null;
            int data = 0;
            Map<String, Integer> enchants = null;
            List<String> lore = null;
            String name = null;
            // for each part of the instruction string check if it
            // contains some data and if so pu it in variables
            for (String part : parts) {
                if (part.contains("type:")) {
                    material = part.substring(5);
                } else if (part.contains("data:")) {
                    data = Byte.valueOf(part.substring(5));
                } else if (part.contains("enchants:")) {
                    enchants = new HashMap<>();
                    for (String enchant : part.substring(9).split(",")) {
                        enchants.put(enchant.split(":")[0], Integer.decode(enchant.split(":")[1]));
                    }
                } else if (part.contains("lore:")) {
                    lore = new ArrayList<>();
                    for (String loreLine : part.substring(5).split(";")) {
                        lore.add(loreLine.replaceAll("_", " "));
                    }
                } else if (part.contains("name:")) {
                    name = part.substring(5).replaceAll("_", " ");
                } else if (part.contains("amount:")) {
                    amount = part;
                } else if (part.contains("conditions:")) {
                    conditions = part;
                }
            }
            // create an item
            String newItemID = null;
            @SuppressWarnings("deprecation")
            QuestItem item = new QuestItem(material, data, enchants, name, lore);
            boolean contains = false;
            for (String itemKey : items.keySet()) {
                if (items.get(itemKey).equals(item)) {
                    contains = true;
                    break;
                }
            }
            if (!contains) {
                // generate new name for an item
                newItemID = "item" + number;
                number++;
                items.put(newItemID, item);
            } else {
                for (String itemName : items.keySet()) {
                    if (items.get(itemName).equals(item)) {
                        newItemID = itemName;
                    }
                }
            }
            ch.getConfigs().get("events").getConfig().set(key,
                    (type + " " + newItemID + " " + amount + " " + conditions).trim());

            // replace event with updated version
            Debug.broadcast("Extracted " + newItemID + " from " + key + " event!");
        }
    }
    // check every condition (it's almost the same code, I didn't know how
    // to do
    // it better
    for (String key : ch.getConfigs().get("conditions").getConfig().getKeys(false)) {
        String instructions = ch.getString("conditions." + key);
        String[] parts = instructions.split(" ");
        String type = parts[0];
        // if this condition has items do the thing
        if (type.equals("hand") || type.equals("item")) {
            // define all variables
            String amount = "";
            String material = null;
            int data = 0;
            Map<String, Integer> enchants = new HashMap<>();
            List<String> lore = new ArrayList<>();
            String name = null;
            String inverted = "";
            // for every part check if it has some data and place it in
            // variables
            for (String part : parts) {
                if (part.contains("type:")) {
                    material = part.substring(5);
                } else if (part.contains("data:")) {
                    data = Byte.valueOf(part.substring(5));
                } else if (part.contains("enchants:")) {
                    for (String enchant : part.substring(9).split(",")) {
                        enchants.put(enchant.split(":")[0], Integer.decode(enchant.split(":")[1]));
                    }
                } else if (part.contains("lore:")) {
                    for (String loreLine : part.substring(5).split(";")) {
                        lore.add(loreLine.replaceAll("_", " "));
                    }
                } else if (part.contains("name:")) {
                    name = part.substring(5).replaceAll("_", " ");
                } else if (part.contains("amount:")) {
                    amount = part;
                } else if (part.equalsIgnoreCase("--inverted")) {
                    inverted = part;
                }
            }
            // create an item
            String newItemID = null;
            @SuppressWarnings("deprecation")
            QuestItem item = new QuestItem(material, data, enchants, name, lore);
            boolean contains = false;
            for (String itemKey : items.keySet()) {
                if (items.get(itemKey).equals(item)) {
                    contains = true;
                    break;
                }
            }
            if (!contains) {
                // generate new name for an item
                newItemID = "item" + number;
                number++;
                items.put(newItemID, item);
            } else {
                for (String itemName : items.keySet()) {
                    if (items.get(itemName).equals(item)) {
                        newItemID = itemName;
                    }
                }
            }
            ch.getConfigs().get("conditions").getConfig().set(key,
                    (type + " item:" + newItemID + " " + amount + " " + inverted).trim());
            Debug.broadcast("Extracted " + newItemID + " from " + key + " condition!");
        }
    }
    // generated all items, now place them in items.yml
    for (String key : items.keySet()) {
        QuestItem item = items.get(key);
        String instruction = item.getMaterial() + " data:" + item.getData();
        if (item.getName() != null) {
            instruction = instruction + " name:" + item.getName().replace(" ", "_");
        }
        if (item.getLore() != null && !item.getLore().isEmpty()) {
            StringBuilder lore = new StringBuilder();
            for (String line : item.getLore()) {
                lore.append(line + ";");
            }
            instruction = instruction + " lore:" + (lore.substring(0, lore.length() - 1).replace(" ", "_"));
        }
        if (item.getEnchants() != null && !item.getEnchants().isEmpty()) {
            StringBuilder enchants = new StringBuilder();
            for (Enchantment enchant : item.getEnchants().keySet()) {
                enchants.append(enchant.toString() + ":" + item.getEnchants().get(enchant) + ",");
            }
            instruction = instruction + " enchants:" + enchants.substring(0, enchants.length() - 1);
        }
        ch.getConfigs().get("items").getConfig().set(key, instruction);
    }
    ch.getConfigs().get("items").saveConfig();
    ch.getConfigs().get("events").saveConfig();
    ch.getConfigs().get("conditions").saveConfig();
    Debug.broadcast("All extracted items has been successfully saved to items.yml!");
    // end of updating to 1.4
    instance.getConfig().set("version", "1.4");
    Debug.broadcast("Conversion to v1.4 finished.");
    updateTo1_4_1();
}

From source file:lineage2.gameserver.model.Player.java

/**
 * Method restore./*from   www  .j a v a  2 s .c  o m*/
 * @param objectId int
 * @return Player
 */
public static Player restore(final int objectId) {
    Player player = null;
    Connection con = null;
    Statement statement = null;
    Statement statement2 = null;
    PreparedStatement statement3 = null;
    ResultSet rset = null;
    ResultSet rset2 = null;
    ResultSet rset3 = null;
    try {
        con = DatabaseFactory.getInstance().getConnection();
        statement = con.createStatement();
        statement2 = con.createStatement();
        rset = statement.executeQuery("SELECT * FROM `characters` WHERE `obj_Id`=" + objectId + " LIMIT 1");
        rset2 = statement2.executeQuery(
                "SELECT `class_id`, `default_class_id` FROM `character_subclasses` WHERE `char_obj_id`="
                        + objectId + " AND `type`=" + SubClassType.BASE_CLASS.ordinal() + " LIMIT 1");
        if (rset.next() && rset2.next()) {
            final ClassId classId = ClassId.VALUES[rset2.getInt("class_id")];
            final ClassId defaultClassId = ClassId.VALUES[rset2.getInt("default_class_id")];
            final PlayerTemplate template = PlayerTemplateHolder.getInstance()
                    .getPlayerTemplate(defaultClassId.getRace(), classId, Sex.VALUES[rset.getInt("sex")]);
            player = new Player(objectId, template);
            player.loadVariables();
            player.loadInstanceReuses();
            player.loadPremiumItemList();
            player.bookmarks.setCapacity(rset.getInt("bookmarks"));
            player.bookmarks.restore();
            player._friendList.restore();
            player._postFriends = CharacterPostFriendDAO.getInstance().select(player);
            CharacterGroupReuseDAO.getInstance().select(player);
            player._login = rset.getString("account_name");
            player.setName(rset.getString("char_name"));
            player.setFace(rset.getInt("face"));
            player.setHairStyle(rset.getInt("hairStyle"));
            player.setHairColor(rset.getInt("hairColor"));
            player.setHeading(0);
            player.setKarma(rset.getInt("karma"));
            player.setPvpKills(rset.getInt("pvpkills"));
            player.setPkKills(rset.getInt("pkkills"));
            player.setLeaveClanTime(rset.getLong("leaveclan") * 1000L);
            if ((player.getLeaveClanTime() > 0) && player.canJoinClan()) {
                player.setLeaveClanTime(0);
            }
            player.setDeleteClanTime(rset.getLong("deleteclan") * 1000L);
            if ((player.getDeleteClanTime() > 0) && player.canCreateClan()) {
                player.setDeleteClanTime(0);
            }
            player.setNoChannel(rset.getLong("nochannel") * 1000L);
            if ((player.getNoChannel() > 0) && (player.getNoChannelRemained() < 0)) {
                player.setNoChannel(0);
            }
            player.setOnlineTime(rset.getLong("onlinetime") * 1000L);
            final int clanId = rset.getInt("clanid");
            if (clanId > 0) {
                player.setClan(ClanTable.getInstance().getClan(clanId));
                player.setPledgeType(rset.getInt("pledge_type"));
                player.setPowerGrade(rset.getInt("pledge_rank"));
                player.setLvlJoinedAcademy(rset.getInt("lvl_joined_academy"));
                player.setApprentice(rset.getInt("apprentice"));
            }
            player.setCreateTime(rset.getLong("createtime") * 1000L);
            player.setDeleteTimer(rset.getInt("deletetime"));
            player.setTitle(rset.getString("title"));
            if (player.getVar("titlecolor") != null) {
                player.setTitleColor(Integer.decode("0x" + player.getVar("titlecolor")));
            }
            if (player.getVar("namecolor") == null) {
                if (player.isGM()) {
                    player.setNameColor(Config.GM_NAME_COLOUR);
                } else if ((player.getClan() != null)
                        && (player.getClan().getLeaderId() == player.getObjectId())) {
                    player.setNameColor(Config.CLANLEADER_NAME_COLOUR);
                } else {
                    player.setNameColor(Config.NORMAL_NAME_COLOUR);
                }
            } else {
                player.setNameColor(Integer.decode("0x" + player.getVar("namecolor")));
            }
            if (Config.AUTO_LOOT_INDIVIDUAL) {
                player._autoLoot = player.getVarB("AutoLoot", Config.AUTO_LOOT);
                player.AutoLootHerbs = player.getVarB("AutoLootHerbs", Config.AUTO_LOOT_HERBS);
            }
            player.setUptime(System.currentTimeMillis());
            player.setLastAccess(rset.getLong("lastAccess"));
            player.setRecomHave(rset.getInt("rec_have"));
            player.setRecomLeft(rset.getInt("rec_left"));
            player.setRecomBonusTime(rset.getInt("rec_bonus_time"));
            if (player.getVar("recLeftToday") != null) {
                player.setRecomLeftToday(Integer.parseInt(player.getVar("recLeftToday")));
            } else {
                player.setRecomLeftToday(0);
            }
            player.setKeyBindings(rset.getBytes("key_bindings"));
            player.setPcBangPoints(rset.getInt("pcBangPoints"));
            player.setFame(rset.getInt("fame"), null);
            player.restoreRecipeBook();
            if (Config.ENABLE_OLYMPIAD) {
                player.setHero(Hero.getInstance().isHero(player.getObjectId()));
                player.setNoble(Olympiad.isNoble(player.getObjectId()));
            }
            player.updatePledgeClass();
            int reflection = 0;
            if ((player.getVar("jailed") != null) && ((System.currentTimeMillis()
                    / 1000) < (Integer.parseInt(player.getVar("jailed")) + 60))) {
                player.setXYZ(-114648, -249384, -2984);
                player.sitDown(null);
                player.block();
                player._unjailTask = ThreadPoolManager.getInstance().schedule(new UnJailTask(player),
                        Integer.parseInt(player.getVar("jailed")) * 1000L);
            } else {
                player.setXYZ(rset.getInt("x"), rset.getInt("y"), rset.getInt("z"));
                String jumpSafeLoc = player.getVar("@safe_jump_loc");
                if (jumpSafeLoc != null) {
                    player.setLoc(Location.parseLoc(jumpSafeLoc));
                    player.unsetVar("@safe_jump_loc");
                }
                String ref = player.getVar("reflection");
                if (ref != null) {
                    reflection = Integer.parseInt(ref);
                    if (reflection > 0) {
                        String back = player.getVar("backCoords");
                        if (back != null) {
                            player.setLoc(Location.parseLoc(back));
                            player.unsetVar("backCoords");
                        }
                        reflection = 0;
                    }
                }
            }
            player.setReflection(reflection);
            EventHolder.getInstance().findEvent(player);
            Quest.restoreQuestStates(player);
            player.getSubClassList().restore();
            player.setActiveSubClass(player.getActiveClassId(), false, 0);
            player.restoreVitality();
            player.getInventory().restore();
            player._menteeMentorList.restore();
            try {
                String var = player.getVar("ExpandInventory");
                if (var != null) {
                    player.setExpandInventory(Integer.parseInt(var));
                }
            } catch (Exception e) {
                _log.error("", e);
            }
            try {
                String var = player.getVar("ExpandWarehouse");
                if (var != null) {
                    player.setExpandWarehouse(Integer.parseInt(var));
                }
            } catch (Exception e) {
                _log.error("", e);
            }
            try {
                String var = player.getVar(NO_ANIMATION_OF_CAST_VAR);
                if (var != null) {
                    player.setNotShowBuffAnim(Boolean.parseBoolean(var));
                }
            } catch (Exception e) {
                _log.error("", e);
            }
            try {
                String var = player.getVar(NO_TRADERS_VAR);
                if (var != null) {
                    player.setNotShowTraders(Boolean.parseBoolean(var));
                }
            } catch (Exception e) {
                _log.error("", e);
            }
            try {
                String var = player.getVar("pet");
                if (var != null) {
                    player.setPetControlItem(Integer.parseInt(var));
                }
            } catch (Exception e) {
                _log.error("", e);
            }
            statement3 = con.prepareStatement(
                    "SELECT obj_Id, char_name FROM characters WHERE account_name=? AND obj_Id!=?");
            statement3.setString(1, player._login);
            statement3.setInt(2, objectId);
            rset3 = statement3.executeQuery();
            while (rset3.next()) {
                final Integer charId = rset3.getInt("obj_Id");
                final String charName = rset3.getString("char_name");
                player._chars.put(charId, charName);
            }
            DbUtils.close(statement3, rset3);
            {
                List<Zone> zones = new ArrayList<Zone>();
                World.getZones(zones, player.getLoc(), player.getReflection());
                if (!zones.isEmpty()) {
                    for (Zone zone : zones) {
                        if (zone.getType() == ZoneType.no_restart) {
                            if (((System.currentTimeMillis() / 1000L) - player.getLastAccess()) > zone
                                    .getRestartTime()) {
                                player.sendMessage(new CustomMessage(
                                        "lineage2.gameserver.clientpackets.EnterWorld.TeleportedReasonNoRestart",
                                        player));
                                player.setLoc(TeleportUtils.getRestartLocation(player, RestartType.TO_VILLAGE));
                            }
                        } else if (zone.getType() == ZoneType.SIEGE) {
                            SiegeEvent<?, ?> siegeEvent = player.getEvent(SiegeEvent.class);
                            if (siegeEvent != null) {
                                player.setLoc(siegeEvent.getEnterLoc(player));
                            } else {
                                Residence r = ResidenceHolder.getInstance()
                                        .getResidence(zone.getParams().getInteger("residence"));
                                player.setLoc(r.getNotOwnerRestartPoint(player));
                            }
                        }
                    }
                }
                zones.clear();
            }
            player.restoreBlockList();
            player._macroses.restore();
            player.refreshExpertisePenalty();
            player.refreshOverloaded();
            player.getWarehouse().restore();
            player.getFreight().restore();
            player.restoreTradeList();
            if (player.getVar("storemode") != null) {
                player.setPrivateStoreType(Integer.parseInt(player.getVar("storemode")));
                player.setSitting(true);
            }
            player.updateKetraVarka();
            player.updateRam();
            player.checkRecom();
            player.restoreVitality();
            player.getSummonList().restore();
        }
    } catch (final Exception e) {
        _log.error("Could not restore char data!", e);
    } finally {
        DbUtils.closeQuietly(statement2, rset2);
        DbUtils.closeQuietly(statement3, rset3);
        DbUtils.closeQuietly(con, statement, rset);
    }
    return player;
}

From source file:com.xpn.xwiki.doc.XWikiDocument.java

/**
 * Adds multiple objects from an new objects creation form.
 * /*from www .j  a va2 s . c  o m*/
 * @since 2.2M2
 */
public List<BaseObject> addXObjectsFromRequest(DocumentReference classReference, String pref,
        XWikiContext context) throws XWikiException {
    @SuppressWarnings("unchecked")
    Map<String, String[]> map = context.getRequest().getParameterMap();
    List<Integer> objectsNumberDone = new ArrayList<Integer>();
    List<BaseObject> objects = new ArrayList<BaseObject>();
    String start = pref + this.localEntityReferenceSerializer.serialize(classReference) + "_";

    for (String name : map.keySet()) {
        if (name.startsWith(start)) {
            int pos = name.indexOf('_', start.length() + 1);
            String prefix = name.substring(0, pos);
            int num = Integer.decode(prefix.substring(prefix.lastIndexOf('_') + 1)).intValue();
            if (!objectsNumberDone.contains(Integer.valueOf(num))) {
                objectsNumberDone.add(Integer.valueOf(num));
                objects.add(addXObjectFromRequest(classReference, pref, num, context));
            }
        }
    }

    return objects;
}

From source file:com.xpn.xwiki.doc.XWikiDocument.java

/**
 * Adds multiple objects from an new objects creation form.
 * //from  w ww . j a va2s  . c o  m
 * @since 2.2.3
 */
public List<BaseObject> updateXObjectsFromRequest(EntityReference classReference, String pref,
        XWikiContext context) throws XWikiException {
    DocumentReference absoluteClassReference = resolveClassReference(classReference);
    @SuppressWarnings("unchecked")
    Map<String, String[]> map = context.getRequest().getParameterMap();
    List<Integer> objectsNumberDone = new ArrayList<Integer>();
    List<BaseObject> objects = new ArrayList<BaseObject>();
    String start = pref + this.localEntityReferenceSerializer.serialize(absoluteClassReference) + "_";

    for (String name : map.keySet()) {
        if (name.startsWith(start)) {
            int pos = name.indexOf('_', start.length() + 1);
            String prefix = name.substring(0, pos);
            int num = Integer.decode(prefix.substring(prefix.lastIndexOf('_') + 1)).intValue();
            if (!objectsNumberDone.contains(Integer.valueOf(num))) {
                objectsNumberDone.add(Integer.valueOf(num));
                objects.add(updateXObjectFromRequest(classReference, pref, num, context));
            }
        }
    }

    return objects;
}