Advertisement
dburyak

Graph with ordered entries

Dec 27th, 2021
1,247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.92 KB | None | 0 0
  1.  
  2.     /*
  3.     new Graph([
  4.             A: [B: 5, H: 2],
  5.             B: [A: 5, C: 7],
  6.             C: [B: 7, D: 3, G: 4],
  7.             D: [C: 20, E: 4],
  8.             E: [F: 5],
  9.             F: [G: 6],
  10.             G: [C: 4],
  11.             H: [G: 3]
  12.     ])
  13.      */
  14.  
  15.     /*
  16.     private static final Graph<String> COMPLEX_GRAPH = new Graph<>(Map.of(
  17.             "A", Map.of("B", 5, "H", 2),
  18.             "B", Map.of("A", 5, "C", 7),
  19.             "C", Map.of("B", 7, "D", 3, "G", 4),
  20.             "D", Map.of("C", 20, "E", 4),
  21.             "E", Map.of("F", 5),
  22.             "F", Map.of("G", 6),
  23.             "G", Map.of("C", 4),
  24.             "H", Map.of("G", 3)
  25.     ));
  26.      */
  27.  
  28.     private static final Graph<String> COMPLEX_GRAPH;
  29.  
  30.     static {
  31.         var fromA = new LinkedHashMap<String, Number>();
  32.         fromA.put("B", 5);
  33.         fromA.put("H", 2);
  34.         var fromB = new LinkedHashMap<String, Number>();
  35.         fromB.put("A", 5);
  36.         fromB.put("C", 7);
  37.         var fromC = new LinkedHashMap<String, Number>();
  38.         fromC.put("B", 7);
  39.         fromC.put("D", 3);
  40.         fromC.put("G", 4);
  41.         var fromD = new LinkedHashMap<String, Number>();
  42.         fromD.put("C", 20);
  43.         fromD.put("E", 4);
  44.         var fromE = new LinkedHashMap<String, Number>();
  45.         fromE.put("F", 5);
  46.         var fromF = new LinkedHashMap<String, Number>();
  47.         fromF.put("G", 6);
  48.         var fromG = new LinkedHashMap<String, Number>();
  49.         fromG.put("C", 4);
  50.         var fromH = new LinkedHashMap<String, Number>();
  51.         fromH.put("G", 3);
  52.  
  53.         var nodes = new LinkedHashMap<String, Map<String, Number>>();
  54.         nodes.put("A", fromA);
  55.         nodes.put("B", fromB);
  56.         nodes.put("C", fromC);
  57.         nodes.put("D", fromD);
  58.         nodes.put("E", fromE);
  59.         nodes.put("F", fromF);
  60.         nodes.put("G", fromG);
  61.         nodes.put("H", fromH);
  62.  
  63.         COMPLEX_GRAPH = new Graph<>(nodes);
  64.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement