Skip to content

Instantly share code, notes, and snippets.

@wmealing
Created October 8, 2013 10:30
Show Gist options
  • Save wmealing/6882734 to your computer and use it in GitHub Desktop.
Save wmealing/6882734 to your computer and use it in GitHub Desktop.
/**
*
*/
package com.example.weightplates;
import java.util.List;
import android.util.Log;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Collections;
/**
* @author wmealing
*
*/
public class Equipment {
public Boolean isMetric = true;
public Barbell barbell;
public List <Plate> plateList;
public Equipment() {
//this.loadSettings();
this.barbell = new Barbell(20, true);
this.plateList = Collections.synchronizedList(new LinkedList<Plate>());
Plate p20 = new Plate(20.0, true);
Plate p10 = new Plate(10.0, true);
this.plateList.add(p20);
this.plateList.add(p20);
this.plateList.add(p10);
this.plateList.add(p10);
}
public void loadSettings() {
// FIXME: load settings from sqlite db here.
// FIXME: redefine ismetric crap.
this.barbell = new Barbell(20, true);
}
public void setupDesiredWeight(double Weight) {
double tmp;
double lastPlateWeight = 0;
Log.i("WMDEBUG", "[SDW] 1. Remove Barbell weight from total");
double RemainingWeight = this.barbell.barbellWeight;
Log.i("WMDEBUG", "[SDW] 2. While we have weight to put on the bar");
while (RemainingWeight >= 0) {
synchronized(this.plateList) {
Iterator<Plate> iterator = this.plateList.iterator();
while (iterator.hasNext()) {
Plate p = iterator.next();
Log.i("WMDEBUG", "[SDW] Iterate through the list, largest weight first");
Log.i("WMDEBUG", "[SDW] We'll see if a " + p.plateWeight + " works");
// FIXME: we have to assume they have pairs, right ?
tmp = RemainingWeight - (p.plateWeight * 2);
if (tmp >= 0) {
Log.i("WMDEBUG", "[SDW] looks like " + p.plateWeight + " will be added to the bar");
RemainingWeight = tmp;
Log.i("WMDEBUG", "[SDW] Remaining weight " + RemainingWeight);
this.plateList.add(p);
}
else {
lastPlateWeight = p.plateWeight;
} // end if tmp
} // end for
} // end sync
if (lastPlateWeight <= RemainingWeight) {
break;
}
}
if ( RemainingWeight != 0) {
Log.i("WMDEBUG", "[SDW] Unaccounted for weight " + RemainingWeight);
}
// Step 2: Find the largest plate that wont take us below zero units left.
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment