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:syncthing.android.service.SyncthingUtils.java

public static String daysToSeconds(String days) {
    return String.valueOf(Long.decode(days) * 86400);
}

From source file:info.magnolia.ui.framework.action.ExportActionTest.java

@Override
@Before/*ww w . j ava2 s . c om*/
public void setUp() throws Exception {
    super.setUp();
    ComponentsTestUtil.setImplementation(AccessDefinition.class, ConfiguredAccessDefinition.class);
    ComponentsTestUtil.setImplementation(AvailabilityDefinition.class, ConfiguredAvailabilityDefinition.class);

    ComponentsTestUtil.setImplementation(TranslationService.class, TranslationServiceImpl.class);
    ComponentsTestUtil.setImplementation(MessagesManager.class, DefaultMessagesManager.class);
    ComponentsTestUtil.setImplementation(Node2BeanProcessor.class, Node2BeanProcessorImpl.class);
    ComponentsTestUtil.setImplementation(TypeMapping.class, TypeMappingImpl.class);
    ComponentsTestUtil.setImplementation(Node2BeanTransformer.class, Node2BeanTransformerImpl.class);
    ComponentsTestUtil.setImplementation(LocaleProvider.class, ContextLocaleProvider.class);
    ComponentsTestUtil.setImplementation(AsyncActionExecutor.class,
            AbstractCommandActionTest.DummyAsyncExecutor.class);

    // Init Command
    Session webSiteSession = MgnlContext.getJCRSession(RepositoryConstants.WEBSITE);
    toCopyNode = webSiteSession.getRootNode().addNode("toCopy");
    toCopyNode.addNode("article", NodeTypes.Page.NAME);
    toCopyNode.getNode("article").setProperty("property_boolean", Boolean.TRUE);
    toCopyNode.getNode("article").setProperty("property_long", Long.decode("1000"));
    toCopyNode.getNode("article").setProperty("property_string", "property");
    toCopyNode.addNode("article/content", NodeTypes.Content.NAME);
    toCopyNode.getNode("article/content").setProperty("property_string", "property");

    outputStream = new ByteArrayOutputStream();

    exportCommand = spy(new ExportCommand());
    doReturn(true).when(exportCommand).checkPermissions(RepositoryConstants.WEBSITE, toCopyNode.getPath(),
            Permission.READ);

    // Init Action and CommandManager
    definition = new ExportActionDefinition();
    definition.setCommand("export");

    ComponentsTestUtil.setImplementation(CommandsManager.class, CommandsManager.class);
    // see for why this is needed.
    ComponentsTestUtil.setInstance(Map.class, params);

    CommandsManager commandsManagerTmp = Components.getComponent(CommandsManager.class);
    Session configSession = MgnlContext.getJCRSession(RepositoryConstants.CONFIG);
    Node exportModuleDef = configSession.getRootNode().addNode("modules", NodeTypes.ContentNode.NAME)
            .addNode("commands", NodeTypes.ContentNode.NAME).addNode("default", NodeTypes.ContentNode.NAME)
            .addNode("export", NodeTypes.ContentNode.NAME);
    exportModuleDef.setProperty("class", ExportCommand.class.getName());
    exportModuleDef.getSession().save();
    commandsManagerTmp.register(ContentUtil.asContent(exportModuleDef.getParent()));
    commandsManager = spy(commandsManagerTmp);
    when(commandsManager.getCommand(CommandsManager.DEFAULT_CATALOG, "export")).thenReturn(exportCommand);
    when(commandsManager.getCommand("export")).thenReturn(exportCommand);
}

From source file:org.jboss.dashboard.ui.NavigationPoint.java

public Section getPage() {
    if (getSectionId() == null)
        return null;
    WorkspaceImpl workspace = getWorkspace();
    if (workspace != null) {
        try {//from  w  w  w  . j  a va2 s. co  m
            Section page = workspace.getSection(Long.decode(getSectionId()));
            if (page != null)
                return page;
        } catch (NumberFormatException nfe) {
        }
        return workspace.getSectionByUrl(getSectionId());
    }
    return null;
}

From source file:syncthing.android.service.SyncthingUtils.java

public static String secondsToDays(String seconds) {
    return String.valueOf(Long.decode(seconds) / 86400);
}

From source file:org.jbpm.formModeler.core.processing.formProcessing.NamespaceManager.java

public FormNamespaceData getNamespace(String fieldName) {
    if (fieldName != null) {
        int lastIndex = fieldName.lastIndexOf(FormProcessor.NAMESPACE_SEPARATOR);
        int previousLastIndex = fieldName.lastIndexOf(FormProcessor.NAMESPACE_SEPARATOR, lastIndex - 1);
        if (previousLastIndex != -1) {
            String formIdString = fieldName.substring(previousLastIndex + 1, lastIndex);
            String namespace = fieldName.substring(0, previousLastIndex);
            String fieldNameInParent = fieldName.substring(lastIndex + 1, fieldName.length());
            if (!"_".equals(formIdString)) {
                Long formId = Long.decode(formIdString);
                try {
                    Form form = subformFinderService.getFormById(formId, namespace);
                    return new FormNamespaceData(form, namespace, fieldNameInParent);
                } catch (Exception e) {
                    log.error("Error: ", e);
                }//from w  w  w  . j av  a 2  s.  c  o  m
            }
        }
    }
    return null;
}

From source file:org.apache.zookeeper.server.persistence.TxnLogToolkit.java

public TxnLogToolkit(String txnLogFileName, String zxidName) throws TxnLogToolkitException {
    txnLogFile = loadTxnFile(txnLogFileName);
    zxid = Long.decode(zxidName);
}

From source file:mil.jpeojtrs.sca.util.AnyUtils.java

/**
 * Attempts to convert the string value to the appropriate Java type.
 * //ww w.  j  a va 2  s .  c om
 * @param stringValue the string form of the value
 * @param type the string form of the TypeCode
 * @return A Java object of theString corresponding to the typecode
 */
private static Object primitiveConvertString(final String stringValue, final String type) {
    if (stringValue == null) {
        return null;
    }
    if ("string".equals(type)) {
        return stringValue;
    } else if ("wstring".equals(type)) {
        return stringValue;
    } else if ("boolean".equals(type)) {
        if ("true".equalsIgnoreCase(stringValue) || "false".equalsIgnoreCase(stringValue)) {
            return Boolean.parseBoolean(stringValue);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid boolean value");
    } else if ("char".equals(type)) {
        switch (stringValue.length()) {
        case 1:
            return stringValue.charAt(0);
        case 0:
            return null;
        default:
            throw new IllegalArgumentException(stringValue + " is not a valid char value");
        }
    } else if ("wchar".equals(type)) {
        return stringValue.charAt(0);
    } else if ("double".equals(type)) {
        return Double.parseDouble(stringValue);
    } else if ("float".equals(type)) {
        return Float.parseFloat(stringValue);
    } else if ("short".equals(type)) {
        return Short.decode(stringValue);
    } else if ("long".equals(type)) {
        return Integer.decode(stringValue);
    } else if ("longlong".equals(type)) {
        return Long.decode(stringValue);
    } else if ("ulong".equals(type)) {
        final long MAX_UINT = 2L * Integer.MAX_VALUE + 1L;
        final Long retVal = Long.decode(stringValue);
        if (retVal < 0 || retVal > MAX_UINT) {
            throw new IllegalArgumentException(
                    "ulong value must be greater than '0' and less than " + MAX_UINT);
        }
        return retVal;
    } else if ("ushort".equals(type)) {
        final int MAX_USHORT = 2 * Short.MAX_VALUE + 1;
        final Integer retVal = Integer.decode(stringValue);
        if (retVal < 0 || retVal > MAX_USHORT) {
            throw new IllegalArgumentException(
                    "ushort value must be greater than '0' and less than " + MAX_USHORT);
        }
        return retVal;
    } else if ("ulonglong".equals(type)) {
        final BigInteger MAX_ULONG_LONG = BigInteger.valueOf(Long.MAX_VALUE).multiply(BigInteger.valueOf(2))
                .add(BigInteger.ONE);
        final BigInteger retVal = AnyUtils.bigIntegerDecode(stringValue);
        if (retVal.compareTo(BigInteger.ZERO) < 0 || retVal.compareTo(MAX_ULONG_LONG) > 0) {
            throw new IllegalArgumentException(
                    "ulonglong value must be greater than '0' and less than " + MAX_ULONG_LONG.toString());
        }
        return retVal;
    } else if ("objref".equals(type)) {
        if ("".equals(stringValue)) {
            return null;
        }
        final List<String> objrefPrefix = Arrays.asList("IOR:", "corbaname:", "corbaloc:");
        for (final String prefix : objrefPrefix) {
            if (stringValue.startsWith(prefix)) {
                return stringValue;
            }
        }
        throw new IllegalArgumentException(stringValue + " is not a valid objref value");
    } else if ("octet".equals(type)) {
        final short MIN_OCTET = 0;
        final short MAX_OCTET = 0xFF;
        final short val = Short.decode(stringValue);
        if (val <= MAX_OCTET && val >= MIN_OCTET) {
            return Short.valueOf(val);
        }
        throw new IllegalArgumentException(stringValue + " is not a valid octet value");
    } else {
        throw new IllegalArgumentException("Unknown CORBA Type: " + type);
    }
}

From source file:org.energy_home.jemma.javagal.rest.resources.LocalServicesResource.java

@Post
public void processPost(String body) {

    String epString = (String) getRequest().getAttributes().get(Resources.PARAMETER_EP);

    if (epString == null) {
        // /{ep} not present
        Parameter timeoutParam = getRequest().getResourceRef().getQueryAsForm()
                .getFirst(ResourcePathURIs.TIMEOUT_PARAM);
        if (timeoutParam != null) {
            timeoutString = timeoutParam.getValue().trim();
            try {
                timeout = Long.decode(Resources.HEX_PREFIX + timeoutString);
            } catch (NumberFormatException nfe) {
                Info info = new Info();
                Status _st = new Status();
                _st.setCode((short) GatewayConstants.GENERAL_ERROR);
                _st.setMessage(nfe.getMessage());
                info.setStatus(_st);/*from  w  ww. j av a 2 s.c om*/
                Info.Detail detail = new Info.Detail();
                info.setDetail(detail);
                getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
                return;

            }
            // if (timeout < 0 || timeout > 0xffff) {
            if (!Util.isUnsigned32(timeout)) {

                Info info = new Info();
                Status _st = new Status();
                _st.setCode((short) GatewayConstants.GENERAL_ERROR);
                _st.setMessage("Error: optional '" + ResourcePathURIs.TIMEOUT_PARAM
                        + "' parameter's value invalid. You provided: " + timeoutString);
                info.setStatus(_st);
                Info.Detail detail = new Info.Detail();
                info.setDetail(detail);
                getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
                return;

            }
        }

        SimpleDescriptor simpleDescriptor;
        try {
            simpleDescriptor = Util.unmarshal(body, SimpleDescriptor.class);
        } catch (Exception jbe) {

            Info info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.GENERAL_ERROR);
            _st.setMessage("Malformed SimpleDesriptor in request");
            info.setStatus(_st);
            Info.Detail detail = new Info.Detail();
            info.setDetail(detail);
            getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
            return;

        }

        // Actual Gal call

        try {
            // Gal Manager check
            proxyGalInterface = getRestManager().getClientObjectKey(-1, getClientInfo().getAddress())
                    .getGatewayInterface();

            // ConfigureEndpoint
            short endPoint = proxyGalInterface.configureEndpoint(timeout, simpleDescriptor);
            if (endPoint > 0) {

                Info info = new Info();
                Status _st = new Status();
                _st.setCode((short) GatewayConstants.SUCCESS);
                info.setStatus(_st);
                Info.Detail detail = new Info.Detail();
                detail.setEndpoint(endPoint);
                info.setDetail(detail);
                getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
                return;

            } else {

                Info info = new Info();
                Status _st = new Status();
                _st.setCode((short) GatewayConstants.GENERAL_ERROR);
                _st.setMessage("Error in creating end point. Not created.");
                info.setStatus(_st);
                Info.Detail detail = new Info.Detail();
                info.setDetail(detail);
                getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
                return;

            }
        } catch (NullPointerException npe) {
            Info info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.GENERAL_ERROR);
            _st.setMessage(npe.getMessage());
            info.setStatus(_st);
            Info.Detail detail = new Info.Detail();
            info.setDetail(detail);
            getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
            return;

        } catch (Exception e1) {
            Info info = new Info();
            Status _st = new Status();
            _st.setCode((short) GatewayConstants.GENERAL_ERROR);
            _st.setMessage(e1.getMessage());
            info.setStatus(_st);
            Info.Detail detail = new Info.Detail();
            info.setDetail(detail);
            getResponse().setEntity(Util.marshal(info), MediaType.APPLICATION_XML);
            return;
        }

    }
}

From source file:org.apache.cocoon.util.JDBCTypeConversions.java

/**
 * Converts an object to a JDBC type. This has just been started
 * and does not do much at the moment.//ww  w .  j a  va 2  s . c o  m
 *
 */
public static Object convert(Object value, String jType) {

    Object object = null;
    if (jType.equalsIgnoreCase("string")) {
        if (value instanceof String) {
            object = value;
        } else {
            object = value.toString();
        }
    } else if (jType.equalsIgnoreCase("int")) {
        if (value instanceof String) {
            object = Integer.decode((String) value);
        } else if (value instanceof Integer) {
            object = value;
        } else {
            //
        }
    } else if (jType.equalsIgnoreCase("long")) {
        if (value instanceof String) {
            object = Long.decode((String) value);
        } else if (value instanceof Long) {
            object = value;
        } else {
            //
        }
    } else {
        // other types need parsing & creation
        //
    }
    return object;
}

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

/**
 * Returns the children of a specific container node. The container type is
 * specified using the type parameter. The condition the returned nodes has
 * to meet is specified using the filter parameter.
 * /* w  w  w .j  av  a 2s.c o  m*/
 * @param node
 *            The node id
 * @param type
 *            The type of the node (zone, folderType(Long), folder)
 * @param filter
 *            The condition the returned nodes has to meet
 * 
 * @return JSON node children of selected node
 */
@SuppressWarnings("unchecked")
@RequestMapping(value = "/persistenceGeo/tree/treeService", produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody List<Treeable> treeService(@RequestParam(value = "node", required = false) String nodeId,
        @RequestParam(value = "type", required = false) String type,
        @RequestParam(value = "filter", required = false) String filter) {

    List<Treeable> nodes = new LinkedList<Treeable>();

    try {

        Long typeId = FoldersAdminService.DEFAULT_FOLDER_TYPE;
        if (StringUtils.isNotBlank(type)
                && (StringUtils.isNumeric(type) || type.equals(ID_ANY_FOLDER_TYPE.toString()))) {
            typeId = Long.decode(type);
        }

        if (!StringUtils.isEmpty(nodeId) && (StringUtils.isNumeric(nodeId)
                || RestFoldersAdminController.UNASSIGNED_LAYERS_VIRTUAL_FOLDER_ID.toString().equals(nodeId))) {
            // The rest of types are consider like folders
            nodes = (List<Treeable>) restFoldersAdminController.loadFoldersById(nodeId, filter).get(ROOT);
        } else {
            // get root folder types
            nodes.addAll(getFoldersByType(typeId, filter));
        }

    } catch (Exception e) {
        LOG.error(e);
    }

    return nodes;
}