当前位置: 首页>>代码示例>>Java>>正文


Java Optional.fromNullable方法代码示例

本文整理汇总了Java中org.whispersystems.libsignal.util.guava.Optional.fromNullable方法的典型用法代码示例。如果您正苦于以下问题:Java Optional.fromNullable方法的具体用法?Java Optional.fromNullable怎么用?Java Optional.fromNullable使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.whispersystems.libsignal.util.guava.Optional的用法示例。


在下文中一共展示了Optional.fromNullable方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: SignalServiceDataMessage

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
/**
 * Construct a SignalServiceDataMessage.
 *
 * @param timestamp The sent timestamp.
 * @param group 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.
 */
public SignalServiceDataMessage(long timestamp, SignalServiceGroup group,
                                List<SignalServiceAttachment> attachments,
                                String body, boolean endSession, int expiresInSeconds,
                                boolean expirationUpdate)
{
  this.timestamp        = timestamp;
  this.body             = Optional.fromNullable(body);
  this.group            = Optional.fromNullable(group);
  this.endSession       = endSession;
  this.expiresInSeconds = expiresInSeconds;
  this.expirationUpdate = expirationUpdate;

  if (attachments != null && !attachments.isEmpty()) {
    this.attachments = Optional.of(attachments);
  } else {
    this.attachments = Optional.absent();
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:29,代码来源:SignalServiceDataMessage.java

示例2: getProximityLock

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private Optional<PowerManager.WakeLock> getProximityLock(PowerManager pm) {
  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    if (pm.isWakeLockLevelSupported(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK)) {
      return Optional.fromNullable(pm.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK,
                                                  "Signal Proximity Lock"));
    } else {
      return Optional.absent();
    }
  } else {
    try {
      return Optional.fromNullable(pm.newWakeLock(PROXIMITY_SCREEN_OFF_WAKE_LOCK, "RedPhone Incall"));
    } catch (Throwable t) {
      Log.e(TAG, "Failed to create proximity lock", t);
      return Optional.absent();
    }
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:18,代码来源:ProximityLock.java

示例3: constructAttachmentFromUri

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
protected static Attachment constructAttachmentFromUri(@NonNull  Context context,
                                                       @NonNull  Uri     uri,
                                                       @NonNull  String  defaultMime,
                                                                 long     size,
                                                                 boolean  hasThumbnail,
                                                       @Nullable String   fileName,
                                                                 boolean  voiceNote)
{
  try {
    Optional<String> resolvedType    = Optional.fromNullable(MediaUtil.getMimeType(context, uri));
    String           fastPreflightId = String.valueOf(SecureRandom.getInstance("SHA1PRNG").nextLong());
    return new UriAttachment(uri, hasThumbnail ? uri : null, resolvedType.or(defaultMime), AttachmentDatabase.TRANSFER_PROGRESS_STARTED, size, fileName, fastPreflightId, voiceNote);
  } catch (NoSuchAlgorithmException e) {
    throw new AssertionError(e);
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:17,代码来源:Slide.java

示例4: read

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public DeviceContact read() throws IOException {
  long   detailsLength     = readRawVarint32();
  byte[] detailsSerialized = new byte[(int)detailsLength];
  Util.readFully(in, detailsSerialized);

  SignalServiceProtos.ContactDetails      details = SignalServiceProtos.ContactDetails.parseFrom(detailsSerialized);
  String                                  number  = details.getNumber();
  Optional<String>                        name    = Optional.fromNullable(details.getName());
  Optional<SignalServiceAttachmentStream> avatar  = Optional.absent();
  Optional<String>                        color   = details.hasColor() ? Optional.of(details.getColor()) : Optional.<String>absent();

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

    avatar = Optional.of(new SignalServiceAttachmentStream(avatarStream, avatarContentType, null, avatarLength, null));
  }

  return new DeviceContact(number, name, avatar, color);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:22,代码来源:DeviceContactsInputStream.java

示例5: generateFullContactUpdate

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void generateFullContactUpdate()
    throws IOException, UntrustedIdentityException, NetworkException
{
  SignalServiceMessageSender messageSender   = messageSenderFactory.create();
  File                       contactDataFile = createTempFile("multidevice-contact-update");

  try {
    DeviceContactsOutputStream out      = new DeviceContactsOutputStream(new FileOutputStream(contactDataFile));
    Collection<ContactData>    contacts = ContactAccessor.getInstance().getContactsWithPush(context);

    for (ContactData contactData : contacts) {
      Uri                                       contactUri = Uri.withAppendedPath(ContactsContract.Contacts.CONTENT_URI, String.valueOf(contactData.id));
      String                                    number     = Util.canonicalizeNumber(context, contactData.numbers.get(0).number);
      Recipient                                 recipient  = RecipientFactory.getRecipientsFromString(context, number, true).getPrimaryRecipient();
      Optional<IdentityDatabase.IdentityRecord> identity   = DatabaseFactory.getIdentityDatabase(context).getIdentity(recipient.getRecipientId());
      Optional<VerifiedMessage>                 verified   = getVerifiedMessage(recipient, identity);
      Optional<String>                          name       = Optional.fromNullable(contactData.name);
      Optional<String>                          color      = getColor(number);

      out.write(new DeviceContact(number, name, getAvatar(contactUri), color, verified));
    }

    out.close();
    sendUpdate(messageSender, contactDataFile, true);
  } catch(InvalidNumberException e) {
    Log.w(TAG, e);
  } finally {
    if (contactDataFile != null) contactDataFile.delete();
  }
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:31,代码来源:MultiDeviceContactUpdateJob.java

示例6: SelectedRecipientsAdapter

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SelectedRecipientsAdapter(@NonNull Context context,
                                 @NonNull Collection<Recipient> existingRecipients,
                                 @Nullable String existingOwner,
                                 @Nullable Set<String> existingAdmins)
{
  this.context             = context;
  this.ownerNumber         = Optional.fromNullable(Util.canonicalizeNumber(context, existingOwner, existingOwner));
  this.adminNumbers        = Optional.fromNullable(Util.canonicalizeNumber(context, existingAdmins));
  this.recipients          = wrapExistingMembers(existingRecipients);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:11,代码来源:SelectedRecipientsAdapter.java

示例7: find

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientWrapper> find(@NonNull Recipient recipient) {
  RecipientWrapper found = null;
  for (RecipientWrapper wrapper : recipients) {
    if (wrapper.getRecipient().equals(recipient)) {
      found = wrapper;
      break;
    }
  }
  return Optional.fromNullable(found);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:11,代码来源:SelectedRecipientsAdapter.java

示例8: SignalServiceUrl

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SignalServiceUrl(String url, String hostHeader,
                        TrustStore trustStore,
                        ConnectionSpec connectionSpec)
{
  this.url            = url;
  this.hostHeader     = Optional.fromNullable(hostHeader);
  this.trustStore     = trustStore;
  this.connectionSpec = Optional.fromNullable(connectionSpec);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:10,代码来源:SignalServiceUrl.java

示例9: onRun

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Override
public void onRun() throws IOException {
  Log.w("DeliveryReceiptJob", "Sending delivery receipt...");
  SignalServiceMessageSender messageSender     = messageSenderFactory.create();
  SignalServiceAddress       textSecureAddress = new SignalServiceAddress(destination, Optional.fromNullable(relay));

  messageSender.sendDeliveryReceipt(textSecureAddress, timestamp);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:9,代码来源:DeliveryReceiptJob.java

示例10: handleMediaMessage

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
private void handleMediaMessage(@NonNull MasterSecretUnion masterSecret,
                                @NonNull SignalServiceEnvelope envelope,
                                @NonNull SignalServiceDataMessage message,
                                @NonNull Optional<Long> smsMessageId)
    throws MmsException
{
  MmsDatabase          database     = DatabaseFactory.getMmsDatabase(context);
  String               localNumber  = TextSecurePreferences.getLocalNumber(context);
  Recipients           recipients   = getMessageDestination(envelope, message);
  IncomingMediaMessage mediaMessage = new IncomingMediaMessage(masterSecret, envelope.getSource(),
                                                               localNumber, message.getTimestamp(), -1,
                                                               message.getExpiresInSeconds() * 1000, false,
                                                               Optional.fromNullable(envelope.getRelay()),
                                                               message.getBody(),
                                                               message.getGroupInfo(),
                                                               message.getAttachments());

  if (message.getExpiresInSeconds() != recipients.getExpireMessages()) {
    handleExpirationUpdate(masterSecret, envelope, message, Optional.<Long>absent());
  }

  Optional<InsertResult> insertResult = database.insertSecureDecryptedMessageInbox(masterSecret, mediaMessage, -1);

  if (insertResult.isPresent()) {
    List<DatabaseAttachment> attachments = DatabaseFactory.getAttachmentDatabase(context).getAttachmentsForMessage(insertResult.get().getMessageId());

    for (DatabaseAttachment attachment : attachments) {
      ApplicationContext.getInstance(context)
                        .getJobManager()
                        .add(new AttachmentDownloadJob(context, insertResult.get().getMessageId(),
                                                       attachment.getAttachmentId()));
    }

    if (smsMessageId.isPresent()) {
      DatabaseFactory.getSmsDatabase(context).deleteMessage(smsMessageId.get());
    }

    MessageNotifier.updateNotification(context, masterSecret.getMasterSecret().orNull(), insertResult.get().getThreadId());
  }
}
 
开发者ID:XecureIT,项目名称:PeSanKita-android,代码行数:41,代码来源:PushDecryptJob.java

示例11: find

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public Optional<RecipientWrapper> find(@NonNull Recipient recipient) {
  RecipientWrapper found = null;
  for (RecipientWrapper wrapper : recipients) {
    if (wrapper.getRecipient().equals(recipient)) found = wrapper;
  }
  return Optional.fromNullable(found);
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:8,代码来源:SelectedRecipientsAdapter.java

示例12: provideSignalMessageSenderFactory

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
@Provides
SignalMessageSenderFactory provideSignalMessageSenderFactory() {
  return new SignalMessageSenderFactory() {
    @Override
    public SignalServiceMessageSender create() {
      return new SignalServiceMessageSender(networkAccess.getConfiguration(context),
                                            TextSecurePreferences.getLocalNumber(context),
                                            TextSecurePreferences.getPushServerPassword(context),
                                            new SignalProtocolStoreImpl(context),
                                            BuildConfig.USER_AGENT,
                                            Optional.fromNullable(MessageRetrievalService.getPipe()),
                                            Optional.<SignalServiceMessageSender.EventListener>of(new SecurityEventListener(context)));
    }
  };
}
 
开发者ID:CableIM,项目名称:Cable-Android,代码行数:16,代码来源:SignalCommunicationModule.java

示例13: read

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
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, null, avatarLength, null));
  }

  return new DeviceGroup(id, name, members, avatar, active);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:28,代码来源:DeviceGroupsInputStream.java

示例14: SignalServiceAttachmentPointer

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
public SignalServiceAttachmentPointer(long id, String contentType, String filename, byte[] key, String relay,
                                      Optional<Integer> size, Optional<byte[]> preview,
                                      Optional<byte[]> digest)
{
  super(contentType, filename);
  this.id      = id;
  this.key     = key;
  this.relay   = Optional.fromNullable(relay);
  this.size    = size;
  this.preview = preview;
  this.digest  = digest;
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:13,代码来源:SignalServiceAttachmentPointer.java

示例15: SignalServiceGroup

import org.whispersystems.libsignal.util.guava.Optional; //导入方法依赖的package包/类
/**
 * Construct a group context.
 * @param type The group message type (update, deliver, quit).
 * @param groupId The group ID.
 * @param name The group title.
 * @param members The group membership list.
 * @param avatar The group avatar icon.
 * @param owner The group owner.
 * @param admins The group admin list.
 */
public SignalServiceGroup(Type type, byte[] groupId, String name,
                          List<String> members,
                          SignalServiceAttachment avatar,
                          String owner, List<String> admins)
{
  this.type    = type;
  this.groupId = groupId;
  this.name    = Optional.fromNullable(name);
  this.members = Optional.fromNullable(members);
  this.avatar  = Optional.fromNullable(avatar);
  this.owner   = Optional.fromNullable(owner);
  this.admins  = Optional.fromNullable(admins);
}
 
开发者ID:XecureIT,项目名称:PeSanKita-lib,代码行数:24,代码来源:SignalServiceGroup.java


注:本文中的org.whispersystems.libsignal.util.guava.Optional.fromNullable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。