本文整理匯總了Java中org.apache.commons.lang.math.RandomUtils.nextLong方法的典型用法代碼示例。如果您正苦於以下問題:Java RandomUtils.nextLong方法的具體用法?Java RandomUtils.nextLong怎麽用?Java RandomUtils.nextLong使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.commons.lang.math.RandomUtils
的用法示例。
在下文中一共展示了RandomUtils.nextLong方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createParam
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private Object createParam(Class type) throws IllegalAccessException, InvocationTargetException,
InstantiationException {
Object param;
if (type == String.class) {
param = "test";
} else if (type == Integer.class || type == Integer.TYPE) {
param = RandomUtils.nextInt();
} else if (type == Long.class || type == Long.TYPE) {
param = RandomUtils.nextLong();
} else if (type == Float.class || type == Float.TYPE) {
param = RandomUtils.nextFloat();
} else if (type == Double.class || type == Double.TYPE) {
param = RandomUtils.nextDouble();
} else if (type == Boolean.class || type == Boolean.TYPE) {
param = RandomUtils.nextBoolean();
} else if (type == BigInteger.class) {
param = new BigInteger(TEST_BIGINTEGER);
} else if (type == List.class) {
param = new ArrayList<>();
} else if (type == XMLGregorianCalendar.class) {
try {
param = DatatypeFactory.newInstance().newXMLGregorianCalendar();
} catch (DatatypeConfigurationException e) {
throw new IllegalArgumentException(e.getMessage(), e);
}
} else {
Constructor[] constructors = type.getConstructors();
param = constructors[0].newInstance();
}
return param;
}
示例2: testAddTask
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
/**
* Tests for
* {@link TaskManagement#addTask(String, boolean, Long, java.util.Date, java.util.Map, Class)}
*
* @throws Exception
* in case the test failed
*/
@Test
public void testAddTask() throws Exception {
final Map<String, String> properties = new HashMap<String, String>();
for (int i = 0; i < 10 + RandomUtils.nextInt(20); i++) {
properties.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
}
final String uniqueTaskName = UUID.randomUUID().toString();
final Long interval = RandomUtils.nextLong();
final Long taskId = taskManagement.addTask(uniqueTaskName, false, interval, new Date(),
properties, TestTaskHandler.class);
ServiceLocator.findService(TransactionManagement.class).execute(new RunInTransaction() {
@Override
public void execute() throws TransactionException {
Task task = taskDao.load(taskId);
Assert.assertNotNull(task);
Assert.assertEquals(task.getUniqueName(), uniqueTaskName);
Assert.assertEquals(task.getTaskInterval(), interval);
for (TaskProperty property : task.getProperties()) {
Assert.assertEquals(property.getPropertyValue(),
properties.get(property.getPropertyKey()));
}
}
});
}
示例3: init
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@PostConstruct
private void init() throws SQLException {
conn = sinkDb.getConnection();
initDb();
assessmentId = RandomUtils.nextLong();
tableNames = Arrays.asList(measureDatumTbl, nodeTripleTbl,
nodeTbl, quadTbl, tripleTbl, varTbl, viewDefTbl, md2nodeTbl,
md2nodeTripleTbl, md2quadTbl, md2tripleTbl, md2varTbl,
md2viewDefTbl, trpl2quadTbl, trpl2viewDefTbl, vd2quadTbl,
vd2varTbl);
}
示例4: testSequentialGetSet
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Test
public void testSequentialGetSet() throws Exception {
AbstractSparseValues mutable = new LongArraySparseMutable(1024);
for (int i = 0; i < mutable.size(); i++) {
long value = RandomUtils.nextLong();
assertFalse(mutable.hasValue(i));
mutable.set(i, value);
assertTrue(mutable.hasValue(i));
assertEquals(value, mutable.get(i));
}
}
示例5: getWorkingDir
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
protected Path getWorkingDir(List<String> localDirs, String user,
String appId) throws IOException {
Path appStorageDir = null;
long totalAvailable = 0L;
long[] availableOnDisk = new long[localDirs.size()];
int i = 0;
// randomly choose the app directory
// the chance of picking a directory is proportional to
// the available space on the directory.
// firstly calculate the sum of all available space on these directories
for (String localDir : localDirs) {
Path curBase = getApplicationDir(new Path(localDir),
user, appId);
long space = 0L;
try {
space = getDiskFreeSpace(curBase);
} catch (IOException e) {
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
}
availableOnDisk[i++] = space;
totalAvailable += space;
}
// throw an IOException if totalAvailable is 0.
if (totalAvailable <= 0L) {
throw new IOException("Not able to find a working directory for "
+ user);
}
// make probability to pick a directory proportional to
// the available space on the directory.
long randomPosition = RandomUtils.nextLong() % totalAvailable;
int dir = 0;
// skip zero available space directory,
// because totalAvailable is greater than 0 and randomPosition
// is less than totalAvailable, we can find a valid directory
// with nonzero available space.
while (availableOnDisk[dir] == 0L) {
dir++;
}
while (randomPosition > availableOnDisk[dir]) {
randomPosition -= availableOnDisk[dir++];
}
appStorageDir = getApplicationDir(new Path(localDirs.get(dir)),
user, appId);
return appStorageDir;
}
示例6: getWorkingDir
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
protected Path getWorkingDir(List<String> localDirs, String user,
String appId) throws IOException {
Path appStorageDir = null;
long totalAvailable = 0L;
long[] availableOnDisk = new long[localDirs.size()];
int i = 0;
// randomly choose the app directory
// the chance of picking a directory is proportional to
// the available space on the directory.
// firstly calculate the sum of all available space on these directories
for (String localDir : localDirs) {
Path curBase = getApplicationDir(new Path(localDir),
user, appId);
long space = 0L;
try {
space = getDiskFreeSpace(curBase);
} catch (IOException e) {
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
}
availableOnDisk[i++] = space;
totalAvailable += space;
}
// throw an IOException if totalAvailable is 0.
if (totalAvailable <= 0L) {
throw new IOException("Not able to find a working directory for "
+ user);
}
// make probability to pick a directory proportional to
// the available space on the directory.
long randomPosition = RandomUtils.nextLong() % totalAvailable;
int dir = 0;
// skip zero available space directory,
// because totalAvailable is greater than 0 and randomPosition
// is less than totalAvailable, we can find a valid directory
// with nonzero available space.
while (availableOnDisk[dir] == 0L) {
dir++;
}
while (randomPosition > availableOnDisk[dir]) {
randomPosition -= availableOnDisk[dir++];
}
appStorageDir = getApplicationDir(new Path(localDirs.get(dir)),
user, appId);
return appStorageDir;
}
示例7: nextConnectionId
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private long nextConnectionId() {
return RandomUtils.nextLong();
}
示例8: getWorkingDir
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
protected Path getWorkingDir(List<String> localDirs, String user,
String appId) throws IOException {
Path appStorageDir = null;
long totalAvailable = 0L;
long[] availableOnDisk = new long[localDirs.size()];
int i = 0;
// randomly choose the app directory
// the chance of picking a directory is proportional to
// the available space on the directory.
// firstly calculate the sum of all available space on these directories
for (String localDir : localDirs) {
Path curBase = getApplicationDir(new Path(localDir),
user, appId);
long space = 0L;
try {
space = getDiskFreeSpace(curBase);
} catch (IOException e) {
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
}
availableOnDisk[i++] = space;
totalAvailable += space;
}
// throw an IOException if totalAvailable is 0.
if (totalAvailable <= 0L) {
throw new IOException("Not able to find a working directory for "
+ user);
}
// make probability to pick a directory proportional to
// the available space on the directory.
long randomPosition = RandomUtils.nextLong() % totalAvailable;
int dir = 0;
// skip zero available space directory,
// because totalAvailable is greater than 0 and randomPosition
// is less than totalAvailable, we can find a valid directory
// with nonzero available space.
while (availableOnDisk[dir] == 0L) {
dir++;
}
while (randomPosition > availableOnDisk[dir]) {
randomPosition -= availableOnDisk[dir++];
}
appStorageDir = getApplicationDir(new Path(localDirs.get(dir)),
user, appId);
return appStorageDir;
}
示例9: random
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Override
public Long random() {
return RandomUtils.nextLong();
}
示例10: getUniqueNumber
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private static String getUniqueNumber() {
return System.currentTimeMillis() + "" + RandomUtils.nextLong();
}
示例11: getWorkingDir
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
protected Path getWorkingDir(List<String> localDirs, String user,
String appId, String userFolder) throws IOException {
Path appStorageDir = null;
long totalAvailable = 0L;
long[] availableOnDisk = new long[localDirs.size()];
int i = 0;
// randomly choose the app directory
// the chance of picking a directory is proportional to
// the available space on the directory.
// firstly calculate the sum of all available space on these directories
for (String localDir : localDirs) {
Path curBase = getApplicationDir(new Path(localDir),
userFolder, appId);
long space = 0L;
try {
space = getDiskFreeSpace(curBase);
} catch (IOException e) {
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
}
availableOnDisk[i++] = space;
totalAvailable += space;
}
// throw an IOException if totalAvailable is 0.
if (totalAvailable <= 0L) {
throw new IOException("Not able to find a working directory for "
+ user);
}
// make probability to pick a directory proportional to
// the available space on the directory.
long randomPosition = RandomUtils.nextLong() % totalAvailable;
int dir = 0;
// skip zero available space directory,
// because totalAvailable is greater than 0 and randomPosition
// is less than totalAvailable, we can find a valid directory
// with nonzero available space.
while (availableOnDisk[dir] == 0L) {
dir++;
}
while (randomPosition > availableOnDisk[dir]) {
randomPosition -= availableOnDisk[dir++];
}
appStorageDir = getApplicationDir(new Path(localDirs.get(dir)),
userFolder, appId);
return appStorageDir;
}
示例12: getWorkingDir
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
protected Path getWorkingDir(List<String> localDirs, String user,
String appId, String userFolder) throws IOException {
Path appStorageDir = null;
long totalAvailable = 0L;
long[] availableOnDisk = new long[localDirs.size()];
int i = 0;
// randomly choose the app directory
// the chance of picking a directory is proportional to
// the available space on the directory.
// firstly calculate the sum of all available space on these directories
for (String localDir : localDirs) {
Path curBase = getApplicationDir(new Path(localDir),
userFolder, appId);
long space = 0L;
try {
space = getDiskFreeSpace(curBase);
} catch (IOException e) {
LOG.warn("Unable to get Free Space for " + curBase.toString(), e);
}
availableOnDisk[i++] = space;
totalAvailable += space;
}
// throw an IOException if totalAvailable is 0.
if (totalAvailable <= 0L) {
throw new IOException("Not able to find a working directory for "
+ user);
}
// make probability to pick a directory proportional to
// the available space on the directory.
long randomPosition = RandomUtils.nextLong() % totalAvailable;
int dir = 0;
// skip zero available space directory,
// because totalAvailable is greater than 0 and randomPosition
// is less than totalAvailable, we can find a valid directory
// with nonzero available space.
while (availableOnDisk[dir] == 0L) {
dir++;
}
while (randomPosition > availableOnDisk[dir]) {
randomPosition -= availableOnDisk[dir++];
}
appStorageDir = getApplicationDir(new Path(localDirs.get(dir)),
userFolder, appId);
return appStorageDir;
}
示例13: getRandomId
import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
/**
* Generates a random long used in ids.
*
* @return A random ID
*/
public static long getRandomId() {
return RandomUtils.nextLong() + 1;
}