com.github.vkorobkov.jfixtures.processor.RowsIndex Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jfixtures Show documentation
Show all versions of jfixtures Show documentation
Easy test data creator for SQL databases
package com.github.vkorobkov.jfixtures.processor;
import com.github.vkorobkov.jfixtures.instructions.InsertRow;
import com.github.vkorobkov.jfixtures.instructions.InstructionVisitor;
import lombok.AllArgsConstructor;
import lombok.EqualsAndHashCode;
import lombok.val;
import java.util.HashMap;
import java.util.Map;
import java.util.Optional;
class RowsIndex implements InstructionVisitor {
private final Map index = new HashMap<>();
public Optional read(String table, String rowName) {
val key = new RowKey(table, rowName);
val row = index.get(key);
return Optional.ofNullable(row);
}
@Override
public void visit(InsertRow row) {
val key = new RowKey(row.getTable(), row.getRowName());
index.put(key, row);
}
@AllArgsConstructor
@EqualsAndHashCode
static final class RowKey {
public final String table;
public final String rowName;
}
}