@Override
 public int getWriteSpeed() {
   int min = Integer.MAX_VALUE;
   for (Disk disk : disks) {
     min = Math.min(min, disk.getWriteSpeed());
   }
   return min;
 }
Exemplo n.º 2
0
 // 代表启动计算机
 public void start() {
   memory.read();
   memory.write();
   cpu.read();
   cpu.write();
   disk.read();
   disk.write();
 }
 @Override
 public int getCapacity() {
   int total = 0;
   for (Disk disk : disks) {
     total += disk.getCapacity();
   }
   return total;
 }
Exemplo n.º 4
0
 /**
  * Finds Disk by hostname, port, and mount path.
  *
  * @param hostname of datanode
  * @param port of datanode
  * @param mountPath of disk
  * @return Disk or null if not found.
  */
 public Disk findDisk(String hostname, int port, String mountPath) {
   DataNode dataNode = findDataNode(hostname, port);
   if (dataNode != null) {
     for (Disk disk : dataNode.getDisks()) {
       if (disk.getMountPath().equals(mountPath)) {
         return disk;
       }
     }
   }
   return null;
 }
Exemplo n.º 5
0
  public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.item_details);

    Intent intent = getIntent();
    disk = (Disk) intent.getSerializableExtra("disk");

    if (intent.hasExtra("fbusername")) {
      fbusername = intent.getStringExtra("fbusername");
    } else {
      fbusername = "******";
    }

    title = (TextView) findViewById(R.id.textView1);
    artist = (TextView) findViewById(R.id.artist);
    status = (TextView) findViewById(R.id.status);
    diskImage = (ImageView) findViewById(R.id.disk_image);

    title.setText(disk.getTitle());
    artist.setText(disk.getArtist());
    status.setText(disk.getStatus());

    // Set up image in view
    byte[] imageAsBytes = Base64.decode(disk.getImageEncoding(), Base64.DEFAULT);
    diskImage.setImageBitmap(BitmapFactory.decodeByteArray(imageAsBytes, 0, imageAsBytes.length));

    // Find the user's profile picture custom view
    profilePictureView = (ProfilePictureView) findViewById(R.id.item_details_profile_pic);
    profilePictureView.setCropped(false);
    Session session = Session.getActiveSession();
    if (session != null && session.isOpened()) {
      // Get the user's data
      makeMeRequest(session);
    }

    // Set up action that will be triggered when user presses the Send button
    ((Button) findViewById(R.id.button2))
        .setOnClickListener(
            new OnClickListener() {
              public void onClick(View view) {
                send_message();
              }
            });

    // Set up action that will be triggered when user presses the Home button
    ((ImageButton) findViewById(R.id.home))
        .setOnClickListener(
            new View.OnClickListener() {
              public void onClick(View view) {
                go_home();
              }
            });
  }
Exemplo n.º 6
0
 public long calculateUnavailableDiskCount() {
   long count = 0;
   for (Datacenter datacenter : datacenters) {
     for (DataNode dataNode : datacenter.getDataNodes()) {
       for (Disk disk : dataNode.getDisks()) {
         if (disk.isDown()) {
           count++;
         }
       }
     }
   }
   return count;
 }
  public IndexedFile(
      Disk disk,
      int recordSize,
      int keySize,
      int indexRecordSize,
      int firstAllocated, // Default ctor
      int indexStart,
      int indexSectors,
      int indexRoot,
      int indexLevels) {
    this.disk = disk;
    this.buffer = new char[disk.getSectorSize()];
    this.recordSize = recordSize;
    this.keySize = keySize;
    this.indexRecordSize = indexRecordSize;

    this.recordsPerSector = this.disk.getSectorSize() / this.recordSize;
    this.firstAllocated = firstAllocated;

    this.indexStart = indexStart;
    this.indexSectors = indexSectors;
    this.indexRoot = indexRoot;
    this.indexLevels = indexLevels;

    this.overflowSectors = 0;
  }
Exemplo n.º 8
0
 public void startup() {
   System.out.println("start the computer!");
   cpu.startup();
   memory.startup();
   disk.startup();
   System.out.println("start computer finished!");
 }
Exemplo n.º 9
0
 public void shutdown() {
   System.out.println("begin to close computer!");
   disk.shutdowm();
   memory.shutdowm();
   cpu.shutdown();
   System.out.println("GG");
 }
Exemplo n.º 10
0
 @Override
 protected void paintComponent(Graphics g) {
   super.paintComponent(g);
   Graphics2D g2 = (Graphics2D) g;
   Rectangle rec = g2.getClipBounds();
   long cap = rec.width * disk.getSize();
   g2.drawLine(rec.x, rec.y, (int) cap, rec.height);
 }
Exemplo n.º 11
0
 public void mousePressed(MouseEvent e) {
   Disk disk = null;
   Rectangle rect = null;
   if (e.getSource() == this) {
     move = false;
   }
   if (e.getSource() instanceof Disk) {
     disk = (Disk) e.getSource();
     startX = (int) disk.getBounds().getX();
     startY = (int) disk.getBounds().getY();
     rect = disk.getBounds(); /* get startX startY and strarTowerPoint */
     for (int i = 0; i < 3 * diskNum; i++) {
       if (rect.contains(points[i].getX(), points[i].getY())) {
         strarTowerPoint = i;
         break;
       }
     }
   }
 }
Exemplo n.º 12
0
 public void mouseDragged(MouseEvent e) {
   Disk disk = null;
   int x, y;
   if (e.getSource() instanceof Disk) {
     move = true;
     disk = (Disk) e.getSource();
     e = SwingUtilities.convertMouseEvent(disk, e, this);
   }
   if (e.getSource() == this) {
     if (move && (disk != null)) {
       x = e.getX();
       y = e.getY();
       if (disk.isPressed() == false) {
         disk.setLocation(x - disk.getWidth() / 2, y - disk.getHeight() / 2);
       } else {
         System.out.println("locked");
       }
     }
   }
 }
  public boolean insertRecord(char[] record) {
    char[] key = getKey(record, 0); // Get key array
    int sectorNum = getSector(convertToString(key)); // Get sector number
    disk.readSector(sectorNum, buffer); // Read the sector to the buffer
    boolean notDuplicate = checkNotDuplicate(buffer, key); // Check duplicate key

    if (notDuplicate) // If its not a duplicate key
    {
      boolean availableSpace =
          findAvailableAndStore(buffer, record); // find an available space in buffer
      if (availableSpace) // Found available space
      {
        disk.writeSector(sectorNum, buffer); // Write the buffer to disk sector
        return true;
      } else // Need to go overflow sectors
      {
        if (overflowSectors == 0) // Oops i don't have a overflow sector
        {
          overflowStart =
              this.indexStart + this.indexSectors; // Allocated the first overflow sector
          disk.readSector(
              overflowStart, buffer); // Read in the first empty overflow sector into buffer
          findAvailableAndStore(buffer, record); // write the record into buffer
          disk.writeSector(overflowStart, buffer); // Write to the disk overflow sector
          overflowSectors++; // Increment number of overflow sectors in use
          return true;
        } else // If not the first time
        {
          int currOverflowSector = overflowStart;
          while ((currOverflowSector < overflowStart + overflowSectors) && notDuplicate) {
            disk.readSector(currOverflowSector, buffer); // Read in overflow sector
            notDuplicate = checkNotDuplicate(buffer, key); // Check duplicate key
            currOverflowSector++; // Move to next overflow sector
          }
          if (notDuplicate) // No duplicate key in overflow sector
          {
            currOverflowSector--; // Back to current overflow sector
            availableSpace =
                findAvailableAndStore(buffer, record); // Find an available space in buffer
            if (!availableSpace) // If not more space in this overflow sector
            {
              currOverflowSector++; // Move to next overflow sector
              overflowSectors++; // Increment number of overflow sectors in use
              disk.readSector(
                  currOverflowSector, buffer); // Read next overflow sector(empty) into buffer
              findAvailableAndStore(buffer, record); // write the record into empty buffer
            }
            disk.writeSector(currOverflowSector, buffer); // Write to the disk overflow sector
            return true;
          } else // Found duplicate key in overflow sector
          return false;
        }
      }
    } else // Same key is found no further action, return false
    return false;
  }
