当前位置: 首页>>代码示例>>Java>>正文


Java NumberHelper.randomInt方法代码示例

本文整理汇总了Java中org.openyu.commons.lang.NumberHelper.randomInt方法的典型用法代码示例。如果您正苦于以下问题:Java NumberHelper.randomInt方法的具体用法?Java NumberHelper.randomInt怎么用?Java NumberHelper.randomInt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.openyu.commons.lang.NumberHelper的用法示例。


在下文中一共展示了NumberHelper.randomInt方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: run

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
public void run()
{
	System.out.println("thread[" + Thread.currentThread().getId() + "] " + " start");
	Integer result = null;
	try
	{
		//				while (result == null)
		//				{
		int randomInt = NumberHelper.randomInt(0, 1000000);
		result = Helper.createInteger(randomInt + "a");
		//				}
	}
	catch (Exception ex)
	{
		ex.printStackTrace();
	}

	System.out.println("thread[" + Thread.currentThread().getId() + "] finish. result="
			+ result);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:21,代码来源:MapCacheImplTest.java

示例2: randomType

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
 * 隨機取得列舉元素.
 *
 * @param <T>
 *            the generic type
 * @param enumType
 *            the enum type
 * @return the t
 */
public static <T extends Enum<T>> T randomType(Class<T> enumType) {
	T result = null;
	//
	if (enumType != null) {
		T[] constants = values(enumType);
		int index = NumberHelper.randomInt(0, constants.length);
		result = constants[index];
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:20,代码来源:EnumHelper.java

示例3: randomOf

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
 * 依權重取
 * 
 * @param values
 * @param weightSum
 * @return
 */
public static <E extends WeightBean> E randomOf(Collection<E> values, int weightSum) {
	E result = null;
	if (CollectionHelper.notEmpty(values)) {
		// 計算所有權重加總
		// #issue: 每次加總會變慢
		// int sum = calcWeightSum(collection);
		// System.out.println("sum: "+sum);
		//
		// #fix 傳入weightSum, ok
		int random = NumberHelper.randomInt(0, weightSum);
		//
		int accu = 0;// 累計權重
		for (E entry : values) {
			int weight = entry.getWeight();
			int low = accu;
			int high = accu + weight;
			if (random >= low && random < high) {
				result = entry;
			}
			accu = high;
			// 若機率=0,則順便算機率
			if (entry.getProbability() == 0d) {
				// 精確到小數點以下10位
				double probability = NumberHelper.divide(weight, weightSum);// 0.0039525692
				entry.setProbability(probability);
			}
		}
	}
	return result;
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:38,代码来源:BeanHelper.java

示例4: insertCat

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
// verified: ok
public void insertCat() {
	createCommonDaoImpl();
	//
	final String ID = "TEST_CAT";

	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		CatPoImpl catPo = new CatPoImpl();
		catPo.setId(ID + randomNumber);
		catPo.setValid(true);

		// #new 加入name
		catPo.addName(Locale.TRADITIONAL_CHINESE, "金吉拉");
		catPo.addName(Locale.US, "Gin Gi La");

		Serializable pk = commonDaoImpl.insert(catPo);
		System.out.println("insert: " + (pk != null ? "[success]" : "[fail]"));
		assertNotNull(pk);

		CatPoImpl existCat = commonDaoImpl.find(CatPoImpl.class, catPo.getSeq());
		assertEquals(catPo.getId(), existCat.getId());
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:32,代码来源:CommonDaoImplWithoutSpringTest.java

示例5: copyCat2Po

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
// 1000000 times: 23410 mills.
// 1000000 times: 23572 mills.
public void copyCat2Po() {
	final String ID = "TEST_CAT";
	// random
	int randomNumber = NumberHelper.randomInt(0, 1000000);
	//
	CatImpl cat = new CatImpl();
	cat.setId(ID + randomNumber);
	cat.setValid(true);
	// #new 加入name
	cat.addName(Locale.TRADITIONAL_CHINESE, "金吉拉");
	cat.addName(Locale.US, "Gin Gi La");
	// System.out.println(cat);
	cat.getAudit().setCreateDate(new Date());
	cat.getAudit().setCreateUser("sys");
	//
	Class<?> result = ClassHelper.getConventionClass(cat);
	System.out.println(result);// CatPoImpl
	//
	CatPoImpl catPo = null;
	//
	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		catPo = ClassHelper.copyProperties(cat);
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");

	System.out.println(catPo);
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:34,代码来源:CommonDaoImplWithoutSpringTest.java

示例6: insert

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
// round: 3.38 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+-
// 0.00], GC.calls: 3, GC.time: 0.02, time.total: 3.38, time.warmup: 0.00,
// time.bench: 3.38
public void insert() {
	createCommonServiceImpl();
	//
	final String ID = "TEST_CAT";
	int count = 10;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		CatImpl cat = new CatImpl();
		cat.setId(ID + randomNumber);
		cat.setValid(true);

		// #new 加入name
		cat.addName(Locale.TRADITIONAL_CHINESE, "金吉拉");
		cat.addName(Locale.US, "Gin Gi La");

		Serializable pk = commonServiceImpl.insert(cat);
		printInsert(i, pk);
		assertNotNull(pk);

		CatImpl foundEntity = commonServiceImpl.find(CatImpl.class, cat.getSeq());
		assertEquals(cat.getId(), foundEntity.getId());
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:34,代码来源:CommonServiceImplTest.java

示例7: insertByPo

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
// round: 3.59 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+-
// 0.00], GC.calls: 3, GC.time: 0.02, time.total: 3.59, time.warmup: 0.00,
// time.bench: 3.59
public void insertByPo() {
	createCommonServiceImpl();
	//
	final String ID = "TEST_CAT";
	int count = 10;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		CatPoImpl cat = new CatPoImpl();
		cat.setId(ID + randomNumber);
		cat.setValid(true);

		// #new 加入name
		cat.addName(Locale.TRADITIONAL_CHINESE, "金吉拉");
		cat.addName(Locale.US, "Gin Gi La");

		Serializable pk = commonServiceImpl.insert(cat);
		printInsert(i, pk);
		assertNotNull(pk);

		CatImpl foundEntity = commonServiceImpl.find(CatImpl.class, cat.getSeq());
		assertEquals(cat.getId(), foundEntity.getId());
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:34,代码来源:CommonServiceImplTest.java

示例8: randomWuxingTypes

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
/**
 * 隨機五行
 * 
 * 自然機率
 * 
 * @return
 */
protected List<WuxingType> randomWuxingTypes() {
	List<WuxingType> wuxings = new LinkedList<WuxingType>();
	//
	int length = WuxingType.values().length;
	for (int i = 0; i < length; i++) {
		int wuxingValue = NumberHelper.randomInt(1, length + 1);
		WuxingType wuxingType = EnumHelper.valueOf(WuxingType.class, wuxingValue);
		wuxings.add(wuxingType);
	}
	return wuxings;
}
 
开发者ID:mixaceh,项目名称:openyu-mix,代码行数:19,代码来源:WuxingMachineImpl.java

示例9: randomInt

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
protected static int randomInt() {
	return NumberHelper.randomInt();
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:4,代码来源:BaseTestSupporter.java

示例10: crudWithNoTx

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
public void crudWithNoTx() throws Exception {
	createSessionFactory();
	//
	Session session = sessionFactory.openSession();
	try {
		//
		final String ID = "TEST_DOG";
		DogPoImpl dogPo = new DogPoImpl();
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);
		String id = ID + randomNumber;
		dogPo.setId(id);

		int result = 0;
		// create
		session.save(dogPo);
		result = 1;
		printInsert(0, result);
		assertTrue(result > 0);

		// retrieve
		// 使用load, 若讀不到資料時會報ObjectNotFoundException
		// 使用get, 若讀不到資料則傳回null
		DogPoImpl foundEntity = (DogPoImpl) session.load(DogPoImpl.class,
				dogPo.getSeq());
		printFind(0, foundEntity);
		assertEquals(id, foundEntity.getId());

		// update
		dogPo.setValid(true);
		result = 0;
		session.update(dogPo);
		result = 1;
		printUpdate(0, result);
		assertTrue(result > 0);

		// delete
		result = 0;
		session.delete(dogPo);
		result = 1;
		printDelete(0, result);
		assertTrue(result > 0);
		//
	} finally {
		// 若設定
		// hibernate.transaction.auto_close_session=true,再呼叫session.close()
		// 會報 org.hibernate.SessionException: Session was already closed
		session.close();
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:52,代码来源:HibernateCfgTest.java

示例11: crudWithTx

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
public void crudWithTx() throws Exception {
	createSessionFactory();
	//
	Session session = sessionFactory.openSession();
	Transaction tx = null;
	try {
		final String ID = "TEST_DOG";
		DogPoImpl dogPo = new DogPoImpl();
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);
		String id = ID + randomNumber;
		dogPo.setId(id);

		// create
		tx = session.beginTransaction();
		int result = 0;
		session.save(dogPo);
		result = 1;
		printInsert(0, result);
		assertTrue(result > 0);

		// tx.commit();

		// retrieve
		// 使用load, 若讀不到資料時會報ObjectNotFoundException
		// 使用get, 若讀不到資料則傳回null
		DogPoImpl foundEntity = (DogPoImpl) session.load(DogPoImpl.class,
				dogPo.getSeq());
		printFind(0, foundEntity);
		assertEquals(id, foundEntity.getId());

		// update
		// tx = session.beginTransaction();
		dogPo.setValid(true);
		result = 0;
		session.update(dogPo);
		result = 1;
		printUpdate(0, result);
		assertTrue(result > 0);

		// tx.commit();

		// delete
		result = 0;
		session.delete(dogPo);
		result = 1;
		printDelete(0, result);
		assertTrue(result > 0);

		tx.commit();
	} catch (Exception ex) {
		ex.printStackTrace();
		//
		if (tx != null)
			tx.rollback();
	} finally {
		// 若設定
		// hibernate.transaction.auto_close_session=true,再呼叫session.close()
		// 會報 org.hibernate.SessionException: Session was already closed
		session.close();
	}
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:64,代码来源:HibernateCfgTest.java

示例12: crud

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
// insert -> find -> delete
//
// 10 times: 1052 mills.
// 10 times: 1172 mills.
// 10 times: 1009 mills.
//
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
// round: 0.39 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+-
// 0.00], GC.calls: 0, GC.time: 0.00, time.total: 0.39, time.warmup: 0.00,
// time.bench: 0.39
public void crud() {
	//
	final String ID = "TEST_DOG";
	// final String NAME = "TEST_NAME";

	int count = 10;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		DogPoImpl dogPo = new DogPoImpl();
		String id = ID + randomNumber;
		dogPo.setId(id);

		// #deprecated, 改成 addName
		// LocaleNameEntity name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.TRADITIONAL_CHINESE);
		// name.setName("拉拉");
		// dogPo.getNames().add(name);
		// //
		// name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.US);
		// name.setName("LaLa");
		// dogPo.getNames().add(name);

		// #new 加入name
		dogPo.addName(Locale.TRADITIONAL_CHINESE, "拉拉");
		dogPo.addName(Locale.US, "LaLa");

		// create
		Serializable pk = commonDao.insert(dogPo);
		printInsert(i, pk);
		assertNotNull(pk);

		// retrieve
		DogPoImpl foundEntity = commonDao.find(DogPoImpl.class, dogPo.getSeq());
		printFind(i, foundEntity);
		assertEquals(id, foundEntity.getId());

		// update
		dogPo.setValid(true);
		int updated = commonDao.update(dogPo);
		printUpdate(i, updated);
		assertTrue(updated > 0);

		// delete
		DogPoImpl deletedEntity = commonDao.delete(DogPoImpl.class, dogPo.getSeq());
		printDelete(i, deletedEntity);
		assertNotNull(deletedEntity);
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:66,代码来源:CommonDaoImplTest.java

示例13: insert

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
@BenchmarkOptions(benchmarkRounds = 1, warmupRounds = 0, concurrency = 1)
// round: 0.30 [+- 0.00], round.block: 0.00 [+- 0.00], round.gc: 0.00 [+-
// 0.00], GC.calls: 0, GC.time: 0.00, time.total: 0.30, time.warmup: 0.00,
// time.bench: 0.30
public void insert() {
	final String ID = "TEST_DOG";

	// random
	int randomNumber = NumberHelper.randomInt(0, 1000000);

	DogPoImpl dogPo = new DogPoImpl();
	dogPo.setId(ID + randomNumber);
	dogPo.setValid(true);
	// audit 已在EntityHelper.doAudit處理,故不需自行處理

	// AuditEntity audit = new AuditEntitySupporter();
	// audit.setCreateUser("sys");
	// audit.setCreateDate(DateHelper.today());
	// dogPo.setAudit(audit);

	// #deprecated, 改成 addName
	// LocaleNameEntity name = new LocaleNameEntitySupporter();
	// name.setLocale(Locale.TRADITIONAL_CHINESE);
	// name.setName("拉拉");
	// dogPo.getNames().add(name);
	// //
	// name = new LocaleNameEntitySupporter();
	// name.setLocale(Locale.US);
	// name.setName("LaLa");
	// dogPo.getNames().add(name);

	// #new 加入name
	dogPo.addName(Locale.TRADITIONAL_CHINESE, "拉拉");
	dogPo.addName(Locale.US, "LaLa");

	Serializable pk = commonDao.insert(dogPo);
	System.out.println("insert: " + (pk != null ? "[success]" : "[fail]"));
	assertNotNull(pk);

	DogPoImpl foundEntity = commonDao.find(DogPoImpl.class, dogPo.getSeq());
	assertEquals(dogPo.getId(), foundEntity.getId());
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:44,代码来源:CommonDaoImplTest.java

示例14: crud

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
// insert -> find -> delete
//
// 10 times: 1052 mills.
// 10 times: 1172 mills.
// 10 times: 1009 mills.
//
// verified: ok
public void crud() {
	createCommonDaoImpl();
	//
	final String ID = "TEST_DOG";
	// final String NAME = "TEST_NAME";

	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		DogPoImpl dogPo = new DogPoImpl();
		String id = ID + randomNumber;
		dogPo.setId(id);

		// #deprecated, 改成 addName
		// LocaleNameEntity name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.TRADITIONAL_CHINESE);
		// name.setName("拉拉");
		// dogPo.getNames().add(name);
		// //
		// name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.US);
		// name.setName("LaLa");
		// dogPo.getNames().add(name);

		// #new 加入name
		dogPo.addName(Locale.TRADITIONAL_CHINESE, "拉拉");
		dogPo.addName(Locale.US, "LaLa");

		// create
		Serializable pk = commonDaoImpl.insert(dogPo);
		System.out.println("#." + i + " insert: " + (pk != null ? "[success]" : "[fail]"));
		assertNotNull(pk);

		// retrieve
		DogPoImpl foundEntity = commonDaoImpl.find(DogPoImpl.class, dogPo.getSeq());
		System.out.println("#." + i + " find: " + (foundEntity != null ? "[success]" : "[fail]"));
		assertEquals(id, foundEntity.getId());

		// update
		dogPo.setValid(true);
		int updated = commonDaoImpl.update(dogPo);
		System.out.println("#." + i + " update: " + (updated > 0 ? "[success]" : "[fail]"));
		assertTrue(updated > 0);

		// delete
		DogPoImpl deletedEntity = commonDaoImpl.delete(DogPoImpl.class, dogPo.getSeq());
		System.out.println("#." + i + " delete: " + (deletedEntity != null ? "[success]" : "[fail]"));
		assertNotNull(deletedEntity);

	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:65,代码来源:CommonDaoImplWithoutSpringTest.java

示例15: insert

import org.openyu.commons.lang.NumberHelper; //导入方法依赖的package包/类
@Test
// verified: ok
public void insert() {
	createCommonDaoImpl();
	//
	final String ID = "TEST_DOG";

	int count = 1;
	long beg = System.currentTimeMillis();
	for (int i = 0; i < count; i++) {
		// random
		int randomNumber = NumberHelper.randomInt(0, 1000000);

		DogPoImpl dogPo = new DogPoImpl();
		dogPo.setId(ID + randomNumber);
		dogPo.setValid(true);
		// audit 已在EntityHelper.doAudit處理,故不需自行處理

		// AuditEntity audit = new AuditEntitySupporter();
		// audit.setCreateUser("sys");
		// audit.setCreateDate(DateHelper.today());
		// dogPo.setAudit(audit);

		// #deprecated, 改成 addName
		// LocaleNameEntity name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.TRADITIONAL_CHINESE);
		// name.setName("拉拉");
		// dogPo.getNames().add(name);
		// //
		// name = new LocaleNameEntitySupporter();
		// name.setLocale(Locale.US);
		// name.setName("LaLa");
		// dogPo.getNames().add(name);

		// #new 加入name
		dogPo.addName(Locale.TRADITIONAL_CHINESE, "拉拉");
		dogPo.addName(Locale.US, "LaLa");

		Serializable pk = commonDaoImpl.insert(dogPo);
		System.out.println("insert: " + (pk != null ? "[success]" : "[fail]"));
		assertNotNull(pk);

		DogPoImpl foundEntity = commonDaoImpl.find(DogPoImpl.class, dogPo.getSeq());
		assertEquals(dogPo.getId(), foundEntity.getId());
	}
	long end = System.currentTimeMillis();
	System.out.println(count + " times: " + (end - beg) + " mills. ");
}
 
开发者ID:mixaceh,项目名称:openyu-commons,代码行数:49,代码来源:CommonDaoImplWithoutSpringTest.java


注:本文中的org.openyu.commons.lang.NumberHelper.randomInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。