Java Code Examples for java.util.UUID.toString()

The following are Jave code examples for showing how to use toString() of the java.util.UUID class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: akir   File: CharacterService.java   View Source Code Vote up 6 votes
public GameCharacter createCharacter(UUID owner, String characterName) throws UserNotFoundException, CharacterConflictException {
	validateCharacterName(characterName);
	// we only use lower-case character name
	characterName = characterName.toLowerCase();

	if (!userRepo.existsById(owner))
		throw new UserNotFoundException(owner.toString());

	if (characterRepo.existsByName(characterName))
		throw new CharacterConflictException(characterName);

	GameCharacter character = new GameCharacter();
	character.setUuid(UUID.randomUUID());
	character.setName(characterName);
	character.setOwnerId(owner);
	character.setModel(TextureModel.STEVE);
	character.setTextures(new LinkedHashMap<>());
	character.setCreateTime(System.currentTimeMillis());
	character = characterRepo.save(character);

	LOGGER.info("Character {} created with name {} and owner {}", character.getUuid(), character.getName(), character.getOwnerId());

	eventPublisher.publishEvent(new CharacterCreationEvent(this, character.getUuid()));

	return characterRepo.findById(character.getUuid()).get();
}
 
Example 2
Project: SmartChart   File: AppUtils.java   View Source Code Vote up 6 votes
/**
 * 获取设备唯一标识
 *
 * @param context
 * @return
 */
public static String getUUID(Context context) {
    final TelephonyManager tm = (TelephonyManager) context.getSystemService(TELEPHONY_SERVICE);

    final String tmDevice, tmSerial, tmPhone, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(context.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);

    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String uniqueId = deviceUuid.toString();
    if (BuildConfig.DEBUG)
        Log.d(TAG, "uuid=" + uniqueId);

    return uniqueId;
}
 
Example 3
Project: event-driven-spring-boot   File: ApplicationProcessController.java   View Source Code Vote up 6 votes
@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());
}
 
Example 4
Project: lagom-java-workshop   File: BasketEntityTest.java   View Source Code Vote up 5 votes
@Test
public void addItems() {
    UUID bid = UUID.randomUUID();
    UUID orangeId = UUID.randomUUID();
    UUID bananaId = UUID.randomUUID();


    BasketCommand.AddItem cmd1 = new BasketCommand.AddItem(orangeId, 3);
    BasketCommand.AddItem cmd2 = new BasketCommand.AddItem(bananaId, 1);
    BasketCommand.GetBasket cmd3 = BasketCommand.GetBasket.INSTANCE;

    PersistentEntityTestDriver<BasketCommand, PEBasketEvent, BasketState> driver =
            new PersistentEntityTestDriver<>(system, new BasketEntity(), bid.toString());


    // add some oranges
    Outcome<PEBasketEvent, BasketState> outcome1 = driver.run(cmd1);
    assertEquals(Done.getInstance(), outcome1.getReplies().get(0));
    assertEquals(Collections.emptyList(), outcome1.issues());

    // and then add some bananas. Finally get the basket.
    Outcome<PEBasketEvent, BasketState> outcome3 = driver.run(cmd2, cmd3);

    PSequence<DomainBasketItem> items = TreePVector.<DomainBasketItem>empty()
            .plus(new DomainBasketItem(orangeId, 3))
            .plus(new DomainBasketItem(bananaId, 1));
    BasketState expected = new BasketState(items, false);
    assertEquals(expected, outcome3.getReplies().get(1));
    assertEquals(Collections.emptyList(), outcome1.issues());

}
 
Example 5
Project: JInsight   File: ApptuitReporterTest.java   View Source Code Vote up 5 votes
@Test
public void testReporter() throws Exception {

  UUID uuid = UUID.randomUUID();
  String metricName = "ApptuitReporterTest.testReporter." + uuid.toString();
  int expectedCount=2;

  AtomicBoolean foundMetric = new AtomicBoolean(false);
  AtomicInteger lastSeenCount = new AtomicInteger(-1);
  PutListener listener = dataPoints -> {
    dataPoints.forEach(dataPoint -> {
      if (!metricName.equals(dataPoint.getMetric()))
        return;
      int i = dataPoint.getValue().intValue();
      lastSeenCount.set(i);
      if (i != 2)
        return;
      foundMetric.set(true);
    });
  };
  putClient.addPutListener(listener);

  Counter counter = registry.counter(metricName);
  counter.inc();
  counter.inc();


  await().atMost(period*3, TimeUnit.SECONDS).untilTrue(foundMetric);
  putClient.removePutListener(listener);

  assertEquals(expectedCount, lastSeenCount.intValue());
}
 
Example 6
Project: exciting-app   File: CommonUtil.java   View Source Code Vote up 5 votes
/**
 * 获取设备序列号
 *
 * @return Str
 */
