IoTSetRequest.java

  1. /**
  2.  *
  3.  * Copyright © 2016-2017 Florian Schmaus
  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.iot.control.element;

  18. import java.util.ArrayList;
  19. import java.util.Collection;
  20. import java.util.Collections;

  21. import org.jivesoftware.smack.packet.IQ;

  22. public class IoTSetRequest extends IQ {

  23.     public static final String ELEMENT = "set";
  24.     public static final String NAMESPACE = Constants.IOT_CONTROL_NAMESPACE;

  25.     private final Collection<SetData> setData;

  26.     public IoTSetRequest(Collection<? extends SetData> setData) {
  27.         super(ELEMENT, NAMESPACE);
  28.         setType(Type.set);

  29.         /*
  30.          * Ugly workaround for the following error prone false positive:
  31.          *
  32.          * IoTSetRequest.java:34: error: incompatible types: Collection<CAP#1> cannot be converted to Collection<SetData>
  33.          * this.setData = Collections.unmodifiableCollection(setDataA);
  34.          *                                                  ^
  35.          * where CAP#1 is a fresh type-variable:
  36.          * CAP#1 extends SetData from capture of ? extends SetData
  37.          */
  38.         Collection<SetData> tmp = new ArrayList<>(setData.size());
  39.         for (SetData data : setData) {
  40.             tmp.add(data);
  41.         }
  42.         this.setData = Collections.unmodifiableCollection(tmp);
  43.     }

  44.     public Collection<SetData> getSetData() {
  45.         return setData;
  46.     }

  47.     @Override
  48.     protected IQChildElementXmlStringBuilder getIQChildElementBuilder(IQChildElementXmlStringBuilder xml) {
  49.         xml.rightAngleBracket();
  50.         xml.append(setData);
  51.         return xml;
  52.     }

  53. }