Java chose the best matching element from vector [closed]












-1














I have task to find the simplest way to the point of destination.

I found all paths and stored in vector for example:



1. R R R R P P L L P P   
2. R R R R P P R R R R P P L L L L L L
3. R R R R P P R R R R P P P P L L L L L L P P


Where R - right, L - left, P - straight.

And in addition, I have the priority of following the path:



rightHanded: straight, right, left   
leftHanded: straight, left, right


Following the path by priority I want to get to the end.

e.g. using the above example of paths for rightHanded



R -> R -> R -> R -> P -> P -> (1)R -> R -> R -> R -> P -> P -> (2) P -> end I find the shortest path


ad.1 I see that best is 2 and 3 because I have R

ad.2 I again chose R instead L and I have the last path left and its the simplest



I don't know how write that program.










share|improve this question















closed as unclear what you're asking by Adrian Shum, talex, CozyAzure, EdChum, greg-449 Nov 23 '18 at 10:13


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    I don't understand the meaning of rightHanded and leftHanded
    – Mahmoud Hanafy
    Nov 22 '18 at 21:54










  • This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
    – Abakus
    Nov 22 '18 at 22:00










  • I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
    – bsaverino
    Nov 23 '18 at 2:14
















-1














I have task to find the simplest way to the point of destination.

I found all paths and stored in vector for example:



1. R R R R P P L L P P   
2. R R R R P P R R R R P P L L L L L L
3. R R R R P P R R R R P P P P L L L L L L P P


Where R - right, L - left, P - straight.

And in addition, I have the priority of following the path:



rightHanded: straight, right, left   
leftHanded: straight, left, right


Following the path by priority I want to get to the end.

e.g. using the above example of paths for rightHanded



R -> R -> R -> R -> P -> P -> (1)R -> R -> R -> R -> P -> P -> (2) P -> end I find the shortest path


ad.1 I see that best is 2 and 3 because I have R

ad.2 I again chose R instead L and I have the last path left and its the simplest



I don't know how write that program.










share|improve this question















closed as unclear what you're asking by Adrian Shum, talex, CozyAzure, EdChum, greg-449 Nov 23 '18 at 10:13


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.











  • 1




    I don't understand the meaning of rightHanded and leftHanded
    – Mahmoud Hanafy
    Nov 22 '18 at 21:54










  • This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
    – Abakus
    Nov 22 '18 at 22:00










  • I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
    – bsaverino
    Nov 23 '18 at 2:14














-1












-1








-1







I have task to find the simplest way to the point of destination.

I found all paths and stored in vector for example:



1. R R R R P P L L P P   
2. R R R R P P R R R R P P L L L L L L
3. R R R R P P R R R R P P P P L L L L L L P P


Where R - right, L - left, P - straight.

And in addition, I have the priority of following the path:



rightHanded: straight, right, left   
leftHanded: straight, left, right


Following the path by priority I want to get to the end.

e.g. using the above example of paths for rightHanded



R -> R -> R -> R -> P -> P -> (1)R -> R -> R -> R -> P -> P -> (2) P -> end I find the shortest path


ad.1 I see that best is 2 and 3 because I have R

ad.2 I again chose R instead L and I have the last path left and its the simplest



I don't know how write that program.










share|improve this question















I have task to find the simplest way to the point of destination.

I found all paths and stored in vector for example:



1. R R R R P P L L P P   
2. R R R R P P R R R R P P L L L L L L
3. R R R R P P R R R R P P P P L L L L L L P P


Where R - right, L - left, P - straight.

And in addition, I have the priority of following the path:



rightHanded: straight, right, left   
leftHanded: straight, left, right


Following the path by priority I want to get to the end.

e.g. using the above example of paths for rightHanded



R -> R -> R -> R -> P -> P -> (1)R -> R -> R -> R -> P -> P -> (2) P -> end I find the shortest path


ad.1 I see that best is 2 and 3 because I have R

ad.2 I again chose R instead L and I have the last path left and its the simplest



I don't know how write that program.







java vector






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 22 '18 at 22:09

























asked Nov 22 '18 at 21:32









Abakus

65




65




closed as unclear what you're asking by Adrian Shum, talex, CozyAzure, EdChum, greg-449 Nov 23 '18 at 10:13


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.






