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

io.hyperfoil.tools.qdup.config.yaml.RegexMapping Maven / Gradle / Ivy

Go to download

Coordinate multiple terminal shell connections for queuing performance tests and collecting output files

There is a newer version: 0.8.3
Show newest version
package io.hyperfoil.tools.qdup.config.yaml;

import io.hyperfoil.tools.qdup.cmd.Cmd;
import io.hyperfoil.tools.qdup.cmd.impl.Regex;

import java.util.*;

public class RegexMapping extends CmdMapping {

   public static final String MISS = "miss";
   public static final String AUTO_CONVERT = "autoConvert";
   public static final String PATTERN = "pattern";
   public static final String ELSE = "else";


   public RegexMapping() {
      super("regex", new CmdEncoder() {
         @Override
         public Object encode(Cmd cmd) {
            if(cmd instanceof Regex){
               Regex r = (Regex)cmd;
               if(r.isMiss()){
                  Map regexMap = new HashMap<>();
                  regexMap.put(PATTERN,r.getPattern());
                  regexMap.put(MISS,r.isMiss());
                  regexMap.put(AUTO_CONVERT,r.isAutoConvert());
                  return regexMap;
               }else{
                  return r.getPattern();
               }
            }else{
               return null;
            }
         }
      });
   }
   @Override
   public Map getMap(Object o) {
      Map rtrn = super.getMap(o);
      if (o instanceof Regex) {
         Regex r = (Regex) o;
         if (r.hasElse()) {
            List elses = new ArrayList<>();
            r.getElses().forEach(miss -> {
               Object defered = defer(miss);
               elses.add(defered);
            });
            rtrn.put(ELSE, elses);
         }
      }
      return rtrn;
   }
}