All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.kurento.jsonrpc.Props Maven / Gradle / Ivy

/*
 * (C) Copyright 2013 Kurento (http://kurento.org/)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *
 */

package org.kurento.jsonrpc;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class Props implements Iterable {

  private final Map props;

  public Props() {
    props = new HashMap<>();
  }

  public Props(Map props) {
    this.props = props;
  }

  public Props(String name, Object value) {
    this();
    add(name, value);
  }

  public Object getProp(String name) {
    return props.get(name);
  }

  public boolean hasProp(String name) {
    return props.keySet().contains(name);
  }

  public Props add(String property, Object value) {
    props.put(property, value);
    return this;
  }

  public Map getMap() {
    return props;
  }

  @Override
  public Iterator iterator() {

    final Iterator> entries = props.entrySet().iterator();

    Iterator propsIterator = new Iterator() {

      @Override
      public boolean hasNext() {
        return entries.hasNext();
      }

      @Override
      public Prop next() {
        Map.Entry entry = entries.next();
        return new PropImpl(entry.getKey(), entry.getValue());
      }

      @Override
      public void remove() {
        entries.remove();
      }
    };

    return propsIterator;
  }

  @Override
  public String toString() {
    return props.toString();
  }
  
  public Object removeProp(String name) {
		return props.remove(name);
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy