Java Code Examples for org.whispersystems.libsignal.util.guava.Optional#fromNullable()

The following examples show how to use org.whispersystems.libsignal.util.guava.Optional#fromNullable() . These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
public SignalServiceAttachmentPointer(long id, String contentType, byte[] key, String relay,
                                      Optional<Integer> size, Optional<byte[]> preview,
                                      Optional<byte[]> digest, Optional<String> fileName,
                                      boolean voiceNote, Optional<String> url)
{
  super(contentType, "");
  this.id        = id;
  this.key       = key;
  this.relay     = Optional.fromNullable(relay);
  this.size      = size;
  this.preview   = preview;
  this.digest    = digest;
  this.fileName  = fileName;
  this.voiceNote = voiceNote;
  this.url       = url;
}
 
Example 2
public @NonNull Optional<String> getUsername() {
  if (FeatureFlags.usernames()) {
    return Optional.fromNullable(username);
  } else {
    return Optional.absent();
  }
}
 
Example 3
public DeviceGroup read() throws IOException {
  long   detailsLength     = readRawVarint32();
  byte[] detailsSerialized = new byte[(int)detailsLength];
  Util.readFully(in, detailsSerialized);

  SignalServiceProtos.GroupDetails details = SignalServiceProtos.GroupDetails.parseFrom(detailsSerialized);

  if (!details.hasId()) {
    throw new IOException("ID missing on group record!");
  }

  byte[]                                  id      = details.getId().toByteArray();
  Optional<String>                        name    = Optional.fromNullable(details.getName());
  List<String>                            members = details.getMembersList();
  Optional<SignalServiceAttachmentStream> avatar  = Optional.absent();
  boolean                                 active  = details.getActive();

  if (details.hasAvatar()) {
    long        avatarLength      = details.getAvatar().getLength();
    InputStream avatarStream      = new ChunkedInputStream.LimitedInputStream(in, avatarLength);
    String      avatarContentType = details.getAvatar().getContentType();

    avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, avatarLength, Optional.<String>absent(), false, "",null));
  }

  return new DeviceGroup(id, name, members, avatar, active);
}
 
Example 4
@Test
public void serialize_and_deserialize_both_address() {
  SignalServiceAddress address      = new SignalServiceAddress(Optional.fromNullable(UUID.randomUUID()), Optional.of("+15552345678"), Optional.<String>absent());
  AddressProto         addressProto = org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer.toProtobuf(address);
  SignalServiceAddress deserialized = org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer.fromProtobuf(addressProto);

  assertEquals(address, deserialized);
}
 
Example 5
@Test
public void serialize_and_deserialize_uuid_address() {
  SignalServiceAddress address      = new SignalServiceAddress(Optional.fromNullable(UUID.randomUUID()), Optional.<String>absent(), Optional.<String>absent());
  AddressProto         addressProto = org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer.toProtobuf(address);
  SignalServiceAddress deserialized = org.whispersystems.signalservice.internal.serialize.SignalServiceAddressProtobufSerializer.fromProtobuf(addressProto);

  assertEquals(address, deserialized);
}
 
Example 6
public SignalUrl(String url, String hostHeader,
                 TrustStore trustStore,
                 ConnectionSpec connectionSpec)
{
  this.url            = url;
  this.hostHeader     = Optional.fromNullable(hostHeader);
  this.trustStore     = trustStore;
  this.connectionSpec = Optional.fromNullable(connectionSpec);
}
 
Example 7
public static SignalServiceCallMessage forHangup(HangupMessage hangupMessage, boolean isMultiRing, Integer destinationDeviceId) {
  return new SignalServiceCallMessage(Optional.absent(),
                                      Optional.absent(),
                                      Optional.absent(),
                                      Optional.of(hangupMessage),
                                      Optional.absent(),
                                      isMultiRing,
                                      Optional.fromNullable(destinationDeviceId));
}
 
Example 8
private SignalServiceContent(SignalServiceDataMessage message, SignalServiceAddress sender, int senderDevice, long timestamp, long serverTimestamp, boolean needsReceipt, SignalServiceContentProto serializedState) {
  this.sender          = sender;
  this.senderDevice    = senderDevice;
  this.timestamp       = timestamp;
  this.serverTimestamp = serverTimestamp;
  this.needsReceipt    = needsReceipt;
  this.serializedState = serializedState;

  this.message            = Optional.fromNullable(message);
  this.synchronizeMessage = Optional.absent();
  this.callMessage        = Optional.absent();
  this.readMessage        = Optional.absent();
  this.typingMessage      = Optional.absent();
}
 
