private void changeConcentrationInSortedNodes(final List<EnvironmentNode> envNodesSurrounding) { if (delta < 0) { double deltaTemp = delta; for (final EnvironmentNode n : envNodesSurrounding) { final double nodeConcentration = n.getConcentration(biomolecule); // if nodeConcentration >= |deltaTemp|, remove the a delta quantity of the biomol only from this node if (nodeConcentration >= FastMath.abs(deltaTemp)) { n.setConcentration(biomolecule, nodeConcentration + deltaTemp); break; // else, remove all molecule of that species from that node and go on till deltaTemp is smaller than nodeConcetration } else { deltaTemp = deltaTemp + nodeConcentration; n.removeConcentration(biomolecule); } } } else { // if delta > 0, simply add delta to the first node of the list (which has been sorted randomly) final Node<Double> target = envNodesSurrounding.get(0); target.setConcentration(biomolecule, target.getConcentration(biomolecule) + delta); } }
.mapToDouble(n -> n.getConcentration(biomolecule)) .distinct() .count() == 1; n1.getConcentration(biomolecule), n2.getConcentration(biomolecule)
private void changeConcentrationInRandomNodes(final List<EnvironmentNode> envNodesSurrounding) { if (delta < 0) { double deltaTemp = delta; while (deltaTemp < 0) { final int index = getRandomGenerator().nextInt(envNodesSurrounding.size()); final EnvironmentNode pickedNode = envNodesSurrounding.get(index); final double nodeConcentration = pickedNode.getConcentration(biomolecule); // if nodeConcentration >= |deltaTemp|, remove the a delta quantity of the biomol only from this node if (nodeConcentration >= FastMath.abs(deltaTemp)) { pickedNode.setConcentration(biomolecule, nodeConcentration + deltaTemp); break; // else, remove all molecule of that species from that node and go on till deltaTemp is smaller than nodeConcetration } else { deltaTemp = deltaTemp + nodeConcentration; pickedNode.removeConcentration(biomolecule); } envNodesSurrounding.remove(index); } } else { // if delta > 0, simply add delta to the first node of the list (which has been sorted randomly) final Node<Double> target = envNodesSurrounding.get(getRandomGenerator().nextInt(envNodesSurrounding.size())); target.setConcentration(biomolecule, target.getConcentration(biomolecule) + delta); } } }