Exemplo n.º 1
0
  /**
   * ** Traverses the DBFactory dependency tree, creating a DBFactoryTree ** @param level The
   * current tree level ** @param dbFact The current DBFactory to add ** @param parentNode The
   * parent node to which a new DBFactoryNode child will be added ** @param addedTables A set of
   * table names added to the current DBFactoryTree *
   */
  private static void _traverseDBFactoryTree(
      int level,
      DBFactory<? extends DBRecord> dbFact,
      DBFactoryTree parentNode,
      Set<String> addedTables) {

    /* no DBFactory? */
    if (dbFact == null) {
      Print.logError("Null DBFactory!");
      return;
    }
    String utableName = dbFact.getUntranslatedTableName();

    /* already added? */
    if (addedTables.contains(utableName)) {
      return;
    }
    addedTables.add(utableName);

    /* add this node */
    // Print.logInfo(StringTools.replicateString("  ",level) + dbFact.getUntranslatedTableName());
    DBFactoryTree dbFactNode = new DBFactoryTree(level, parentNode, dbFact);
    parentNode.addChild(dbFactNode);

    /* find dependent children */
    DBFactory<? extends DBRecord> childFact[] = dbFact.getChildFactories();
    for (int i = 0; i < childFact.length; i++) {
      int index = childFact[i].getParentTables().indexOf(utableName);
      if (level == index) {
        DBFactoryTree._traverseDBFactoryTree(level + 1, childFact[i], dbFactNode, addedTables);
      } else if (!addedTables.contains(childFact[i].getUntranslatedTableName())) {
        Print.logWarn(
            "Skipping table in heiarchy: "
                + utableName
                + " ==> "
                + childFact[i].getUntranslatedTableName());
      }
    }
  }
Exemplo n.º 2
0
  public static void main(String[] args) throws IOException {
    BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
    String line = null;
    String[] split = null;

    int cases = Integer.valueOf(reader.readLine());
    int N, j, z, min, max, result;

    String matching = null, newMatch = null, tmpLine;
    Set<String> set = new HashSet<String>();
    boolean noResult = false;

    for (int i = 1; i <= cases; i++) {
      N = Integer.valueOf(reader.readLine());
      set = new HashSet<String>();
      noResult = false;
      result = 0;
      min = Integer.MAX_VALUE;
      max = Integer.MIN_VALUE;

      for (z = 0; z < N; z++) {
        line = reader.readLine();
        tmpLine = REGEX_PATTERN.matcher(line).replaceAll("$1");

        if (set.isEmpty()) {
          set.add(tmpLine);
        } else if (!set.contains(tmpLine)) {
          noResult = true;
          break;
        }

        min = Math.min(min, line.length());
        max = Math.max(max, line.length());
      }

      if (!noResult) {
        result = max - min;
      }

      if (noResult) {
        System.out.printf("Case #%d: Fegla Won%n", i);
      } else {
        System.out.printf("Case #%d: %d%n", i, result);
      }
    }
  }
  @RequestMapping(value = VIDEO_SEARCH_PATH, method = RequestMethod.GET)
  public @ResponseBody String[] searchVideo(
      @RequestParam(value = "username") String uName,
      @RequestParam(value = "video") String videoHash,
      HttpServletResponse response) {
    System.out.println("Search from:" + uName);
    if (!user_vidNameMap.containsKey(uName)) {
      response.setStatus(402); // client not connected
      return null;
    }

    Set<String> users = vidName_UserMap.get(videoHash);

    if (users == null) {
      System.out.println("Srearching main server\n");
      try {
        users = masterService.psSearch(hostAdder, videoHash);
      } catch (Exception e) {
        System.err.println(e.getMessage());
        return null;
      }
      if (users == null) return null;
      if (vidName_UserMap.containsKey(videoHash)) {
        vidName_UserMap.get(videoHash).addAll(users);
      } else {
        Set<String> s = new HashSet<String>();
        s.addAll(users);
        vidName_UserMap.put(videoHash, s);
      }
    } else {
      Iterator<String> it = users.iterator();
      while (it.hasNext()) {
        String temp = it.next();
        if (!activeUsers.contains(temp)) {
          it.remove();
        }
      }
    }
    System.out.println("Search result : " + Arrays.asList(users.toArray(new String[0])));
    // String [] a = new String[]
    return users.toArray(new String[0]);
  }