@RequestMapping(value = CLIENT_CONNECT_PATH, method = RequestMethod.POST)
  public @ResponseBody int connectClient(@RequestBody String allVid) {
    try {
      int reply = FAILED;
      String[] videos = allVid.split(",");
      String uName = videos[0].trim();
      videos = java.util.Arrays.copyOfRange(videos, 1, videos.length);
      // System.out.println("Client connect"+hostAdder+" "+uName+" "+ Arrays.asList(videos));
      int ans = masterService.psConnectClient(hostAdder, uName, videos);
      // System.out.println("ans =" +ans +" "+FAILED);
      while (ans == PS_NOT_CONNECTED) {
        reconnectToMS();
        ans = masterService.psConnectClient(hostAdder, uName, videos);
      }
      if (ans == FAILED) return FAILED;
      // System.out.println("Clinet "+ uName + " connected");

      if (user_vidNameMap.containsKey(uName)) {
        reply = CLIENT_ALREADY_CONNECTED;
      } else {
        reply = CLIENT_CONNECTED;
        user_vidNameMap.put(uName, new HashSet<String>());
      }
      // System.out.println("Clinet "+ uName + " connected");

      Set<String> vidSet = user_vidNameMap.get(uName);
      for (int i = 0; i < videos.length; i++) {
        String temp = videos[i].trim();
        // System.out.println("add video");

        if (!temp.equals("")) {
          vidSet.add(temp);
          addTovidName_UserMap(uName, temp);
        }
      }
      // System.out.println("Clinet "+ uName + " connected");

      userAliveMap.put(uName, new Long(System.currentTimeMillis() + TTL));
      // System.out.println("Clinet "+ uName + " connected");

      activeUsers.add(uName);
      System.out.println("Clinet " + uName + " connected");
      return reply;
    } catch (Exception e) {
      System.out.println("Error: " + e.getMessage());
      return FAILED;
    }
  }
 private void addTovidName_UserMap(String user, String video) {
   if (vidName_UserMap.containsKey(video)) {
     vidName_UserMap.get(video).add(user);
   } else {
     Set<String> s = new HashSet<String>();
     s.add(user);
     vidName_UserMap.put(video, s);
   }
 }
  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);
      }
    }
  }
Example #4
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());
      }
    }
  }