美文网首页
【代码块】Arguments类源码

【代码块】Arguments类源码

作者: 悠哉的小C | 来源:发表于2020-01-18 22:42 被阅读0次
    package org.apache.jmeter.config;
     
    import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.LinkedHashMap;
    import java.util.List;
    import java.util.Map;
    import org.apache.jmeter.testelement.property.CollectionProperty;
    import org.apache.jmeter.testelement.property.JMeterProperty;
    import org.apache.jmeter.testelement.property.PropertyIterator;
    import org.apache.jmeter.testelement.property.TestElementProperty;
     
    public class Arguments extends ConfigTestElement implements Serializable, Iterable<JMeterProperty> {
        private static final long serialVersionUID = 240L;
        public static final String ARGUMENTS = "Arguments.arguments";
     
        public Arguments() {
            this.setProperty(new CollectionProperty("Arguments.arguments", new ArrayList()));
        }
     
        public CollectionProperty getArguments() {
            return (CollectionProperty)this.getProperty("Arguments.arguments");
        }
     
        public void clear() {
            super.clear();
            this.setProperty(new CollectionProperty("Arguments.arguments", new ArrayList()));
        }
     
        public void setArguments(List<Argument> arguments) {
            this.setProperty(new CollectionProperty("Arguments.arguments", arguments));
        }
     
        public Map<String, String> getArgumentsAsMap() {
            PropertyIterator iter = this.getArguments().iterator();
            LinkedHashMap argMap = new LinkedHashMap();
     
            while(iter.hasNext()) {
                Argument arg = (Argument)iter.next().getObjectValue();
                if (!argMap.containsKey(arg.getName())) {
                    argMap.put(arg.getName(), arg.getValue());
                }
            }
     
            return argMap;
        }
     
        public void addArgument(String name, String value) {
            this.addArgument(new Argument(name, value, (String)null));
        }
     
        public void addArgument(Argument arg) {
            TestElementProperty newArg = new TestElementProperty(arg.getName(), arg);
            if (this.isRunningVersion()) {
                this.setTemporary(newArg);
            }
     
            this.getArguments().addItem(newArg);
        }
     
        public void addArgument(String name, String value, String metadata) {
            this.addArgument(new Argument(name, value, metadata));
        }
     
        public void addArgument(String name, String value, String metadata, String description) {
            this.addArgument(new Argument(name, value, metadata, description));
        }
     
        public PropertyIterator iterator() {
            return this.getArguments().iterator();
        }
     
        public String toString() {
            StringBuilder str = new StringBuilder();
            PropertyIterator iter = this.getArguments().iterator();
     
            while(iter.hasNext()) {
                Argument arg = (Argument)iter.next().getObjectValue();
                String metaData = arg.getMetaData();
                str.append(arg.getName());
                if (metaData == null) {
                    str.append("=");
                } else {
                    str.append(metaData);
                }
     
                str.append(arg.getValue());
                String desc = arg.getDescription();
                if (desc != null) {
                    str.append("(");
                    str.append(desc);
                    str.append(")");
                }
     
                if (iter.hasNext()) {
                    str.append("&");
                }
            }
     
            return str.toString();
        }
     
        public void removeArgument(int row) {
            if (row < this.getArguments().size()) {
                this.getArguments().remove(row);
            }
     
        }
     
        public void removeArgument(Argument arg) {
            PropertyIterator iter = this.getArguments().iterator();
     
            while(iter.hasNext()) {
                Argument item = (Argument)iter.next().getObjectValue();
                if (arg.equals(item)) {
                    iter.remove();
                }
            }
     
        }
     
        public void removeArgument(String argName) {
            PropertyIterator iter = this.getArguments().iterator();
     
            while(iter.hasNext()) {
                Argument arg = (Argument)iter.next().getObjectValue();
                if (arg.getName().equals(argName)) {
                    iter.remove();
                }
            }
     
        }
     
        public void removeArgument(String argName, String argValue) {
            PropertyIterator iter = this.getArguments().iterator();
     
            while(iter.hasNext()) {
                Argument arg = (Argument)iter.next().getObjectValue();
                if (arg.getName().equals(argName) && argValue.equals(arg.getValue())) {
                    iter.remove();
                }
            }
     
        }
     
        public void removeAllArguments() {
            this.getArguments().clear();
        }
     
        public void addEmptyArgument() {
            this.addArgument(new Argument("", "", (String)null));
        }
     
        public int getArgumentCount() {
            return this.getArguments().size();
        }
     
        public Argument getArgument(int row) {
            Argument argument = null;
            if (row < this.getArguments().size()) {
                argument = (Argument)this.getArguments().get(row).getObjectValue();
            }
     
            return argument;
        }
    }
    

    相关文章

      网友评论

          本文标题:【代码块】Arguments类源码

          本文链接:https://www.haomeiwen.com/subject/hculzctx.html