Example 9
public @NonNull Optional<String> getE164() {
  return Optional.fromNullable(e164);
}
 
Example 10
public SignalServiceContent(SignalServiceSyncMessage synchronizeMessage) {
  this.message            = Optional.absent();
  this.synchronizeMessage = Optional.fromNullable(synchronizeMessage);
  this.callMessage        = Optional.absent();
  this.readMessage        = Optional.absent();
}
 
Example 11
public Reader(Cursor cursor, @Nullable MasterSecret masterSecret) {
  this.cursor       = cursor;
  this.masterSecret = Optional.fromNullable(masterSecret);
}
 
Example 12
public Phone build() {
  return new Phone(value, type, Optional.fromNullable(label));
}
 
Example 13
@NonNull
public Optional<String> getFileName() {
  return Optional.fromNullable(attachment.getFileName());
}
 
Example 14
@Override
public @NonNull Optional<SignalGroupV1Record> getMatching(@NonNull SignalGroupV1Record record) {
  return Optional.fromNullable(localByGroupId.get(GroupId.v1orThrow(record.getGroupId())));
}
 
Example 15
public @NonNull Optional<GroupId> getGroupId() {
  return Optional.fromNullable(groupId);
}
 
Example 16
/**
 * Construct a SignalServiceDataMessage.
 *
 * @param timestamp The sent timestamp.
 * @param group The group information (or null if none).
 * @param groupV2 The group information (or null if none).
 * @param attachments The attachments (or null if none).
 * @param body The message contents.
 * @param endSession Flag indicating whether this message should close a session.
 * @param expiresInSeconds Number of seconds in which the message should disappear after being seen.
 */
SignalServiceDataMessage(long timestamp,
                         SignalServiceGroup group, SignalServiceGroupV2 groupV2,
                         List<SignalServiceAttachment> attachments,
                         String body, boolean endSession, int expiresInSeconds,
                         boolean expirationUpdate, byte[] profileKey, boolean profileKeyUpdate,
                         Quote quote, List<SharedContact> sharedContacts, List<Preview> previews,
                         Sticker sticker, boolean viewOnce, Reaction reaction, RemoteDelete remoteDelete)
{
  try {
    this.group = SignalServiceGroupContext.createOptional(group, groupV2);
  } catch (InvalidMessageException e) {
    throw new AssertionError(e);
  }

  this.timestamp             = timestamp;
  this.body                  = OptionalUtil.absentIfEmpty(body);
  this.endSession            = endSession;
  this.expiresInSeconds      = expiresInSeconds;
  this.expirationUpdate      = expirationUpdate;
  this.profileKey            = Optional.fromNullable(profileKey);
  this.profileKeyUpdate      = profileKeyUpdate;
  this.quote                 = Optional.fromNullable(quote);
  this.sticker               = Optional.fromNullable(sticker);
  this.viewOnce              = viewOnce;
  this.reaction              = Optional.fromNullable(reaction);
  this.remoteDelete          = Optional.fromNullable(remoteDelete);

  if (attachments != null && !attachments.isEmpty()) {
    this.attachments = Optional.of(attachments);
  } else {
    this.attachments = Optional.absent();
  }

  if (sharedContacts != null && !sharedContacts.isEmpty()) {
    this.contacts = Optional.of(sharedContacts);
  } else {
    this.contacts = Optional.absent();
  }

  if (previews != null && !previews.isEmpty()) {
    this.previews = Optional.of(previews);
  } else {
    this.previews = Optional.absent();
  }
}
 
Example 17
public Phone build() {
  return new Phone(value, type, Optional.fromNullable(label));
}
 
Example 18
/**
 * The UUID of the member that made the change.
 */
public static Optional<UUID> editorUuid(DecryptedGroupChange change) {
  return Optional.fromNullable(change != null ? UuidUtil.fromByteStringOrNull(change.getEditor()) : null);
}
 
Example 19
public void setSelectedTransport(@Nullable  TransportOption transportOption) {
  this.selectedOption = Optional.fromNullable(transportOption);
  notifyTransportChangeListeners();
}
 
Example 20
/**
 * Returns and removes any content that is dependent on the provided message id.
 * @param sender        The sender of the message in question.
 * @param sentTimestamp The sent timestamp of the message in question.
 */
public Optional<List<SignalServiceContent>> retrieve(@NonNull RecipientId sender, long sentTimestamp) {
  return Optional.fromNullable(cache.remove(new MessageId(sender, sentTimestamp)));
}