public void transferSafe(inventory target, ressources item) { var amount = newContent[item]; if (amount > target.getFreeSpace()) { amount = target.getFreeSpace(); } target.newContent[item] += amount; this.newContent[item] -= amount; }