GithubHelp home page GithubHelp logo

Nested collections/arrays about owner HOT 3 OPEN

matteobaccan avatar matteobaccan commented on June 18, 2024
Nested collections/arrays

from owner.

Comments (3)

lviggiano avatar lviggiano commented on June 18, 2024

Hi @alexeyr.

This is possible (with the version available on the master branch which is currently not released yet):

servers=www.google.com:80, www.github.com:8080
public class Server {
    private final String name;
    private final Integer port;

    public Server(String spec) {  // you need to parse spec, ok... some work to do, but not that bad...
        String[] split = spec.split(":", -1);
        name = split[0];
        if (split.lenght > =2) 
            port = Integer.valueOf(split[1]);
        else 
            port = 80;
    }
    public String getName() { return name; }
    public Integer getPort() { return port; } 
}

public interface ServerConfig extends Config {
    Server[] servers;
    // or 
    List<Server> servers;
}

Another option I am thinking about is this:

public class Server {
    private final String name;
    private final Integer port;

    public Server(String name, Integer port) {  
        this.name = name; 
        this.port = port;
    }
    public String getName() { return name; }
    public Integer getPort() { return port; } 
}

public interface ServerConfig extends Config {
    @ConverterClass(ServerConverter.class)
    Server[] servers;
    // or 
    List<Server> servers;
}

public class ServerConverter extends Converter<Server> {
    public Server convert(Method targetMethod, String text) {
        String[] split = text.split(":", -1);
        String name = split[0];
        Integer port = 80;
        if (split.lenght >= 2) 
            port = Integer.valueOf(split[1]);
        return new Server(name, port);
    }
}

The @ConverterClass annotation is not implemented, but it is very easy to add, and I kind of like it. What's your opinion?

I have a different idea about config nesting, and I don't find it to be suitable for collections/arrays.

Notice that collections and arrays are already available in the master branch, and will be included in the next release.

Opinions?

from owner.

alexeyr avatar alexeyr commented on June 18, 2024

I did consider this approach, but it doesn't scale well if you need more than 2 or 3 properties, or default values.

from owner.

lviggiano avatar lviggiano commented on June 18, 2024

I'll consider this when I'll implement the nesting in config. Maybe it will be implemented as per your suggestion. This implementation makes sense.

from owner.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.