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:com.emergya.persistenceGeo.web.RestFoldersAdminController.java

/**
 * This method loads layers.json related with a folder
 * //from  w w  w.  j  a  v a 2 s  .c  o  m
 * @param username
 * 
 * @return JSON file with layers
 */
@RequestMapping(value = "/persistenceGeo/moveFolderTo", method = RequestMethod.POST, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> moveFolderTo(@RequestParam("folderId") String folderId,
        @RequestParam("toFolder") String toFolder,
        @RequestParam(value = "toOrder", required = false) String toOrder) {
    Map<String, Object> result = new HashMap<String, Object>();
    FolderDto folder = null;
    try {
        /*
         * //TODO: Secure with logged user String username = ((UserDetails)
         * SecurityContextHolder.getContext()
         * .getAuthentication().getPrincipal()).getUsername();
         */
        Long idFolder = Long.decode(folderId);
        folder = (FolderDto) foldersAdminService.getById(idFolder);
        folder.setIdParent(Long.decode(toFolder));
        if (toOrder != null) {
            folder.setOrder(Integer.decode(toOrder));
        }
        folder = (FolderDto) foldersAdminService.update(folder);

        result.put(SUCCESS, true);
    } catch (Exception e) {
        e.printStackTrace();
        result.put(SUCCESS, false);
    }

    result.put(RESULTS, folder != null ? 1 : 0);
    result.put(ROOT, folder);

    return result;
}

From source file:org.videolan.vlc.gui.JumpToTimeFragment.java

private void updateValue(int delta, int resId) {
    int max = 59;
    long length = mLibVLC.getLength();
    EditText edit = null;//from   w w w  .ja  v  a  2  s.c om
    switch (resId) {
    case R.id.jump_hours:
        edit = mHours;
        if (length < 59 * HOURS_IN_MILLIS)
            max = (int) (length / HOURS_IN_MILLIS);
        break;
    case R.id.jump_minutes:
        edit = mMinutes;
        length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
        if (length < 59 * MINUTES_IN_MILLIS)
            max = (int) (length / MINUTES_IN_MILLIS);
        break;
    case R.id.jump_seconds:
        length -= Long.decode(mHours.getText().toString()).longValue() * HOURS_IN_MILLIS;
        length -= Long.decode(mMinutes.getText().toString()).longValue() * MINUTES_IN_MILLIS;
        if (length < 59000)
            max = (int) (length / 1000);
        edit = mSeconds;
    }
    if (edit != null) {
        int value = Integer.parseInt(edit.getText().toString()) + delta;
        if (value < 0)
            value = max;
        else if (value > max)
            value = 0;
        edit.setText(String.format("%02d", value));
    }
}

From source file:ar.com.qbe.siniestros.model.utils.MimeMagic.MagicMatch.java

/**
 * set the bitmask that will be applied for this magic match
 *
 * @param value DOCUMENT ME!//from   www  .j av  a 2s . c o  m
 */
public void setBitmask(String value) {
    if (value != null) {
        this.bitmask = Long.decode(value).intValue();
    }
}

From source file:com.yahoo.pulsar.common.naming.NamespaceBundleFactory.java

public NamespaceBundles getBundles(NamespaceName nsname, BundlesData bundleData) {
    long[] partitions;
    if (bundleData == null) {
        partitions = new long[] { Long.decode(FIRST_BOUNDARY), Long.decode(LAST_BOUNDARY) };
    } else {/*from w  w  w.  ja va  2s . co  m*/
        partitions = new long[bundleData.boundaries.size()];
        for (int i = 0; i < bundleData.boundaries.size(); i++) {
            partitions[i] = Long.decode(bundleData.boundaries.get(i));
        }
    }
    return new NamespaceBundles(nsname, partitions, this);
}

From source file:org.jaxygen.typeconverter.util.BeanUtil.java

/**
 * Method goes through bean getters, and check if the returned value matches
 * the validator passed in {\link StringPropertyValidator} or {\link
 * NumberPropertyValidator} Method check all methods which returns primitive
 * type, Long or Integer or a bean class annotated but the {link Validable}
 * annotation type and does not takes any argument.
 *
 * @param bean Bean under validation.//from   w ww .  ja  v a 2s  .c  o m
 * @throws InvocationTargetException .
 * @throws IllegalAccessException .
 * @throws IllegalArgumentException .
 * @throws InvalidPropertyFormat .
 */
public static void validateBean(Object bean) throws IllegalArgumentException, IllegalAccessException,
        InvocationTargetException, InvalidPropertyFormat {

    Method[] getters = bean.getClass().getMethods();
    for (Method m : getters) {
        if (m.getName().startsWith("get") && m.getParameterTypes().length == 0 && m.getReturnType() != null) {
            if ((m.getReturnType().isPrimitive() || m.getReturnType().equals(Long.class)
                    || m.getReturnType().equals(Integer.class) || m.getReturnType().equals(String.class))) {
                StringPropertyValidator sp = m.getAnnotation(StringPropertyValidator.class);
                NumberPropertyValidator np = m.getAnnotation(NumberPropertyValidator.class);
                Object rc = m.invoke(bean);
                String propertyName = m.getName().substring(3);
                if (sp != null) {
                    if (rc == null) {
                        throw new InvalidPropertyFormat("Property " + propertyName + " must be set");
                    }
                    String v = rc.toString();
                    if (sp.maximalLength() < v.length()) {
                        throw new InvalidPropertyFormat("Property " + propertyName
                                + " is to long. Maximal length is " + sp.maximalLength());
                    }
                    if (sp.minimalLength() > v.length()) {
                        throw new InvalidPropertyFormat("Property " + propertyName
                                + " is to short. Minimal length is " + sp.minimalLength());
                    }
                    if (sp.regex().length() > 0) {
                        if (Pattern.matches(sp.regex(), v) == false) {
                            throw new InvalidPropertyFormat(
                                    "Property " + propertyName + " not match regular expression:" + sp.regex());
                        }
                    }
                }
                if (np != null) {
                    Long v = Long.decode(rc.toString());
                    if (v > np.maxValue()) {
                        throw new InvalidPropertyFormat("Property " + propertyName
                                + " value is to big. Maximal value is " + np.maxValue());
                    }
                    if (v < np.minValue()) {
                        throw new InvalidPropertyFormat("Property " + propertyName
                                + " value is to low. Minimal value is " + np.minValue());
                    }
                }
            }
        } else if (m.getReturnType().isAnnotationPresent(Validable.class)) {
            Object rc = m.invoke(bean);
            if (rc != null) {
                validateBean(rc);
            }
        }
    }

}

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

/**
 * Validates that the duration is a valid number and that it is not too 
 * large. The largeness restriction is based on the multiplier used to
 * convert this value to its internal milliseconds representation.
 * /*  w w  w  .j av  a  2s .  c o  m*/
 * @param duration The duration to be validated.
 * 
 * @return The duration as a long value or null if the duration was null or
 *          an empty string.
 * 
 * @throws ValidationException Thrown if there is an error.
 */
public static Long validateChunkDuration(final String duration) throws ValidationException {

    LOGGER.info("Validating the chunk duration.");

    if (StringUtils.isEmptyOrWhitespaceOnly(duration)) {
        return null;
    }

    try {
        Long longDuration = Long.decode(duration);

        if (longDuration > (Long.MAX_VALUE / CHUNK_DURATION_MULTIPLIER)) {
            throw new ValidationException(ErrorCode.MOBILITY_INVALID_CHUNK_DURATION,
                    "The chunk duration is too great. It can be at most "
                            + (Long.MAX_VALUE / CHUNK_DURATION_MULTIPLIER));
        }

        return longDuration * CHUNK_DURATION_MULTIPLIER;
    } catch (NumberFormatException e) {
        throw new ValidationException(ErrorCode.MOBILITY_INVALID_CHUNK_DURATION,
                "The chunk duration is invalid: " + duration);
    }
}

From source file:uni.bielefeld.cmg.sparkhit.hadoop.decodec.util.Parameter.java

public DefaultParam importCommandLine() {

    /* Assigning Parameter ID to an ascending number */
    putParameterID();/*  w w w .jav  a  2s  .  c om*/

    /* Assigning parameter descriptions to each parameter ID */
    addParameterInfo();

    /* need a Object parser of PosixParser class for the function parse of CommandLine class */
    PosixParser parser = new PosixParser();

    /* print out help information */
    HelpParam help = new HelpParam(parameter, parameterMap);

    /* check each parameter for assignment */
    try {
        long input_limit = -1;
        int threads = Runtime.getRuntime().availableProcessors();

        /* Set Object cl of CommandLine class for Parameter storage */
        CommandLine cl = parser.parse(parameter, arguments, true);
        if (cl.hasOption(HELP)) {
            help.printHelp();
            System.exit(0);
        }

        if (cl.hasOption(HELP2)) {
            help.printHelp();
            System.exit(0);
        }

        if (cl.hasOption(VERSION)) {
            System.exit(0);
        }

        /* Checking all parameters */

        String value;

        if ((value = cl.getOptionValue(INPUT_BZ2)) != null) {
            param.inputFqPath = value;
            param.bz2 = true;
        }

        /* not applicable for HDFS and S3 */
        /* using TextFileBufferInput for such purpose */
        //         File inputFastq = new File(param.inputFqPath).getAbsoluteFile();
        //         if (!inputFastq.exists()){
        //            err.println("Input query file not found.");
        //            return;
        //i         }
        if ((value = cl.getOptionValue(INPUT_GZ)) != null) {
            param.inputFqPath = value;
            param.gz = true;
        } else if (cl.getOptionValue(INPUT_BZ2) == null) {
            help.printHelp();
            System.exit(0);
            //throw new IOException("Input query file not specified.\nUse -help for list of options");
        }

        if ((value = cl.getOptionValue(INPUT_SPLIT)) != null) {
            param.splitsize = Long.decode(value);
        }

        if ((value = cl.getOptionValue(OUTPUT_FILE)) != null) {
            param.outputPath = value;
        } else {
            info.readMessage("Output file not set of -outfile options");
            info.screenDump();
        }

        if (cl.hasOption(OUTPUT_OVERWRITE)) {
            param.overwrite = true;
        }

        if ((value = cl.getOptionValue(OUTPUT_FORMAT)) != null) {
            param.outputFormat = Integer.decode(value);
        }

        File outfile = new File(param.outputPath).getAbsoluteFile();
        if (outfile.exists()) {
            info.readParagraphedMessages(
                    "Output file : \n\t" + param.outputPath + "\nalready exists, will be overwrite.");
            info.screenDump();
            Runtime.getRuntime().exec("rm -rf " + param.outputPath);
        }

    } catch (IOException e) { // Don`t catch this, NaNaNaNa, U can`t touch this.
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (RuntimeException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    } catch (ParseException e) {
        info.readMessage("Parameter settings incorrect.");
        info.screenDump();
        e.printStackTrace();
        System.exit(0);
    }

    return param;
}

From source file:org.energyos.espi.common.repositories.jpa.ResourceRepositoryImpl.java

@SuppressWarnings("unchecked")
@Override/* w ww.  j  av  a 2s.  c  o  m*/
public List<IdentifiedObject> findAllRelated(Linkable linkable) {
    if (linkable.getRelatedLinkHrefs().isEmpty()) {
        return new ArrayList<>();
    }
    List<IdentifiedObject> temp = em.createNamedQuery(linkable.getAllRelatedQuery())
            .setParameter("relatedLinkHrefs", linkable.getRelatedLinkHrefs()).getResultList();
    // Check for specific related that do not have their href's stored
    // in the DB or imported objects that have the external href's stored
    if (temp.isEmpty()) {
        try {
            Boolean localTimeParameterFlag = false;
            Boolean readingTypeFlag = false;
            Boolean electricPowerUsageFlag = false;
            Boolean electricPowerQualityFlag = false;

            Long localTimeParameterId = null;
            Long readingTypeId = null;
            Long electricPowerUsageId = null;
            Long electricPowerQualityId = null;

            for (String href : linkable.getRelatedLinkHrefs()) {
                for (String token : href.split("/")) {
                    if (localTimeParameterFlag) {
                        if (token.length() != 0) {
                            localTimeParameterId = Long.decode(token);
                        }
                        localTimeParameterFlag = false;
                    }

                    if (readingTypeFlag) {
                        if (token.length() != 0) {
                            readingTypeId = Long.decode(token);
                        }
                        readingTypeFlag = false;
                    }

                    if (electricPowerUsageFlag) {
                        if (token.length() != 0) {
                            electricPowerUsageId = Long.decode(token);
                        }
                        electricPowerUsageFlag = false;
                    }

                    if (electricPowerQualityFlag) {
                        if (token.length() != 0) {
                            electricPowerQualityId = Long.decode(token);
                        }
                        electricPowerQualityFlag = false;
                    }

                    if (token.equals("LocalTimeParameters")) {
                        localTimeParameterFlag = true;
                    }

                    if (token.equals("ReadingType")) {
                        readingTypeFlag = true;
                    }

                    if (token.equals("ElectricPowerUsageSummary")) {
                        electricPowerUsageFlag = true;
                    }

                    if (token.equals("ElectricPowerQualitySummary")) {
                        electricPowerQualityFlag = true;
                    }
                }

                if (readingTypeId != null) {
                    temp.add(findById(readingTypeId, ReadingType.class));
                    readingTypeId = null;
                }

                if ((localTimeParameterId != null)) {
                    temp.add(findById(localTimeParameterId, TimeConfiguration.class));
                }

                if ((electricPowerUsageId != null)) {
                    temp.add(findById(electricPowerUsageId, ElectricPowerUsageSummary.class));
                }

                if ((electricPowerQualityId != null)) {
                    temp.add(findById(electricPowerQualityId, ElectricPowerQualitySummary.class));
                }
            }

        } catch (NoResultException e) {
            // We haven't processed the related record yet, so just return the
            // empty temp
            System.out.printf(
                    "**** findAllRelated(Linkable linkable) NoResultException: %s\n     Processed 'related' link before processing 'self' link\n",
                    e.toString());

        } catch (Exception e) {
            // We haven't processed the related record yet, so just return the
            // empty temp
            System.out.printf("**** findAllRelated(Linkable linkable) Exception: %s\n", e.toString());

        }

    }
    return temp;
}

From source file:org.onosproject.rest.resources.IntentsWebResource.java

/**
 * Withdraw intent./*from  w w  w.  j av  a 2  s. c  o m*/
 * Withdraws the specified intent from the system.
 *
 * @param appId application identifier
 * @param key   intent key
 */
@DELETE
@Path("{appId}/{key}")
public void deleteIntentById(@PathParam("appId") String appId, @PathParam("key") String key) {
    final ApplicationId app = get(CoreService.class).getAppId(appId);

    Intent intent = get(IntentService.class).getIntent(Key.of(key, app));
    IntentService service = get(IntentService.class);

    if (intent == null) {
        intent = service.getIntent(Key.of(Long.decode(key), app));
    }
    if (intent == null) {
        // No such intent.  REST standards recommend a positive status code
        // in this case.
        return;
    }

    Key k = intent.key();

    // set up latch and listener to track uninstall progress
    CountDownLatch latch = new CountDownLatch(1);

    IntentListener listener = new DeleteListener(k, latch);
    service.addListener(listener);

    try {
        // request the withdraw
        service.withdraw(intent);

        try {
            latch.await(WITHDRAW_EVENT_TIMEOUT_SECONDS, TimeUnit.SECONDS);
        } catch (InterruptedException e) {
            log.info("REST Delete operation timed out waiting for intent {}", k);
        }
        // double check the state
        IntentState state = service.getIntentState(k);
        if (state == WITHDRAWN || state == FAILED) {
            service.purge(intent);
        }

    } finally {
        // clean up the listener
        service.removeListener(listener);
    }
}

From source file:ClientManager.java

private void getConfig() throws IOException, MalformedContentNameStringException {
    Properties confFile = new Properties();
    FileInputStream confStream = new FileInputStream("config.properties");
    confFile.load(confStream);//from   w w  w . jav  a 2 s. co m

    dpid = Long.decode(confFile.getProperty("dpid"));
    ip = InetAddress.getByName(confFile.getProperty("ip"));

    out.println("Datapath ID dpid=" + Long.toHexString(dpid));
    controller = confFile.getProperty("server");
    controller_port = Integer.decode(confFile.getProperty("port", "6635"));
    out.println("Found server address: " + controller + ":" + controller_port);

    content = new HashMap<ContentName, ContentProps>();

    String entrypoint;
    for (int i = 0; (entrypoint = confFile.getProperty("entry." + i)) != null; i++) {
        int cost = Integer.parseInt(confFile.getProperty("entry." + i + ".cost", "0"));
        int priority = Integer.parseInt(confFile.getProperty("entry." + i + ".priority", "0"));

        content.put(ContentName.fromURI(entrypoint), new ContentProps(cost, priority));

        out.println("Found entrypoint  " + entrypoint + " @ cost=" + cost + " and priority=" + priority);
    }
}