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


Java RandomUtils類代碼示例

本文整理匯總了Java中org.apache.commons.lang3.RandomUtils的典型用法代碼示例。如果您正苦於以下問題:Java RandomUtils類的具體用法?Java RandomUtils怎麽用?Java RandomUtils使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


RandomUtils類屬於org.apache.commons.lang3包,在下文中一共展示了RandomUtils類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: addDocument

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
private Document addDocument(int i) {
    Document document = new Document();
    document.add(new StringField("key1", "key" + i, Field.Store.YES));
    document.add(new IntField("key2", i * 100000, Field.Store.YES));
    document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES));
    document.add(new LongField("key4", (long) i * 100000, Field.Store.YES));
    document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES));
    document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES));
    document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES));
    document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5))));
    document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000)));
    document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000)));
    document.add(new LongField("key11", (long) i * 50000, Field.Store.YES));
    document.add(new IntField("key12", i * 50000, Field.Store.YES));
    document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES));
    document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES));
    document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES));
    return document;
}
 
開發者ID:shijiebei2009,項目名稱:RedisDirectory,代碼行數:20,代碼來源:TestLucene.java

示例2: testDownloadGzip

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testDownloadGzip() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final int length = 1457;
    final byte[] content = RandomUtils.nextBytes(length);
    final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final InputStream in = new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback());
    assertNotNull(in);
    new StreamCopier(status, status).transfer(in, new NullOutputStream());
    assertEquals(content.length, status.getOffset());
    assertEquals(content.length, status.getLength());
    in.close();
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:27,代碼來源:S3ReadFeatureTest.java

示例3: testCreateAndGet

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testCreateAndGet(){
	Account.Builder builder = Account.newBuilder();
	long uid = System.currentTimeMillis();
	long id = (uid * 10 + 1);
	builder.setId(id);
	builder.setBalance(RandomUtils.nextInt(0, 1000));
	builder.setCreateTime(System.currentTimeMillis());
	builder.setFeeUnit(FeeUnit.CNY);
	builder.setFrozen(RandomUtils.nextInt(0, 100));
	builder.setIncome(RandomUtils.nextInt(0, 1000));
	builder.setSandbox(false);
	builder.setKey(System.currentTimeMillis());
	builder.setNotification(AccountNotification.EMAIL);
	builder.setPermissions(AccountPermission.ALLOW_IN_VALUE | AccountPermission.ALLOW_OUT_VALUE);
	builder.setRank(1);
	builder.setRiskLevel(Account.RiskLevel.HIGH);
	this.accountRepository.create(builder.build());
	
	
}
 
開發者ID:jigsaw-projects,項目名稱:jigsaw-payment,代碼行數:22,代碼來源:TestAccountRepository.java

示例4: getRandomIdWithException

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
/**
 * Get a random integer except the one(s) in the the ex
 * @param vType vertex label
 * @param ex unsorted list of unique numbers to exclude
 * @return an integer not in the exclude list or -1 if not found
 */
public int getRandomIdWithException(String vType, List<Integer> ex) {
    int start = idBean.getMinId(vType);
    int end = idBean.getMaxId(vType);
    boolean found = false;
    int rnd = -1;
    if (ex.size() > (end - start))
        return rnd;
    while (!found) {
        rnd = RandomUtils.nextInt(start, end + 1);
        if (false == ex.contains(rnd)) {
            found = true;
        }
    }
    return rnd;
}
 
開發者ID:IBM,項目名稱:janusgraph-utils,代碼行數:22,代碼來源:IdStore.java

示例5: testReadCloseReleaseEntity

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testReadCloseReleaseEntity() throws Exception {
    final Host host = new Host(new S3Protocol(), new S3Protocol().getDefaultHostname(), new Credentials(
            System.getProperties().getProperty("s3.key"), System.getProperties().getProperty("s3.secret")
    ));
    final S3Session session = new S3Session(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("test-us-east-1-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
    final Path file = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final int length = 2048;
    final byte[] content = RandomUtils.nextBytes(length);
    final TransferStatus status = new TransferStatus().length(content.length);
    status.setChecksum(new SHA256ChecksumCompute().compute(new ByteArrayInputStream(content), status));
    final OutputStream out = new S3WriteFeature(session).write(file, status, new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), out);
    out.close();
    final CountingInputStream in = new CountingInputStream(new S3ReadFeature(session).read(file, status, new DisabledConnectionCallback()));
    in.close();
    assertEquals(0L, in.getByteCount(), 0L);
    new S3DefaultDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:24,代碼來源:S3ReadFeatureTest.java

示例6: generateLocations

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
private Set<Location> generateLocations(LocationSpec locationSpec) {
    Set<Location> result = new HashSet<>();

    List<Location> originalLocationStubs = getLocationStubs();
    val locationStubs = originalLocationStubs.stream().filter(l -> RandomUtils.nextBoolean()).collect(toList());
    if (isEmpty(locationStubs)) {
        int randomLocationPosition = RandomUtils.nextInt(0, originalLocationStubs.size() - 1);
        Location randomLocationStub = originalLocationStubs.get(randomLocationPosition);
        locationStubs.add(randomLocationStub);
    }

    int locationsLimit = min(locationSpec.getMax(), locationStubs.size());
    int countLocations = RandomUtils.nextInt(1, locationsLimit);

    IntStream.range(0, countLocations).forEachOrdered(i -> {
        Location locationStub = locationStubs.get(i);
        updateLocationStubToLocation(locationSpec, locationStub);
        result.add(locationStub);
    });

    return result;
}
 
開發者ID:xm-online,項目名稱:xm-ms-entity,代碼行數:23,代碼來源:XmEntityGeneratorService.java

示例7: testWriteTildeFilename

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testWriteTildeFilename() throws Exception {
    final LocalSession session = new LocalSession(new Host(new LocalProtocol(), new LocalProtocol().getDefaultHostname()));
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final LocalWriteFeature feature = new LocalWriteFeature(session);
    final Path workdir = new LocalHomeFinderFeature(session).find();
    final Path test = new Path(workdir, String.format("~$%s", new AsciiRandomStringService().random()), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(2048);
    final TransferStatus status = new TransferStatus().length(content.length);
    final OutputStream out = feature.write(test, status, new DisabledConnectionCallback());
    new StreamCopier(status, status).withOffset(status.getOffset()).withLimit(status.getLength()).transfer(new ByteArrayInputStream(content), out);
    out.flush();
    out.close();
    final ByteArrayOutputStream b = new ByteArrayOutputStream(content.length);
    IOUtils.copy(new LocalReadFeature(session).read(test, new TransferStatus().length(content.length), new DisabledConnectionCallback()), b);
    assertArrayEquals(content, b.toByteArray());
    assertTrue(new DefaultFindFeature(session).find(test));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(test).getSize());
    new LocalDeleteFeature(session).delete(Collections.singletonList(test), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:22,代碼來源:LocalWriteFeatureTest.java

示例8: testDeleteFile

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testDeleteFile() throws Exception {
    final Host host = new Host(new SpectraProtocol() {
        @Override
        public Scheme getScheme() {
            return Scheme.http;
        }
    }, System.getProperties().getProperty("spectra.hostname"), Integer.valueOf(System.getProperties().getProperty("spectra.port")), new Credentials(
            System.getProperties().getProperty("spectra.user"), System.getProperties().getProperty("spectra.key")
    ));
    final SpectraSession session = new SpectraSession(host, new DisabledX509TrustManager(),
            new DefaultX509KeyManager());
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
    final Path container = new Path("cyberduck", EnumSet.of(Path.Type.volume));
    final Path test = new Path(container, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
    final byte[] content = RandomUtils.nextBytes(1024);
    final HttpResponseOutputStream<StorageObject> out = new S3WriteFeature(session).write(test, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.write(content, out);
    out.close();
    assertTrue(new S3FindFeature(session).find(test));
    new S3MultipleDeleteFeature(session).delete(Arrays.asList(test, test), new DisabledLoginCallback(), new Delete.DisabledCallback());
    assertFalse(new S3FindFeature(session).find(test));
    session.close();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:26,代碼來源:SpectraMultipleDeleteFeatureTest.java

示例9: generate

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Override
public Object generate(DefaultContext ctx) throws Exception {
    Number number = Number.class.cast(RandomUtils.nextInt(0, 127));
    Class<?> type = ctx.getType();
    if (!type.isPrimitive()) {
        return ReflectionUtils.stringToNumber(number, type);
    }
    if (type == Integer.TYPE) {
        return number.intValue();
    } else if (type == Long.TYPE) {
        return number.longValue();
    } else if (type == Byte.TYPE) {
        return number.byteValue();
    } else if (type == Float.TYPE) {
        return number.floatValue();
    } else if (type == Double.TYPE) {
        return number.doubleValue();
    } else if (type == Short.TYPE) {
        return number.shortValue();
    }
    throw new RandomitoException("did not generate number value for type: " + type);
}
 
開發者ID:randomito,項目名稱:randomito-all,代碼行數:23,代碼來源:NumberGenerator.java

示例10: testCopyFile

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testCopyFile() throws Exception {
    final Path home = DriveHomeFinderService.MYDRIVE_FOLDER;
    final Path vault = new Path(home, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.directory));
    final Path source = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(vault, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final CryptoVault cryptomator = new CryptoVault(vault, new DisabledPasswordStore());
    cryptomator.create(session, null, new VaultCredentials("test"));
    final DefaultVaultRegistry registry = new DefaultVaultRegistry(new DisabledPasswordStore(), new DisabledPasswordCallback(), cryptomator);
    session.withRegistry(registry);
    final byte[] content = RandomUtils.nextBytes(40500);
    final TransferStatus status = new TransferStatus();
    new CryptoBulkFeature<>(session, new DisabledBulkFeature(), new DriveDeleteFeature(session), cryptomator).pre(Transfer.Type.upload, Collections.singletonMap(source, status), new DisabledConnectionCallback());
    new StreamCopier(new TransferStatus(), new TransferStatus()).transfer(new ByteArrayInputStream(content), new CryptoWriteFeature<>(session, new DriveWriteFeature(session), cryptomator).write(source, status.length(content.length), new DisabledConnectionCallback()));
    assertTrue(new CryptoFindFeature(session, new DefaultFindFeature(session), cryptomator).find(source));
    final CopyWorker worker = new CopyWorker(Collections.singletonMap(source, target), new TestSessionPool(session, registry), PathCache.empty(), new DisabledProgressListener(), new DisabledConnectionCallback());
    worker.run(session);
    assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session), cryptomator).find(source));
    assertTrue(new CryptoFindFeature(session, new DriveFindFeature(session), cryptomator).find(target));
    final ByteArrayOutputStream out = new ByteArrayOutputStream(content.length);
    assertEquals(content.length, IOUtils.copy(new CryptoReadFeature(session, new DriveReadFeature(session), cryptomator).read(target, new TransferStatus().length(content.length), new DisabledConnectionCallback()), out));
    assertArrayEquals(content, out.toByteArray());
    new DeleteWorker(new DisabledLoginCallback(), Collections.singletonList(vault), PathCache.empty(), new DisabledProgressListener()).run(session);
    session.close();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:26,代碼來源:CopyWorkerTest.java

示例11: testRwRouteWithTransaction2

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testRwRouteWithTransaction2() {

    mapper.findByStatus((short) 1);

    transactionTemplate.execute(new TransactionCallback<Void>() {
        @Override
        public Void doInTransaction(TransactionStatus status) {

            mapper.findByStatus((short) 2);

            UserEntity entity = new UserEntity();
            entity.setCreatedAt(new Date());
            entity.setEmail(RandomStringUtils.random(6, true, true) + "@163.com");
            entity.setMobile("13800" + RandomUtils.nextLong(100000, 999999));
            entity.setType((short) 1);
            entity.setStatus((short) 1);
            mapper.insert(entity);

            mapper.findByStatus((short) 2);

            return null;
        }
    });
    System.out.println();
}
 
開發者ID:warlock-china,項目名稱:azeroth,代碼行數:27,代碼來源:MybatisTest.java

示例12: testCopy

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testCopy() throws Exception {
    final Host host = new Host(new SFTPProtocol(), "test.cyberduck.ch", new Credentials(
            System.getProperties().getProperty("sftp.user"), System.getProperties().getProperty("sftp.password")
    ));
    final SFTPSession session = new SFTPSession(host);
    session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
    session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());

    final Path source = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final Path target = new Path(new SFTPHomeDirectoryService(session).find(), new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    new DefaultTouchFeature<Void>(new DefaultUploadFeature<Void>(new SFTPWriteFeature(session))).touch(source, new TransferStatus());
    final byte[] content = RandomUtils.nextBytes(524);
    final TransferStatus status = new TransferStatus().length(content.length);
    final OutputStream out = new SFTPWriteFeature(session).write(source, status, new DisabledConnectionCallback());
    assertNotNull(out);
    new StreamCopier(status, status).withLimit(new Long(content.length)).transfer(new ByteArrayInputStream(content), out);
    out.close();
    new DefaultCopyFeature(session).copy(source, target, new TransferStatus(), new DisabledConnectionCallback());
    assertTrue(new DefaultFindFeature(session).find(source));
    assertTrue(new DefaultFindFeature(session).find(target));
    assertEquals(content.length, new DefaultAttributesFinderFeature(session).find(target).getSize());
    new SFTPDeleteFeature(session).delete(Arrays.asList(source, target), new DisabledLoginCallback(), new Delete.DisabledCallback());
    session.close();
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:26,代碼來源:DefaultCopyFeatureTest.java

示例13: testSplit

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testSplit() throws Exception {
    final FileBuffer buffer = new FileBuffer();
    buffer.truncate(200L);
    assertEquals(200L, buffer.length(), 0L);
    final byte[] chunk = RandomUtils.nextBytes(100);
    buffer.write(chunk, 0L);
    assertEquals(200L, buffer.length(), 0L);
    final byte[] compare = new byte[100];
    buffer.read(compare, 0L);
    final byte[] empty = new byte[100];
    buffer.read(empty, 100L);
    assertArrayEquals(new byte[100], empty);
    final byte[] overFileEnd = new byte[150];
    assertEquals(100L, buffer.read(overFileEnd, 0L));
    assertNotEquals(IOUtils.EOF, buffer.read(empty, 100L));
    assertEquals(IOUtils.EOF, buffer.read(new byte[1], 200L));
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:19,代碼來源:FileBufferTest.java

示例14: testWriteZeroLength

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testWriteZeroLength() throws Exception {
    final OneDriveBufferWriteFeature feature = new OneDriveBufferWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(0);
    final TransferStatus status = new TransferStatus();
    status.setLength(-1L);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    new StreamCopier(status, status).transfer(in, out);
    in.close();
    out.flush();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:24,代碼來源:OneDriveBufferWriteFeatureTest.java

示例15: testWrite

import org.apache.commons.lang3.RandomUtils; //導入依賴的package包/類
@Test
public void testWrite() throws Exception {
    final OneDriveWriteFeature feature = new OneDriveWriteFeature(session);
    final Path container = new OneDriveHomeFinderFeature(session).find();
    final byte[] content = RandomUtils.nextBytes(5 * 1024 * 1024);
    final TransferStatus status = new TransferStatus();
    status.setLength(content.length);
    final Path file = new Path(container, new AlphanumericRandomStringService().random(), EnumSet.of(Path.Type.file));
    final HttpResponseOutputStream<Void> out = feature.write(file, status, new DisabledConnectionCallback());
    final ByteArrayInputStream in = new ByteArrayInputStream(content);
    final byte[] buffer = new byte[32 * 1024];
    assertEquals(content.length, IOUtils.copyLarge(in, out, buffer));
    in.close();
    out.close();
    assertNull(out.getStatus());
    assertTrue(new DefaultFindFeature(session).find(file));
    final byte[] compare = new byte[content.length];
    final InputStream stream = new OneDriveReadFeature(session).read(file, new TransferStatus().length(content.length), new DisabledConnectionCallback());
    IOUtils.readFully(stream, compare);
    stream.close();
    assertArrayEquals(content, compare);
    new OneDriveDeleteFeature(session).delete(Collections.singletonList(file), new DisabledLoginCallback(), new Delete.DisabledCallback());
}
 
開發者ID:iterate-ch,項目名稱:cyberduck,代碼行數:24,代碼來源:OneDriveWriteFeatureTest.java


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