コード例 #1
0
  public void summarizePlayer(int playerID) {
    Player p = players.get(playerID);
    Map<Integer, Playing> playersGames = p.games;
    Set<Integer> gamesKeys = playersGames.keySet();
    Integer[] gameIDs = gamesKeys.toArray(new Integer[gamesKeys.size()]);

    System.out.println("Player: " + p);
    System.out.println("Total Gamerscore: " + p.getGamerScore());
    System.out.printf(
        "%4s %-20s %-16s %-16s %-16s \n", " ", "Game", "Achievements", "Gamerscore", "IGN");
    System.out.println(
        "--------------------------------------------------------------------------------");
    for (int i = 0; i < gameIDs.length; i++) {
      Game g = games.get(gameIDs[i]);
      Playing playerInfo = p.games.get(gameIDs[i]);
      int nPlayerAchieve = playerInfo.achievements.size();
      int nTotalAchieve = g.achievements.size();
      System.out.printf(
          "%4s %-20s %-16s %-16s %-16s \n",
          (i + 1 + "."),
          g,
          (nPlayerAchieve + "/" + nTotalAchieve),
          (playerInfo.getPoints() + " pts"),
          playerInfo.ign);
    }

    System.out.printf("\n%4s %-16s %-16s \n", " ", "Friend", "Gamerscore");
    System.out.println(
        "--------------------------------------------------------------------------------");
    printSortedPlayers(p.friends);
  }
コード例 #2
0
  @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]);
  }