本文整理汇总了Java中java.util.UUID类的典型用法代码示例。如果您正苦于以下问题:Java UUID类的具体用法?Java UUID怎么用?Java UUID使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
UUID类属于java.util包,在下文中一共展示了UUID类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testFindLargeUpload
import java.util.UUID; //导入依赖的package包/类
@Test
public void testFindLargeUpload() throws Exception {
final B2Session session = new B2Session(
new Host(new B2Protocol(), new B2Protocol().getDefaultHostname(),
new Credentials(
System.getProperties().getProperty("b2.user"), System.getProperties().getProperty("b2.key")
)));
final Path bucket = new Path("test-cyberduck", EnumSet.of(Path.Type.directory, Path.Type.volume));
session.open(new DisabledHostKeyCallback(), new DisabledLoginCallback());
session.login(new DisabledPasswordStore(), new DisabledLoginCallback(), new DisabledCancelCallback());
final Path file = new Path(bucket, UUID.randomUUID().toString(), EnumSet.of(Path.Type.file));
final B2StartLargeFileResponse startResponse = session.getClient().startLargeFileUpload(
new B2FileidProvider(session).getFileid(bucket, new DisabledListProgressListener()),
file.getName(), null, Collections.emptyMap());
assertNotNull(new DefaultAttributesFinderFeature(session).find(file));
session.getClient().cancelLargeFileUpload(startResponse.getFileId());
session.close();
}
示例2: setupAdmin
import java.util.UUID; //导入依赖的package包/类
private void setupAdmin(SpringUserService userService) {
String username = "admin";
logger.info("Setup {}", username);
SpringUser admin;
Optional<SpringUser> userOptional = userService.findUserByUsername(username);
if(userOptional.isPresent()){
admin = userOptional.get();
String roles = admin.getRoles();
if(!roles.contains("ROLE_ADMIN") || !roles.contains("ROLE_USER")) {
admin.setRoles("ROLE_USER,ROLE_ADMIN");
}
} else {
admin = new SpringUserEntity();
admin.setUsername("admin");
admin.setRoles("ROLE_USER,ROLE_ADMIN");
admin.setPassword("admin");
admin.setEmail("[email protected]");
admin.setToken(UUID.randomUUID().toString());
admin.setEnabled(true);
}
userService.save(admin);
}
示例3: findReadableCharacteristic
import java.util.UUID; //导入依赖的package包/类
private BluetoothGattCharacteristic findReadableCharacteristic(BluetoothGattService service, UUID characteristicUUID) {
BluetoothGattCharacteristic characteristic = null;
int read = BluetoothGattCharacteristic.PROPERTY_READ;
List<BluetoothGattCharacteristic> characteristics = service.getCharacteristics();
for (BluetoothGattCharacteristic c : characteristics) {
if ((c.getProperties() & read) != 0 && characteristicUUID.equals(c.getUuid())) {
characteristic = c;
break;
}
}
// As a last resort, try and find ANY characteristic with this UUID, even if it doesn't have the correct properties
if (characteristic == null) {
characteristic = service.getCharacteristic(characteristicUUID);
}
return characteristic;
}
示例4: load
import java.util.UUID; //导入依赖的package包/类
/**
* Gets the stored Forge accounts from the storage
*
* @param context calling context
* @return a hash map of all Forge accounts stored
*/
public static HashMap<UUID, ForgeAccount> load(Context context) {
// Create new hash map
HashMap<UUID, ForgeAccount> accounts = new HashMap<>();
// If storage file exists
if (context.getFileStreamPath(context.getString(R.string.filename_forge_accounts)).exists()) {
// Open file stream
FileInputStream inputStream;
try {
inputStream = context.openFileInput(context.getString(R.string.filename_forge_accounts));
// Open input stream
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
// Place the file contents into a string
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
StringBuilder stringBuilder = new StringBuilder();
String line;
while ((line = bufferedReader.readLine()) != null) {
stringBuilder.append(line);
}
// Initialise GSON
Gson gson = new Gson();
// Create a list of Forge Accounts from the JSON string
List<ForgeAccount> accountList =
gson.fromJson(stringBuilder.toString(), new TypeToken<List<ForgeAccount>>() {
}.getType());
// Iterate through each Forge account and add it to the hash map
for (ForgeAccount account : accountList) {
accounts.put(account.getId(), account);
}
} catch (Exception e) {
// If there is an error, log it
Log.e(Forge.ERROR_LOG, e.getMessage());
}
}
return accounts;
}
示例5: startCreditApplicationProcess
import java.util.UUID; //导入依赖的package包/类
@PostMapping("/")
public RedirectView startCreditApplicationProcess() {
//Create Credit Application Number
UUID creditApplicationNumber = UUID.randomUUID();
Date applicationTime = new Date();
LOGGER.info("Created a new Credit Application Number: " + creditApplicationNumber.toString());
// We are saving the initial status
CreditApplicationStatus status = new CreditApplicationStatus(creditApplicationNumber.toString(), applicationTime);
repository.save(status);
LOGGER.info("Saved " + status.toString());
// We are sending a CreditApplicationNumberGeneratedEvent
CreditApplicationNumberGeneratedEvent event = new CreditApplicationNumberGeneratedEvent();
event.setApplicationNumber(creditApplicationNumber.toString());
event.setCreationTime(applicationTime);
applicationProcessChannels.creditApplicationNumberGeneratedOut()
.send(MessageBuilder.withPayload(event).build());
LOGGER.info("Sent " + event.toString());
return new RedirectView(nextProcessStepUrl + creditApplicationNumber.toString());
}
示例6: shouldSetupAttachmentTitleFromAnnotation
import java.util.UUID; //导入依赖的package包/类
@Test
public void shouldSetupAttachmentTitleFromAnnotation() {
final String uuid = UUID.randomUUID().toString();
final TestResult result = new TestResult().withUuid(uuid);
lifecycle.scheduleTestCase(result);
lifecycle.startTestCase(uuid);
attachmentWithTitleAndType("parameter value");
lifecycle.stopTestCase(uuid);
lifecycle.writeTestCase(uuid);
assertThat(results.getTestResults())
.flatExtracting(TestResult::getAttachments)
.extracting("name", "type")
.containsExactly(tuple("attachment with parameter value", "text/plain"));
}
示例7: createLocalizedBillingResourceInDB
import java.util.UUID; //导入依赖的package包/类
private LocalizedBillingResource createLocalizedBillingResourceInDB(
UUID objID, String locale, String billingResourceDataType,
byte[] billingResourceValue) throws Exception {
final LocalizedBillingResource billingResource = createLocalizedBillingResource(
objID, locale, billingResourceDataType, billingResourceValue);
runTX(new Callable<Void>() {
@Override
public Void call() throws Exception {
ds.persist(billingResource);
return null;
}
});
return findLocalizedBillingResourceInDB(billingResource);
}
示例8: ShardUpsertRequest
import java.util.UUID; //导入依赖的package包/类
public ShardUpsertRequest(ShardId shardId,
@Nullable String[] updateColumns,
@Nullable Reference[] insertColumns,
@Nullable String routing,
UUID jobId) {
super(shardId, routing, jobId);
assert updateColumns != null || insertColumns != null
: "Missing updateAssignments, whether for update nor for insert";
this.updateColumns = updateColumns;
this.insertColumns = insertColumns;
if (insertColumns != null) {
insertValuesStreamer = new Streamer[insertColumns.length];
for (int i = 0; i < insertColumns.length; i++) {
insertValuesStreamer[i] = insertColumns[i].valueType().streamer();
}
}
}
示例9: copyApk
import java.util.UUID; //导入依赖的package包/类
private static File copyApk(Context context, InputStream inputStream) {
try {
File file = new File(getApkDir(context), System.currentTimeMillis() + "_" + UUID.randomUUID() + ".apk");
OutputStream out = new FileOutputStream(file);
byte[] buffer = new byte[4096];
int read;
while ((read = inputStream.read(buffer)) != -1) {
out.write(buffer, 0, read);
}
inputStream.close();
inputStream = null;
out.flush();
out.close();
out = null;
return file;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
示例10: createGraphEntityMutation
import java.util.UUID; //导入依赖的package包/类
private GraphEntityMutation createGraphEntityMutation(BatchMutation batchMutation) {
GraphEntity.Builder builder = new GraphEntity.Builder();
Name name = TartanImplTestConstants.ATTR_DUMMY_ATTRIBUTE_NAME;
String attributeValue = "Dummy Attribute";
Metadata metadata = new MockMetadata();
GraphAttribute graphAttribute = new GraphAttribute(name, attributeValue, metadata);
builder.addAttribute(graphAttribute);
Entity.ID newEntityID = Entity.ID.valueOf("urn:entity:" + TartanImplTestConstants.ATTR_PARENT_ID.getName()
+ "." + TartanImplTestConstants.ATTR_PARENT_ID.getName() + "/" + UUID.randomUUID());
builder.setID(newEntityID);
GraphEntity entity = builder.build();
OperationPipeline assemblyLine = new OperationPipeline();
NewEntity newEntity = util.createNewEntity(TartanImplTestConstants.ATTR_PARENT_ID);
CreateEntity createEntity = new CreateEntity(newEntity);
assemblyLine.add(createEntity);
if(null == batchMutation){
MutationExecutorFactory factory = new MockMutationExecuterFactory();
batchMutation = new GraphMutation(factory );
}
GraphEntityMutation graphEntityMutation = new GraphEntityMutation(entity, assemblyLine, batchMutation);
return graphEntityMutation;
}
示例11: addsChangeStartingAtExactEndOfThirdSegment
import java.util.UUID; //导入依赖的package包/类
@Test
public void addsChangeStartingAtExactEndOfThirdSegment() {
this.builder.with(RuleChangeBuilder::input, Arrays.asList("VOICE", "CME", "ED", "UK", "INDEX"));
this.builder.with(RuleChangeBuilder::output, Collections.singletonList("Rate:2.0"));
this.builder.with(RuleChangeBuilder::changeRange,
new DateRange(NOW.plus(Period.ofWeeks(8)), NOW.plus(Period.ofWeeks(9))));
final List<RuleChange> ruleChanges = this.builder.build();
assertThat(ruleChanges, hasSize(1));
final List<RuleChange> originals = getChangesByType(ruleChanges, Type.ORIGINAL);
assertThat(originals, hasSize(0));
final List<RuleChange> newChanges = getChangesByType(ruleChanges, Type.NEW);
assertThat(newChanges, hasSize(1));
assertRuleChange(newChanges.get(0), Type.NEW, null, new UUID(0, 2),
new String[]{"VOICE", "CME", "ED", "UK", "INDEX"}, Collections.singletonMap("Rate", "2.0"),
NOW.plus(Period.ofWeeks(8)), NOW.plus(Period.ofWeeks(9)));
}
示例12: getInvoiceCoupons
import java.util.UUID; //导入依赖的package包/类
@GET
@Path("/{invoiceId}/coupons")
@Consumes({ "application/json" })
@Produces({ "application/json", "text/plain" })
@io.swagger.annotations.ApiOperation(value = "Returns a list of coupon adresses along with their balance.", notes = "", response = AddressValuePair.class, responseContainer = "List", tags={ })
@io.swagger.annotations.ApiResponses(value = {
@io.swagger.annotations.ApiResponse(code = 200, message = "returns the balance for each coupon", response = AddressValuePair.class, responseContainer = "List"),
@io.swagger.annotations.ApiResponse(code = 404, message = "invoice id not found", response = AddressValuePair.class, responseContainer = "List") })
public Response getInvoiceCoupons(@ApiParam(value = "the id of the invoice to get the coupons balances for",required=true) @PathParam("invoiceId") UUID invoiceId
,@Context SecurityContext securityContext)
throws NotFoundException {
return delegate.getInvoiceCoupons(invoiceId,securityContext);
}
示例13: insertSelectPlayerMetaTest
import java.util.UUID; //导入依赖的package包/类
@Test
public void insertSelectPlayerMetaTest() throws ClassNotFoundException {
final Plugin plugin = mockPlugin();
plugin.getConfig().set("sql.enabled", true);
Factory.initialize(plugin);
try (PlayerMetaController controller = Factory.createPlayerDataController()) {
for (final PlayerMeta item : controller.getAll()) {
controller.remove(item);
}
final UUID uuid = UUID.randomUUID();
final PlayerMeta playerMeta = new PlayerData();
assertThrows(IllegalArgumentException.class, () -> controller.store(playerMeta));
assertEquals(0, controller.size());
playerMeta.setUuid(uuid);
controller.store(playerMeta);
assertEquals(0, controller.size());
playerMeta.setName("Sample");
controller.store(playerMeta);
assertEquals(1, controller.size());
assertEquals(uuid, controller.getById(playerMeta.getId()).getUUID());
} catch (final Exception e) {
Logger.getLogger(this.getClass().getSimpleName()).log(Level.WARNING, "Failed to run test.", e);
Assert.fail();
}
}
示例14: testConvert
import java.util.UUID; //导入依赖的package包/类
@Test
public void testConvert() {
final UUID uuid = IdUtils.create();
final byte[] bytes = IdUtils.toBytes(uuid);
assertArrayEquals(bytes, converter.convertToDatabaseColumn(uuid));
assertEquals(uuid, converter.convertToEntityAttribute(bytes));
}
示例15: getActorGuid
import java.util.UUID; //导入依赖的package包/类
public UUID getActorGuid() {
try {
return UUID.fromString(actor);
} catch (IllegalArgumentException e) {
return null;
}
}