private OrdinalConfigSource wrapSource(ConfigSource source) { io.helidon.config.spi.ConfigSource myCs = ConfigSources.create(source.getProperties()).build(); return new OrdinalConfigSource(myCs, source.getOrdinal()); }
@Test public void testGetConfigSources() { Iterable<ConfigSource> configSources = config.getConfigSources(); Assert.assertNotNull(configSources); // check descending sorting int prevOrdinal = Integer.MAX_VALUE; for (ConfigSource configSource : configSources) { Assert.assertTrue(configSource.getOrdinal() <= prevOrdinal); prevOrdinal = configSource.getOrdinal(); } }
/** * ConfigSources are sorted with descending ordinal. * If 2 ConfigSources have the same ordinal, then they get sorted according to their name, alphabetically. */ private List<ConfigSource> sortDescending(List<ConfigSource> configSources) { configSources.sort( (configSource1, configSource2) -> { int compare = Integer.compare(configSource2.getOrdinal(), configSource1.getOrdinal()); if (compare == 0) { return configSource1.getName().compareTo(configSource2.getName()); } return compare; }); return configSources; }
private JsonObject toJsonObject(ConfigSource source){ return Json.createObjectBuilder().add(String.valueOf(source.getOrdinal()), source.getName()).build(); }
@GET @Path("/sources") @Produces(MediaType.APPLICATION_JSON) @Operation(description = "Getting all the current config sources") @APIResponse(responseCode = "200", description = "Successfull, returning the config sources in JSON format") public Response getConfigSources(){ JsonArrayBuilder arrayBuilder = Json.createArrayBuilder(); for(ConfigSource source:config.getConfigSources()){ arrayBuilder.add(Json.createObjectBuilder().add(String.valueOf(source.getOrdinal()), source.getName()).build()); } return Response.ok(arrayBuilder.build()).build(); }
@Override public int compare(ConfigSource o1, ConfigSource o2) { int v1 = o1.getOrdinal(); int v2 = o2.getOrdinal(); if ( v1 > v2 ) { return -11; } if ( v1 < v2 ) { return +1; } // if 2 config sources have the same ordinal, // provide consistent order by sorting them // according to their name. if (o2.getName() != null && o1.getName() != null) { return o2.getName().compareTo(o1.getName()); } return 0; } });
private OrdinalConfigSource wrapSource(ConfigSource source) { io.helidon.config.spi.ConfigSource myCs = ConfigSources.create(source.getProperties()).build(); return new OrdinalConfigSource(myCs, source.getOrdinal()); }