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.soaplab.clients.BatchTestClient.java

/*************************************************************************
 * Get Long from Object returned by a SoaplabMap; may be null.
 *************************************************************************/
@SuppressWarnings("unused")
private static Long getLong(Object value) {
    if (value == null)
        return null;
    try {//from  www. j  a v  a2s  .co  m
        return Long.decode(value.toString());
    } catch (NumberFormatException e) {
        return null;
    }
}

From source file:org.jboss.dashboard.ui.components.DashboardFilterHandler.java

public synchronized void actionStore(CommandRequest request) {
    Map parameters = request.getRequestObject().getParameterMap();

    // Initialize parameters and properties to default.
    showPropertyNames = false;//from  w ww.  j ava 2  s  . c o m
    showRefreshButton = false;
    showApplyButton = false;
    showClearButton = false;
    showSubmitOnChange = false;
    isShortMode = false;
    showLegend = false;
    showAutoRefresh = false;
    properties.clear();
    notAllowedProperties.clear();

    // Component options.
    if (parameters.containsKey(PARAM_SHOW_REFRESH_BUTTON))
        showRefreshButton = true;
    if (parameters.containsKey(PARAM_SHOW_PROPERTY_NAMES))
        showPropertyNames = true;
    if (parameters.containsKey(PARAM_SHOW_CLEAR_BUTTON))
        showClearButton = true;
    if (parameters.containsKey(PARAM_SHOW_APPLY_BUTTON))
        showApplyButton = true;
    if (parameters.containsKey(PARAM_SHOW_SUBMIT_ON_CHANGE))
        showSubmitOnChange = true;
    if (parameters.containsKey(PARAM_SHORT_MODE))
        isShortMode = true;
    if (parameters.containsKey(PARAM_SHOW_LEGEND))
        showLegend = true;
    if (parameters.containsKey(PARAM_SHOW_AUTO_REFRESH))
        showAutoRefresh = true;

    // Component properties.
    DashboardFilterProperty[] allProperties = getAllPropertiesForCurrentFilter();
    for (int i = 0; i < allProperties.length; i++) {
        DashboardFilterProperty property = allProperties[i];
        String dataProviderCode = property.getDataProviderCode();
        String propertyId = property.getPropertyId();

        String visibleParamKey = new StringBuffer().append(PARAM_VISIBLE).append("/").append(dataProviderCode)
                .append("/").append(propertyId).toString();
        String drillDownParamKey = new StringBuffer().append(PARAM_SECTION).append("/").append(dataProviderCode)
                .append("/").append(propertyId).toString();
        boolean isVisible = parameters.containsKey(visibleParamKey);
        Long sectionId = null;
        if (parameters.containsKey(drillDownParamKey)) {
            String sectionIdStr = ((String[]) parameters.get(drillDownParamKey))[0];
            if (!PARAM_DRILLDOWN_DISABLED.equals(sectionIdStr))
                sectionId = Long.decode(sectionIdStr);
        }

        if (!isVisible && sectionId == null)
            continue;

        // Property must be added?
        DashboardFilterProperty prop = getDashboardFilterPropertyForCurrentFilter(dataProviderCode, propertyId);
        if (prop == null)
            prop = new DashboardFilterProperty(dataProviderCode, propertyId, getFilter(), null, false);

        // Check if another property with same identifier.
        if (getDashboardFilterProperty(propertyId) != null) {
            // Another property with same id is already set to the filter.
            // Filter cannot use two properties with same property id., so show warning.
            notAllowedProperties.add(prop);
            continue;
        }

        // Add property to this component.
        properties.add(prop);

        // Set property parameters
        prop.setBeingFiltered(false);
        prop.setVisible(isVisible);
        prop.setSectionId(sectionId);
    }
}

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

/**
 * test the data against a long/*from   w  ww .  j  av a 2 s.c  om*/
 *
 * @param data the data we are testing
 *
 * @return if we have a match
 */
private boolean testLong(ByteBuffer data) {
    log.debug("testLong()");

    long val = 0;
    String test = new String(match.getTest().array());
    char comparator = match.getComparator();
    long bitmask = match.getBitmask();

    val = byteArrayToLong(data);

    // apply bitmask before the comparison
    val = val & bitmask;

    long tst = Long.decode(test).longValue();

    log.debug("testLong(): testing '" + Long.toHexString(val) + "' against '" + test + "' => '"
            + Long.toHexString(tst) + "'");

    switch (comparator) {
    case '=':
        return val == tst;

    case '!':
        return val != tst;

    case '>':
        return val > tst;

    case '<':
        return val < tst;
    }

    return false;
}

From source file:org.entrystore.repository.config.PropertiesConfiguration.java

/**
 * @see se.kth.cid.config.Config#getColor(java.lang.String)
 *///w  w  w .  ja v a  2s  .c  o  m
public Color getColor(String key) {
    Color result = null;
    String value = getString(key);

    if (value != null) {
        try {
            if (!value.startsWith("0x"))
                result = Color.decode(value);
            else {
                int rgb = Long.decode(value).intValue();
                result = new Color(rgb);
            }
        } catch (NumberFormatException nfe) {
        }
    }

    return result;
}

From source file:org.apache.pulsar.broker.web.PulsarWebResource.java

protected NamespaceBundle validateNamespaceBundleRange(NamespaceName fqnn, BundlesData bundles,
        String bundleRange) {// ww  w.j av  a 2s  .co m
    try {
        checkArgument(bundleRange.contains("_"), "Invalid bundle range");
        String[] boundaries = bundleRange.split("_");
        Long lowerEndpoint = Long.decode(boundaries[0]);
        Long upperEndpoint = Long.decode(boundaries[1]);
        Range<Long> hashRange = Range.range(lowerEndpoint, BoundType.CLOSED, upperEndpoint,
                (upperEndpoint.equals(NamespaceBundles.FULL_UPPER_BOUND)) ? BoundType.CLOSED : BoundType.OPEN);
        NamespaceBundle nsBundle = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundle(fqnn,
                hashRange);
        NamespaceBundles nsBundles = pulsar().getNamespaceService().getNamespaceBundleFactory().getBundles(fqnn,
                bundles);
        nsBundles.validateBundle(nsBundle);
        return nsBundle;
    } catch (Exception e) {
        log.error("[{}] Failed to validate namespace bundle {}/{}", clientAppId(), fqnn.toString(), bundleRange,
                e);
        throw new RestException(e);
    }
}

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

/**
 * This method loads json file with layer types
 * //from   w w w .  jav a  2  s  . c  o m
 * @param username
 * 
 * @return JSON file with layer types
 */
