Ad
Code
Diff
  • import java.util.Map;
    import java.util.HashMap;
    import java.util.Set;
    import java.util.HashSet;
    
    public class DependencyTracker {
      
      Map<String, Set<String>> theDependencies = new HashMap<>();
      
      public Set<String> getDependencies(String dependencyName) {
        Set<String> allDependencies = new HashSet<>();
        Set<String> directDependencies = getDirectDependencies(dependencyName);
        
        allDependencies.addAll(directDependencies);
        for (String subDependency : directDependencies) {
          allDependencies.addAll(getDependencies(subDependency));
        }
        return allDependencies;
      }
      
      public void registerDependency(String dependent, String dependedUpon) {
        Set<String> currentDependencies = getDirectDependencies(dependent);
        currentDependencies.add(dependedUpon);
        theDependencies.put(dependent, currentDependencies);
      }
      
      private Set<String> getDirectDependencies(String dependencyName) {
        return theDependencies.getOrDefault(dependencyName, new HashSet<>());
      }
    }
    • import java.util.Map;
    • import java.util.HashMap;
    • import java.util.Set;
    • import java.util.HashSet;
    • public class DependencyTracker {
    • Map<String, Set<String>> theDependencies = new HashMap<>();
    • public Set<String> getDependencies(String dependencyName) {
    • return getDirectDependencies(dependencyName);
    • Set<String> allDependencies = new HashSet<>();
    • Set<String> directDependencies = getDirectDependencies(dependencyName);
    • allDependencies.addAll(directDependencies);
    • for (String subDependency : directDependencies) {
    • allDependencies.addAll(getDependencies(subDependency));
    • }
    • return allDependencies;
    • }
    • // If "a" depends on "b," "a" is `dependent` and "b" is dependendUpon
    • public void registerDependency(String dependent, String dependedUpon) {
    • Set<String> currentDependencies = getDirectDependencies(dependent);
    • currentDependencies.add(dependedUpon);
    • theDependencies.put(dependent, currentDependencies);
    • }
    • private Set<String> getDirectDependencies(String dependencyName) {
    • return theDependencies.getOrDefault(dependencyName, new HashSet<>());
    • }
    • }
Code
Diff
  • import java.util.Map;
    import java.util.HashMap;
    
    public class DependencyTracker {
      
      Map<String, String> theDependencies = new HashMap<>();
      
      public String getDependencies(String dependencyName) {
        return theDependencies.getOrDefault(dependencyName, "");
      }
      
      // If "a" depends on "b," "a" is `dependent` and "b" is dependendUpon
      public void registerDependency(String dependent, String dependedUpon) {
        theDependencies.put(dependent, dependedUpon);
      }
    }
    • import java.util.Map;
    • import java.util.HashMap;
    • public class DependencyTracker {
    • String theDependency = "";
    • Map<String, String> theDependencies = new HashMap<>();
    • public String getDependencies(String dependencyName) {
    • return theDependency;
    • return theDependencies.getOrDefault(dependencyName, "");
    • }
    • // If "a" depends on "b," "a" is `dependent` and "b" is dependendUpon
    • public void registerDependency(String dependent, String dependedUpon) {
    • theDependency = "H";
    • theDependencies.put(dependent, dependedUpon);
    • }
    • }
public class FizzBuzz {
  public static String evaluate(String input) {
    return input;
  }
}