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

io.dekorate.halkyon.adapter.CapabilityConfigAdapter 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 io.dekorate.halkyon.config.CapabilityConfig;
import java.lang.String;
import java.util.Comparator;
import io.dekorate.project.Project;
import io.dekorate.halkyon.config.CapabilityConfigBuilder;
import io.dekorate.project.BuildInfo;
import io.dekorate.halkyon.config.Parameter;
import java.lang.Object;
import java.util.List;
import io.dekorate.project.ScmInfo;
import java.util.Arrays;
import io.dekorate.halkyon.annotation.HalkyonCapability;
import java.util.Map;

public class CapabilityConfigAdapter {


    public static CapabilityConfig adapt(HalkyonCapability instance) {
        return newBuilder(instance).build();
    }

    public static CapabilityConfigBuilder newBuilder(HalkyonCapability instance) {
        return new CapabilityConfigBuilder(new io.dekorate.halkyon.config.CapabilityConfig(null,
            null,
            instance.category(),
            instance.type(),
            instance.name(),
            instance.version(),
            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 CapabilityConfig adapt(Map map) {
        return new io.dekorate.halkyon.config.CapabilityConfig(
null,
null,
               (String)(map instanceof Map ? ((Map)map).getOrDefault("category", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("type", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("name", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("version", "") : ""),
               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 CapabilityConfigBuilder newBuilder(Map map) {
        return new CapabilityConfigBuilder(new io.dekorate.halkyon.config.CapabilityConfig(
null,
null,
               (String)(map instanceof Map ? ((Map)map).getOrDefault("category", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("type", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("name", null) : null),
               (String)(map instanceof Map ? ((Map)map).getOrDefault("version", "") : ""),
               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