Add docs for IEnergy.
This commit is contained in:
@@ -4,18 +4,48 @@ import com.raoulvdberge.refinedstorage.api.util.Action;
|
|||||||
|
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An energy container.
|
||||||
|
*/
|
||||||
public interface IEnergy {
|
public interface IEnergy {
|
||||||
void decreaseCapacity(UUID id, int amount);
|
/**
|
||||||
|
* @param id id of the storage
|
||||||
|
* @param amount the amount
|
||||||
|
*/
|
||||||
|
void removeCapacity(UUID id, int amount);
|
||||||
|
|
||||||
int extract(int amount, Action action);
|
/**
|
||||||
|
* @param id id of the storage
|
||||||
|
* @param amount the amount
|
||||||
|
*/
|
||||||
|
void addCapacity(UUID id, int amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the capacity
|
||||||
|
*/
|
||||||
int getCapacity();
|
int getCapacity();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return the amount stored
|
||||||
|
*/
|
||||||
int getStored();
|
int getStored();
|
||||||
|
|
||||||
void increaseCapacity(UUID id, int amount);
|
/**
|
||||||
|
* @param amount the amount stored
|
||||||
|
*/
|
||||||
|
void setStored(int amount);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param amount the amount
|
||||||
|
* @param action the action
|
||||||
|
* @return the energy extracted
|
||||||
|
*/
|
||||||
|
int extract(int amount, Action action);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param amount the amount
|
||||||
|
* @param action the action
|
||||||
|
* @return the energy inserted
|
||||||
|
*/
|
||||||
int insert(int amount, Action action);
|
int insert(int amount, Action action);
|
||||||
|
|
||||||
void setStored(int energyAmount);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,28 +13,28 @@ public final class Energy implements IEnergy {
|
|||||||
protected int capacity;
|
protected int capacity;
|
||||||
protected int energy;
|
protected int energy;
|
||||||
|
|
||||||
private final Map<UUID, Integer> energyStorages;
|
private final Map<UUID, Integer> storages;
|
||||||
|
|
||||||
public Energy(int controllerCapacity) {
|
public Energy(int controllerCapacity) {
|
||||||
this.energyStorages = new Object2ObjectOpenHashMap<>();
|
this.storages = new Object2ObjectOpenHashMap<>();
|
||||||
this.energyStorages.put(DEFAULT_UUID, controllerCapacity);
|
this.storages.put(DEFAULT_UUID, controllerCapacity);
|
||||||
|
|
||||||
calculateCapacity();
|
calculateCapacity();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void calculateCapacity() {
|
private void calculateCapacity() {
|
||||||
long newCapacity = energyStorages.values().stream().mapToLong(Long::valueOf).sum();
|
long newCapacity = storages.values().stream().mapToLong(Long::valueOf).sum();
|
||||||
|
|
||||||
this.capacity = (int) Math.min(newCapacity, Integer.MAX_VALUE);
|
this.capacity = (int) Math.min(newCapacity, Integer.MAX_VALUE);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void decreaseCapacity(UUID id, int amount) {
|
public void removeCapacity(UUID id, int amount) {
|
||||||
if (id.equals(DEFAULT_UUID)) {
|
if (id.equals(DEFAULT_UUID)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.energyStorages.remove(id);
|
this.storages.remove(id);
|
||||||
|
|
||||||
calculateCapacity();
|
calculateCapacity();
|
||||||
}
|
}
|
||||||
@@ -45,13 +45,13 @@ public final class Energy implements IEnergy {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int energyExtracted = Math.min(energy, maxExtract);
|
int extracted = Math.min(energy, maxExtract);
|
||||||
|
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
energy -= energyExtracted;
|
energy -= extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return energyExtracted;
|
return extracted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -65,12 +65,12 @@ public final class Energy implements IEnergy {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void increaseCapacity(UUID id, int amount) {
|
public void addCapacity(UUID id, int amount) {
|
||||||
if (id.equals(DEFAULT_UUID) || amount <= 0) {
|
if (id.equals(DEFAULT_UUID) || amount <= 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.energyStorages.merge(id, amount, (k, v) -> amount);
|
this.storages.merge(id, amount, (k, v) -> amount);
|
||||||
|
|
||||||
calculateCapacity();
|
calculateCapacity();
|
||||||
}
|
}
|
||||||
@@ -81,17 +81,17 @@ public final class Energy implements IEnergy {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
int energyReceived = Math.min(capacity - energy, maxReceive);
|
int inserted = Math.min(capacity - energy, maxReceive);
|
||||||
|
|
||||||
if (action == Action.PERFORM) {
|
if (action == Action.PERFORM) {
|
||||||
energy += energyReceived;
|
energy += inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
return energyReceived;
|
return inserted;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setStored(int energy) {
|
public void setStored(int amount) {
|
||||||
this.energy = Math.min(energy, this.capacity);
|
this.energy = Math.min(amount, this.capacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user