codesimian
Class Liquid

java.lang.Object
  extended by codesimian.CS
      extended by codesimian.IndependentCS
          extended by codesimian.Liquid
All Implemented Interfaces:
CodeSimian

public class Liquid
extends IndependentCS

Something that can be split or combined into Liquids of different amounts totaling the same. Each type of Liquid has a String name. To avoid creating Liquids, they can not be instantiated except by methods within Liquid. (Liquid's old name is NamedResource)

By default, you can not create a Liquid with a different name than the Liquid(s) you use to create it, but later some final classes may be written to allow certain conversions depending on the names and amounts. For example, I might build a class that lets you trade "liquidTypeOnKeyboard" for "liquidMoveMouse".

Class Liquid can create each type of Liquid only once. LiquidStart takes certain types of Liquid so that nobody else can, then distributes them.

For example, class FreeLiquid should receive many types of Liquid, which it gives for free, but it may refuse to give if you ask too often or for any other reason.

Now 9/2007, codesimian does not use the Liquid class much, but it should... And it should be accessed with L(Liquid.class) and setL(someLiquid)


Nested Class Summary
static class Liquid.NotMyName
          thrown when you try to combine 2 Liquids whose Liquid.name are different
 
Field Summary
 java.lang.String name
           
 
Fields inherited from class codesimian.CS
DESCRIPTION, END, EXECPROXY, HEAP, JAVACODE, MYFUEL, NAME, NEWINSTANCE, NULL, PARENT, PARSEPRIORITY, PREV, TESTER, THIS
 
Method Summary
 void add(Liquid iHaveTheSameName, double takeAmount)
          Remove Liquid from iHaveTheSameName and add it to my amount.
 void addAll(Liquid iHaveTheSameName)
          remove all resource from iHaveTheSameName and add it to my amount
 double amount()
           
static Liquid[] doChemistry(Chemist chemist, Liquid[] inputLiquids)
          All Liquid transformations go through this function.
static void init(boolean allowFindSelfJar)
          If not allowJarsDotFindSelf, Does not do anything that requires Jars.findSelf be called.
 java.lang.String name()
          cant change this name because that would require a String variable and IndependentCS must use very little memory.
static Liquid newEmptyLiquid(java.lang.String name)
          useful if you expect to receive a certain type of liquid later.
static Liquid newLiquid(java.lang.String name, double amount, Liquid paymentForCharsOfNewName)
          this is the only way to create a Liquid that does not have the same name as any other Liquid.
 Liquid remove(double amount)
          remove some or all of my amount
 Liquid removeAll()
          makes this Liquid worthless and returns all its amount in a new Liquid that nobody else has a reference to so they cant remove from it.
 boolean setName()
           
 
Methods inherited from class codesimian.IndependentCS
B, BForProxy, C, CForProxy, countP, D, decrementMyFuel, deleteP, description, DForProxy, F, FForProxy, fuel, getExec, heap, I, IForProxy, insertD, insertL, insertL, insertL1, insertP, J, JForProxy, keyword, L, L, LForProxy, LForProxy, maxP, minP, myFuel, newInstance, P, parent, prevD, prevL, PType, S, setD, setD, setFuel, setL, setL, setL, setL1, setMyFuel, setP, setPrevExec, SForProxy, toString, V, VForProxy, Z, ZForProxy
 
Methods inherited from class codesimian.CS
addB, addC, addD, addF, addI, addJ, addL, addP, addP, addP, addP, addP, addS, addZ, clone, cost, deleteP, GETB, GETC, GETD, GETF, GETI, GETJ, GETL, getObject, GETS, GETZ, indexP, indexPName, insertB, insertC, insertF, insertI, insertJ, insertS, insertZ, isIllusion, L, L, L, maxD, minD, overwrites, parsePriority, PB, PC, PD, PF, PI, PJ, PL, prevB, prevC, prevF, prevI, prevJ, prevS, prevZ, proxyOf, PS, PZ, reflect, reflect, reflect6, setB, SETB, setB, setC, SETC, setC, setCost, SETD, setDescription, setExec, setF, SETF, setF, setHeap, setI, SETI, setI, setJ, setJ, SETJ, SETL, setL, setL, setName, setObject, setParent, setParsePriority, setProxyOf, setPType, setS, setS, SETS, setTester, setZ, SETZ, setZ, tester, toJavaCode, voidReflect
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

name

public final java.lang.String name
Method Detail

name

public java.lang.String name()
Description copied from class: IndependentCS
cant change this name because that would require a String variable and IndependentCS must use very little memory. Like CS, this class has no variables.

Overrides:
name in class IndependentCS

setName

public boolean setName()

amount

public double amount()

init

public static void init(boolean allowFindSelfJar)
If not allowJarsDotFindSelf, Does not do anything that requires Jars.findSelf be called. For example, does not call LiquidStart.liquidStart() because that uses CodesimianOptions.

If not allowJarsDotFindSelf then you should call LiquidStart.liquidStart() later.

One thing this init() does is gives to FreeLiquid: a new Liquid named liquidCharsOfNewLiquid. Each X units of this allows you to create a new Liquid with X characters in its name. It may be split and/or combined with other Liquids without using more of this.


newEmptyLiquid

public static Liquid newEmptyLiquid(java.lang.String name)
useful if you expect to receive a certain type of liquid later. Store it in the returned Liquid.


newLiquid

public static Liquid newLiquid(java.lang.String name,
                               double amount,
                               Liquid paymentForCharsOfNewName)
this is the only way to create a Liquid that does not have the same name as any other Liquid. If the name already exists, an Error is thrown.

The name must be paid for with a Liquid whose name is "resourceCharsOfNewLiquid" and whose amount is at least name.length().

If you create a new Liquid of amount 0, it means that type of Liquid can not exist.


remove

public Liquid remove(double amount)
remove some or all of my amount


removeAll

public Liquid removeAll()
makes this Liquid worthless and returns all its amount in a new Liquid that nobody else has a reference to so they cant remove from it.


addAll

public void addAll(Liquid iHaveTheSameName)
remove all resource from iHaveTheSameName and add it to my amount


add

public void add(Liquid iHaveTheSameName,
                double takeAmount)
         throws NeedLiquid
Remove Liquid from iHaveTheSameName and add it to my amount. Throws NeedLiquid if iHaveTheSameName does not have enough liquid to give.

Throws:
NeedLiquid

doChemistry

public static Liquid[] doChemistry(Chemist chemist,
                                   Liquid[] inputLiquids)
                            throws NeedLiquids
All Liquid transformations go through this function.

A Chemist requires certain types of Liquids and certain amounts.

Extra Liquid is not consumed. Liquids of the wrong type are ignored.

If enough of the required types of Liquid are present, then Liquids are returned (described by chemist.chemistOutputAmounts()), else a NeedLiquids is thrown.

Throws:
NeedLiquids