use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class GeometryBufferProcess method process.
@Override
protected void process(final Channel<Record> in, final Channel<Record> out, final Record object) {
final Geometry geometry = object.getGeometry();
if (geometry == null) {
out.write(object);
} else {
final Geometry bufferedGeometry = geometry.buffer(this.buffer);
final Record newObject = Records.copy(object, bufferedGeometry);
out.write(newObject);
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class OrderedEqualCompareProcessor method run.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Override
protected void run(final Channel<Record> in) {
this.running = true;
final Channel<Record>[] channels = new Channel[] { in, this.otherIn };
Record previousEqualObject = null;
final Record[] objects = new Record[2];
final boolean[] guard = new boolean[] { true, true };
final MultiInputSelector alt = new MultiInputSelector();
while (this.running) {
final int index = alt.select(channels, guard);
if (index == -1) {
if (in.isClosed()) {
logNoMatch(objects, this.otherIn, true);
return;
} else if (this.otherIn.isClosed()) {
logNoMatch(objects, in, false);
return;
} else {
}
} else {
final Channel<Record> channel = channels[index];
final Record readObject = readObject(channel);
if (index == 0 && this.recordDefinition1 == null) {
setRecordDefinition1(readObject.getRecordDefinition());
} else if (index == 1 && this.recordDefinition2 == null) {
setRecordDefinition2(readObject.getRecordDefinition());
}
if (readObject != null) {
if (previousEqualObject != null && DataType.equal(previousEqualObject, readObject)) {
if (index == 0) {
RecordLog.error(getClass(), "Duplicate in " + this.sourceName, readObject);
} else {
RecordLog.error(getClass(), "Duplicate in " + this.otherName, readObject);
}
} else {
Record sourceObject;
Record otherObject;
final int oppositeIndex = (index + 1) % 2;
if (index == 0) {
sourceObject = readObject;
otherObject = objects[oppositeIndex];
} else {
sourceObject = objects[oppositeIndex];
otherObject = readObject;
}
final Object value = readObject.getValue(this.fieldName);
if (value == null) {
RecordLog.error(getClass(), "Missing key value for " + this.fieldName, readObject);
} else if (objects[oppositeIndex] == null) {
objects[index] = readObject;
guard[index] = false;
guard[oppositeIndex] = true;
} else {
final Object sourceValue = sourceObject.getValue(this.fieldName);
final Comparable<Object> sourceComparator;
if (sourceValue instanceof Number) {
final Number number = (Number) sourceValue;
final Double doubleValue = number.doubleValue();
sourceComparator = (Comparable) doubleValue;
} else {
sourceComparator = (Comparable<Object>) sourceValue;
}
Object otherValue = otherObject.getValue(this.fieldName);
if (otherValue instanceof Number) {
final Number number = (Number) otherValue;
otherValue = number.doubleValue();
}
// TODO duplicates
final int compare = sourceComparator.compareTo(otherValue);
if (compare == 0) {
final Set<String> notEqualFieldNames = getNotEqualFieldNames(sourceObject, otherObject);
final boolean geometryEquals = geometryEquals(sourceObject, otherObject);
if (!geometryEquals) {
final String geometryFieldName = sourceObject.getRecordDefinition().getGeometryFieldName();
notEqualFieldNames.add(geometryFieldName);
}
if (!notEqualFieldNames.isEmpty()) {
logNotEqual(sourceObject, otherObject, notEqualFieldNames, geometryEquals);
}
objects[0] = null;
objects[1] = null;
guard[0] = true;
guard[1] = true;
previousEqualObject = sourceObject;
} else if (compare < 0) {
// other object is bigger, keep other
// object
logNoMatch(sourceObject, false);
objects[0] = null;
objects[1] = otherObject;
guard[0] = true;
guard[1] = false;
} else {
// source is bigger, keep source object
logNoMatch(otherObject, true);
objects[0] = sourceObject;
objects[1] = null;
guard[0] = false;
guard[1] = true;
}
}
}
}
}
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class AbstractMergeProcess method addSavedObjects.
private RecordDefinition addSavedObjects(final RecordDefinition currentType, final String currentTypeName, final Channel<Record> out, final boolean[] guard, final Record[] objects) {
final Record sourceObject = objects[SOURCE_INDEX];
final Record otherObject = objects[OTHER_INDEX];
if (sourceObject == null) {
if (otherObject == null) {
return null;
} else {
addOtherObject(otherObject);
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return otherObject.getRecordDefinition();
}
} else if (otherObject == null) {
if (sourceObject == null) {
return null;
} else {
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
return sourceObject.getRecordDefinition();
}
} else {
final RecordDefinition sourceType = sourceObject.getRecordDefinition();
final String sourceTypeName = sourceType.getPath();
final RecordDefinition otherType = otherObject.getRecordDefinition();
final String otherTypeName = otherType.getPath();
if (sourceTypeName.equals(currentTypeName)) {
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = otherObject;
guard[OTHER_INDEX] = false;
return currentType;
} else if (otherTypeName.equals(currentTypeName)) {
addOtherObject(otherObject);
objects[SOURCE_INDEX] = sourceObject;
guard[SOURCE_INDEX] = false;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return currentType;
} else {
processObjects(currentType, out);
final int nameCompare = sourceTypeName.toString().compareTo(otherTypeName.toString());
if (nameCompare < 0) {
// If the first feature type name is < second feature type
// name
// then add the first feature and save the second feature
// for later
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = otherObject;
guard[OTHER_INDEX] = false;
return sourceType;
} else if (nameCompare == 0) {
// If both features have the same type them add them
addSourceObject(sourceObject);
addOtherObject(otherObject);
objects[SOURCE_INDEX] = null;
guard[SOURCE_INDEX] = true;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return sourceType;
} else {
// If the first feature type name is > second feature type
// name
// then add the second feature and save the first feature
// for later
addOtherObject(otherObject);
objects[SOURCE_INDEX] = sourceObject;
guard[SOURCE_INDEX] = false;
objects[OTHER_INDEX] = null;
guard[OTHER_INDEX] = true;
return otherType;
}
}
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class AbstractMergeProcess method run.
@Override
@SuppressWarnings("unchecked")
protected void run(final Channel<Record> in, final Channel<Record> out) {
setUp();
try {
RecordDefinition currentType = null;
String currentTypeName = null;
final Channel<Record>[] channels = ArrayUtil.newArray(in, this.otherIn);
final boolean[] guard = new boolean[] { true, true };
final Record[] objects = new Record[2];
final String[] typePaths = new String[2];
for (int i = 0; i < 2; i++) {
try {
final Channel<Record> channel = channels[i];
if (channel == null) {
guard[i] = false;
} else {
Record object = null;
boolean test = false;
do {
object = channel.read();
test = testObject(object);
} while (!test);
if (test) {
objects[i] = object;
typePaths[i] = objects[i].getRecordDefinition().getPath();
}
}
} catch (final ClosedException e) {
guard[i] = false;
}
}
final Record otherObject = objects[OTHER_INDEX];
if (typePaths[SOURCE_INDEX] != null) {
final Record sourceObject = objects[SOURCE_INDEX];
if (typePaths[OTHER_INDEX] != null) {
final int nameCompare = typePaths[SOURCE_INDEX].toString().compareTo(typePaths[OTHER_INDEX].toString());
if (nameCompare <= 0) {
currentType = sourceObject.getRecordDefinition();
currentTypeName = typePaths[SOURCE_INDEX];
addSourceObject(sourceObject);
objects[SOURCE_INDEX] = null;
if (nameCompare != 0) {
guard[OTHER_INDEX] = false;
}
}
if (nameCompare >= 0) {
currentType = otherObject.getRecordDefinition();
currentTypeName = typePaths[OTHER_INDEX];
addOtherObject(otherObject);
objects[OTHER_INDEX] = null;
if (nameCompare != 0) {
guard[SOURCE_INDEX] = false;
}
}
} else {
currentType = sourceObject.getRecordDefinition();
currentTypeName = typePaths[SOURCE_INDEX];
if (otherObject != null) {
addSourceObject(otherObject);
}
}
} else {
currentType = otherObject.getRecordDefinition();
currentTypeName = typePaths[OTHER_INDEX];
if (otherObject != null) {
addOtherObject(otherObject);
}
objects[OTHER_INDEX] = null;
}
try {
final MultiInputSelector alt = new MultiInputSelector();
final boolean running = true;
while (running) {
final int channelIndex = alt.select(channels, guard, 1000);
if (channelIndex >= 0) {
final Record object = channels[channelIndex].read();
if (testObject(object)) {
final RecordDefinition recordDefinition = object.getRecordDefinition();
final String typePath = recordDefinition.getPath();
if (currentTypeName == null) {
currentTypeName = typePath;
currentType = recordDefinition;
init(recordDefinition);
}
if (typePath.equals(currentTypeName)) {
currentTypeName = typePath;
currentType = recordDefinition;
if (channelIndex == SOURCE_INDEX) {
addSourceObject(object);
} else {
addOtherObject(object);
}
} else {
objects[channelIndex] = object;
addObjectFromOtherChannel(channels, guard, objects, channelIndex);
currentType = addSavedObjects(currentType, currentTypeName, out, guard, objects);
if (currentType != null) {
currentTypeName = currentType.getPath();
}
}
}
} else {
if (channels[0].isClosed()) {
guard[1] = true;
} else if (channels[1].isClosed()) {
guard[0] = true;
}
}
}
} finally {
try {
while (addSavedObjects(currentType, currentTypeName, out, guard, objects) != null) {
}
processObjects(currentType, out);
} finally {
}
}
} finally {
this.otherIn.readDisconnect();
tearDown();
}
}
use of com.revolsys.record.Record in project com.revolsys.open by revolsys.
the class AddDefaultValuesProcess method process.
private void process(final Record record) {
final RecordDefinition type = record.getRecordDefinition();
boolean process = true;
if (this.schemaName != null) {
if (!PathUtil.getPath(type.getPath()).equals(this.schemaName)) {
process = false;
}
}
if (process) {
processDefaultValues(record, getDefaultValues(type));
}
for (int i = 0; i < type.getFieldCount(); i++) {
final Object value = record.getValue(i);
if (value instanceof Record) {
process((Record) value);
}
}
}
Aggregations