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:de.juwimm.cms.remote.EditionServiceSpringImpl.java

private Integer getIntegerAttributeValue(Element ael, String attributeName) {
    String attribute = ael.getAttribute(attributeName);
    Integer retValue = null;//from w w w. j  av  a 2 s.  c om
    if (attribute != null && !attribute.isEmpty()) {
        try {
            retValue = Integer.decode(attribute);
        } catch (Exception e) {
            if (log.isInfoEnabled())
                log.info("getIntegerAttributeValue could not find value for key: " + attributeName);
        }
    }
    return retValue;
}

From source file:de.juwimm.cms.remote.EditionServiceSpringImpl.java

/**
 * @see de.juwimm.cms.remote.EditionServiceSpring#importDocumentsAndPictures(org.w3c.dom.Document, de.juwimm.cms.model.UnitHbm, boolean, java.io.File)
 *//*from  ww w  .  j  a  v a2s.  c  om*/
protected void importDocumentsAndPictures(org.w3c.dom.Document doc, UnitHbm ul, boolean useNewIds,
        File directory) throws Exception {
    if (log.isInfoEnabled())
        log.info("begin importDocumentsAndPictures");
    // if (!context.getRollbackOnly()) {
    try {
        SiteHbm site = getUserHbmDao().load(AuthenticationHelper.getUserName()).getActiveSite();
        Iterator itdocs = XercesHelper.findNodes(doc, "/edition/documents/document");
        Iterator itpics = XercesHelper.findNodes(doc, "/edition/pictures/picture");
        // end of parsing the document
        if ((itdocs != null && itdocs.hasNext()) || useNewIds) {
            if (log.isDebugEnabled())
                log.debug("DELETING DOCS");
            Collection docs = null;
            if (ul == null) {
                docs = getDocumentHbmDao().findAllPerSite(site.getSiteId());
            } else {
                docs = getDocumentHbmDao().findAll(ul.getUnitId());
            }
            Iterator it = docs.iterator();
            while (it.hasNext()) {
                de.juwimm.cms.model.DocumentHbm docl = (de.juwimm.cms.model.DocumentHbm) it.next();
                getDocumentHbmDao().remove(docl);
            }
            if (log.isDebugEnabled())
                log.debug("IMPORTING DOCS");
            while (itdocs.hasNext()) {
                Element el = (Element) itdocs.next();
                Integer id = new Integer(el.getAttribute("id"));
                String strDocName = XercesHelper.getNodeValue(el, "./name");
                String strMimeType = el.getAttribute("mimeType");
                int unitId = Integer.decode(el.getAttribute("unitId"));
                // byte[] file = Base64.decode(XercesHelper.getNodeValue(el, "./file"));
                File fle = new File(directory.getParent() + File.separator + "d" + id);
                byte[] file = new byte[(int) fle.length()];
                new FileInputStream(fle).read(file);
                fle.delete();

                if (useNewIds) {
                    de.juwimm.cms.model.DocumentHbm document = null;
                    if (ul == null) {
                        Integer oldUnitId = new Integer(el.getAttribute("unitId"));
                        Integer newUnitId = mappingUnits.get(oldUnitId);
                        UnitHbm unitForPic = getUnitHbmDao().load(newUnitId);

                        document = getDocumentHbmDao()
                                .create(createDocumentHbm(file, strDocName, strMimeType, null, unitForPic));
                    } else {
                        document = getDocumentHbmDao()
                                .create(createDocumentHbm(file, strDocName, strMimeType, null, ul));
                    }
                    mappingDocs.put(id, document.getDocumentId());
                } else {
                    if (ul == null) {
                        ul = getUnitHbmDao().load(unitId);
                    }
                    getDocumentHbmDao().create(createDocumentHbm(file, strDocName, strMimeType, id, ul));
                }
            }
        }
        System.gc();
        if ((itpics != null && itpics.hasNext()) || useNewIds) {
            if (log.isDebugEnabled())
                log.debug("DELETING PICS");
            Collection<PictureHbm> pics = null;
            if (ul == null) {
                pics = getPictureHbmDao().findAllPerSite(site.getSiteId());
            } else {
                pics = getPictureHbmDao().findAllPerUnit(ul.getUnitId());
            }
            getPictureHbmDao().remove(pics);

            if (log.isDebugEnabled())
                log.debug("IMPORTING PICS");
            while (itpics.hasNext()) {
                Element el = (Element) itpics.next();
                Integer id = new Integer(el.getAttribute("id"));
                String strMimeType = el.getAttribute("mimeType");
                String strPictureName = XercesHelper.getNodeValue(el, "./pictureName");
                String strAltText = XercesHelper.getNodeValue(el, "./altText");
                String title = XercesHelper.getNodeValue(el, "./title");

                File fle = new File(directory.getParent() + File.separator + "f" + id);
                byte[] file = new byte[(int) fle.length()];
                new FileInputStream(fle).read(file);
                fle.delete();

                File fleThumb = new File(directory.getParent() + File.separator + "t" + id);
                byte[] thumbnail = new byte[(int) fleThumb.length()];
                new FileInputStream(fleThumb).read(thumbnail);
                fleThumb.delete();

                byte[] preview = null;
                File flePreview = new File(directory.getParent() + File.separator + "p" + id);
                // not every picture may have a custom preview-image
                if (flePreview.exists() && flePreview.canRead()) {
                    preview = new byte[(int) flePreview.length()];
                    new FileInputStream(flePreview).read(preview);
                    flePreview.delete();
                }

                if (useNewIds) {
                    PictureHbm pic = null;
                    if (ul == null) {
                        Integer oldUnitId = new Integer(el.getAttribute("unitId"));
                        Integer newUnitId = mappingUnits.get(oldUnitId);
                        UnitHbm unitForPic = getUnitHbmDao().load(newUnitId);
                        pic = getPictureHbmDao().create(createPictureHbm(thumbnail, file, preview, strMimeType,
                                strAltText, title, strPictureName, null, unitForPic));
                    } else {
                        pic = getPictureHbmDao().create(createPictureHbm(thumbnail, file, preview, strMimeType,
                                strAltText, title, strPictureName, null, ul));
                    }
                    if (log.isDebugEnabled())
                        log.debug("mappingPics OLD " + id + " NEW " + pic.getPictureId());
                    mappingPics.put(id, pic.getPictureId());
                } else {
                    createPictureHbm(thumbnail, file, preview, strMimeType, strAltText, title, strPictureName,
                            id, ul);
                }
            }
        }
    } catch (Exception exe) {
        // here are only finder-exceptions thrown. Should not occure, so what to do with it?
        // context.setRollbackOnly();
        log.error("Error occured importDocumentsAndPictures", exe);
    }
    // }
    if (log.isInfoEnabled())
        log.info("end importDocumentsAndPictures");
}

From source file:lineage2.gameserver.Config.java

/**
 * Method loadOtherConfig./*w  w  w  .j  av a  2  s .c  o m*/
 */
public static void loadOtherConfig() {
    ExProperties otherSettings = load(OTHER_CONFIG_FILE);
    AWAKING_FREE = otherSettings.getProperty("AwakingFree", false);
    DEEPBLUE_DROP_RULES = otherSettings.getProperty("UseDeepBlueDropRules", true);
    DEEPBLUE_DROP_MAXDIFF = otherSettings.getProperty("DeepBlueDropMaxDiff", 8);
    DEEPBLUE_DROP_RAID_MAXDIFF = otherSettings.getProperty("DeepBlueDropRaidMaxDiff", 2);
    SWIMING_SPEED = otherSettings.getProperty("SwimingSpeedTemplate", 50);
    INVENTORY_MAXIMUM_NO_DWARF = otherSettings.getProperty("MaximumSlotsForNoDwarf", 80);
    INVENTORY_MAXIMUM_DWARF = otherSettings.getProperty("MaximumSlotsForDwarf", 100);
    INVENTORY_MAXIMUM_GM = otherSettings.getProperty("MaximumSlotsForGMPlayer", 250);
    QUEST_INVENTORY_MAXIMUM = otherSettings.getProperty("MaximumSlotsForQuests", 100);
    MULTISELL_SIZE = otherSettings.getProperty("MultisellPageSize", 10);
    WAREHOUSE_SLOTS_NO_DWARF = otherSettings.getProperty("BaseWarehouseSlotsForNoDwarf", 100);
    WAREHOUSE_SLOTS_DWARF = otherSettings.getProperty("BaseWarehouseSlotsForDwarf", 120);
    WAREHOUSE_SLOTS_CLAN = otherSettings.getProperty("MaximumWarehouseSlotsForClan", 200);
    FREIGHT_SLOTS = otherSettings.getProperty("MaximumFreightSlots", 10);
    SHOW_ENCHANT_EFFECT_RESULT = otherSettings.getProperty("ShowEnchantEffectResult", false);
    OVERENCHANT_LIMIT1 = otherSettings.getProperty("overEnchantLimit1", 3);
    OVERENCHANT_LIMIT2 = otherSettings.getProperty("overEnchantLimit2", 6);
    OVERENCHANT_LIMIT3 = otherSettings.getProperty("overEnchantLimit3", 9);
    OVERENCHANT_LIMIT4 = otherSettings.getProperty("overEnchantLimit4", 19);
    OVERENCHANT_MUL1 = otherSettings.getProperty("overEnchantMul1", 2);
    OVERENCHANT_MUL2 = otherSettings.getProperty("overEnchantMul2", 3);
    OVERENCHANT_MUL3 = otherSettings.getProperty("overEnchantMul3", 4);
    OVERENCHANT_MUL4 = otherSettings.getProperty("overEnchantMul4", 5);
    BLESSED_ARMOR_WEAPON_MUL = otherSettings.getProperty("blessedArmorWeaponMul", 1.5);
    REGEN_SIT_WAIT = otherSettings.getProperty("RegenSitWait", false);
    STARTING_ADENA = otherSettings.getProperty("StartingAdena", 0);
    STARTING_LEVEL = otherSettings.getProperty("StartingLevel", 1);
    UNSTUCK_SKILL = otherSettings.getProperty("UnstuckSkill", true);
    RESPAWN_RESTORE_CP = otherSettings.getProperty("RespawnRestoreCP", 0.) / 100;
    RESPAWN_RESTORE_HP = otherSettings.getProperty("RespawnRestoreHP", 65.) / 100;
    RESPAWN_RESTORE_MP = otherSettings.getProperty("RespawnRestoreMP", 0.) / 100;
    MAX_PVTSTORE_SLOTS_DWARF = otherSettings.getProperty("MaxPvtStoreSlotsDwarf", 5);
    MAX_PVTSTORE_SLOTS_OTHER = otherSettings.getProperty("MaxPvtStoreSlotsOther", 4);
    MAX_PVTCRAFT_SLOTS = otherSettings.getProperty("MaxPvtManufactureSlots", 20);
    SENDSTATUS_TRADE_JUST_OFFLINE = otherSettings.getProperty("SendStatusTradeJustOffline", false);
    SENDSTATUS_TRADE_MOD = otherSettings.getProperty("SendStatusTradeMod", 1.);
    ANNOUNCE_MAMMON_SPAWN = otherSettings.getProperty("AnnounceMammonSpawn", true);
    GM_NAME_COLOUR = Integer.decode("0x" + otherSettings.getProperty("GMNameColour", "FFFFFF"));
    GM_HERO_AURA = otherSettings.getProperty("GMHeroAura", false);
    NORMAL_NAME_COLOUR = Integer.decode("0x" + otherSettings.getProperty("NormalNameColour", "FFFFFF"));
    CLANLEADER_NAME_COLOUR = Integer.decode("0x" + otherSettings.getProperty("ClanleaderNameColour", "FFFFFF"));
    GAME_POINT_ITEM_ID = otherSettings.getProperty("GamePointItemId", -1);
    SAFE_ENCHANT_LVL = otherSettings.getProperty("SafeEnchant", 0);
    REMOVE_UNKNOWN_QUEST = otherSettings.getProperty("RemoveUnknownQuest", false);
    ALLOW_MENTOR_BUFFS_IN_OFFLINE_MODE = otherSettings.getProperty("AllowMentorBuffsInOfflineMode", false);
}

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

/**
 * Returns the label from some prompt response key.
 * //w  w w  . j av  a  2s . co  m
 * @param prompt A ChoicePrompt prompt.
 * 
 * @param key A choice key valid for the ChoicePrompt.
 * 
 * @return The choice's label value.
 * 
 * @throws DomainException Thrown if the prompt isn't a choice prompt, the 
 *                      'key' isn't a number, or the key is not a valid
 *                      choice for the prompt.
 */
private String getChoiceLabelFrom(final Prompt prompt, final String key) throws DomainException {

    Map<Integer, LabelValuePair> choices;
    if (prompt instanceof CustomChoicePrompt) {
        choices = ((CustomChoicePrompt) prompt).getAllChoices();
    } else if (prompt instanceof ChoicePrompt) {
        choices = ((ChoicePrompt) prompt).getChoices();
    } else {
        throw new DomainException("The prompt isn't a choice prompt.");
    }

    Integer keyInt;
    try {
        keyInt = Integer.decode(key);
    } catch (NumberFormatException e) {
        throw new DomainException("The key is not a number.", e);
    }

    LabelValuePair vlp = choices.get(keyInt);
    if (vlp == null) {
        throw new DomainException("The key is unknown.");
    } else {
        return vlp.getLabel();
    }
}

From source file:org.kchine.r.server.RListener.java

public static String[] Wait(String millisec) {
    try {/*from  ww  w. j  a  va 2s .c o  m*/
        Thread.sleep(Integer.decode(millisec));
        return new String[] { "OK" };
    } catch (Exception e) {
        e.printStackTrace();
        return new String[] { "NOK", convertToPrintCommand(PoolUtils.getStackTraceAsString(e)) };
    }
}

From source file:org.ramadda.util.Utils.java

/**
 * _more_//from  w ww  . j a  va 2  s .c om
 *
 * @param value _more_
 * @param dflt _more_
 *
 * @return _more_
 */
public static Color decodeColor(String value, Color dflt) {
    if (value == null) {
        return dflt;
    }
    value = value.trim();
    if (value.equals("null")) {
        return null;
    }
    String s = value;
    try {
        if (Pattern.matches(HEX_COLOR_PATTERN, s) && !s.startsWith("#")) {
            // add # so Integer will decode it properly
            s = "#" + s;
        }

        return new Color(Integer.decode(s).intValue());
    } catch (Exception e) {
        return COLORNAMES.get(value.toLowerCase());
    }
}

From source file:com.marklogic.contentpump.Command.java

static void applyBatchTxn(Configuration conf, CommandLine cmdline, int maxBatch) {
    String batchSize = cmdline.getOptionValue(BATCH_SIZE);
    int batch = MarkLogicConstants.DEFAULT_BATCH_SIZE > maxBatch ? maxBatch
            : MarkLogicConstants.DEFAULT_BATCH_SIZE;
    if (batchSize != null) {
        batch = Integer.decode(batchSize);
        if (batch > maxBatch) {
            LOG.warn("The setting for " + BATCH_SIZE + " is changed to " + maxBatch);
            batch = maxBatch;/*w w  w.  jav a2s .c om*/
        }
        conf.setInt(MarkLogicConstants.BATCH_SIZE, batch);
    }

    String txnSize = cmdline.getOptionValue(TRANSACTION_SIZE);
    if (txnSize != null) {
        int txn = Integer.decode(txnSize);
        if (txn * batch > MAX_TXN_SIZE) {
            txn = MAX_TXN_SIZE / batch;
            LOG.warn("The setting for " + TRANSACTION_SIZE + " is changed to " + txn);
        }
        conf.setInt(MarkLogicConstants.TXN_SIZE, txn);
    }
}

