Android Open Source - Divide_And_Conquer_Card_Shuffler Move






From Project

Back to project page Divide_And_Conquer_Card_Shuffler.

License

The source code is released under:

MIT License

If you think the Android project Divide_And_Conquer_Card_Shuffler listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.andrewkeeton.divide.and.conquer.card.shuffler;
//from  w  ww  .  jav a 2  s .c om
import static junit.framework.Assert.*;

import java.util.ArrayList;

import android.os.Parcel;
import android.os.Parcelable;

// TODO: Make serializable.
public class Move implements Parcelable {
  
  public enum MoveType {
    DEAL, PICKUP, BOTTOM, NONE
  };

  public MoveType mType;
  public int mValue;
  
  public Move() {
    this(MoveType.NONE, -1);
  }
  
  public Move(MoveType type, int value) {
    mType = type;
    mValue = value;
  }
  
  @Override
  public boolean equals(Object obj) {
    Move move1 = this;
    Move move2 = (Move) obj;
    
    return (move1.mType == move2.mType) && (move1.mValue == move2.mValue);
  }
  
  @Override
  public String toString() {
    String prefix;
    
    switch(mType) {
    case DEAL:
      prefix = "D";
      break;
    case PICKUP:
      prefix = "P";
      break;
    case BOTTOM:
      prefix = "B";
      break;
    case NONE:
      prefix = "N";
      break;
    default:
      prefix = "E";
      fail();
      break;
    }
    
    return prefix + mValue;
  }
  
  static public Move fromString(String str) {
    assertTrue("str.length() >= 2", str.length() >= 2);
    
    MoveType type = MoveType.NONE;
    int value = -1;
    
    switch (str.charAt(0)) {
    case 'D':
      type = MoveType.DEAL;
      break;
    case 'P':
      type = MoveType.PICKUP;
      break;
    case 'B':
      type = MoveType.BOTTOM;
      break;
    case 'N':
      type = MoveType.NONE;
      break;
    case 'E':
      fail();
      break;
    default:
      fail();
      break;
    };
    
    value = Integer.valueOf(str.substring(1));
    
    Move move = new Move(type, value);
    //Log.w(MainActivity.TAG_MOVE, str + " -> " + move.toString());
    
    return move;
  }
  
  static public ArrayList<Move> arrayListFromString(String str) {
    ArrayList<Move> moves = new ArrayList<Move>();
    str = str.substring(1, str.length() - 1);
    if (str.length() == 0) {
      return moves;
    }
    
    String strMoves[] = str.split(", ");
    
    for (String strMove : strMoves) {
      moves.add(Move.fromString(strMove));
    }
    
    //Log.w(MainActivity.TAG_MOVE, str + " -> " + moves.toString());
    
    return moves;
  }
  
  /// Parcelable methods
  public int describeContents() {
    return 0;
  }
  
  public void writeToParcel(Parcel out, int flags) {
    out.writeInt(mType.ordinal());
    out.writeInt(mValue);
  }
  
  public static final Parcelable.Creator<Move> CREATOR = new Parcelable.Creator<Move>() {
    
    public Move createFromParcel(Parcel in) {
      return new Move(in);
    }
    
    public Move[] newArray(int size) {
      return new Move[size];
    }
  };
  
  private Move(Parcel in) {
    mType = MoveType.values()[in.readInt()];
    mValue = in.readInt();
  }
  ///
}




Java Source Code List

com.andrewkeeton.divide.and.conquer.card.shuffler.AutoResizeTextView.java
com.andrewkeeton.divide.and.conquer.card.shuffler.Card.java
com.andrewkeeton.divide.and.conquer.card.shuffler.EstimateTime.java
com.andrewkeeton.divide.and.conquer.card.shuffler.MainActivity.java
com.andrewkeeton.divide.and.conquer.card.shuffler.Move.java
com.andrewkeeton.divide.and.conquer.card.shuffler.PileOfCards.java
com.andrewkeeton.divide.and.conquer.card.shuffler.SettingsActivity.java
com.andrewkeeton.divide.and.conquer.card.shuffler.SetupFragment.java
com.andrewkeeton.divide.and.conquer.card.shuffler.ShufflerFragment.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.BillingReceiver.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.BillingService.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.Consts.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.PurchaseDatabase.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.PurchaseObserver.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.ResponseHandler.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.Security.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.util.Base64DecoderException.java
com.andrewkeeton.divide.and.conquer.card.shuffler.billing.util.Base64.java