Example usage for java.lang Long decode

List of usage examples for java.lang Long decode

Introduction

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

Prototype

public static Long decode(String nm) throws NumberFormatException 

Source Link

Document

Decodes a String into a Long .

Usage

From source file:org.apache.marmotta.commons.sesame.facading.util.FacadeUtils.java

/**
 * Transform a value passed as string to the base type (i.e. non-complex type) given as argument
 *
 * @param <T>/*  w  ww .ja  v a  2  s .  c om*/
 * @param value
 * @param returnType
 * @return
 * @throws IllegalArgumentException
 */
@SuppressWarnings("unchecked")
public static <T> T transformToBaseType(String value, Class<T> returnType) throws IllegalArgumentException {
    // transformation to appropriate primitive type
    /*
     * README: the "dirty" cast: "(T) x" instead of "returnType.cast(x)" is required since
     * .cast does not work for primitive types (int, double, float, etc...).
     * Somehow it results in a ClassCastException
     */
    if (Integer.class.equals(returnType) || int.class.equals(returnType)) {
        if (value == null) {
            return (T) (Integer) (0);
        }
        return (T) (Integer.decode(value));
    } else if (Long.class.equals(returnType) || long.class.equals(returnType)) {
        if (value == null) {
            return (T) (Long) (0L);
        }
        return (T) (Long.decode(value));
    } else if (Double.class.equals(returnType) || double.class.equals(returnType)) {
        if (value == null) {
            return (T) (Double) (0.0);
        }
        return (T) (Double.valueOf(value));
    } else if (Float.class.equals(returnType) || float.class.equals(returnType)) {
        if (value == null) {
            return (T) (Float) (0.0F);
        }
        return (T) (Float.valueOf(value));
    } else if (Byte.class.equals(returnType) || byte.class.equals(returnType)) {
        if (value == null) {
            return (T) (Byte) ((byte) 0);
        }
        return (T) (Byte.decode(value));
    } else if (Boolean.class.equals(returnType) || boolean.class.equals(returnType)) {
        return (T) (Boolean.valueOf(value));
    } else if (Character.class.equals(returnType) || char.class.equals(returnType)) {
        if (value == null) {
            if (Character.class.equals(returnType)) {
                return null;
            } else {
                return (T) new Character((char) 0);
            }
        } else if (value.length() > 0) {
            return (T) (Character) (value.charAt(0));
        } else {
            return null;
        }
    } else if (Locale.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            return returnType.cast(LocaleUtils.toLocale(value));
        }
    } else if (Date.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            try {
                return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value).toDate());
            } catch (final IllegalArgumentException e) {
                e.printStackTrace();
                return null;
            }
        }
    } else if (DateTime.class.equals(returnType)) {
        if (value == null) {
            return null;
        } else {
            try {
                return returnType.cast(ISODateTimeFormat.dateTimeParser().parseDateTime(value));
            } catch (final IllegalArgumentException e) {
                e.printStackTrace();
                return null;
            }
        }
    } else if (String.class.equals(returnType)) {
        return returnType.cast(value);
    } else {
        throw new IllegalArgumentException(
                "primitive type " + returnType.getName() + " not supported by transformation");
    }
}

From source file:org.apache.hadoop.hdfs.server.diskbalancer.TestDiskBalancerRPC.java

@Test
public void testgetDiskBalancerBandwidth() throws Exception {
    RpcTestHelper rpcTestHelper = new RpcTestHelper().invoke();
    DataNode dataNode = rpcTestHelper.getDataNode();
    String planHash = rpcTestHelper.getPlanHash();
    int planVersion = rpcTestHelper.getPlanVersion();
    NodePlan plan = rpcTestHelper.getPlan();

    dataNode.submitDiskBalancerPlan(planHash, planVersion, PLAN_FILE, plan.toJson(), false);
    String bandwidthString = dataNode.getDiskBalancerSetting(DiskBalancerConstants.DISKBALANCER_BANDWIDTH);
    long value = Long.decode(bandwidthString);
    Assert.assertEquals(10L, value);/*w  w  w .  j  a v  a2  s . c o  m*/
}

From source file:com.l2jfree.config.L2Properties.java

public long getLong(String name, long deflt) {
    String val = getProperty(name);
    if (val == null)
        return deflt;

    try {/*from   w w  w  . j  a  v a2  s  .  c o m*/
        return Long.decode(val);
    } catch (Exception e) {
        throw new IllegalArgumentException("Integer value required, but found: " + val);
    }
}

From source file:com.emergya.persistenceGeo.web.RestFoldersAdminController.java

/**
 * This method saves a folder related with a user
 * /*from   w ww  . j a v  a 2 s .c o  m*/
 * @param user
 */
@RequestMapping(value = "/persistenceGeo/saveFolder/{username}", method = RequestMethod.POST)
public @ResponseBody FolderDto saveFolder(@PathVariable String username, @RequestParam("name") String name,
        @RequestParam("enabled") String enabled, @RequestParam("isChannel") String isChannel,
        @RequestParam("isPlain") String isPlain,
        @RequestParam(value = "parentFolder", required = false) String parentFolder) {
    try {
        /*
         * //TODO: Secure with logged user String username = ((UserDetails)
         * SecurityContextHolder.getContext()
         * .getAuthentication().getPrincipal()).getUsername();
         */
        UserDto user = userAdminService.obtenerUsuario(username);
        if (StringUtils.isEmpty(parentFolder) || !StringUtils.isNumeric(parentFolder)) {
            FolderDto rootFolder = foldersAdminService.getRootFolder(user.getId());
            return saveFolderBy(name, enabled, isChannel, isPlain,
                    rootFolder != null ? rootFolder.getId() : null, user.getId(), null);
        } else {
            return saveFolderBy(name, enabled, isChannel, isPlain, Long.decode(parentFolder), user.getId(),
                    null);
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:com.emergya.persistenceGeo.web.RestLayersAdminController.java

/**
 * This method loads layers.json related with a user
 * // w  ww.  j a va  2s.c  om
 * @param username
 * 
 * @return JSON file with layers
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/persistenceGeo/loadLayersByGroup/{groupId}", produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> loadLayersByGroup(@PathVariable String groupId) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<LayerDto> layers = null;
    try {
        if (groupId != null && canAccess(Long.decode(groupId))) {
            layers = layerAdminService.getLayersByAuthority(Long.decode(groupId));
        } else {
            layers = ListUtils.EMPTY_LIST;
        }
        for (LayerDto layer : layers) {
            if (layer.getId() != null && layer.getData() != null) {
                loadedLayers.put(layer.getId(), layer.getData());
                layer.setData(null);
                layer.setServer_resource("rest/persistenceGeo/getLayerResource/" + layer.getId());
            }
        }
        result.put(SUCCESS, true);
    } catch (Exception e) {
        e.printStackTrace();
        result.put(SUCCESS, false);
    }

    result.put(RESULTS, layers.size());
    result.put(ROOT, layers);

    return result;
}

From source file:es.itecban.deployment.executionmanager.gui.swf.service.PlanLaunchManager.java

public ExecutionReportType getReportFromCodifiedPlanId(String planId) throws DatatypeConfigurationException {
    ExecutionReportType planReport = null;
    // the planId given is a concatenation of the name of the plan and the
    // startTime of the plan of the report
    String reportName = planId.substring(0, planId.lastIndexOf('|'));
    String calendarString = planId.substring(planId.lastIndexOf('|') + 1);
    long calendarMiliSecs = Long.decode(calendarString);
    GregorianCalendar gregCalendar = new GregorianCalendar();
    gregCalendar.setTimeInMillis(calendarMiliSecs);
    XMLGregorianCalendar xmlCalendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(gregCalendar);
    planReport = reportManager.findExecutionReportByPlanId(reportName, xmlCalendar);
    return planReport;
}

From source file:pt.webdetails.cda.cache.CacheScheduleManager.java

private void execute(IParameterProvider requestParams, OutputStream out) throws PluginHibernateException {
    Long id = Long.decode(requestParams.getParameter("id").toString());
    Session s = getHibernateSession();/* www  . ja v a2s.  c  o  m*/
    CachedQuery q = (CachedQuery) s.load(CachedQuery.class, id);

    if (q == null) {
        // Query doesn't exist or is not set for auto-caching
        return;
    }
    try {
        q.execute();
        q.updateNext();
        CacheActivator.reschedule(queue);
        out.write("{\"status\": \"ok\"}".getBytes(ENCODING));
    } catch (Exception ex) {
        logger.error(ex);
        try {
            out.write("{\"status\": \"error\"}".getBytes(ENCODING));
        } catch (Exception ex1) {
            logger.error(ex1);
        }
    } finally {
        s.beginTransaction();
        s.update(q);
        s.flush();
        s.getTransaction().commit();
        s.close();
    }
}

From source file:org.squale.squaleweb.applicationlayer.action.results.ReviewAction.java

/**
 * /* w w w  .  j  a va  2 s.co  m*/
 * @param pForm le formulaire
 * @param pRequest la requte
 * @return les paramtres
 */
private Object[] getParams(ActionForm pForm, HttpServletRequest pRequest) {
    ActionErrors errors = new ActionErrors();
    Object[] paramIn = null;
    ParamReviewForm currentForm = (ParamReviewForm) pForm;
    int index = 0;
    int nbDays = currentForm.getNbDays();
    String tre = currentForm.getTre();
    String ruleId = currentForm.getRuleId();
    String componentId = currentForm.getComponentId();

    ComponentDTO comp = new ComponentDTO();
    comp.setID(Long.decode(componentId).longValue());
    Date date = null;
    // Conversion en une date
    if (nbDays > 0) {
        GregorianCalendar gc = new GregorianCalendar();
        gc.add(Calendar.DATE, -nbDays);
        date = gc.getTime();
    }
    String treLabel = WebMessages.getString(pRequest, tre);
    if (ruleId.length() > 0) {
        paramIn = new Object[] { comp, tre, treLabel, date, Long.decode(ruleId) };
    } else {
        paramIn = new Object[] { comp, tre, treLabel, date, null };
    }
    return paramIn;
}

From source file:org.jbpm.formModeler.core.processing.fieldHandlers.multipleSubform.SubFormSendHandler.java

public void actionDeleteItem(CommandRequest request) throws Exception {
    String[] uids = request.getRequestObject().getParameterValues("child_uid_value");
    String uid = "";
    if (uids != null) {
        for (int i = 0; i < uids.length; i++) {
            if (uids[i] != null && !"".equals(uids[i]))
                uid = uids[i];/*from   w  w  w. j  a  v  a  2 s .c o  m*/
        }
    }
    String sIndex = request.getParameter(uid + "_index");
    String parentFormId = request.getParameter(uid + "_parentFormId");
    String parentNamespace = request.getParameter(uid + "_parentNamespace");
    String fieldName = request.getParameter(uid + "_field");
    String inputName = request.getParameter(uid + "_inputName");

    Form parentForm = subformFinderService.getFormById(Long.decode(parentFormId), parentNamespace);

    getFormProcessor().setValues(parentForm, parentNamespace, request.getRequestObject().getParameterMap(),
            request.getFilesByParamName());
    Field field = parentForm.getField(fieldName);
    FieldHandler handler = getFieldHandlersManager().getHandler(field.getFieldType());
    if (handler instanceof CreateDynamicObjectFieldHandler) {
        CreateDynamicObjectFieldHandler fHandler = (CreateDynamicObjectFieldHandler) handler;
        int index = Integer.decode(sIndex).intValue();
        Object deletedResultValue = fHandler.deleteElementInPosition(parentForm, parentNamespace, fieldName,
                index);

        List<Integer> removedValues = helper.getRemovedFieldPositions(inputName);

        if (removedValues == null)
            helper.setRemovedFieldPositions(inputName, (removedValues = new ArrayList<Integer>()));

        removedValues.add(index);

        getFormProcessor().modify(parentForm, parentNamespace, fieldName, deletedResultValue);
    } else {
        log.error("Cannot delete value in a field which is not a CreateDynamicObjectFieldHandler.");
    }
    getFormProcessor().clearFieldErrors(parentForm, parentNamespace);
}

From source file:com.l2jfree.gameserver.templates.StatsSet.java

/**
 * Returns the long associated to the key put in parameter ("name").
 * /*from w ww .j  av a2s  .  co  m*/
 * @param name : String designating the key in the set
 * @return long : value associated to the key
 */
public final long getLong(String name) {
    Object val = get(name);
    if (val == null)
        throw new IllegalArgumentException("Integer value required, but not specified");
    if (val instanceof Number)
        return ((Number) val).longValue();
    try {
        return Long.decode((String) val);
    } catch (Exception e) {
        throw new IllegalArgumentException("Integer value required, but found: " + val);
    }
}