/**
   * Required for making Beacon parcelable
   *
   * @param in parcel
   */
  protected Beacon(Parcel in) {
    int size = in.readInt();

    this.mIdentifiers = new ArrayList<Identifier>(size);
    for (int i = 0; i < size; i++) {
      mIdentifiers.add(Identifier.parse(in.readString()));
    }
    mDistance = in.readDouble();
    mRssi = in.readInt();
    mTxPower = in.readInt();
    mBluetoothAddress = in.readString();
    mBeaconTypeCode = in.readInt();
    mServiceUuid = in.readInt();
    int dataSize = in.readInt();
    this.mDataFields = new ArrayList<Long>(dataSize);
    for (int i = 0; i < dataSize; i++) {
      mDataFields.add(in.readLong());
    }
    int extraDataSize = in.readInt();
    if (LogManager.isVerboseLoggingEnabled()) {
      LogManager.d(TAG, "reading " + extraDataSize + " extra data fields from parcel");
    }
    this.mExtraDataFields = new ArrayList<Long>(extraDataSize);
    for (int i = 0; i < extraDataSize; i++) {
      mExtraDataFields.add(in.readLong());
    }
    mManufacturer = in.readInt();
    mBluetoothName = in.readString();
  }
 protected Region(Parcel in) {
   mUniqueId = in.readString();
   mBluetoothAddress = in.readString();
   int size = in.readInt();
   mIdentifiers = new ArrayList<Identifier>(size);
   for (int i = 0; i < size; i++) {
     String identifierString = in.readString();
     if (identifierString == null) {
       mIdentifiers.add(null);
     } else {
       Identifier identifier = Identifier.parse(identifierString);
       mIdentifiers.add(identifier);
     }
   }
 }
 /**
  * Convenience method allowing the third beacon identifier to be set as a String. It will be
  * parsed into an Identifier object
  *
  * @param id3String string to parse into an identifier
  * @return builder
  */
 public Builder setId3(String id3String) {
   mId3 = Identifier.parse(id3String);
   return this;
 }
 /**
  * Convenience method allowing the second beacon identifier to be set as a String. It will be
  * parsed into an Identifier object
  *
  * @param id2String string to parse into an identifier
  * @return builder
  */
 public Builder setId2(String id2String) {
   mId2 = Identifier.parse(id2String);
   return this;
 }
 /**
  * Convenience method allowing the first beacon identifier to be set as a String. It will be
  * parsed into an Identifier object
  *
  * @param id1String string to parse into an identifier
  * @return builder
  */
 public Builder setId1(String id1String) {
   mId1 = Identifier.parse(id1String);
   return this;
 }
Exemple #6
0
  /**
   * Parse a string and set the value accordingly.
   *
   * @param <T> Type of object to parse
   * @param string The string to parse. May be null. The string should be in Oak markup so "a
   *     string", `/Some/Path`, etc.
   * @return The parsed value.
   * @see #toString(List)
   * @throws ParsingException Thrown if the string cannot be parsed correctly.
   */
  @SuppressWarnings("unchecked")
  public <T> T parse(@Nullable String string) throws ParsingException {
    final T result;

    assert string != null : "Null string";

    if (string.equals("null")) {
      result = null;
    } else {
      switch (this) {
        case text: // "a string"
          try {
            result = (T) StringU.removeQuotes(string);
          } catch (final RuntimeException e) {
            throw new ParsingException("Missing quotes");
          }
          break;

        case identifier:
          // Verify
          Identifier.parse(string);
          result = (T) string;
          break;

        case path:
          result = (T) Path.parse(string);
          if (result == null) {
            throw new ParsingException("Invalid path: " + string);
          }
          break;

        case bool:
          // Boolean.parse() is not strict enough
          if (string.equals("true")) {
            result = (T) Boolean.TRUE;
          } else if (string.equals("false")) {
            result = (T) Boolean.FALSE;
          } else {
            throw new ParsingException("Invalid boolean, should be (true/false): " + string);
          }
          break;

        case z:
          try {
            // Remove optional trailing 'z'
            final int length = string.length();
            if (length > 1 && string.charAt(length - 1) == 'z') {
              result = (T) new Long(string.substring(0, length - 1));
            } else {
              result = (T) new Long(string);
            }
          } catch (final NumberFormatException e) {
            throw new ParsingException("Invalid integer (Long): " + string, e);
          }
          break;

        case Z:
          try {
            // Remove trailing 'Z'
            final int end = string.length() - 1;
            if (end < 0 || string.charAt(end) != 'Z') {
              throw new ParsingException("Invalid number");
            }
            result = (T) new Long(string.substring(0, end));
          } catch (final NumberFormatException e) {
            throw new ParsingException("Invalid INTEGER (BigInteger): " + string, e);
          }
          break;

        case f:
          try {
            // Remove optional trailing 'f'
            final int length = string.length();
            if (length > 1 && string.charAt(length - 1) == 'f') {
              result = (T) new Double(string.substring(0, length - 1));
            } else {
              result = (T) new Double(string);
            }
          } catch (final NumberFormatException e) {
            throw new ParsingException("Invalid float (Double): " + string, e);
          }
          break;

        case F:
          try {
            // Remove trailing 'F'
            final int end = string.length() - 1;
            if (end < 0 || string.charAt(end) != 'F') {
              throw new ParsingException("Invalid number");
            }
            result = (T) new Long(string.substring(0, end));
          } catch (final NumberFormatException e) {
            throw new ParsingException("Invalid FLOAT (BigDecimal): " + string, e);
          }
          break;

        case cardinality:
          try {
            result = (T) Cardinality.newInstance(string);
          } catch (final Cardinality.Exception e) {
            throw new ParsingException("Invalid cardinality: " + string, e);
          }
          break;

        case date:
          if (string.length() == 0 || string.charAt(0) != '@') {
            throw new ParsingException("Invalid date, missing leading '@': " + string);
          }
          try {
            result = (T) DateU.parseStandardDate(string.substring(1));
          } catch (final DateTimeParseException e) {
            throw new ParsingException("Invalid date: " + string);
          }
          break;

        case time:
          if (string.length() == 0 || string.charAt(0) != '@') {
            throw new ParsingException("Invalid time, missing leading '@': " + string);
          }
          try {
            result = (T) DateU.parseStandardDate(string.substring(1));
          } catch (final DateTimeParseException e) {
            throw new ParsingException("Invalid time: " + string);
          }
          break;

        case datetime:
          if (string.length() == 0 || string.charAt(0) != '@') {
            throw new ParsingException("Invalid datetime, missing leading '@': " + string);
          }
          try {
            result = (T) DateU.parseStandardDate(string.substring(1));
          } catch (final DateTimeParseException e) {
            throw new ParsingException("Invalid datetime: " + string);
          }
          break;

        case any:
        default:
          throw new UnexpectedException(string);
      }
    }

    return result;
  }