UndecidedOmemoIdentityException.java

  1. /**
  2.  *
  3.  * Copyright 2017 Paul Schaub
  4.  *
  5.  * Licensed under the Apache License, Version 2.0 (the "License");
  6.  * you may not use this file except in compliance with the License.
  7.  * You may obtain a copy of the License at
  8.  *
  9.  *     http://www.apache.org/licenses/LICENSE-2.0
  10.  *
  11.  * Unless required by applicable law or agreed to in writing, software
  12.  * distributed under the License is distributed on an "AS IS" BASIS,
  13.  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14.  * See the License for the specific language governing permissions and
  15.  * limitations under the License.
  16.  */
  17. package org.jivesoftware.smackx.omemo.exceptions;

  18. import java.util.Collection;
  19. import java.util.HashSet;
  20. import java.util.Set;

  21. import org.jivesoftware.smackx.omemo.internal.OmemoDevice;

  22. /**
  23.  * Exception that is thrown when the user tries to encrypt a message for a undecided device.
  24.  *
  25.  * @author Paul Schaub
  26.  */
  27. public class UndecidedOmemoIdentityException extends Exception {
  28.     private static final long serialVersionUID = -6591706422506879747L;
  29.     private final HashSet<OmemoDevice> devices = new HashSet<>();

  30.     public UndecidedOmemoIdentityException(OmemoDevice contact) {
  31.         super();
  32.         this.devices.add(contact);
  33.     }

  34.     public UndecidedOmemoIdentityException(Collection<OmemoDevice> devices) {
  35.         super();
  36.         this.devices.addAll(devices);
  37.     }

  38.     /**
  39.      * Return the HashSet of undecided devices.
  40.      *
  41.      * @return undecided devices
  42.      */
  43.     public Set<OmemoDevice> getUndecidedDevices() {
  44.         return this.devices;
  45.     }

  46.     /**
  47.      * Add all undecided devices of another Exception to this Exceptions HashSet of undecided devices.
  48.      *
  49.      * @param other other Exception
  50.      */
  51.     public void join(UndecidedOmemoIdentityException other) {
  52.         this.devices.addAll(other.getUndecidedDevices());
  53.     }
  54. }