Java stores simulation data through map

From , 3 Years ago, written in Java, viewed 75 times.
URL https://pastebin.vip/view/4910fcda
  1. import java.util.ArrayList;
  2. import java.util.HashMap;
  3. import java.util.List;
  4. import java.util.Map;
  5.  
  6. public class Test {
  7.      
  8.     private static Map<String,Location> memMap=new HashMap<String,Location>();
  9.      
  10.     public Map<String,Location>  getMap(int type){
  11.         if(type==0){
  12.             return new HashMap<String,Location>();
  13.         }else{
  14.             return memMap;
  15.         }
  16.     }
  17.      
  18.     public void setMap(Location location){
  19.          memMap.put(location.getCarNumber(), location);
  20.     }
  21.      
  22.     /**
  23.      * 获取已知位置数据
  24.      * @return
  25.      */
  26.     public List<Location>  getMonitorLocation(){
  27.         List<Location> locationList=new ArrayList<Location>();
  28.         String [] carMembers=getCarMember(4);
  29.         for (int i = 0; i < carMembers.length; i++) {
  30.             String carNumber=carMembers[i];
  31.             Location location=memMap.get(carNumber);
  32.             locationList.add(location);
  33.         }
  34.         return locationList;
  35.     }
  36.      
  37.     /**
  38.      * 获取map包含的key
  39.      * @param loop
  40.      * @return
  41.      */
  42.     public String[]  getCarMember(int loop){
  43.         Map<String,Location> map=new HashMap<String,Location>();
  44.         for (int i = 0; i < loop; i++) {
  45.             Map<String,Location> mapOfType=getMap(i);//获取到不同的map类型的数据
  46.             for (String key: mapOfType.keySet()) {
  47.                 if(key!=null){
  48.                     map.put(key, mapOfType.get(key));
  49.                 }
  50.             }
  51.         }
  52.         String [] carMembers=new String [map.size()];
  53.         int i=0;
  54.         for (String key: map.keySet()) {
  55.             if(key!=null){
  56.                 carMembers[i]=key;
  57.                 i++;
  58.             }
  59.         }
  60.         return carMembers;
  61.     }
  62.      
  63.     public static void main(String[] args) {
  64.         Test.memMap.put("川A00737", new Location("川A00737","四川省成都市"));
  65.         Test test=new Test();
  66.         System.out.println("键的长度:"+test.getCarMember(5).length);
  67.         List<Location> list=test.getMonitorLocation();
  68.         System.out.println("集合长度:"+list.size());
  69.          
  70.     }
  71.      
  72.  
  73. }
  74. //java/7030

Reply to "Java stores simulation data through map"

Here you can reply to the paste above

captcha

https://burned.cc - Burn After Reading Website