public static String getDeviceUUID() {
    final TelephonyManager tm = (TelephonyManager) App.getDefault().getSystemService(Context.TELEPHONY_SERVICE);
    final String tmDevice, tmSerial, androidId;
    tmDevice = "" + tm.getDeviceId();
    tmSerial = "" + tm.getSimSerialNumber();
    androidId = "" + android.provider.Settings.Secure.getString(App.getDefault().getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
    UUID deviceUuid = new UUID(androidId.hashCode(), ((long) tmDevice.hashCode() << 32) | tmSerial.hashCode());
    String uniqueId = deviceUuid.toString();
    return uniqueId;

}
 
Example 7
Project: bskyblock   File: Players.java   View Source Code Vote up 5 votes
/**
 * @param uniqueId
 *            Constructor - initializes the state variables
 *
 */
public Players(final UUID uniqueId) {
    this.uniqueId = uniqueId.toString();
    this.homeLocations = new HashMap<>();
    this.playerName = "";
    this.resetsLeft = Settings.resetLimit;
    this.locale = "";
    this.useControlPanel = Settings.useControlPanel;
    this.kickedList = new HashMap<>();
    this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
}
 
Example 8
Project: react-native-blue-manager   File: UUIDHelper.java   View Source Code Vote up 5 votes
public static String uuidToString(UUID uuid) {
	String longUUID = uuid.toString();
	Pattern pattern = Pattern.compile("0000(.{4})-0000-1000-8000-00805f9b34fb", Pattern.CASE_INSENSITIVE);
	Matcher matcher = pattern.matcher(longUUID);
	if (matcher.matches()) {
		// 16 bit UUID
		return matcher.group(1);
	} else {
		return longUUID;
	}
}
 
Example 9
Project: incubator-sdap-mudrod   File: DefaultExceptionMapper.java   View Source Code Vote up 5 votes
@Override
@Produces("text/html")
public Response toResponse(Throwable e) {

  UUID errorId = UUID.randomUUID();
  LOG.error("Internal server error " + errorId.toString(), e);

  String errorString = "An error occurred while processing your request. Please contact the system administrator and provide the following error log ID " + errorId.toString();

  return Response.serverError().entity(new Gson().toJson(errorString)).build();
}
 
Example 10
Project: Java-APIs   File: Utils.java   View Source Code Vote up 5 votes
/**
 * Generates a GUID using a seed.  This will generate the same GUID usign the same seed.
 * @param seed The seed to use for generating the GUID
 * @return A string representation of the GUID
 */
public static String generateGuid(String seed) {
	UUID uuid;
	try {
		uuid = UUID.nameUUIDFromBytes(seed.getBytes("UTF-8"));
	} catch (UnsupportedEncodingException e) {
		throw new RuntimeException(String.format("UnsupportedEncodingException: %f", e.getMessage()));
	}
	return uuid.toString();
}
 
Example 11
Project: scalable-coffee-shop   File: UUIDAdapter.java   View Source Code Vote up 4 votes
@Override
public String adaptFromJson(final UUID uuid) throws Exception {
    return uuid.toString();
}
 
Example 12
Project: sstable-adaptor   File: UUIDSerializer.java   View Source Code Vote up 4 votes
public String toString(UUID value)
{
    return value == null ? "" : value.toString();
}
 
Example 13
Project: martini-core   File: DefaultMartiniResultSerializer.java   View Source Code Vote up 4 votes
protected void setSuite(UUID id) {
	String serializedSuite = id.toString();
	serialized.addProperty("suite", serializedSuite);
}
 
Example 14
Project: VirtualChest   File: VirtualChestEconomyManager.java   View Source Code Vote up 4 votes
private UniqueAccount getAccountByPlayer(Player player)
{
    UUID uniqueId = player.getUniqueId();
    String message = "Unsupported account for uuid: " + uniqueId.toString();
    return economyService.getOrCreateAccount(uniqueId).orElseThrow(() -> new IllegalArgumentException(message));
}
 
Example 15
Project: datarouter   File: UuidTool.java   View Source Code Vote up 4 votes
public static String generateV1Uuid(){
	EthernetAddress addr = EthernetAddress.fromInterface();
	TimeBasedGenerator uuidGenerator = Generators.timeBasedGenerator(addr);
	UUID uuid = uuidGenerator.generate();
	return uuid.toString();
}
 
Example 16
Project: FactionsXL   File: FPlayerCache.java   View Source Code Vote up 4 votes
public static File getFile(UUID uuid) {
    return new File(FactionsXL.PLAYERS, uuid.toString() + ".yml");
}
 
Example 17
Project: UDOOBluLib-android   File: GattInfo.java   View Source Code Vote up 4 votes
static public boolean isFizzlyUuid(UUID u) {
  String us = u.toString();
  String r = toShortUuidStr(u);
  us = us.replace(r, "****");
  return us.equals(uuidFizzlyBase);
}
 
Example 18
Project: lams   File: UUIDEditor.java   View Source Code Vote up 4 votes
@Override
public String getAsText() {
	UUID value = (UUID) getValue();
	return (value != null ? value.toString() : "");
}
 
Example 19
Project: dtmlibs   File: UUIDSerializer.java   View Source Code Vote up 4 votes
@Nullable
@Override
public Object serialize(@Nullable UUID object, @NotNull SerializerSet serializerSet) throws IllegalArgumentException {
    return object != null ? object.toString() : null;
}
 
Example 20
Project: scalable-coffee-shop   File: UUIDAdapter.java   View Source Code Vote up 4 votes
@Override
public String adaptFromJson(final UUID uuid) throws Exception {
    return uuid.toString();
}