package tachyon.worker;

/**
 * Where to store a block within a block store. Currently, this is a wrapper on an integer
 * representing the tier to put this block.
 */
public class BlockStoreLocation {
  private static final int sAnyTier = -1;
  private static final int sAnyDir = -2;
  private final int mTier;
  private final int mDir;

  public static BlockStoreLocation anyTier() {
    return new BlockStoreLocation(sAnyTier, sAnyDir);
  }

  public static BlockStoreLocation anyDirInTier(int tier) {
    return new BlockStoreLocation(tier, sAnyDir);
  }

  public BlockStoreLocation(int tier, int dir) {
    mTier = tier;
    mDir = dir;
  }

  public int tier() {
    return mTier;
  }

  public int dir() {
    return mDir;
  }

  @Override
  public String toString() {
    String result = "";
    if (mDir == sAnyDir) {
      result += "any dir";
    } else {
      result += "dir " + mDir;
    }

    if (mTier == sAnyTier) {
      result += ", any tier"
    } else {
      result += ", tier " + mTier;
    }
    return result;
  }
}

@@ -279,9 +279,9 @@
  = -
-2
+1
 ;%0A  
@@ -299,24 +299,29 @@
 al int mTier
+Alias
 ;%0A  private 
@@ -334,16 +334,21 @@
 int mDir
+Index
 ;%0A%0A  pub
@@ -504,16 +504,21 @@
 int tier
+Alias
 ) %7B%0A    
@@ -551,16 +551,21 @@
 ion(tier
+Alias
 , sAnyDi
@@ -609,16 +609,21 @@
 int tier
+Alias
 , int di
@@ -623,16 +623,21 @@
  int dir
+Index
 ) %7B%0A    
@@ -645,15 +645,25 @@
 Tier
+Alias
  = tier
+Alias
 ;%0A  
@@ -672,21 +672,336 @@
 mDir
+Index
  = dir
+Index
 ;%0A  %7D%0A%0A
+  // A helper function to derive StorageDirId from a BlockLocation.%0A  // TODO: remove this method when master also understands BlockLocation%0A  public long getStorageDirId() %7B%0A    // TODO: double check if mTierAlias is really the level%0A    return (mTierAlias %3C%3C 24) + (mTierAlias %3C%3C 16) + mDirIndex;%0A  %7D%0A%0A%0A
   pu
@@ -1030,24 +1030,29 @@
 return mTier
+Alias
 ;%0A  %7D%0A%0A  pub
@@ -1078,24 +1078,29 @@
  return mDir
+Index
 ;%0A  %7D%0A%0A  @Ov
@@ -1171,16 +1171,21 @@
 if (mDir
+Index
  == sAny
@@ -1260,16 +1260,21 @@
 %22 + mDir
+Index
 ;%0A    %7D%0A
@@ -1287,16 +1287,21 @@
 f (mTier
+Alias
  == sAny
@@ -1336,16 +1336,17 @@
 ny tier%22
+;
 %0A    %7D e
@@ -1384,16 +1384,21 @@
  + mTier
+Alias
 ;%0A    %7D%0A
@@ -1420,10 +1420,11 @@
 lt;%0A  %7D%0A
+%0A
 %7D%0A

Add a helper function to derive StorageDirId from BlockLocation