Exemplo n.º 14
0
 /**
  * Compare this disk's information to the given disk's for ordering.
  *
  * <p>Note, currently only equality is based only on their free space.
  *
  * @param other disk to compare to this disk
  * @return positive if this disk is greater than the given disk, zero if they are equal, and
  *     negative if this disk is less than the given disk
  */
 @Override
 public int compareTo(Disk other) {
   if (other != null) {
     int result = other.freeSpace() - freeSpace();
     if (result == 0) {
       return myId - other.myId;
     } else {
       return result;
     }
   }
   return -1;
 }
  // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<DELETE THIS FUNCTION WHEN
  // DONE>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
  public int getSectorPublic(String key) // Returns sector number indicated by key
      {
    boolean notFound = true; // Not found the target sector
    boolean notDoneCurrSector = true; // Not done with comparing the current sector
    char[] keyChar = new char[keySize];
    key.getChars(0, key.length(), keyChar, 0); // Convert the key to characters
    char[] currSector = new char[disk.getSectorSize()];
    int address = indexRoot; // Start from root sector
    int currLevel = 0; // Count current tree level

    while (notFound) {
      disk.readSector(address, currSector); // Read sector to buffer
      int currKeyPlace = 0; // First index of the KeyOne
      notDoneCurrSector = true; // Reset notDone

      while (notDoneCurrSector) {
        boolean lastKeyInSector = false; // is the last key in sector
        int compVal = 0;
        int nextKeyPlace = currKeyPlace + indexRecordSize; // Get next Key place
        if (nextKeyPlace >= disk.getSectorSize()
            || currSector[nextKeyPlace] == 0) // if current key is the last key in sector
        lastKeyInSector = true;
        else
          compVal = compareKeys(keyChar, getKey(currSector, nextKeyPlace)); // Compare with next Key

        if (compVal == -1
            || lastKeyInSector) // If argument key is less than next key, or last key in sector
        {
          address = getSectorNumber(currSector, currKeyPlace); // Get the address of the current key
          notDoneCurrSector = false;
          currLevel++; // Increment leve;
        } else // Else if equals or greater than next key
        currKeyPlace = nextKeyPlace; // Set current key equals to next key
      }
      if (currLevel == indexLevels) // When we get to bottom tree level
      notFound = false; // We done, we found the sector number
    }

    return address;
  }
Exemplo n.º 16
0
  // Validate each hardware component (Datacenter, DataNode, and Disk) are unique
  protected void validateUniqueness() throws IllegalStateException {
    logger.trace("begin validateUniqueness.");
    HashSet<Datacenter> datacenterSet = new HashSet<Datacenter>();
    HashSet<DataNode> dataNodeSet = new HashSet<DataNode>();
    HashSet<Disk> diskSet = new HashSet<Disk>();

    for (Datacenter datacenter : datacenters) {
      if (!datacenterSet.add(datacenter)) {
        throw new IllegalStateException("Duplicate Datacenter detected: " + datacenter.toString());
      }
      for (DataNode dataNode : datacenter.getDataNodes()) {
        if (!dataNodeSet.add(dataNode)) {
          throw new IllegalStateException("Duplicate DataNode detected: " + dataNode.toString());
        }
        for (Disk disk : dataNode.getDisks()) {
          if (!diskSet.add(disk)) {
            throw new IllegalStateException("Duplicate Disk detected: " + disk.toString());
          }
        }
      }
    }
    logger.trace("complete validateUniqueness.");
  }
Exemplo n.º 17
0
  private void goal(Club player) {
    if (players[0] == player) {
      goal[0] = true;
      goal[2] = true;
      disk.setX(field.getWidth() / 2);
      disk.setY(0 + 2 * disk.getRadius() + 100);
    } else {
      goal[1] = true;
      goal[2] = true;
      disk.setX(field.getWidth() / 2);
      disk.setY(field.getHeight() - 2 * disk.getRadius() - 100);
    }

    player.incScore();

    disk.setDx(0);
    disk.setDy(0);
  }
Exemplo n.º 18
0
  private boolean goalCase() {

    if ((disk.getX() < gateEndX) && (disk.getX() > gateStartX)) {
      if (disk.getY() + disk.getRadius() < 0) {
        goal(players[0]);
      }
      if (disk.getY() - disk.getRadius() > field.getHeight()) {
        goal(players[1]);
      }
      return true;
    }
    return false;
  }
Exemplo n.º 19
0
  public void move(float speed) {

    for (Strikeable item : players) {
      if (item.isStrike(this.disk)) {
        item.strike(this.disk);
      }
    }

    for (Strikeable item : gatePoints) {
      if (item.isStrike(this.disk)) {
        item.strike(this.disk);
      }
    }

    if (field.isStrike(this.disk)) {
      field.strike(this.disk);
    }

    disk.setX((disk.getX() + disk.getDx() / speed));
    disk.setY((disk.getY() + disk.getDy() / speed));

    slow();

    colisionCase();
    if (goalCase()) {}

    players[0].setDx((players[0].getX() - oldx));
    players[0].setDy((players[0].getY() - oldy));
    oldx = players[0].getX();
    oldy = players[0].getY();

    players[1].setDx((players[1].getX() - oldx1));
    players[1].setDy((players[1].getY() - oldy1));
    oldx1 = players[1].getX();
    oldy1 = players[1].getY();
  }
Exemplo n.º 20
0
 public void shutdown() {
   System.out.println("Computer shutdown...");
   cpu.shutdown();
   memory.shutdown();
   disk.shutdown();
 }
Exemplo n.º 21
0
 public void startup() {
   System.out.println("Computer startup...");
   cpu.startup();
   memory.startup();
   disk.startup();
 }
Exemplo n.º 22
0
 public void mouseReleased(MouseEvent e) {
   Disk disk = null;
   move = false;
   Rectangle rect = null;
   int x = 0, y = 0;
   boolean containPoint = false;
   int px = 0, py = 0;
   int endI = 0;
   if (e.getSource() instanceof Disk) {
     /* contain point */
     disk = (Disk) e.getSource();
     e = SwingUtilities.convertMouseEvent(disk, e, this);
     x = e.getX();
     y = e.getY();
     rect = disk.getBounds();
     for (int i = 0; i < points.length; i++) {
       px = points[i].getX();
       py = points[i].getY();
       if (rect.contains(px, py)) {
         endI = i;
         containPoint = true;
       }
     }
     if (disk != null && containPoint) {
       /* contain point */
       if ((px != startX) && (py != startY)) {
         System.out.println("px  py" + px + "  " + py + "  x,  y" + x + "  " + y);
         if (points[endI].isHavaDisk()) {
           /* point hava disk */
           System.out.println("------------------startI" + strarTowerPoint);
           System.out.println("------------------endI" + endI);
           System.out.println(endI + "---------point hava disk----------");
           disk.setLocation(startX, startY);
         } else {
           if (endI == diskNum - 1 || endI == diskNum * 2 - 1 || endI == diskNum * 3 - 1) {
             /* to botton */
             points[endI].putDisk(disk, this);
             System.out.println("------------------startI" + strarTowerPoint);
             System.out.println("------------------endI" + endI);
             System.out.println("********to botton put**********************");
             points[strarTowerPoint].setHavaDisk(false);
             if (strarTowerPoint != diskNum - 1
                 || strarTowerPoint != diskNum * 2 - 1
                 || strarTowerPoint != diskNum * 3 - 1) {
               /*
                * not
                * from
                * botton
                */
               (points[strarTowerPoint + 1].getDisk()).setPressed(false);
               points[strarTowerPoint].setHavaDisk(false);
             } else {
               points[strarTowerPoint].setHavaDisk(false);
             }
           } else {
             /* not to botton */
             if (points[endI + 1].isHavaDisk()) {
               /*
                * next have
                * disk
                */
               Disk tempDisk = points[endI + 1].getDisk();
               if ((tempDisk.getNum() - disk.getNum()) >= 1) {
                 /*
                  * bigger
                  * than
                  * points[EndI+1]
                  */
                 points[endI].putDisk(disk, this);
                 System.out.println("------------------startI" + strarTowerPoint);
                 System.out.println("------------------endI" + endI);
                 System.out.println(
                     "********not to botton and next hava disk put**********************");
                 points[strarTowerPoint].setHavaDisk(false);
                 System.out.println("#################" + points[strarTowerPoint].isHavaDisk());
                 System.out.println("#################" + points[endI].isHavaDisk());
                 if (strarTowerPoint != diskNum - 1
                     || strarTowerPoint != diskNum * 2 - 1
                     || strarTowerPoint != diskNum * 3 - 1) {
                   (points[strarTowerPoint].getDisk()).setPressed(false);
                   points[strarTowerPoint].setHavaDisk(false);
                   tempDisk.setPressed(true);
                 } else {
                   points[strarTowerPoint].setHavaDisk(false);
                   // points[endI].setHavaDisk(true);
                   tempDisk.setPressed(true);
                 }
               } else {
                 /* small than points[EndI+1] */
                 System.out.println("----------small---------");
                 disk.setLocation(startX, startY);
               }
             } else {
               /* next not have disk */
               int minMoveNum = ((endI / diskNum) + 1) * diskNum;
               for (int j = endI + 1; j < minMoveNum; j++) {
                 if (points[j].isHavaDisk()) {}
               }
               System.out.println("---------next not have disk----------");
               disk.setLocation(startX, startY);
             }
           }
         }
       }
     }
     if (disk != null && !containPoint) {
       /* not contain point */
       System.out.println("---------not contain point----------");
       disk.setLocation(startX, startY);
     }
   }
 }
  public boolean findRecord(char[] record) {
    char[] key = getKey(record, 0); // Get key array
    int sectorNum = getSector(convertToString(key)); // Get sector number
    disk.readSector(sectorNum, buffer); // Read the sector to the buffer

    int numKeysChecked = 0; // Count number of key we checked
    int nextKeyPlace = 0; // Index of next key
    int compVal = 1;

    while ((numKeysChecked < recordsPerSector)
        && (buffer[nextKeyPlace] != 0)
        && compVal
            != 0) { // while not the last record in buffer && has next record && not the same Keys
      char[] tempKey = getKey(buffer, nextKeyPlace); // Get keys from buffer
      compVal = compareKeys(key, tempKey); // Compare key
      numKeysChecked++; // Increment number of keys checked
      nextKeyPlace = nextKeyPlace + recordSize; // Move to next key place
    }
    if (compVal == 0) // If found
    {
      char[] tmpRecord =
          getRecord(
              buffer,
              nextKeyPlace - recordSize); // Back to previous key place where we found the key
      copyRecord(tmpRecord, record); // Copy the entire found record into parameter record
      return true;
    } else if ((compVal != 0)
        && (numKeysChecked
            < recordsPerSector)) // If not found and there is still space left, we know its not in
                                 // file
    return false;
    else // If not found and sector is full, we need to check overflow sectors
    {
      int currOverflowSector = overflowStart; // First overflow sector
      numKeysChecked = 0; // Count number of key we checked
      nextKeyPlace = 0; // Index of next key
      compVal = 1;

      while ((currOverflowSector < overflowStart + overflowSectors)
          && compVal != 0) { // While has more overflow sectors and not found
        disk.readSector(currOverflowSector, buffer); // Read in overflow sector to buffer
        while ((numKeysChecked < recordsPerSector) && (buffer[nextKeyPlace] != 0) && compVal != 0) {
          char[] tempKey = getKey(buffer, nextKeyPlace); // Get keys from buffer
          compVal = compareKeys(key, tempKey); // Compare key
          numKeysChecked++; // Increment number of keys checked
          nextKeyPlace = nextKeyPlace + recordSize; // Move to next key place
        }
        currOverflowSector++; // Move to next overflow sector
      }
      if (compVal != 0) // Not found in overflow sector
      return false;
      else {
        char[] tmpRecord =
            getRecord(
                buffer,
                nextKeyPlace - recordSize); // Back to previous key place where we found the key
        copyRecord(tmpRecord, record); // Copy the entire found record into parameter record
        return true;
      }
    }
  }
Exemplo n.º 24
0
 public float[] diskFields() {
   return new float[] {disk.getX(), disk.getY(), disk.getRadius()};
 }
Exemplo n.º 25
0
  private void colisionCase() {

    int gateWidth = gateEndX - gateStartX;

    if ((disk.getX() - disk.getRadius() - fieldBorder < 0) && (disk.getDx() < 0)) {

      disk.setX(0 + disk.getRadius() + fieldBorder);
      disk.inverseDx();
    }

    if ((disk.getX() + disk.getRadius() + fieldBorder > field.getWidth()) && (disk.getDx() > 0)) {

      disk.setX(field.getWidth() - disk.getRadius() - fieldBorder);
      disk.inverseDx();
    }

    if ((disk.getY() - disk.getRadius() - fieldBorder < 0)
        && (disk.getDy() < 0)
        && !((disk.getX() < gateEndX) && (disk.getX() > gateStartX))) {

      disk.setY(0 + disk.getRadius() + fieldBorder);
      disk.inverseDy();
    }

    if ((disk.getY() + disk.getRadius() + fieldBorder > field.getHeight())
        && (disk.getDy() > 0)
        && !((disk.getX() < gateEndX) && (disk.getX() > gateStartX))) {

      disk.setY(field.getHeight() - disk.getRadius() - fieldBorder);
      disk.inverseDy();
    }
  }
Exemplo n.º 26
0
 private void slow() {
   double sp = Math.sqrt(disk.getDx() * disk.getDx() + disk.getDy() * disk.getDy());
   if ((disk.getDx() == 0) && (disk.getDy() == 0)) {
     sp = 1;
   }
   disk.setDx(
       (float)
           (Math.signum(disk.getDx())
               * (Math.abs(disk.getDx()) - Math.abs(disk.getDx() * fading / sp))));
   disk.setDy(
       (float)
           (Math.signum(disk.getDy())
               * (Math.abs(disk.getDy()) - Math.abs(disk.getDy() * fading / sp))));
 }