TopSwop implementation in java