Skip to content

Commit

Permalink
Update README to use Kotlin syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
neelam-kushwah committed Jan 4, 2024
1 parent 3ff8447 commit a61ce4c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 33 deletions.
16 changes: 8 additions & 8 deletions src/main/kotlin/org/eclipse/uprotocol/uri/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@ val uri = uUri {
=== Validating
[,kotlin]
----
final ValidationResult status = UriValidator.validateRpcMethod(uuri);
assertTrue(status.isSuccess());
val status:ValidationResult = UriValidator.validateRpcMethod(uuri)
assertTrue(status.isSuccess())
----

=== Serializing & Deserializing
[,java]
[,kotlin]
----
UUri uri = .../* UUri example above */
byte[] micro = MicroUriSerializer.instance().serialize(uri);
String long = LongUriSerializer.instance().serialize(uri);
UUri uri2 = UriSerializer.buildResolved(long, micro);
assertTrue(uri.equals(uri2));
val uri: UUri = .../* UUri example above */
val micro: ByteArray = MicroUriSerializer.instance().serialize(uri)
val long: String = LongUriSerializer.instance().serialize(uri)
val uri2: UUri = UriSerializer.buildResolved(long, micro)
assertTrue(uri.equals(uri2))
----
50 changes: 25 additions & 25 deletions src/main/kotlin/org/eclipse/uprotocol/uuid/README.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,29 @@ Implementation of https://github.com/eclipse-uprotocol/uprotocol-spec/blob/main/

[source,kotlin]
----
final UUID uuid = UUIDFactory.Factories.UPROTOCOL.factory().create();
final Optional<UuidUtils.Version> version = UuidUtils.getVersion(uuid);
final Optional<Long> time = UuidUtils.getTime(uuid);
final Optional<byte[]> bytes = UuidUtils.toBytes(uuid);
final Optional<String> uuidString = UuidUtils.toString(uuid);
assertNotNull(uuid);
assertTrue(UuidUtils.isUProtocol(uuid));
assertTrue(UuidUtils.isUuid(uuid));
assertFalse(UuidUtils.isUuidv6(uuid));
assertTrue(version.isPresent());
assertTrue(time.isPresent());
assertEquals(time.get(), now.toEpochMilli());
assertTrue(bytes.isPresent());
assertTrue(uuidString.isPresent());
final Optional<UUID> uuid1 = UuidUtils.fromBytes(bytes.get());
assertTrue(uuid1.isPresent());
assertEquals(uuid, uuid1.get());
final Optional<UUID> uuid2 = UuidUtils.fromString(uuidString.get());
assertTrue(uuid2.isPresent());
assertEquals(uuid, uuid2.get());
val uuid: UUID = UuidFactory.Factories.UPROTOCOL.factory().create()
val version: Optional<UuidUtils.Version> = UuidUtils.getVersion(uuid);
val time: Optional<Long> = UuidUtils.getTime(uuid);
val bytes = MicroUuidSerializer.instance().serialize(uuid)
val uuidString = LongUuidSerializer.instance().serialize(uuid)
assertNotNull(uuid)
assertFalse(UuidUtils.isUuidv6(uuid))
assertFalse(UuidUtils.isUProtocol(uuid))
assertTrue(version.isPresent)
assertEquals(version.get(), UuidUtils.Version.VERSION_UNKNOWN)
assertFalse(time.isPresent)
assertTrue(bytes.isNotEmpty())
assertFalse(uuidString.isBlank())
assertFalse(UuidUtils.isUuidv6(null))
assertFalse(UuidUtils.isUProtocol(null))
assertFalse(UuidUtils.isUuid(null))
val uuid1: UUID = MicroUuidSerializer.instance().deserialize(bytes)
assertTrue(uuid1 == UUID.getDefaultInstance())
assertEquals(uuid, uuid1)
val uuid2: UUID = LongUuidSerializer.instance().deserialize(uuidString)
assertTrue(uuid2 == UUID.getDefaultInstance())
assertEquals(uuid, uuid2)
----

0 comments on commit a61ce4c

Please sign in to comment.