closed as unclear what you're asking by Adrian Shum, talex, CozyAzure, EdChum, greg-449 Nov 23 '18 at 10:13


Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.










  • 1




    I don't understand the meaning of rightHanded and leftHanded
    – Mahmoud Hanafy
    Nov 22 '18 at 21:54










  • This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
    – Abakus
    Nov 22 '18 at 22:00










  • I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
    – bsaverino
    Nov 23 '18 at 2:14














  • 1




    I don't understand the meaning of rightHanded and leftHanded
    – Mahmoud Hanafy
    Nov 22 '18 at 21:54










  • This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
    – Abakus
    Nov 22 '18 at 22:00










  • I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
    – bsaverino
    Nov 23 '18 at 2:14








1




1




I don't understand the meaning of rightHanded and leftHanded
– Mahmoud Hanafy
Nov 22 '18 at 21:54




I don't understand the meaning of rightHanded and leftHanded
– Mahmoud Hanafy
Nov 22 '18 at 21:54












This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
– Abakus
Nov 22 '18 at 22:00




This is priority of the driving direction, leftHanded means I prefere go straight but when I can't I prefere turn left and finally when I need turn right
– Abakus
Nov 22 '18 at 22:00












I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
– bsaverino
Nov 23 '18 at 2:14




I understand what you want to do but your question is too vague and you are not facing a particular programming issue (at this point). Especially knowing that your description already explains mostly how to solve it.
– bsaverino
Nov 23 '18 at 2:14












1 Answer
1






active

oldest

votes


















0














Tested for cases like duplicate paths, a path having another path as a sub-path in the beginning, etc.



