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:fr.gael.dhus.olingo.v1.V1Processor.java

@Override
public ODataResponse updateEntity(PutMergePatchUriInfo uri_info, InputStream content, String rq_content_type,
        boolean merge, String content_type) throws ODataException {
    EntityProviderReadProperties properties = EntityProviderReadProperties.init().mergeSemantic(merge).build();
    ODataEntry entry = EntityProvider.readEntry(rq_content_type, uri_info.getStartEntitySet(), content,
            properties);//from  w  ww . j av a 2  s.  co m

    fr.gael.dhus.database.object.User current_user = ApplicationContextProvider.getBean(SecurityService.class)
            .getCurrentUser();

    EdmEntityType target_et = uri_info.getTargetEntitySet().getEntityType();
    try {
        String target_entity = target_et.getName();
        if (target_entity.equals(V1Model.SYNCHRONIZER.getEntityName())) {
            if (V1Model.SYNCHRONIZER.isAuthorized(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                Synchronizer s = new Synchronizer(key);
                s.updateFromEntry(entry);
            } else {
                throw new ODataException("You are not authorized to update a product synchronizer");
            }
        } else if (target_entity.equals(V1Model.USER.getEntityName())) {
            String key = uri_info.getKeyPredicates().get(0).getLiteral();
            User u = new User(key);
            if (u.isAuthorize(current_user)) {
                u.updateFromEntry(entry);
            } else {
                throw new ODataException("You are not authorized to update this user");
            }
        } else if (target_entity.equals(V1Model.USER_SYNCHRONIZER.getEntityName())) {
            if (V1Model.USER_SYNCHRONIZER.isAuthorized(current_user)) {
                long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
                UserSynchronizer s = new UserSynchronizer(key);
                s.updateFromEntry(entry);
            } else {
                throw new ODataException("You are not authorized to update a user synchronizer");
            }
        } else {
            throw new ODataException("Given EntitySet is not writable");
        }
    } catch (NullPointerException e) {
        return ODataResponse.status(HttpStatusCodes.NOT_FOUND).build();
    }

    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
}

From source file:org.ohmage.validator.SurveyResponseValidators.java

/**
 * Validates the number of survey responses to skip.
 * /*ww w  .  j av  a 2  s . co m*/
 * @param surveyResponsesToSkip The value to be validated.
 * 
 * @return The number of rows to skip as given by the user or the default
 *          value 0.
 * 
 * @throws ValidationException Thrown if the value cannot be parsed or is
 *                         negative.
 */
public static long validateNumSurveyResponsesToSkip(final String surveyResponsesToSkip)
        throws ValidationException {

    if (StringUtils.isEmptyOrWhitespaceOnly(surveyResponsesToSkip)) {
        return 0;
    }

    try {
        long value = Long.decode(surveyResponsesToSkip);

        if (value < 0) {
            throw new ValidationException(ErrorCode.SERVER_INVALID_NUM_TO_SKIP,
                    "The number of survy responses cannot be negative: " + value);
        }

        return value;
    } catch (NumberFormatException e) {
        throw new ValidationException(ErrorCode.SERVER_INVALID_NUM_TO_SKIP,
                "The number of survey responses to skip was not a number.", e);
    }
}

From source file:org.ohmage.validator.SurveyResponseValidators.java

/**
 * Validates the number of survey responses to process.
 * //from   w  w w. j a v a2s.com
 * @param surveyResponsesToProcess The value to be validated.
 * 
 * @param limit The maximum allowed value.
 * 
 * @return The number of rows to analyze as given by the user or the 
 *          default value which is the parameterized limit.
 * 
 * @throws ValidationException Thrown if the value cannot be parsed.
 */
public static long validateNumSurveyResponsesToProcess(final String surveyResponsesToProcess, final long limit)
        throws ValidationException {

    if (StringUtils.isEmptyOrWhitespaceOnly(surveyResponsesToProcess)) {
        return limit;
    }

    try {
        long value = Long.decode(surveyResponsesToProcess);

        if (value > limit) {
            throw new ValidationException(ErrorCode.SERVER_INVALID_NUM_TO_RETURN,
                    "The number of survey responses to process was larger than the limit: " + limit);
        }

        return value;
    } catch (NumberFormatException e) {
        throw new ValidationException(ErrorCode.SERVER_INVALID_NUM_TO_RETURN,
                "The number of survey responses to process was not a number.", e);
    }
}

From source file:org.simplx.args.MainArgs.java

/**
 * Returns the argument of the given {@code long} option from the command
 * line. If the option is not specified, return {@code defaultValue}. The
 * number is parsed according to {@link Long#decode(String)}, except that a
 * leading plus sign is accepted.//from  w ww .  j  av a 2  s  .  co m
 *
 * @param option       The option specification.
 * @param defaultValue The value to return if the option is not specified.
 * @param doc          Usage documentation for the option (@see {@link
 *                     #getString(String,String,String...)} getString}).
 *
 * @return The value for the option, or {@code defaultValue}.
 *
 * @throws NumberFormatException The argument is not a valid number.
 * @throws CommandLineException  No argument was present.
 */
public long getLong(String option, long defaultValue, String... doc)
        throws CommandLineException, NumberFormatException {

    String str = getArgument(option, "long", doc);
    try {
        if (str == null) {
            return defaultValue;
        }
        // ignore leading plus
        if (str.length() > 0 && str.charAt(0) == '+') {
            str = str.substring(1);
        }
        return Long.decode(str);
    } catch (NumberFormatException e) {
        throw numException(e, option);
    }
}

From source file:fr.gael.dhus.olingo.v1.V1Processor.java

@Override
public ODataResponse deleteEntity(DeleteUriInfo uri_info, String content_type) throws ODataException {
    fr.gael.dhus.database.object.User current_user = ApplicationContextProvider.getBean(SecurityService.class)
            .getCurrentUser();/* ww w.j a v  a 2 s .co  m*/

    EdmEntityType target_et = uri_info.getTargetEntitySet().getEntityType();
    String target_name = target_et.getName();
    if (target_name.equals(V1Model.SYNCHRONIZER.getEntityName())) {
        if (V1Model.SYNCHRONIZER.isAuthorized(current_user)) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Synchronizer.delete(key);
        } else {
            throw new ODataException("You are not authorized to delete a product synchronizer");
        }
    } else if (target_name.equals(V1Model.USER_SYNCHRONIZER.getEntityName())) {
        if (V1Model.USER_SYNCHRONIZER.isAuthorized(current_user)) {
            long key = Long.decode(uri_info.getKeyPredicates().get(0).getLiteral());
            Synchronizer.delete(key); // using the same method to delete
        } else {
            throw new ODataException("You are not authorized to delete a user synchronizer");
        }
    } else {
        throw new ODataException("Given EntitySet is not writable");
    }

    return ODataResponse.status(HttpStatusCodes.NO_CONTENT).build();
}

From source file:org.catechis.Stats.java

/**
*This method should be private except for testing.
*//*from  w ww  .j a  v a2 s.c  o  m*/
public void updateWritingROF(long date_delta, int int_level) {
    if (int_level > (allowed_number_of_levels - 1)) {
        int_level = (allowed_number_of_levels - 1);
    }
    String w_rof_m = (String) w_rof_milliseconds.get(int_level);
    if (w_rof_m.equals("0")) {
        // THIS SHOULD BE THE FIRST TIME TRHU, SO VALUES ARE 0
        //log.add("--- writing rof set for level "+int_level+" milliseconds "+date_delta);
        w_rof_milliseconds.set(int_level, Long.toString(date_delta));
        w_rof_running_count.set(int_level, "0");
    } else {
        try {
            long old_milliseconds = Long.decode(w_rof_m).longValue();
            long new_milliseconds = date_delta + old_milliseconds;
            int old_running_count = Integer.parseInt((String) w_rof_running_count.get(int_level));
            int new_running_count = old_running_count + 1;
            w_rof_milliseconds.set(int_level, Long.toString(new_milliseconds));
            w_rof_running_count.set(int_level, Integer.toString(new_running_count));
            //log.add("--- writing updated "+w_rof_m+" + "+date_delta+" = "+new_milliseconds+" rc "+new_running_count);
        } catch (java.lang.NumberFormatException nfe) {
            // got: Error For input string: "-2177145000" with long old_milliseconds = Long.decode(w_rof_m).longValue();
            //Should really do this in the if statement above
            //log.add("--- writing nfe");
            w_rof_milliseconds.set(int_level, Long.toString(date_delta));
            w_rof_running_count.set(int_level, "0");
        }
    }
}

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

/**
 * This method saves a layer related with a user
 * //from  w  ww  .  j  av a2 s.c  o m
 * @param username
 * @param uploadfile
 */
@RequestMapping(value = "/persistenceGeo/saveLayerByGroup/{idGroup}", method = RequestMethod.POST)
public @ResponseBody LayerDto saveLayerByGroup(@PathVariable String idGroup, @RequestParam("name") String name,
        @RequestParam("type") String type,
        @RequestParam(value = "properties", required = false) String properties,
        @RequestParam(value = "enabled", required = false) String enabled,
        @RequestParam(value = "order_layer", required = false) String order_layer,
        @RequestParam(value = "is_channel", required = false) String is_channel,
        @RequestParam(value = "publicized", required = false) String publicized,
        @RequestParam(value = "server_resource", required = false) String server_resource,
        @RequestParam(value = "folderId", required = false) String folderId,
        @RequestParam(value = "idFile", required = false) String idFile) {
    try {
        /*
        //TODO: Secure with logged user
        String username = ((UserDetails) SecurityContextHolder.getContext()
              .getAuthentication().getPrincipal()).getUsername(); 
         */
        // Create the layerDto
        LayerDto layer = new LayerDto();
        // Assign the user group
        AuthorityDto group = userAdminService.obtenerGrupoUsuarios(Long.decode(idGroup));
        layer.setAuthId(group.getId());

        //Copy layerData
        layer = copyDataToLayer(name, type, properties, enabled, order_layer, is_channel, publicized,
                server_resource, idFile, layer, folderId, true);

        return layer;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.catechis.Stats.java

/**
*This method should be private except for testing.
*///from w  ww  .  ja va 2  s. c  o m
public void updateReadingROF(long date_delta, int int_level) {
    String r_rof_m = (String) r_rof_milliseconds.get(int_level);
    if (r_rof_m.equals("0")) {
        // THIS SHOULD BE THE FIRST TIME TRHU, SO VALUES ARE 0
        //log.add("--- reading rof set for level "+int_level+" milliseconds "+date_delta);
        r_rof_milliseconds.set(int_level, Long.toString(date_delta));
        r_rof_running_count.set(int_level, "0");
    } else {
        try {
            long old_milliseconds = Long.decode(r_rof_m).longValue();
            ;
            long new_milliseconds = (date_delta + old_milliseconds);
            int old_running_count = Integer.parseInt((String) r_rof_running_count.get(int_level));
            int new_running_count = old_running_count + 1;
            r_rof_milliseconds.set(int_level, Long.toString(new_milliseconds));
            r_rof_running_count.set(int_level, Integer.toString(new_running_count));
            //log.add("--- reading updated level "+int_level+" rc "+new_running_count+" - "+r_rof_m+" + "+date_delta+" = "+new_milliseconds);

        } catch (java.lang.NumberFormatException nfe) {
            // got: Error For input string: "-2177145000" with long old_milliseconds = Long.decode(w_rof_m).longValue();
            //Should really do this in the if statement above
            //log.add("--- writing nfe ");
            r_rof_milliseconds.set(int_level, Long.toString(date_delta));
            r_rof_running_count.set(int_level, "0");
        }
    }
}

From source file:org.apache.catalina.core.NamingContextListener.java

/**
 * Set the specified environment entries in the naming context.
 *///w w  w  .  j av a  2 s. c o m
public void addEnvironment(ContextEnvironment env) {

    Object value = null;
    // Instantiating a new instance of the correct object type, and
    // initializing it.
    String type = env.getType();
    try {
        if (type.equals("java.lang.String")) {
            value = env.getValue();
        } else if (type.equals("java.lang.Byte")) {
            if (env.getValue() == null) {
                value = new Byte((byte) 0);
            } else {
                value = Byte.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Short")) {
            if (env.getValue() == null) {
                value = new Short((short) 0);
            } else {
                value = Short.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Integer")) {
            if (env.getValue() == null) {
                value = new Integer(0);
            } else {
                value = Integer.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Long")) {
            if (env.getValue() == null) {
                value = new Long(0);
            } else {
                value = Long.decode(env.getValue());
            }
        } else if (type.equals("java.lang.Boolean")) {
            value = Boolean.valueOf(env.getValue());
        } else if (type.equals("java.lang.Double")) {
            if (env.getValue() == null) {
                value = new Double(0);
            } else {
                value = Double.valueOf(env.getValue());
            }
        } else if (type.equals("java.lang.Float")) {
            if (env.getValue() == null) {
                value = new Float(0);
            } else {
                value = Float.valueOf(env.getValue());
            }
        } else if (type.equals("java.lang.Character")) {
            if (env.getValue() == null) {
                value = new Character((char) 0);
            } else {
                if (env.getValue().length() == 1) {
                    value = new Character(env.getValue().charAt(0));
                } else {
                    throw new IllegalArgumentException();
                }
            }
        } else {
            log(sm.getString("naming.invalidEnvEntryType", env.getName()));
        }
    } catch (NumberFormatException e) {
        log(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    } catch (IllegalArgumentException e) {
        log(sm.getString("naming.invalidEnvEntryValue", env.getName()));
    }

    // Binding the object to the appropriate name
    if (value != null) {
        try {
            if (debug >= 2)
                log("  Adding environment entry " + env.getName());
            createSubcontexts(envCtx, env.getName());
            envCtx.bind(env.getName(), value);
        } catch (NamingException e) {
            log(sm.getString("naming.invalidEnvEntryValue", e));
        }
    }

}

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

/**
 * Copy layer data /*  w  w w  . j a  va 2 s .  c o m*/
 * 
 * @param name
 * @param type
 * @param properties
 * @param enabled
 * @param order_layer
 * @param is_channel
 * @param publicized
 * @param server_resource
 * @param uploadfile
 * @param layer
 * @param update
 * 
 * @throws IOException
 */
private LayerDto copyDataToLayer(String name, String type, String properties, String enabled,
        String order_layer, String is_channel, String publicized, String server_resource, String idFile,
        LayerDto layer, String folderId, Boolean update) {
    // Add request parameter
    layer.setName(name);
    layer.setType(type);
    layer.setServer_resource(server_resource);
    layer.setEnabled(enabled != null ? enabled.toLowerCase().equals("true") : false);
    layer.setOrder(order_layer);
    layer.setPertenece_a_canal(is_channel != null ? is_channel.toLowerCase().equals("true") : false);
    layer.setPublicized(publicized != null ? publicized.toLowerCase().equals("true") : false);
    //Folder id
    if (!StringUtils.isEmpty(folderId) && StringUtils.isNumeric(folderId)) {
        layer.setFolderId(Long.decode(folderId));
    }

    // Layer properties
    if (properties != null) {
        layer.setProperties(getMapFromString(properties));
    }

    //Only if a file has been saved
    if (idFile != null) {
        File temp = loadFiles.get(Long.decode(idFile));
        // Layer data
        if (temp != null) {
            layer.setData(temp);
        }
    }

    // Save the layer
    if (update != null) {
        if (update) {
            layer = (LayerDto) layerAdminService.update(layer);
        } else {
            layer = (LayerDto) layerAdminService.create(layer);
        }
    } else {
        // temp layer
        loadedLayers.put(Long.decode(idFile), layer.getData());
        layer.setData(null);
        layer.setServer_resource("rest/persistenceGeo/getLayerResource/" + idFile);
    }

    if (layer.getId() != null && layer.getData() != null) {
        // 
        loadedLayers.put(layer.getId(), layer.getData());
        layer.setData(null);
        layer.setServer_resource("rest/persistenceGeo/getLayerResource/" + layer.getId());
    }

    if (idFile != null && loadFiles.containsKey(idFile)) {
        loadFiles.remove(idFile);
    }

    return layer;
}