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

io.dekorate.halkyon.adapter.RequiredCapabilityConfigAdapter Maven / Gradle / Ivy

There is a newer version: 2.0.0.beta2
Show newest version
package io.dekorate.halkyon.adapter;

import java.nio.file.Path;
import java.util.stream.Collectors;
import java.lang.String;
import java.util.Comparator;
import io.dekorate.project.Project;
import io.dekorate.project.BuildInfo;
import io.dekorate.halkyon.annotation.HalkyonRequiredCapability;
import io.dekorate.halkyon.config.Parameter;
import java.lang.Object;
import java.util.List;
import io.dekorate.halkyon.config.RequiredCapabilityConfig;
import io.dekorate.project.ScmInfo;
import java.util.Arrays;
import io.dekorate.halkyon.config.RequiredCapabilityConfigBuilder;
import java.util.Map;

public class RequiredCapabilityConfigAdapter {


    public static RequiredCapabilityConfig adapt(HalkyonRequiredCapability instance) {
        return newBuilder(instance).build();
    }

    public static RequiredCapabilityConfigBuilder newBuilder(HalkyonRequiredCapability instance) {
        return new RequiredCapabilityConfigBuilder(new io.dekorate.halkyon.config.RequiredCapabilityConfig(null,
            null,
            instance.name(),
            instance.category(),
            instance.type(),
            instance.boundTo(),
            instance.autoBindable(),
            Arrays.asList(instance.parameters()).stream().map(i ->new io.dekorate.halkyon.config.Parameter(i.name(),
            i.value())).collect(Collectors.toList()).toArray(new io.dekorate.halkyon.config.Parameter[0])));
    }

    public static RequiredCapabilityConfig adapt(Map map) {
        return new io.dekorate.halkyon.config.RequiredCapabilityConfig(
null,
null,
               (String)(map instanceof Map ? ((Map)map).getOrDefault("name", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("category", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("type", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("boundTo", "") : ""),
               Boolean.parseBoolean(String.valueOf(map instanceof Map ? ((Map)map).getOrDefault("autoBindable","false") : "false")),
               Arrays.stream((Map[])(map instanceof Map ? ((Map)map).getOrDefault("parameters" , new Map[0]) : new Map[0])).map(i ->new io.dekorate.halkyon.config.Parameter(
               (String)(i instanceof Map ? ((Map)i).getOrDefault("name", null) : null),
               (String)(i instanceof Map ? ((Map)i).getOrDefault("value", null) : null))).toArray(size-> new io.dekorate.halkyon.config.Parameter[size]));
    }

    public static RequiredCapabilityConfigBuilder newBuilder(Map map) {
        return new RequiredCapabilityConfigBuilder(new io.dekorate.halkyon.config.RequiredCapabilityConfig(
null,
null,
               (String)(map instanceof Map ? ((Map)map).getOrDefault("name", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("category", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("type", "") : ""),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("boundTo", "") : ""),
               Boolean.parseBoolean(String.valueOf(map instanceof Map ? ((Map)map).getOrDefault("autoBindable","false") : "false")),
               Arrays.stream((Map[])(map instanceof Map ? ((Map)map).getOrDefault("parameters" , new Map[0]) : new Map[0])).map(i ->new io.dekorate.halkyon.config.Parameter(
               (String)(i instanceof Map ? ((Map)i).getOrDefault("name", null) : null),
               (String)(i instanceof Map ? ((Map)i).getOrDefault("value", null) : null))).toArray(size-> new io.dekorate.halkyon.config.Parameter[size])));
    }

    public static String[] toStringArray(Object o) {
                if (o instanceof String[]) {
          return (String[]) o;
        }
        if (o instanceof String) {
          String s =  (String) o;
          return s.split(",[ ]*");
        }
        else if (o instanceof List) {
          List c = (List) o;
          String[] result = new String[c.size()]; 
          for (int i=0; i <= c.size(); i++) {
            result[i] = String.valueOf(c.get(i));
          }
          return result;
        }
        return new String[0];
    

    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy