Example #1
0
  private void readOldState(DataInputStream dis) throws IOException, TeamException {
    int repoSize = dis.readInt();
    boolean version1 = false;
    if (repoSize == STATE_FILE_VERSION_1) {
      version1 = true;
      repoSize = dis.readInt();
    }
    for (int i = 0; i < repoSize; i++) {
      ICVSRepositoryLocation root = KnownRepositories.getInstance().getRepository(dis.readUTF());
      RepositoryRoot repoRoot = getRepositoryRootFor(root);

      // read branch tags associated with this root
      int tagsSize = dis.readInt();
      CVSTag[] branchTags = new CVSTag[tagsSize];
      for (int j = 0; j < tagsSize; j++) {
        String tagName = dis.readUTF();
        int tagType = dis.readInt();
        branchTags[j] = new CVSTag(tagName, tagType);
      }
      // Ignore the branch tags since they are handled differently now
      // addBranchTags(root, branchTags);

      // read the number of projects for this root that have version tags
      int projSize = dis.readInt();
      if (projSize > 0) {
        for (int j = 0; j < projSize; j++) {
          String name = dis.readUTF();
          Set tagSet = new HashSet();
          int numTags = dis.readInt();
          for (int k = 0; k < numTags; k++) {
            tagSet.add(new CVSTag(dis.readUTF(), CVSTag.VERSION));
          }
          CVSTag[] tags = (CVSTag[]) tagSet.toArray(new CVSTag[tagSet.size()]);
          repoRoot.addTags(name, tags);
        }
      }
      // read the auto refresh filenames for this project
      if (version1) {
        try {
          projSize = dis.readInt();
          if (projSize > 0) {
            for (int j = 0; j < projSize; j++) {
              String name = dis.readUTF();
              Set filenames = new HashSet();
              int numFilenames = dis.readInt();
              for (int k = 0; k < numFilenames; k++) {
                filenames.add(name + "/" + dis.readUTF()); // $NON-NLS-1$
              }
              repoRoot.setAutoRefreshFiles(
                  name, (String[]) filenames.toArray(new String[filenames.size()]));
            }
          }
        } catch (EOFException e) {
          // auto refresh files are not persisted, continue and save them next time.
        }
      }
      broadcastRepositoryChange(repoRoot);
    }
  }
Example #2
0
 public static File[] toFileArray(Collection fileObjects) {
   Set files = new HashSet(fileObjects.size() * 4 / 3 + 1);
   for (Iterator i = fileObjects.iterator(); i.hasNext(); ) {
     files.add(FileUtil.toFile((FileObject) i.next()));
   }
   files.remove(null);
   return (File[]) files.toArray(new File[files.size()]);
 }
Example #3
0
  @Override
  void solve(Set<? extends Job> jobs) {
    Job[] sortedJobs = jobs.toArray(new Job[jobs.size()]);
    Arrays.sort(sortedJobs, Job::compareArrivalTime);

    processTime = totWT = 0;
    long usefulTime = 0;
    int jobCount = jobs.size();
    PriorityQueue<Job> queue = new PriorityQueue<>(Job::compareBurstTime);
    for (Job job : sortedJobs) {
      if (job == null) {
        jobCount--;
        continue;
      }

      while (!queue.isEmpty() && processTime < job.getArrivalTime()) {
        Job nextJob = queue.poll();
        long arrivalTime = nextJob.getArrivalTime();
        long burstTime = nextJob.getBurstTime();

        if (processTime < nextJob.getArrivalTime()) {
          processList.add(new RunningProcess("Idle", arrivalTime - processTime));
          processTime = arrivalTime;
        }

        processList.add(new RunningProcess("P" + nextJob.getId(), burstTime));
        usefulTime += burstTime;
        totWT += processTime - arrivalTime;
        processTime += burstTime;
      }

      queue.add(job);
    }

    while (!queue.isEmpty()) {
      Job nextJob = queue.poll();
      long arrivalTime = nextJob.getArrivalTime();
      long burstTime = nextJob.getBurstTime();

      if (processTime < nextJob.getArrivalTime()) {
        processList.add(new RunningProcess("Idle", arrivalTime - processTime));
        processTime = arrivalTime;
      }

      processList.add(new RunningProcess("P" + nextJob.getId(), burstTime));
      usefulTime += burstTime;
      totWT += processTime - arrivalTime;
      processTime += burstTime;
    }

    totRT = totWT;
    totTAT = totWT + usefulTime;

    avgRT = avgWT = (double) totWT / (double) jobCount;
    avgTAT = (double) totTAT / (double) jobCount;

    utilization = usefulTime * 100.0 / processTime;
  }
 /** descendingkeySet.toArray returns contains all keys */
 public void testDescendingDescendingKeySetToArray() {
   ConcurrentNavigableMap map = dmap5();
   Set s = map.descendingKeySet();
   Object[] ar = s.toArray();
   assertEquals(5, ar.length);
   assertTrue(s.containsAll(Arrays.asList(ar)));
   ar[0] = m10;
   assertFalse(s.containsAll(Arrays.asList(ar)));
 }
 /**
  * Returns a string array containing the default JMX domains of all available MBeanServers in this
  * JVM.
  *
  * @return a string array of JMX default domains
  */
 public static String[] getMBeanServerDomains() {
   Set<String> domains = new HashSet<String>();
   for (MBeanServer mbs : MBeanServerFactory.findMBeanServer(null)) {
     String domain = mbs.getDefaultDomain();
     if (domain == null) domain = "DefaultDomain";
     domains.add(domain);
   }
   return domains.toArray(new String[domains.size()]);
 }
  @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]);
  }
Example #7
0
 static String[] getOrderedEdgeLabels(Graph g) {
   Set labelSet = new HashSet();
   for (Iterator i = g.getNodeIterator(); i.hasNext(); ) {
     GraphId id = (GraphId) i.next();
     labelSet.addAll(g.getEdgeLabels(id));
   }
   log.debug(labelSet.size() + " labels in labelset.");
   String[] result = (String[]) labelSet.toArray(new String[labelSet.size()]);
   Arrays.sort(result);
   return result;
 }
  private static String[] findStandardMBeans(URL codeBase) throws Exception {
    Set<String> names;
    if (codeBase.getProtocol().equalsIgnoreCase("file") && codeBase.toString().endsWith("/"))
      names = findStandardMBeansFromDir(codeBase);
    else names = findStandardMBeansFromJar(codeBase);

    Set<String> standardMBeanNames = new TreeSet<String>();
    for (String name : names) {
      if (name.endsWith("MBean")) {
        String prefix = name.substring(0, name.length() - 5);
        if (names.contains(prefix)) standardMBeanNames.add(prefix);
      }
    }
    return standardMBeanNames.toArray(new String[0]);
  }
Example #9
0
 /**
  * Method getKnownTags.
  *
  * @param repository
  * @param set
  * @param i
  * @param monitor
  * @return CVSTag[]
  */
 public CVSTag[] getKnownTags(
     ICVSRepositoryLocation repository, IWorkingSet set, int tagType, IProgressMonitor monitor)
     throws CVSException {
   if (set == null) {
     return getKnownTags(repository, tagType);
   }
   ICVSRemoteResource[] folders = getFoldersForTag(repository, CVSTag.DEFAULT, monitor);
   folders = filterResources(set, folders);
   Set tags = new HashSet();
   for (int i = 0; i < folders.length; i++) {
     ICVSRemoteFolder folder = (ICVSRemoteFolder) folders[i];
     tags.addAll(Arrays.asList(getKnownTags(folder, tagType)));
   }
   return (CVSTag[]) tags.toArray(new CVSTag[tags.size()]);
 }
Example #10
0
  /** Get the list of known branch tags for a given remote root. */
  public CVSTag[] getKnownTags(ICVSFolder project, int tagType) {
    try {
      CVSTag[] tags = getKnownTags(project);
      Set result = new HashSet();
      for (int i = 0; i < tags.length; i++) {
        CVSTag tag = tags[i];
        if (tag.getType() == tagType) result.add(tag);
      }

      return (CVSTag[]) result.toArray(new CVSTag[result.size()]);
    } catch (CVSException e) {
      CVSUIPlugin.log(e);
      return new CVSTag[0];
    }
  }
Example #11
0
  /**
   * On distribue 2 cartes troupes à chaque joueur Methode appelé dans "distributionCartesDepart(x,
   * y)"
   *
   * @param hjoueur hashset des joueurs
   * @param htitre hashset des titres
   */
  public void distributionTitreDepart(Set<Joueur> hjoueur, Set<Titre> htitre) {
    // On copie le hashSet des titre dans un tableau
    // On modifiera donc uniquement le tableau et non le hashSet d'initialisation
    Titre[] tabtitre = htitre.toArray(new Titre[htitre.size()]);
    // On convertit le tableau en liste pour mélanger et plus de simplicitée.
    ArrayList<Titre> list = new ArrayList<Titre>(Arrays.asList(tabtitre));
    Collections.shuffle(list);

    for (Joueur j : hjoueur) {
      // On affecte le titre au joueur
      j.setTitre(list.get(0));
      // On supprimer le titre de la liste pour ne pas le redonner
      list.remove(0);
    }
  }
 public static ConnectionStatistics[] getPoolStatistics() {
   Set<ConnectionStatistics> stats = new HashSet<ConnectionStatistics>();
   Iterator<TcpConnectionManager> it = poolTable_.values().iterator();
   while (it.hasNext()) {
     TcpConnectionManager cp = it.next();
     ConnectionStatistics cs =
         new ConnectionStatistics(
             cp.getLocalEndPoint(),
             cp.getRemoteEndPoint(),
             cp.getPoolSize(),
             cp.getConnectionsInUse());
     stats.add(cs);
   }
   return stats.toArray(new ConnectionStatistics[0]);
 }
Example #13
0
 public ICVSRemoteResource[] getFoldersForTag(
     ICVSRepositoryLocation location, CVSTag tag, IProgressMonitor monitor) throws CVSException {
   monitor = Policy.monitorFor(monitor);
   try {
     monitor.beginTask(
         NLS.bind(
             CVSUIMessages.RepositoryManager_fetchingRemoteFolders, new String[] {tag.getName()}),
         100);
     if (tag.getType() == CVSTag.HEAD) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     if (tag.getType() == CVSTag.DATE) {
       ICVSRemoteResource[] resources =
           location.members(tag, false, Policy.subMonitorFor(monitor, 60));
       RepositoryRoot root = getRepositoryRootFor(location);
       ICVSRemoteResource[] modules =
           root.getDefinedModules(tag, Policy.subMonitorFor(monitor, 40));
       ICVSRemoteResource[] result = new ICVSRemoteResource[resources.length + modules.length];
       System.arraycopy(resources, 0, result, 0, resources.length);
       System.arraycopy(modules, 0, result, resources.length, modules.length);
       return result;
     }
     Set result = new HashSet();
     // Get the tags for the location
     RepositoryRoot root = getRepositoryRootFor(location);
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       List tags = Arrays.asList(root.getAllKnownTags(path));
       if (tags.contains(tag)) {
         ICVSRemoteFolder remote =
             root.getRemoteFolder(path, tag, Policy.subMonitorFor(monitor, 100));
         result.add(remote);
       }
     }
     return (ICVSRemoteResource[]) result.toArray(new ICVSRemoteResource[result.size()]);
   } finally {
     monitor.done();
   }
 }
Example #14
0
 /** Get the list of known version tags for a given project. */
 public CVSTag[] getKnownTags(ICVSRepositoryLocation location, int tagType) {
   Set result = new HashSet();
   RepositoryRoot root = (RepositoryRoot) repositoryRoots.get(location.getLocation(false));
   if (root != null) {
     String[] paths = root.getKnownRemotePaths();
     for (int i = 0; i < paths.length; i++) {
       String path = paths[i];
       CVSTag[] tags = root.getAllKnownTags(path);
       for (int j = 0; j < tags.length; j++) {
         CVSTag tag = tags[j];
         if (tag.getType() == tagType) result.add(tag);
       }
     }
   }
   return (CVSTag[]) result.toArray(new CVSTag[0]);
 }
 /** list all application refs that are present in the provided list of targets */
 public TargetModuleID[] listAppRefs(String[] targets) throws IOException {
   if (!isConnected()) {
     throw new IllegalStateException(
         localStrings.getString("enterprise.deployment.client.disconnected_state"));
   }
   Vector tmpVector = new Vector();
   DomainConfig domainCfg =
       ProxyFactory.getInstance(dasConnection).getDomainRoot().getDomainConfig();
   Map serverProxies = domainCfg.getStandaloneServerConfigMap();
   Map clusterProxies = domainCfg.getClusterConfigMap();
   Map clusteredServerProxies = domainCfg.getClusteredServerConfigMap();
   for (int i = 0; i < targets.length; i++) {
     Set proxySet = null;
     if (serverProxies.get(targets[i]) != null) {
       StandaloneServerConfig tgtProxy =
           (StandaloneServerConfig)
               domainCfg.getContainee(XTypes.STANDALONE_SERVER_CONFIG, targets[i]);
       proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG);
     } else if (clusterProxies.get(targets[i]) != null) {
       ClusterConfig tgtProxy =
           (ClusterConfig) domainCfg.getContainee(XTypes.CLUSTER_CONFIG, targets[i]);
       proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG);
     } else if (clusteredServerProxies.get(targets[i]) != null) {
       ClusteredServerConfig tgtProxy =
           (ClusteredServerConfig)
               domainCfg.getContainee(XTypes.CLUSTERED_SERVER_CONFIG, targets[i]);
       proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG);
     } else if (TargetType.DOMAIN.equals(targets[i])) {
       StandaloneServerConfig tgtProxy =
           (StandaloneServerConfig) domainCfg.getContainee(XTypes.STANDALONE_SERVER_CONFIG, DAS);
       proxySet = tgtProxy.getContaineeSet(XTypes.DEPLOYED_ITEM_REF_CONFIG);
     } else {
       return null;
     }
     Object[] appRefs = proxySet.toArray();
     for (int k = 0; k < appRefs.length; k++) {
       SunTarget aTarget = new SunTarget(serverId);
       aTarget.setAppServerInstance(targets[i]);
       aTarget.setConnectionSource(dasConnection);
       DeployedItemRefConfig item = (DeployedItemRefConfig) appRefs[k];
       SunTargetModuleID tgtId = new SunTargetModuleID(item.getRef(), aTarget);
       tmpVector.add(tgtId);
     }
   }
   SunTargetModuleID[] result = new SunTargetModuleID[tmpVector.size()];
   return (TargetModuleID[]) tmpVector.toArray(result);
 }
Example #16
0
 // If the game is not yet over (ie: at least two players have planets or
 // fleets remaining), returns -1. If the game is over (ie: only one player
 // is left) then that player's number is returned. If there are no
 // remaining players, then the game is a draw and 0 is returned.
 public int Winner() {
   Set<Integer> remainingPlayers = new TreeSet<Integer>();
   for (Planet p : planets) {
     remainingPlayers.add(p.Owner());
   }
   for (Fleet f : fleets) {
     remainingPlayers.add(f.Owner());
   }
   switch (remainingPlayers.size()) {
     case 0:
       return 0;
     case 1:
       return ((Integer) remainingPlayers.toArray()[0]).intValue();
     default:
       return -1;
   }
 }
Example #17
0
  public void solve() throws IOException {
    int n = nextInt();
    int m = nextInt();

    for (int i = 0; i <= m; i++) for (int j = 0; j <= m; j++) set.add(i * i + j * j);

    Integer[] a = set.toArray(new Integer[0]);
    boolean[] hash = new boolean[a[a.length - 1] + 1];

    for (int i = 0; i < a.length; i++) hash[a[i]] = true;

    for (int i = 0; i < a.length - n; i++) {
      for (int j = i + 1; j < a.length; j++) {
        int d = a[j] - a[i];
        int val = a[j];
        boolean flag = true;
        for (int k = 0; k < n - 2; k++) {
          val += d;
          if (val > a[a.length - 1] || !hash[val]) {
            flag = false;
            break;
          }
        }
        if (flag) {
          list.add(new sequence(a[i], d));
        }
      }
    }

    if (list.size() == 0) out.println("NONE");
    else {
      Collections.sort(list);
      for (sequence s : list) {
        out.println(s.a + " " + s.d);
      }
    }
  }
 public static String[] getApplicationNames() {
   Set result = getApplicationNameSet();
   return (String[]) result.toArray(new String[result.size()]);
 }
Example #19
0
  // Graham Scan
  public Point[] grahamScan(Set<Point> pointSet) {
    Point[] myPS = pointSet.toArray(new Point[pointSet.size()]);

    // (0): find the lowest point
    int min = 0;
    for (int i = 1; i < myPS.length; i++) {
      if (myPS[i].y == myPS[min].y) {
        if (myPS[i].x > myPS[min].x) min = i;
      } else if (myPS[i].y < myPS[min].y) min = i;
    }
    // move min to beginning of array
    swapPoints(myPS, 0, min);

    // the base point
    // System.out.println("BASE POINT: " + myPS[0].stringPoint());

    // (1): find angles from base (pointSet[min])
    // make array size n-1
    ArrayList<PointData> ccw = new ArrayList<PointData>();
    double ang;
    for (int i = 1; i < myPS.length; i++) {
      ang = findAngle(myPS[0], myPS[i]);
      ccw.add(new PointData(ang, myPS[i]));
    }
    // add the pivot point
    // ccw.add(new PointData(0, myPS[1]));

    // (2): Sort ccw by ccw angles
    Collections.sort(ccw); // DOES THIS USE QUICKSORT?

    // testing
    for (Iterator<PointData> i = ccw.iterator(); i.hasNext(); ) {
      PointData data = i.next();
      // System.out.println(data.angle + " --- " + data.p.stringPoint());
    }

    // (3): create the stack(convex hull) of Points
    // initialize
    Stack<Point> pointStack = new Stack<Point>();
    // push base
    pointStack.push(myPS[0]);
    // if the base ONLY exists
    if (ccw.isEmpty()) {
      // System.out.println("A BASE HULL!");
      Point[] basehull = new Point[1];
      basehull[0] = pointStack.pop();
      return basehull;
    }

    // push rightmost ccw element
    pointStack.push(ccw.get(0).p);
    // then we look for CH points
    int n = 1;
    while (n < ccw.size()) {
      // System.out.println("entering STACK");
      Point c = pointStack.pop();
      // System.out.println("POPPING " + c.stringPoint() );
      Point p = pointStack.peek();
      Point nPoint = ccw.get(n).p;
      // System.out.println("CHECKING POINTS: \n" +
      // p.stringPoint() + "\n" +
      // c.stringPoint() + "\n" +
      // nPoint.stringPoint());
      // System.out.println("ISLEFT: "+ isLeft(p, c, nPoint) );
      if (isLeft(p, c, nPoint) < 0) {
        pointStack.push(c);
        pointStack.push(nPoint);
        n++;
      }
    }

    // stack to array
    Point[] convexhull = new Point[pointStack.size()];
    int z = 0;
    // System.out.println("THE CONVEX HULL:");
    while (pointStack.empty() == false) {
      Point hullpoint = pointStack.pop();
      // System.out.println(hullpoint.stringPoint());
      convexhull[z] = hullpoint;
      z++;
    }

    // return the array pf the stack
    return convexhull;
  }