Tape equillibrium impl in java