67
|
1 |
/*
|
|
2 |
* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description:
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
package com.nokia.mj.impl.cenrep;
|
|
19 |
|
|
20 |
import com.nokia.mid.cenrep.CentralRepositoryException;
|
|
21 |
/**
|
|
22 |
* Class for central repository key representation
|
|
23 |
*/
|
|
24 |
class CentralRepositoryKey
|
|
25 |
{
|
|
26 |
|
|
27 |
/**
|
|
28 |
* Default constructor.
|
|
29 |
*/
|
|
30 |
protected CentralRepositoryKey()
|
|
31 |
{
|
|
32 |
}
|
|
33 |
|
|
34 |
/**
|
|
35 |
* Returns long value represantion.
|
|
36 |
*
|
|
37 |
* @param value string represantion of key.
|
|
38 |
* @throws CentralRepositoryException, if key is null, empty, negative
|
|
39 |
* or not valid.
|
|
40 |
*/
|
|
41 |
static long getLongValue(String value)
|
|
42 |
throws CentralRepositoryException
|
|
43 |
{
|
|
44 |
if (value == null || value.length() == 0)
|
|
45 |
{
|
|
46 |
throw new CentralRepositoryException("Key is null or empty!");
|
|
47 |
}
|
|
48 |
|
|
49 |
String numStr = value;
|
|
50 |
|
|
51 |
// Negative value is not allowed
|
|
52 |
if (numStr.startsWith("-"))
|
|
53 |
{
|
|
54 |
throw new CentralRepositoryException("Nagative value is not allowed!");
|
|
55 |
}
|
|
56 |
|
|
57 |
// Check for optional radix prefix.
|
|
58 |
int radix = 10;
|
|
59 |
if (numStr.startsWith("0x"))
|
|
60 |
{
|
|
61 |
radix = 16;
|
|
62 |
numStr = numStr.substring(2);
|
|
63 |
}
|
|
64 |
|
|
65 |
return Long.parseLong(numStr, radix);
|
|
66 |
}
|
|
67 |
|
|
68 |
};
|