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

org.itest.impl.ITestParamStateImpl Maven / Gradle / Ivy

The newest version!
package org.itest.impl;

import org.itest.json.simple.ITestSimpleJsonState;
import org.itest.param.ITestParamState;

import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

public class ITestParamStateImpl implements ITestParamState {
    protected Map elements;

    String value;

    private Map attributes;

    public ITestParamStateImpl(){}
    public ITestParamStateImpl(ITestParamState paramState) {
        this.value = paramState.getValue();
        Iterable paramNames = paramState.getNames();
        if (null != paramNames) {
            for (String paramName : paramNames) {
                addElement(paramName, paramState.getElement(paramName));
            }
        }
        Iterable attributeNames = paramState.getAttributeNames();
        if ( null != attributeNames ) {
            for (String attributeName : attributeNames) {
                addAttribute(attributeName, paramState.getAttribute(attributeName));
            }
        }
    }

    public void addAttribute(String key, String value) {
        if(null==attributes){
            attributes=new HashMap();
        }
        attributes.put(key,value);
    }

    @Override
    public Integer getSizeParam() {
        return null == elements ? null : elements.size();
    }

    public void addElement(String token, ITestParamState iTestParamsImpl) {
        if (null == elements) {
            elements = createElements();
        }
        elements.put(token, iTestParamsImpl);
    }

    @Override
    public Collection getNames() {
        return elements == null ? null : elements.keySet();
    }

    @Override
    public ITestParamState getElement(String name) {
        return elements == null ? null : elements.get(name);
    }

    @Override
    public String getValue() {
        return value;
    }

    @Override
    public String getAttribute(String name) {
        return null == attributes ? null : attributes.get(name);
    }

    public Iterable getAttributeNames() {
        return null == attributes ? null : attributes.keySet();
    }

    public void setValue(String value){
        this.value=value;
    }
    private static Map emptyMap() {
        return Collections.emptyMap();
    }

    public void initElements() {
        if (null == elements) {
            elements = createElements();
        }
    }
    @Override
    public String toString() {
        StringBuilder sb = new StringBuilder();
        if (null == elements) {
            sb.append(":").append(getValue());
        } else {
            sb.append(elements);
        }
        return sb.toString();
    }
    private static Map createElements(){
        return ITestSimpleJsonState.createElements();
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy