Android Open Source - CalWatch Cl Symbolic Weight






From Project

Back to project page CalWatch.

License

The source code is released under:

GNU General Public License

If you think the Android project CalWatch 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

// $Id: ClSymbolicWeight.java,v 1.11 1999/04/20 00:26:41 gjb Exp $
////  ww w.  ja  va2 s.  co m
// Cassowary Incremental Constraint Solver
// Original Smalltalk Implementation by Alan Borning
// This Java Implementation by Greg J. Badros, <gjb@cs.washington.edu>
// http://www.cs.washington.edu/homes/gjb
// (C) 1998, 1999 Greg J. Badros and Alan Borning
// See ../LICENSE for legal details regarding this software
//
// ClSymbolicWeight

package EDU.Washington.grad.gjb.cassowary;

import java.util.*;

public class ClSymbolicWeight 
{

  public ClSymbolicWeight(int cLevels)
    { 
      _values = new double[cLevels];
      // FIXGJB: ok to assume these get initialized to 0?
//       for (int i = 0; i < cLevels; i++) {
//   _values[i] = 0;
//       }
    }

  public ClSymbolicWeight(double w1, double w2, double w3)
    { 
      _values = new double[3];
      _values[0] = w1;
      _values[1] = w2;
      _values[2] = w3;
    }

  public ClSymbolicWeight(double[] weights)
    { 
      final int cLevels = weights.length;
      _values = new double[cLevels];
      for (int i = 0; i < cLevels; i++) {
  _values[i] = weights[i];
      }
    }

  public static final ClSymbolicWeight clsZero = new ClSymbolicWeight(0.0, 0.0, 0.0);

  public Object clone()
    {
      return new ClSymbolicWeight(_values);
    }

  public ClSymbolicWeight times(double n)
    {
      ClSymbolicWeight clsw = (ClSymbolicWeight) clone();
      for (int i = 0; i < _values.length; i++) {
        clsw._values[i] *= n;
      }
      return clsw;
    }

  public ClSymbolicWeight divideBy(double n)
    {
      // assert(n != 0);
      ClSymbolicWeight clsw = (ClSymbolicWeight) clone();
      for (int i = 0; i < _values.length; i++) {
        clsw._values[i] /= n;
      }
      return clsw;
    }

  public ClSymbolicWeight add(ClSymbolicWeight cl)
    {
      // assert(cl.cLevels() == cLevels());
      
      ClSymbolicWeight clsw = (ClSymbolicWeight) clone();
      for (int i = 0; i < _values.length; i++) {
        clsw._values[i] += cl._values[i];
      }
      return clsw;
    }

  public ClSymbolicWeight subtract(ClSymbolicWeight cl)
    {
      // assert(cl.cLevels() == cLevels());

      ClSymbolicWeight clsw = (ClSymbolicWeight) clone();
      for (int i = 0; i < _values.length; i++) {
        clsw._values[i] -= cl._values[i];
      }
      return clsw;
    }

  public boolean lessThan(ClSymbolicWeight cl)
    {
      // assert cl.cLevels() == cLevels()
      for (int i = 0; i < _values.length; i++) {
  if (_values[i] < cl._values[i])
    return true;
  else if (_values[i] > cl._values[i])
    return false;
      }
      return false; // they are equal
    }
  
  public boolean lessThanOrEqual(ClSymbolicWeight cl)
    {
      // assert cl.cLevels() == cLevels()
      for (int i = 0; i < _values.length; i++) {
  if (_values[i] < cl._values[i])
    return true;
  else if (_values[i] > cl._values[i])
    return false;
      }
      return true; // they are equal
    }
  
  public
    boolean equal(ClSymbolicWeight cl)
    {
      for (int i = 0; i < _values.length; i++) {
  if (_values[i] != cl._values[i])
    return false;
      }
      return true; // they are equal
    }

  public boolean greaterThan(ClSymbolicWeight cl)
    {
      return !this.lessThanOrEqual(cl);
    }

  public boolean greaterThanOrEqual(ClSymbolicWeight cl)
    {
      return !this.lessThan(cl);
    }
  
  public boolean isNegative()
    {
      return this.lessThan(clsZero);
    }

  public double asDouble()
    {
      ClSymbolicWeight clsw = (ClSymbolicWeight) clone();
      double sum  =  0;
      double factor = 1;
      double multiplier = 1000;
      for (int i = _values.length - 1; i >= 0; i--) 
        {
  sum += _values[i] * factor;
  factor *= multiplier;
  }
      return sum;
    }
  
  public String toString()
    { 
      StringBuffer bstr = new StringBuffer("[");
      for (int i = 0; i < _values.length-1; i++) {
  bstr.append(_values[i]);
  bstr.append(",");
      }
      bstr.append(_values[_values.length-1]);
      bstr.append("]");
      return bstr.toString();
    }

  public int cLevels()
    { return _values.length; }

  private double[] _values;

}




Java Source Code List

EDU.Washington.grad.gjb.cassowary.CL.java
EDU.Washington.grad.gjb.cassowary.ClAbstractVariable.java
EDU.Washington.grad.gjb.cassowary.ClConstraint.java
EDU.Washington.grad.gjb.cassowary.ClDouble.java
EDU.Washington.grad.gjb.cassowary.ClDummyVariable.java
EDU.Washington.grad.gjb.cassowary.ClEditConstraint.java
EDU.Washington.grad.gjb.cassowary.ClEditInfo.java
EDU.Washington.grad.gjb.cassowary.ClEditOrStayConstraint.java
EDU.Washington.grad.gjb.cassowary.ClLinearConstraint.java
EDU.Washington.grad.gjb.cassowary.ClLinearEquation.java
EDU.Washington.grad.gjb.cassowary.ClLinearExpression.java
EDU.Washington.grad.gjb.cassowary.ClLinearInequality.java
EDU.Washington.grad.gjb.cassowary.ClObjectiveVariable.java
EDU.Washington.grad.gjb.cassowary.ClPoint.java
EDU.Washington.grad.gjb.cassowary.ClSimplexSolver.java
EDU.Washington.grad.gjb.cassowary.ClSlackVariable.java
EDU.Washington.grad.gjb.cassowary.ClStayConstraint.java
EDU.Washington.grad.gjb.cassowary.ClStrength.java
EDU.Washington.grad.gjb.cassowary.ClSymbolicWeight.java
EDU.Washington.grad.gjb.cassowary.ClTableau.java
EDU.Washington.grad.gjb.cassowary.ClTestColumns.java
EDU.Washington.grad.gjb.cassowary.ClTests.java
EDU.Washington.grad.gjb.cassowary.ClVariable.java
EDU.Washington.grad.gjb.cassowary.ExCLConstraintNotFound.java
EDU.Washington.grad.gjb.cassowary.ExCLError.java
EDU.Washington.grad.gjb.cassowary.ExCLInternalError.java
EDU.Washington.grad.gjb.cassowary.ExCLNonlinearExpression.java
EDU.Washington.grad.gjb.cassowary.ExCLNotEnoughStays.java
EDU.Washington.grad.gjb.cassowary.ExCLRequiredFailure.java
EDU.Washington.grad.gjb.cassowary.ExCLTooDifficult.java
EDU.Washington.grad.gjb.cassowary.Set.java
EDU.Washington.grad.gjb.cassowary.Timer.java
EDU.Washington.grad.gjb.cassowary.sym.java
EDU.Washington.grad.gjb.cassowary.testClLinearExpression.java
EDU.Washington.grad.gjb.cassowary.testClStrength.java
org.dwallach.calwatch.ApplicationTest.java
org.dwallach.calwatch.BatteryWrapper.java
org.dwallach.calwatch.CalWatchFaceService.java
org.dwallach.calwatch.CalendarFetcher.java
org.dwallach.calwatch.ClockFace.java
org.dwallach.calwatch.ClockState.java
org.dwallach.calwatch.Constants.java
org.dwallach.calwatch.EventLayoutTest.java
org.dwallach.calwatch.EventLayoutUniformTest.java
org.dwallach.calwatch.EventLayoutUniform.java
org.dwallach.calwatch.EventLayout.java
org.dwallach.calwatch.EventWrapper.java
org.dwallach.calwatch.MyViewAnim.java
org.dwallach.calwatch.PaintCan.java
org.dwallach.calwatch.PathCache.java
org.dwallach.calwatch.PhoneActivity.java
org.dwallach.calwatch.PreferencesHelper.java
org.dwallach.calwatch.TimeWrapper.java
org.dwallach.calwatch.VersionWrapper.java
org.dwallach.calwatch.WatchCalendarService.java
org.dwallach.calwatch.WearReceiverService.java
org.dwallach.calwatch.WearSender.java
org.dwallach.calwatch.WireEvent.java
org.dwallach.calwatch.WireUpdate.java
org.dwallach.calwatch.XWatchfaceReceiver.java