0

I have an a list of stores(getStore(..))s, which is getting all the stores from DB

what I'm trying to do is to add additional stores from properties file.(trying to build the list)

here's how my properties file look like

yard=1085:BELF:BELGRADE FIXTURES
yard=3238:SKWS:SKOKIE WAREHOUSE
yard=3239:PLDC:PLANO DC
yard=3339:HCDC:HOLIDAY CITY DC

here's how I'm trying to get the list.

@Value("#{'${yard}'.split(',')}#{T(java.util.Collections).emptyList()}") 
private List<String> myList;

here how I'm trying to add the additional stores to the list

    public List<Store> additionalYardList() {
    List<Store> stores = storesApi.getStores();
    for (String yard : myList) {
        String[] yardArray = yard.split(":");
        Store store = new Store();
        store.setNumber(Integer.parseInt(yardArray[0]));
        store.setAbbr(yardArray[1]);
        store.setName(yardArray[2]);
        LOG.debug(store.getAbbr());
        stores.add(store);
    }
    return stores;
}

Then will do a Stream to merge

    public List<Store> getAllStores() {
    return Stream.of(additionalYardList(), storesApi.getStores()).flatMap(List::stream).collect(Collectors.toList());
}

}

My Store object fields are: (number- abbr - name )

Nothing is been added to that list, Any idea what am I missing?

Samarland
  • 561
  • 1
  • 10
  • 23
  • 1
    You can't do it like this. Each line needs a unique key. A properties file is like a HashMap. I don't see why you're using one at all. Just a file withh. each line being a new item would do. – user207421 Feb 27 '18 at 23:09

1 Answers1

1

Duplicate yard keys, please correct properties file to have unique keys.

Change it from

yard=1085:BELF:BELGRADE FIXTURES
yard=3238:SKWS:SKOKIE WAREHOUSE
yard=3239:PLDC:PLANO DC
yard=3339:HCDC:HOLIDAY CITY DC

To

yard=1085:BELF:BELGRADE FIXTURES,3238:SKWS:SKOKIE WAREHOUSE,3239:PLDC:PLANO DC,3339:HCDC:HOLIDAY CITY DC

And then you could load them with below code.

@Value("#{'${yard}'.split(',')}") 
 private List<String> myList;

This has been already answered here.

Vikram Palakurthi
  • 2,406
  • 1
  • 27
  • 30