@RequestMapping(value = "/persistenceGeo/updateLayer", method = RequestMethod.GET, produces = {
        MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody LayerDto updateLayerByUser(@RequestParam("name") String name,
        @RequestParam("type") String type, @RequestParam(value = "layer_id") String layerId,
        @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 = (LayerDto) layerAdminService.getById(Long.decode(layerId));

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

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

From source file:com.intel.hadoop.hbase.dot.KEY.java

public int parseCommandLine(final String[] args) {
    // (but hopefully something not as painful as cli options).
    int errCode = 0;
    if (args.length < 1) {
        printUsage();//from w ww  .  j  a va 2  s  . co m
        return -1;
    }

    for (int i = 0; i < args.length; i++) {
        String cmd = args[i];
        if (cmd.equals("-h") || cmd.startsWith("--h")) {
            printUsage();
            break;
        }

        final String colnum = "--colnum=";
        if (cmd.startsWith(colnum)) {
            int val = Integer.parseInt(cmd.substring(colnum.length()));
            if (val <= 0 || val > this.MAX_COLUMN_NUM)
                val = this.DEFAULT_COLUMN_NUM;
            this.colNum = val;
            this.conf.setLong(KEY.OPTION_COLNUM, this.colNum);
            continue;
        }

        final String cf = "--cfnum=";
        if (cmd.startsWith(cf)) {
            int val = Integer.parseInt(cmd.substring(cf.length()));
            if (val <= 0 || val > this.MAX_FAMILY_NUM)
                val = this.DEFAULT_FAMILY_NUM;
            this.cfNum = val;
            this.conf.setInt(KEY.OPTION_CFNUM, this.cfNum);
            continue;
        }

        final String rows = "--rownum=";
        if (cmd.startsWith(rows)) {
            long val = Long.decode(cmd.substring(rows.length()));
            if (val < 0 || val > this.MAX_ROW_NUM)
                val = this.DEFAULT_ROW_NUM;
            this.rowNum = val;
            continue;
        }

        final String regions = "--regions=";
        if (cmd.startsWith(regions)) {
            int val = Integer.parseInt(cmd.substring(regions.length()));
            if (val <= 0 || val > this.MAX_REGION_NUM)
                val = this.DEFAULT_REGION_NUMBER;
            this.regionNumber = val;
            continue;
        }

        final String enabledot = "--enabledot";
        if (cmd.startsWith(enabledot)) {
            this.createDotTable = true;
            continue;
        }

        final String table = "--table=";
        if (cmd.startsWith(table)) {
            this.tableName = cmd.substring(table.length());
            continue;
        }
    }

    if (this.tableName == null) {
        printUsage("Please specify the table name");
        errCode = -2;
    }

    this.baseRowNumber = 1L;
    while (this.baseRowNumber < this.rowNum) {
        this.baseRowNumber *= 10L;
    }

    this.conf.setLong(KEY.OPTION_BASEROWNUM, this.baseRowNumber);
    this.conf.setLong(KEY.OPTION_REGIONROWNUM, this.rowNum / this.regionNumber);

    System.out.println("cfnum = " + this.cfNum);
    System.out.println("colnum = " + this.colNum);
    System.out.println("rownum = " + this.rowNum);
    System.out.println("baseRowNumber = " + this.baseRowNumber);
    System.out.println("tablename = " + this.tableName);
    System.out.println("Presplit Region number = " + this.regionNumber);
    System.out.println("row per region = " + this.rowNum / this.regionNumber);
    System.out.println("Also create dot table = " + this.createDotTable);
    return errCode;
}

From source file:org.jboss.dashboard.ui.config.components.sections.SectionsPropertiesHandler.java

public void actionPromoveParent(final CommandRequest request) {
    try {//w w w.  j a  va2 s.  c  o m

        HibernateTxFragment txFragment = new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                WorkspaceImpl workspace = (WorkspaceImpl) getWorkspace();
                Section section;
                if (getSelectedSectionId() != null) {
                    section = workspace.getSection(Long.decode(getSelectedSectionId()));
                    if (section != null) {
                        Section oldParent = section.getParent();
                        if (oldParent != null) {
                            changeParent(section, oldParent, oldParent.getParent());
                            UIServices.lookup().getSectionsManager().store(section);
                        }
                    }
                }
            }
        };

        txFragment.execute();
        this.setDuplicateSection(Boolean.FALSE);
        this.setCreateSection(Boolean.FALSE);
        this.setSelectedSectionId(null);

    } catch (Exception e) {
        log.error("Error: " + e.getMessage());
    }
}

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

/**
 * This method loads all channel folders in a zone
 * /*from  ww  w. j  a  va  2 s  .c om*/
 * @param filter
 *            can be null
 *            {@link RestFoldersAdminController#ALL_CHANNEL_IN_ZONES} or id
 *            zone to filter
 * 
 * @return JSON file with folders
 */
@RequestMapping(value = "/persistenceGeo/loadChannels", produces = { MediaType.APPLICATION_JSON_VALUE })
public @ResponseBody Map<String, Object> loadChannels(
        @RequestParam(value = "filter", required = false) String filter) {
    Map<String, Object> result = new HashMap<String, Object>();
    List<FolderDto> folders = null;
    List<FolderDto> previusFolders = null;
    try {
        if (filter != null) {
            if (filter.contains(ALL_CHANNEL_IN_ZONES)) {
                previusFolders = foldersAdminService.getChannelFolders(Boolean.TRUE, null, Boolean.TRUE);
            } else {
                Long zoneId = null;
                try {
                    zoneId = Long.decode(filter);
                    previusFolders = foldersAdminService.getChannelFolders(null, zoneId, Boolean.TRUE);
                } catch (Exception e) {
                    previusFolders = foldersAdminService.getChannelFolders(Boolean.FALSE, null, Boolean.TRUE);
                }
            }

            if (filter.contains(HIDE_IPT_CHANNELS)) {
                List<FolderDto> filteredFolders = new ArrayList<FolderDto>();

                for (FolderDto folder : previusFolders) {
                    if (folder.getIsPlain() == null) {
                        filteredFolders.add(folder);
                    }
                }
                previusFolders = filteredFolders;
            }

        } else {
            previusFolders = foldersAdminService.getChannelFolders(Boolean.FALSE, null, Boolean.TRUE);
        }
        folders = new LinkedList<FolderDto>();

        for (FolderDto subRes : previusFolders) {
            TreeFolderDto folder = (TreeFolderDto) FoldersUtils.getFolderDecorator().applyStyle(subRes,
                    FolderStyle.NORMAL);
            if (filter != null && filter.contains(SHOW_FOLDER_LAYERS)) {
                folder.setLeaf(false);
            } else {
                folder.setLeaf(true);
            }
            folders.add(folder);
        }
        result.put(SUCCESS, true);
    } catch (Exception e) {
        e.printStackTrace();
        result.put(SUCCESS, false);
    }

    result.put(RESULTS, folders != null ? folders.size() : 0);
    result.put(ROOT, folders);

    return result;
}

From source file:org.jboss.dashboard.ui.config.components.sections.SectionsPropertiesHandler.java

public void actionSetParent(final CommandRequest request) {
    try {//w  ww.j av  a2 s  .  c  o  m

        HibernateTxFragment txFragment = new HibernateTxFragment() {
            protected void txFragment(Session session) throws Exception {
                WorkspaceImpl workspace = (WorkspaceImpl) getWorkspace();
                Section section;
                if (getSelectedSectionId() != null) {
                    section = workspace.getSection(Long.decode(getSelectedSectionId()));
                    if (section != null) {
                        Section oldParent = section.getParent();

                        Section newParent = null;
                        Section[] brothers;
                        if (oldParent != null)
                            brothers = workspace.getAllChildSections(oldParent.getId());
                        else
                            brothers = workspace.getAllRootSections();
                        if (brothers != null) {
                            for (int i = 0; i < brothers.length && newParent == null; i++) {
                                if (i > 0 && brothers[i].getId().equals(section.getId()))
                                    newParent = brothers[i - 1];
                            }
                        }

                        if (newParent != null) {
                            changeParent(section, oldParent, newParent);
                            UIServices.lookup().getSectionsManager().store(section);
                        }
                    }
                }
            }
        };

        txFragment.execute();
        this.setDuplicateSection(Boolean.FALSE);
        this.setCreateSection(Boolean.FALSE);
        this.setSelectedSectionId(null);

    } catch (Exception e) {
        log.error("Error: " + e.getMessage());
    }
}