@Override
public IndexMappingBuffer take() {
if (currentBuffer == null)
return null;
SimpleIndices fromIndices = from.getIndices();
SimpleIndices toIndices = to.getIndices();
int size = fromIndices.size();
if (size == 0) {
IndexMappingBuffer r = currentBuffer;
currentBuffer = null;
return r;
}
if (symmetryIterator != null) {
OUT:
while (symmetryIterator.hasNext()) {
Symmetry s = symmetryIterator.next();
IndexMappingBuffer tempBuffer = currentBuffer.clone();
for (int i = 0; i < size; ++i)
if (!tempBuffer.tryMap(fromIndices.get(s.newIndexOf(i)), toIndices.get(i)))
continue OUT;
tempBuffer.addSignum(s.isAntiSymmetry());
return tempBuffer;
}
symmetryIterator = null;
currentBuffer = null;
return null;
}
if (fromIndices.getSymmetries().isEmpty()) {
IndexMappingBuffer tempBuffer = currentBuffer;
for (int i = 0; i < size; ++i)
if (!tempBuffer.tryMap(fromIndices.get(i), toIndices.get(i))) {
currentBuffer = null;
return null;
}
currentBuffer = null;
return tempBuffer;