From source file:org.apache.hadoop.hive.ql.exec.Utilities.java

/**
 * Gets the default notification interval to send progress updates to the tracker. Useful for
 * operators that may not output data for a while.
 *
 * @param hconf//from   ww  w  .java2s  .  co  m
 * @return the interval in milliseconds
 */
public static int getDefaultNotificationInterval(Configuration hconf) {
    int notificationInterval;
    Integer expInterval = Integer.decode(hconf.get("mapred.tasktracker.expiry.interval"));

    if (expInterval != null) {
        notificationInterval = expInterval.intValue() / 2;
    } else {
        // 5 minutes
        notificationInterval = 5 * 60 * 1000;
    }
    return notificationInterval;
}

From source file:de.juwimm.cms.remote.ContentServiceSpringImpl.java

/**
 * Gets used documents and pictures/*from ww  w .ja va2 s . c  o  m*/
 * @param contentVersions - content versions where to find
 * @param withHistory - if true selects the history version also
 * @param documents - list of used documents
 * @param pictures - list of used pictures
 */
private void getUsedResourcesFromContentVersions(Map<ViewComponentHbm, List<ContentVersionHbm>> contentVersions,
        Map<Integer, ResourceUsageState> documents, Map<Integer, ResourceUsageState> pictures) {
    if (contentVersions == null || contentVersions.size() == 0) {
        return;
    }

    for (Entry<ViewComponentHbm, List<ContentVersionHbm>> contentVersionGroup : contentVersions.entrySet()) {
        Integer maxVersion = getMaxVersion(contentVersionGroup.getValue());
        for (ContentVersionHbm contentVersion : contentVersionGroup.getValue()) {
            String content = contentVersion.getText();
            ResourceUsageState state = null;
            Integer currentVersion = Integer.decode(contentVersion.getVersion());
            if (currentVersion < maxVersion) {
                state = ResourceUsageState.UsedInOlderVersions;
            } else if (currentVersion == maxVersion) {
                state = ResourceUsageState.Used;
            }
            if (content != null) {
                try {
                    Document domDocument = XercesHelper.string2Dom(content);
                    //tags from content that represent documents and pictures
                    getResourcesFromContentVersion(domDocument, state, documents, "document", "src");
                    getResourcesFromContentVersion(domDocument, state, pictures, "picture", "description");
                    getResourcesFromContentVersion(domDocument, state, pictures, "image", "src");
                } catch (Exception e) {
                    log.info("could not parse used ressources: " + e.getMessage());
                    if (log.isDebugEnabled())
                        log.debug("Parsing Error", e);
                }
            }
        }
    }
}

From source file:com.sun.honeycomb.adm.client.AdminClientImpl.java

/**
 * Direct all to fetch one and only one//from w ww .ja va2  s  . co m
 * node. Expects input in the form of
 * node-xxx (where xxx is 101-116)
 * or just the number alone (101 through 116)
 */
public HCNode getNode(byte cellId, String fru) throws MgmtException, ConnectException {
    String lowerName = fru.toLowerCase();

    if (lowerName.startsWith("node-")) {
        lowerName = lowerName.substring(5);
    }
    int nodeId = Integer.decode(lowerName).intValue();
    return getNode(cellId, nodeId);

}