示例#1
0
 @Override
 public Part clone() {
   final Part part = new Part();
   part.clickAction = this.clickAction;
   part.hover = this.hover;
   part.localizedText = this.localizedText;
   part.localizedTextParameters =
       this.localizedTextParameters == null ? null : this.localizedTextParameters.clone();
   part.text = this.text;
   return part;
 }
示例#2
0
  /**
   * Converts the given {@link Map} to a chat message Part.
   *
   * @param map the map to convert to a chat message Part
   * @see ConfigurationSerializable
   */
  public static Part deserialize(final Map<String, Object> map) {
    final Part part = new Part();
    part.clickAction = (Click) map.get("click");
    part.hover = (Hover) map.get("hover");

    final Boolean localizedText = (Boolean) map.get("localizedText");
    part.localizedText = localizedText != null && localizedText;

    final Object localizedTextParameters = map.get("localizedTextParameters");
    if (localizedTextParameters != null) {
      if (localizedTextParameters instanceof String) {
        part.localizedTextParameters = new String[] {(String) localizedTextParameters};
      } else if (localizedTextParameters instanceof String[]) {
        part.localizedTextParameters = (String[]) localizedTextParameters;
      } else if (localizedTextParameters instanceof Collection) {
        final Object[] collection = ((Collection<?>) localizedTextParameters).toArray();
        final int length = collection.length;
        final String[] array = new String[length];
        for (int i = 0; i < length; i++) {
          if (collection[i] instanceof String) {
            array[i] = (String) collection[i];
          } else {
            throw new IllegalArgumentException(
                Arrays.toString(collection) + " is not a valid Part.localizedTextParameters");
          }
        }
        part.localizedTextParameters = array;
      } else {
        throw new IllegalArgumentException(
            localizedTextParameters + " is not a valid Part.localizedTextParameters");
      }
    }

    part.text = (String) map.get("text");
    return part;
  }