當前位置: 首頁>>代碼示例>>Java>>正文


Java RandomUtils.nextLong方法代碼示例

本文整理匯總了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;
}
 
開發者ID:epam,項目名稱:NGB,代碼行數:33,代碼來源:ExternalDBBindingTest.java

示例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()));
            }

        }
    });

}
 
開發者ID:Communote,項目名稱:communote-server,代碼行數:34,代碼來源:TaskManagementTest.java

示例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);
}
 
開發者ID:SmartDataAnalytics,項目名稱:R2RLint,代碼行數:12,代碼來源:RdbSink.java

示例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));
   }
}
 
開發者ID:shopping24,項目名稱:solr-bmax-queryparser,代碼行數:13,代碼來源:LongArraySparseMutableTest.java

示例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;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:49,代碼來源:DockerContainerExecutor.java

示例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;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:49,代碼來源:DefaultContainerExecutor.java

示例7: nextConnectionId

import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private long nextConnectionId() {
    return RandomUtils.nextLong();
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:4,代碼來源:CopycatTransportClient.java

示例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;
}
 
開發者ID:aliyun-beta,項目名稱:aliyun-oss-hadoop-fs,代碼行數:49,代碼來源:DockerContainerExecutor.java

示例9: random

import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
@Override
public Long random() {
	return RandomUtils.nextLong();
}
 
開發者ID:namics,項目名稱:java-random,代碼行數:5,代碼來源:LongGenerator.java

示例10: getUniqueNumber

import org.apache.commons.lang.math.RandomUtils; //導入方法依賴的package包/類
private static String getUniqueNumber() {
	return System.currentTimeMillis() + "" + RandomUtils.nextLong();
}
 
開發者ID:chenjianjx,項目名稱:wsdl2html,代碼行數:4,代碼來源:Wsdl2HtmlMain.java

示例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;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:49,代碼來源:DockerContainerExecutor.java

示例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;
}
 
開發者ID:hopshadoop,項目名稱:hops,代碼行數:49,代碼來源:DefaultContainerExecutor.java

示例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;
}
 
開發者ID:Knewton,項目名稱:KassandraMRHelper,代碼行數:9,代碼來源:RandomStudentEventGenerator.java


注:本文中的org.apache.commons.lang.math.RandomUtils.nextLong方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。