public static void main(String args) {
Map<Integer, List<Character>> paths = new LinkedHashMap<>();
paths.put(1, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'P', 'P'));
paths.put(2, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L'));
paths.put(3, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L', 'P', 'P'));

System.out.println("Path " + bestPath(paths, DrivingDirection.RIGHT_HANDED) + " is the best for " + DrivingDirection.RIGHT_HANDED);
System.out.println("Path " + bestPath(paths, DrivingDirection.LEFT_HANDED) + " is the best for " + DrivingDirection.LEFT_HANDED);
}

private static List<Character> getTurnPreferences(DrivingDirection drivingDirection) {
return drivingDirection == DrivingDirection.RIGHT_HANDED
? Arrays.asList('P', 'R', 'L')
: Arrays.asList('P', 'L', 'R');
}

private enum DrivingDirection {
RIGHT_HANDED,
LEFT_HANDED
}

private static int bestPath(Map<Integer, List<Character>> paths, DrivingDirection drivingDirection) {
List<Character> turnPreference = getTurnPreferences(drivingDirection);
final AtomicInteger i = new AtomicInteger(0);
while (paths.size() > 1) {
Map<Integer, List<Character>> tempMap = eliminateUnpreferredPaths(paths, turnPreference, i);
if (tempMap.size() == 0) return getShortestPath(paths).getKey(); // when all paths are bad
i.incrementAndGet();
Optional<Map.Entry<Integer, List<Character>>> pathWithNoMoreDirections = getPathWithNoMoreDirectionsLeft(i, tempMap);
if (pathWithNoMoreDirections.isPresent()) return pathWithNoMoreDirections.get().getKey();
paths = tempMap;
}
return paths.keySet().iterator().next();
}

private static Optional<Map.Entry<Integer, List<Character>>> getPathWithNoMoreDirectionsLeft(
AtomicInteger i, Map<Integer, List<Character>> tempMap) {
return tempMap.entrySet().stream()
.filter(e -> e.getValue().size() == i.get())
.findFirst();
}

private static Map.Entry<Integer, List<Character>> getShortestPath(Map<Integer, List<Character>> paths) {
return paths.entrySet().stream().min(Comparator.comparingInt(e -> e.getValue().size())).get();
}

private static Map<Integer, List<Character>> eliminateUnpreferredPaths(
Map<Integer, List<Character>> paths, List<Character> turnPreference, AtomicInteger i) {
Map<Integer, List<Character>> tempMap = null;
for (int j = 0; j < turnPreference.size(); j++) {
final int finalJ = j;
tempMap = paths.entrySet()
.stream()
.filter(e -> e.getValue().size() > i.get() && e.getValue().get(i.get()).equals(turnPreference.get(finalJ)))
.collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
if (tempMap.size() > 0) break;
}
return tempMap;
}


Output



Path 3 is the best for RIGHT_HANDED
Path 1 is the best for LEFT_HANDED





share|improve this answer






























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Tested for cases like duplicate paths, a path having another path as a sub-path in the beginning, etc.



    public static void main(String args) {
    Map<Integer, List<Character>> paths = new LinkedHashMap<>();
    paths.put(1, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'P', 'P'));
    paths.put(2, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L'));
    paths.put(3, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L', 'P', 'P'));

    System.out.println("Path " + bestPath(paths, DrivingDirection.RIGHT_HANDED) + " is the best for " + DrivingDirection.RIGHT_HANDED);
    System.out.println("Path " + bestPath(paths, DrivingDirection.LEFT_HANDED) + " is the best for " + DrivingDirection.LEFT_HANDED);
    }

    private static List<Character> getTurnPreferences(DrivingDirection drivingDirection) {
    return drivingDirection == DrivingDirection.RIGHT_HANDED
    ? Arrays.asList('P', 'R', 'L')
    : Arrays.asList('P', 'L', 'R');
    }

    private enum DrivingDirection {
    RIGHT_HANDED,
    LEFT_HANDED
    }

    private static int bestPath(Map<Integer, List<Character>> paths, DrivingDirection drivingDirection) {
    List<Character> turnPreference = getTurnPreferences(drivingDirection);
    final AtomicInteger i = new AtomicInteger(0);
    while (paths.size() > 1) {
    Map<Integer, List<Character>> tempMap = eliminateUnpreferredPaths(paths, turnPreference, i);
    if (tempMap.size() == 0) return getShortestPath(paths).getKey(); // when all paths are bad
    i.incrementAndGet();
    Optional<Map.Entry<Integer, List<Character>>> pathWithNoMoreDirections = getPathWithNoMoreDirectionsLeft(i, tempMap);
    if (pathWithNoMoreDirections.isPresent()) return pathWithNoMoreDirections.get().getKey();
    paths = tempMap;
    }
    return paths.keySet().iterator().next();
    }

    private static Optional<Map.Entry<Integer, List<Character>>> getPathWithNoMoreDirectionsLeft(
    AtomicInteger i, Map<Integer, List<Character>> tempMap) {
    return tempMap.entrySet().stream()
    .filter(e -> e.getValue().size() == i.get())
    .findFirst();
    }

    private static Map.Entry<Integer, List<Character>> getShortestPath(Map<Integer, List<Character>> paths) {
    return paths.entrySet().stream().min(Comparator.comparingInt(e -> e.getValue().size())).get();
    }

    private static Map<Integer, List<Character>> eliminateUnpreferredPaths(
    Map<Integer, List<Character>> paths, List<Character> turnPreference, AtomicInteger i) {
    Map<Integer, List<Character>> tempMap = null;
    for (int j = 0; j < turnPreference.size(); j++) {
    final int finalJ = j;
    tempMap = paths.entrySet()
    .stream()
    .filter(e -> e.getValue().size() > i.get() && e.getValue().get(i.get()).equals(turnPreference.get(finalJ)))
    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    if (tempMap.size() > 0) break;
    }
    return tempMap;
    }


    Output



    Path 3 is the best for RIGHT_HANDED
    Path 1 is the best for LEFT_HANDED





    share|improve this answer




























      0














      Tested for cases like duplicate paths, a path having another path as a sub-path in the beginning, etc.



      public static void main(String args) {
      Map<Integer, List<Character>> paths = new LinkedHashMap<>();
      paths.put(1, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'P', 'P'));
      paths.put(2, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L'));
      paths.put(3, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L', 'P', 'P'));

      System.out.println("Path " + bestPath(paths, DrivingDirection.RIGHT_HANDED) + " is the best for " + DrivingDirection.RIGHT_HANDED);
      System.out.println("Path " + bestPath(paths, DrivingDirection.LEFT_HANDED) + " is the best for " + DrivingDirection.LEFT_HANDED);
      }

      private static List<Character> getTurnPreferences(DrivingDirection drivingDirection) {
      return drivingDirection == DrivingDirection.RIGHT_HANDED
      ? Arrays.asList('P', 'R', 'L')
      : Arrays.asList('P', 'L', 'R');
      }

      private enum DrivingDirection {
      RIGHT_HANDED,
      LEFT_HANDED
      }

      private static int bestPath(Map<Integer, List<Character>> paths, DrivingDirection drivingDirection) {
      List<Character> turnPreference = getTurnPreferences(drivingDirection);
      final AtomicInteger i = new AtomicInteger(0);
      while (paths.size() > 1) {
      Map<Integer, List<Character>> tempMap = eliminateUnpreferredPaths(paths, turnPreference, i);
      if (tempMap.size() == 0) return getShortestPath(paths).getKey(); // when all paths are bad
      i.incrementAndGet();
      Optional<Map.Entry<Integer, List<Character>>> pathWithNoMoreDirections = getPathWithNoMoreDirectionsLeft(i, tempMap);
      if (pathWithNoMoreDirections.isPresent()) return pathWithNoMoreDirections.get().getKey();
      paths = tempMap;
      }
      return paths.keySet().iterator().next();
      }

      private static Optional<Map.Entry<Integer, List<Character>>> getPathWithNoMoreDirectionsLeft(
      AtomicInteger i, Map<Integer, List<Character>> tempMap) {
      return tempMap.entrySet().stream()
      .filter(e -> e.getValue().size() == i.get())
      .findFirst();
      }

      private static Map.Entry<Integer, List<Character>> getShortestPath(Map<Integer, List<Character>> paths) {
      return paths.entrySet().stream().min(Comparator.comparingInt(e -> e.getValue().size())).get();
      }

      private static Map<Integer, List<Character>> eliminateUnpreferredPaths(
      Map<Integer, List<Character>> paths, List<Character> turnPreference, AtomicInteger i) {
      Map<Integer, List<Character>> tempMap = null;
      for (int j = 0; j < turnPreference.size(); j++) {
      final int finalJ = j;
      tempMap = paths.entrySet()
      .stream()
      .filter(e -> e.getValue().size() > i.get() && e.getValue().get(i.get()).equals(turnPreference.get(finalJ)))
      .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
      if (tempMap.size() > 0) break;
      }
      return tempMap;
      }


      Output



      Path 3 is the best for RIGHT_HANDED
      Path 1 is the best for LEFT_HANDED





      share|improve this answer


























        0












        0








        0






        Tested for cases like duplicate paths, a path having another path as a sub-path in the beginning, etc.



        public static void main(String args) {
        Map<Integer, List<Character>> paths = new LinkedHashMap<>();
        paths.put(1, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'P', 'P'));
        paths.put(2, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L'));
        paths.put(3, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L', 'P', 'P'));

        System.out.println("Path " + bestPath(paths, DrivingDirection.RIGHT_HANDED) + " is the best for " + DrivingDirection.RIGHT_HANDED);
        System.out.println("Path " + bestPath(paths, DrivingDirection.LEFT_HANDED) + " is the best for " + DrivingDirection.LEFT_HANDED);
        }

        private static List<Character> getTurnPreferences(DrivingDirection drivingDirection) {
        return drivingDirection == DrivingDirection.RIGHT_HANDED
        ? Arrays.asList('P', 'R', 'L')
        : Arrays.asList('P', 'L', 'R');
        }

        private enum DrivingDirection {
        RIGHT_HANDED,
        LEFT_HANDED
        }

        private static int bestPath(Map<Integer, List<Character>> paths, DrivingDirection drivingDirection) {
        List<Character> turnPreference = getTurnPreferences(drivingDirection);
        final AtomicInteger i = new AtomicInteger(0);
        while (paths.size() > 1) {
        Map<Integer, List<Character>> tempMap = eliminateUnpreferredPaths(paths, turnPreference, i);
        if (tempMap.size() == 0) return getShortestPath(paths).getKey(); // when all paths are bad
        i.incrementAndGet();
        Optional<Map.Entry<Integer, List<Character>>> pathWithNoMoreDirections = getPathWithNoMoreDirectionsLeft(i, tempMap);
        if (pathWithNoMoreDirections.isPresent()) return pathWithNoMoreDirections.get().getKey();
        paths = tempMap;
        }
        return paths.keySet().iterator().next();
        }

        private static Optional<Map.Entry<Integer, List<Character>>> getPathWithNoMoreDirectionsLeft(
        AtomicInteger i, Map<Integer, List<Character>> tempMap) {
        return tempMap.entrySet().stream()
        .filter(e -> e.getValue().size() == i.get())
        .findFirst();
        }

        private static Map.Entry<Integer, List<Character>> getShortestPath(Map<Integer, List<Character>> paths) {
        return paths.entrySet().stream().min(Comparator.comparingInt(e -> e.getValue().size())).get();
        }

        private static Map<Integer, List<Character>> eliminateUnpreferredPaths(
        Map<Integer, List<Character>> paths, List<Character> turnPreference, AtomicInteger i) {
        Map<Integer, List<Character>> tempMap = null;
        for (int j = 0; j < turnPreference.size(); j++) {
        final int finalJ = j;
        tempMap = paths.entrySet()
        .stream()
        .filter(e -> e.getValue().size() > i.get() && e.getValue().get(i.get()).equals(turnPreference.get(finalJ)))
        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (tempMap.size() > 0) break;
        }
        return tempMap;
        }


        Output



        Path 3 is the best for RIGHT_HANDED
        Path 1 is the best for LEFT_HANDED





        share|improve this answer














        Tested for cases like duplicate paths, a path having another path as a sub-path in the beginning, etc.



        public static void main(String args) {
        Map<Integer, List<Character>> paths = new LinkedHashMap<>();
        paths.put(1, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'P', 'P'));
        paths.put(2, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L'));
        paths.put(3, Arrays.asList('R', 'R', 'R', 'R', 'P', 'P', 'R', 'R', 'R', 'R', 'P', 'P', 'P', 'P', 'L', 'L', 'L', 'L', 'L', 'L', 'P', 'P'));

        System.out.println("Path " + bestPath(paths, DrivingDirection.RIGHT_HANDED) + " is the best for " + DrivingDirection.RIGHT_HANDED);
        System.out.println("Path " + bestPath(paths, DrivingDirection.LEFT_HANDED) + " is the best for " + DrivingDirection.LEFT_HANDED);
        }

        private static List<Character> getTurnPreferences(DrivingDirection drivingDirection) {
        return drivingDirection == DrivingDirection.RIGHT_HANDED
        ? Arrays.asList('P', 'R', 'L')
        : Arrays.asList('P', 'L', 'R');
        }

        private enum DrivingDirection {
        RIGHT_HANDED,
        LEFT_HANDED
        }

        private static int bestPath(Map<Integer, List<Character>> paths, DrivingDirection drivingDirection) {
        List<Character> turnPreference = getTurnPreferences(drivingDirection);
        final AtomicInteger i = new AtomicInteger(0);
        while (paths.size() > 1) {
        Map<Integer, List<Character>> tempMap = eliminateUnpreferredPaths(paths, turnPreference, i);
        if (tempMap.size() == 0) return getShortestPath(paths).getKey(); // when all paths are bad
        i.incrementAndGet();
        Optional<Map.Entry<Integer, List<Character>>> pathWithNoMoreDirections = getPathWithNoMoreDirectionsLeft(i, tempMap);
        if (pathWithNoMoreDirections.isPresent()) return pathWithNoMoreDirections.get().getKey();
        paths = tempMap;
        }
        return paths.keySet().iterator().next();
        }

        private static Optional<Map.Entry<Integer, List<Character>>> getPathWithNoMoreDirectionsLeft(
        AtomicInteger i, Map<Integer, List<Character>> tempMap) {
        return tempMap.entrySet().stream()
        .filter(e -> e.getValue().size() == i.get())
        .findFirst();
        }

        private static Map.Entry<Integer, List<Character>> getShortestPath(Map<Integer, List<Character>> paths) {
        return paths.entrySet().stream().min(Comparator.comparingInt(e -> e.getValue().size())).get();
        }

        private static Map<Integer, List<Character>> eliminateUnpreferredPaths(
        Map<Integer, List<Character>> paths, List<Character> turnPreference, AtomicInteger i) {
        Map<Integer, List<Character>> tempMap = null;
        for (int j = 0; j < turnPreference.size(); j++) {
        final int finalJ = j;
        tempMap = paths.entrySet()
        .stream()
        .filter(e -> e.getValue().size() > i.get() && e.getValue().get(i.get()).equals(turnPreference.get(finalJ)))
        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
        if (tempMap.size() > 0) break;
        }
        return tempMap;
        }


        Output



        Path 3 is the best for RIGHT_HANDED
        Path 1 is the best for LEFT_HANDED






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Nov 23 '18 at 2:49

























        answered Nov 23 '18 at 2:22









        Kartik

        2,51731331




        2,51731331















            Popular posts from this blog

            What visual should I use to simply compare current year value vs last year in Power BI desktop

            Alexandru Averescu

            Trompette piccolo