Choosing a data structure for orgaininsng data with a list of values ​​in java

I have a map, as shown below, in which there is a key, and the values ​​are of type List:

Map<String, List<String> newdatamap = new HashMap<>();
map.put ("RtyName", Arrays.asList("wpn", "wpfnb", "dgeft", "xbthy"));
map.put ("rtyRate", Arrays.asList("dd", "ww", "trrty", "httyure"))

I would like to add another card from the previous card, so there is a key, and its value will be given above. Is this the correct data structure and how to implement it?

I need something like this shown below

Key         Value

B1          RtyName  ----> "weepn", "weepfnb", "eedgeft", "xbteehy"
            rtyRate ----->"deed", "ww", "terrty", "hteetyure"



B2          RtyName  ----> "SSSweepn", "wpefSSSnb", "GGeGdgeft", "xbteYYYYhy"
            rtyRate ----->"WWded", "wTeTYw", "YYYYtrerty", "IIIehttyure"

As shown above, only a new key is entered on the card, and its value is the previous card.

so it’s like Map<String, Map<String, List<String>>>that which becomes a complex data structure, I can organize a data structure such as one class containing a map, so it will look like

Map<B1 , RtyName>
Map<B2 ,rtyRate>

and the payer contains a list of values, such as

 RtyName  ----> "SSSweepn", "wpefSSSnb", "GGeGdgeft", "xbteYYYYhy"
  rtyRate ----->"deed", "ww", "terrty", "hteetyure"

, B1 , RtyName, , "wpn", "wpfnb", "dgeft" "," xbthy "

, , , - .

, , Guava

  final Table<String, String, List<String>> values = HashBasedTable.create();
values.put("B1", "RtyName", Lists.newArrayList("weepn", "weepfnb", "eedgeft", "xbteehy"));
System.out.println(values.get("B1", "RtyName")); // prints the list

, , , B1 Rtyname Rtyname,

+4
2

:

Map<Integer, List<String>> dataMap = new HashMap<>();
dataMap.put("B1".hashCode()+"RtyName".hashCode(), Arrays.asList("weepn", "weepfnb", "eedgeft", "xbteehy"));
dataMap.put("B1".hashCode()+"rtyRate".hashCode(), Arrays.asList("deed", "ww", "terrty", "hteetyure"));
dataMap.put("B2".hashCode()+"RtyName".hashCode(), Arrays.asList("SSSweepn", "wpefSSSnb", "GGeGdgeft", "xbteYYYYhy"));
dataMap.put("B2".hashCode()+"rtyRate".hashCode(), Arrays.asList("WWded", "wTeTYw", "YYYYtrerty", "IIIehttyure"));

:

B1, RtyName  ----> "weepn", "weepfnb", "eedgeft", "xbteehy"
B1, rtyRate ----->"deed", "ww", "terrty", "hteetyure"

B2, RtyName  ----> "SSSweepn", "wpefSSSnb", "GGeGdgeft", "xbteYYYYhy"
B2, rtyRate ----->"WWded", "wTeTYw", "YYYYtrerty", "IIIehttyure"

, hashCode - String, . , String ( - ), .

, , String :

dataMap.put("B1"+"RtyName", Arrays.asList(/*your list here*/));

( "" ), , , Map. ( , hashCode.)

, List , , Map:

Map<List<String>, String> valueMap = new HashMap<>(); //New map for value->key 
for(String key: dataMap.keySet()) //Get all keys
    valueMap.put(dataMap.get(key), key); //Create mapping value->key

, String values keys, , Map:

Map<String, String> itemMap = new HashMap<>(); //New map for item->key mapping
    for(String key: dataMap.keySet()) //Get all keys and iterate through
        for(String item: dataMap.get(key)) //For each item in your value list
            itemMap.put(item, key); //Create new mapping item->key
+1

:

ABC , , , RtyName rtyRate:

public class ABC {
    private List<String> RtyName;
    private List<String> rtyRate;

    public ABC(List<String> RtyName, List<String> rtyRate) {
        setRtyNames(RtyName);
        setRtyRates(rtyRate);
    }

    public void setRtyNames(List<String> RtyName) {
        this.RtyName = RtyName;
    }

    public List<String> getRtyNames() {
        return this.RtyName;
    }

    public void setRtyRates(List<String> rtyRate) {
        this.rtyRate = rtyRate;
    }

    public List<String> getRtyRates() {
        return this.rtyRate;
    }
}

, :

Map<String, ABC> newdatamap = new HashMap<>();

, , , , , ABC, ABC ( ):

List<String> RtyName = Arrays.asList("wpn", "wpfnb", "dgeft", "xbthy");
List<String> rtyRate = Arrays.asList("dd", "ww", "trrty", "httyure");
newdatamap.put("B1", new ABC(RtyName, rtyRate));

:

newdatamap.put("B2", new ABC(Arrays.asList("SSSweepn", "wpefSSSnb", "GGeGdgeft", "xbteYYYYhy"), 
                             Arrays.asList("WWded", "wTeTYw", "YYYYtrerty", "IIIehttyure"));

get(String), :

ABC data = newdatamap.get("B1);

, :

List<String> RtyNames = newdatamap.get("B1").getRtyNames();

-, . , , RtyName rtyRate.

RtyName rtyRate , .. wpn - , dd - , . , , , :

public class RtyEntry {
    private String name;
    private String rate;

    public RtyEntry(String name, String rate) {
        setName(name);
        setRate(rate);
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getName() {
        return this.name;
    }

    public void setRate(String rate) {
        this.rate = rate;
    }

    public String getRate() {
        return this.rate;
    }
}

ABC, RtyEntry, :

public class ABC {
    private List<RtyEntry> rtyEntries;

    public ABC(List<RtyEntry> rtyEntries) {
        this.rtyEntries = rtyEntries;
    }

    public ABC() {
        this.rtyEntries = new ArrayList<>();
    }

    public void setRtyEntries(List<RtyEntry> rtyEntries) {
        this.rtyEntries = rtyEntries;
    }

    public List<RtyEntry> getRtyEntries() {
        return this.rtyEntries;
    }

    // convenience methods

    public void addRtyEntry(RtyEntry entry) {
        this.rtyEntries.add(entry);
    }
}

:

RtyEntry entry1 = new RtyEntry("wpn", "dd");
List<RtyEntry> entries = Arrays.asList(entry1, ...);
newdatamap.put("B1", new ABC(entries));

:

newdatamap.get("B1").addRtyEntry(new RtyEntry("wpfnb", "ww"));

:

ABC data = newdatamap.get("B1");
List<RtyEntry> entries = data.getRtyEntries();
for (RtyEntry entry : entries) {
    System.out.println(entry.getName() + " has a rate of: " + entry.getRate());
}

, :

List<RtyEntry> entries = newdatamap.get("B1").getRtyEntries();

.

0

All Articles