Commit 8e3aa425 authored by Ryan Berkheimer's avatar Ryan Berkheimer
Browse files

added more 'final' keywords where possible. added some docstrings to classes without docstrings.

parent 42222960
......@@ -28,18 +28,18 @@ public class ContainerRecord implements IContainerRecord {
* from an existing set of Collections.
* @param collections Collections to be used in ContainerRecord construction
*/
public ContainerRecord(List<ICollection> collections) {
public ContainerRecord(final List<ICollection> collections) {
this.generateId();
this.setCollections(collections);
}
public ContainerRecord(IContainerRecord containerRecord) {
public ContainerRecord(final IContainerRecord containerRecord) {
this.generateId();
this.setCollections(containerRecord.getCollections());
this.setTransformations(containerRecord.getTransformations());
}
public ContainerRecord(List<ICollection> collections, List<ITransformation> transformations) {
public ContainerRecord(final List<ICollection> collections, final List<ITransformation> transformations) {
this.generateId();
this.setCollections(collections);
this.setTransformations(transformations);
......@@ -65,13 +65,13 @@ public class ContainerRecord implements IContainerRecord {
this.id = UUID.randomUUID();
}
private void setCollections(List<ICollection> collections) {
private void setCollections(final List<ICollection> collections) {
this.collections = collections.stream().map(collection -> {
return collection.getCopy();
}).collect(Collectors.toList());
}
private void setTransformations(List<ITransformation> transformations) {
private void setTransformations(final List<ITransformation> transformations) {
this.transformations = transformations;
}
......
......@@ -31,7 +31,7 @@ public class ProtocolRecord implements IProtocolRecord {
private List<UUID> uuids;
private String connectionId;
public ProtocolRecord(IConnection connection, Map<IRecord, Map<String,Object>> recordMap) {
public ProtocolRecord(final IConnection connection, final Map<IRecord, Map<String, Object>> recordMap) {
this.setConnectionId(connection.getId());
this.setTransformationMap(connection.getTransformationMap());
this.setRecordMap(recordMap);
......@@ -42,7 +42,7 @@ public class ProtocolRecord implements IProtocolRecord {
return this.connectionId;
}
public Map<String, Map<String,Object>> getTransformationMap(){
public Map<String, Map<String, Object>> getTransformationMap() {
return this.transformationMap;
}
......@@ -54,13 +54,13 @@ public class ProtocolRecord implements IProtocolRecord {
return this.uuids;
}
public Map<IRecord,Map<String,Object>> getRecordMap() {
public Map<IRecord, Map<String, Object>> getRecordMap() {
return this.recordMap;
}
public List<IRecord> getRecordsByCollection(String collectionId) {
List<IRecord> collectionRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((String)e.getValue().get("COLLECTION")).equals(collectionId)) {
public List<IRecord> getRecordsByCollection(final String collectionId) {
final List<IRecord> collectionRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((String) e.getValue().get("COLLECTION")).equals(collectionId)) {
return true;
}
return false;
......@@ -71,9 +71,9 @@ public class ProtocolRecord implements IProtocolRecord {
return new ArrayList<IRecord>();
}
public List<IRecord> getRecordsByUUID(UUID uuid) {
List<IRecord> uuidRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((UUID)e.getValue().get("UUID")).equals(uuid)) {
public List<IRecord> getRecordsByUUID(final UUID uuid) {
final List<IRecord> uuidRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((UUID) e.getValue().get("UUID")).equals(uuid)) {
return true;
}
return false;
......@@ -84,8 +84,8 @@ public class ProtocolRecord implements IProtocolRecord {
return new ArrayList<IRecord>();
}
public List<IRecord> getRecordsByUUID(String uuid) {
List<IRecord> uuidRecords = this.recordMap.entrySet().stream().filter(e -> {
public List<IRecord> getRecordsByUUID(final String uuid) {
final List<IRecord> uuidRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((UUID) e.getValue().get("UUID")).equals(UUID.fromString(uuid))) {
return true;
}
......@@ -98,10 +98,10 @@ public class ProtocolRecord implements IProtocolRecord {
}
@SuppressWarnings("unchecked")
public List<IRecord> getRecordsByClassifier(String key, Object value) {
List<IRecord> classRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((Map<String,Object>)e.getValue().get("CLASSIFIERS")).keySet().contains(key)) {
if (((List<String>)((Map<String,Object>)e.getValue().get("CLASSIFIERS")).get(key)).contains(value)) {
public List<IRecord> getRecordsByClassifier(final String key, final Object value) {
final List<IRecord> classRecords = this.recordMap.entrySet().stream().filter(e -> {
if (((Map<String, Object>) e.getValue().get("CLASSIFIERS")).keySet().contains(key)) {
if (((List<String>) ((Map<String, Object>) e.getValue().get("CLASSIFIERS")).get(key)).contains(value)) {
return true;
}
}
......@@ -114,15 +114,18 @@ public class ProtocolRecord implements IProtocolRecord {
}
@SuppressWarnings("unchecked")
public List<IRecord> getRecordsByTransformation(String transformationId) {
public List<IRecord> getRecordsByTransformation(final String transformationId) {
if (this.getTransformationMap().containsKey(transformationId)) {
ITransformation transformationInstance = (ITransformation)this.getTransformationMap().get(transformationId).get("instance");
Map<String,String> parameterMapSpec = (Map<String,String>)this.getTransformationMap().get(transformationId).get("parameters");
String uuidParam = ProtocolRecordUtils.getUUIDParameter(parameterMapSpec);
Map<String,List<IRecord>> parameterMap = ProtocolRecordUtils.buildParameterMap(this, parameterMapSpec);
final ITransformation transformationInstance = (ITransformation) this.getTransformationMap()
.get(transformationId).get("instance");
final Map<String, String> parameterMapSpec = (Map<String, String>) this.getTransformationMap()
.get(transformationId).get("parameters");
final String uuidParam = ProtocolRecordUtils.getUUIDParameter(parameterMapSpec);
final Map<String, List<IRecord>> parameterMap = ProtocolRecordUtils.buildParameterMap(this,
parameterMapSpec);
if (uuidParam != null && !uuidParam.isEmpty()) {
return ListUtils.flatten(this.getUUIDs().stream().map(uuid -> {
Map<String,List<IRecord>> uuidParams = new HashMap<String,List<IRecord>>(parameterMap);
final Map<String, List<IRecord>> uuidParams = new HashMap<String, List<IRecord>>(parameterMap);
uuidParams.replace(uuidParam, this.getRecordsByUUID(uuid));
return transformationInstance.process(uuidParams);
}).collect(Collectors.toList()));
......@@ -133,19 +136,19 @@ public class ProtocolRecord implements IProtocolRecord {
return null;
}
private void setTransformationMap(Map<String, Map<String,Object>> transformationMap) {
private void setTransformationMap(final Map<String, Map<String, Object>> transformationMap) {
this.transformationMap = transformationMap;
}
private void setConnectionId(String connectionId) {
private void setConnectionId(final String connectionId) {
this.connectionId = connectionId;
}
private void setRecordMap(Map<IRecord, Map<String,Object>> recordMap) {
private void setRecordMap(final Map<IRecord, Map<String, Object>> recordMap) {
this.recordMap = recordMap;
}
private void setUUIDs(Map<IRecord, Map<String,Object>> recordMap) {
private void setUUIDs(final Map<IRecord, Map<String, Object>> recordMap) {
this.uuids = ListUtils.eliminateDuplicates(recordMap.values().stream().map(v -> {
return (UUID) v.get("UUID");
}).collect(Collectors.toList()));
......
......@@ -24,12 +24,12 @@ public class SchemaRecord implements IRecord {
private List<ICondition> conditions = null;
private Boolean valid = true;
public SchemaRecord(List<Map<String,Object>> fieldMaps, List<Map<String,Object>> conditionMaps) {
public SchemaRecord(final List<Map<String, Object>> fieldMaps, final List<Map<String, Object>> conditionMaps) {
this.initializeFields(fieldMaps);
this.initializeConditions(conditionMaps);
}
public SchemaRecord(IRecord record) {
public SchemaRecord(final IRecord record) {
this.setFields(record.getFields());
if (record.getConditions() != null) {
this.setConditions(record.getConditions());
......@@ -37,17 +37,18 @@ public class SchemaRecord implements IRecord {
}
/**
* Creates a new SchemaRecord from a list of IFields.
* When this constructor is used, the IFields passed are all copied
* into new IField instances for parallelization safety
* @param fields A list of IFields which will be used to create new IFields
* and add to a SchemaRecord
* Creates a new SchemaRecord from a list of IFields. When this constructor is
* used, the IFields passed are all copied into new IField instances for
* parallelization safety
*
* @param fields A list of IFields which will be used to create new IFields and
* add to a SchemaRecord
*/
public SchemaRecord(List<IField> fields) {
public SchemaRecord(final List<IField> fields) {
this.setFields(fields);
}
public SchemaRecord(IRecord record, List<Map<String,Object>> fieldMaps) {
public SchemaRecord(final IRecord record, final List<Map<String, Object>> fieldMaps) {
this.initializeFields(fieldMaps);
this.setConditions(record.getConditions());
}
......@@ -56,104 +57,103 @@ public class SchemaRecord implements IRecord {
return new SchemaRecord(this);
}
private void initializeFields(List<Map<String,Object>> fieldMaps) {
private void initializeFields(final List<Map<String, Object>> fieldMaps) {
this.fields = fieldMaps.stream().map(fieldMap -> {
IField f = new DefaultField(fieldMap);
return f;
}).collect(Collectors.toList());
final IField f = new DefaultField(fieldMap);
return f;
}).collect(Collectors.toList());
}
private void initializeConditions(List<Map<String,Object>> conditionMaps) {
private void initializeConditions(final List<Map<String, Object>> conditionMaps) {
this.conditions = conditionMaps.stream().map(conditionMap -> {
try {
ICondition c = ConditionTypeFactory.create(conditionMap);
final ICondition c = ConditionTypeFactory.create(conditionMap);
return c;
} catch (Exception e) {
} catch (final Exception e) {
return null;
}
}).collect(Collectors.toList());
}
public void setFields(List<IField> fields) {
public void setFields(final List<IField> fields) {
this.fields = fields.stream().map(f -> {
try {
IField newField = new DefaultField(f);
final IField newField = new DefaultField(f);
return newField;
} catch (Exception e) {
} catch (final Exception e) {
return null;
}
}).collect(Collectors.toList());
}
public void setConditions(List<ICondition> conditions) {
public void setConditions(final List<ICondition> conditions) {
this.conditions = conditions.stream().map(c -> {
try {
ICondition newCondition = ConditionTypeFactory.create(c);
final ICondition newCondition = ConditionTypeFactory.create(c);
return newCondition;
} catch (Exception e) {
} catch (final Exception e) {
return null;
}
}).collect(Collectors.toList());
}
public void setField(Object field, Object fieldValue) {
public void setField(final Object field, final Object fieldValue) {
if (field instanceof String) {
String castField = (String) field;
final String castField = (String) field;
try {
this.fields.stream().filter(f -> f.getName().equals(castField))
.findFirst().get().setValue(fieldValue);
} catch (Exception e) {
this.fields.stream().filter(f -> f.getName().equals(castField)).findFirst().get().setValue(fieldValue);
} catch (final Exception e) {
}
} else if (field instanceof IField) {
IField castField = (IField) field;
final IField castField = (IField) field;
try {
this.fields.stream().filter(f -> f.getName().equals(castField.getName()))
.findFirst().get().setValue(fieldValue);
} catch (Exception e) {}
this.fields.stream().filter(f -> f.getName().equals(castField.getName())).findFirst().get()
.setValue(fieldValue);
} catch (final Exception e) {
}
}
}
public void setCondition(Object condition, Object conditionValue) {
public void setCondition(final Object condition, final Object conditionValue) {
if (condition instanceof String) {
String castCondition = (String) condition;
final String castCondition = (String) condition;
try {
this.conditions.stream().filter(c -> c.getId().equals(castCondition))
.findFirst().get().setValue(conditionValue);
} catch (Exception e) {
this.conditions.stream().filter(c -> c.getId().equals(castCondition)).findFirst().get()
.setValue(conditionValue);
} catch (final Exception e) {
}
} else if (condition instanceof ICondition) {
ICondition castCondition = (ICondition) condition;
final ICondition castCondition = (ICondition) condition;
try {
this.conditions.stream().filter(c -> c.getId().equals(castCondition.getId()))
.findFirst().get().setValue(conditionValue);
} catch (Exception e) {}
this.conditions.stream().filter(c -> c.getId().equals(castCondition.getId())).findFirst().get()
.setValue(conditionValue);
} catch (final Exception e) {
}
}
}
public IField getField(String fieldId) {
public IField getField(final String fieldId) {
try {
return this.fields.stream().filter(field -> field.getId().equals(fieldId))
.findFirst().get();
} catch (Exception e) {
return this.fields.stream().filter(field -> field.getId().equals(fieldId)).findFirst().get();
} catch (final Exception e) {
return null;
}
}
public Boolean hasField(String fieldId) {
return this.fields.stream().filter(field -> field.getId().equals(fieldId))
.findFirst().isPresent();
public Boolean hasField(final String fieldId) {
return this.fields.stream().filter(field -> field.getId().equals(fieldId)).findFirst().isPresent();
}
public Boolean hasCondition(String conditionId) {
return this.conditions.stream().filter(condition -> condition.getId().equals(conditionId))
.findFirst().isPresent();
public Boolean hasCondition(final String conditionId) {
return this.conditions.stream().filter(condition -> condition.getId().equals(conditionId)).findFirst()
.isPresent();
}
public ICondition getCondition(String conditionId) {
public ICondition getCondition(final String conditionId) {
try {
return this.conditions.stream().filter(condition -> condition.getId().equals(conditionId))
.findFirst().get();
} catch (Exception e) {
return this.conditions.stream().filter(condition -> condition.getId().equals(conditionId)).findFirst()
.get();
} catch (final Exception e) {
return null;
}
}
......@@ -174,7 +174,7 @@ public class SchemaRecord implements IRecord {
return this.conditions.stream().map(condition -> condition.getId()).collect(Collectors.toList());
}
public void setValid(Boolean valid) {
public void setValid(final Boolean valid) {
this.valid = valid;
}
......
......@@ -15,17 +15,17 @@ public class BaseRejection {
private List<String> reasons = null;
private IRecord record = null;
public BaseRejection(IRecord record) {
public BaseRejection(final IRecord record) {
setRecord(record);
initializeReasons();
}
public BaseRejection(IRecord record, List<String> reasons) {
public BaseRejection(final IRecord record, final List<String> reasons) {
setRecord(record);
setReasons(reasons);
}
public BaseRejection(IRejection rejection) {
public BaseRejection(final IRejection rejection) {
setRecord(rejection.getRecord());
setReasons(rejection.getReasons());
}
......@@ -42,15 +42,15 @@ public class BaseRejection {
this.reasons = Collections.synchronizedList(new ArrayList<String>());
}
public void addReason(String reason) {
public void addReason(final String reason) {
this.reasons.add(reason);
}
private void setRecord(IRecord record) {
private void setRecord(final IRecord record) {
this.record = record;
}
private void setReasons(List<String> reasons) {
private void setReasons(final List<String> reasons) {
this.reasons = Collections.synchronizedList(new ArrayList<String>(reasons));
}
......
......@@ -10,20 +10,20 @@ import gov.noaa.messageapi.interfaces.IRejection;
*/
public class DefaultRejection extends BaseRejection implements IRejection {
public DefaultRejection(IRecord record) {
public DefaultRejection(final IRecord record) {
super(record);
}
public DefaultRejection(IRecord record, String reason) {
public DefaultRejection(final IRecord record, final String reason) {
super(record);
addReason(reason);
}
public DefaultRejection(IRecord record, List<String> reasons) {
public DefaultRejection(final IRecord record, final List<String> reasons) {
super(record, reasons);
}
public DefaultRejection(IRejection rejection) {
public DefaultRejection(final IRejection rejection) {
super(rejection);
}
......
......@@ -31,8 +31,7 @@ public class BaseRequest {
protected List<IRecord> records;
private IRecord requestRecord;
public BaseRequest(String type, ISchema schema, IContainer container,
IProtocol protocol) {
public BaseRequest(final String type, final ISchema schema, final IContainer container, final IProtocol protocol) {
this.setType(type);
this.copySchema(schema);
this.copyContainer(container);
......@@ -44,7 +43,7 @@ public class BaseRequest {
/**
* Standard constructor from request - default is to deep copy everything.
*/
public BaseRequest(IRequest request) {
public BaseRequest(final IRequest request) {
this.setType(request.getType());
this.copySchema(request.getSchema());
this.copyContainer(request.getContainer());
......@@ -54,12 +53,14 @@ public class BaseRequest {
}
/**
* Allows specification of a list of named components that will be deep-copied on constructor.
* Allowed values are 'schema', 'container', 'protocol', 'records'
* Allows specification of a list of named components that will be deep-copied
* on constructor. Allowed values are 'schema', 'container', 'protocol',
* 'records'
*
* @param request
* @param copyComponents
*/
public BaseRequest(IRequest request, List<String> copyComponents) {
public BaseRequest(final IRequest request, final List<String> copyComponents) {
this.setType(request.getType());
if (copyComponents.contains("schema")) {
this.copySchema(request.getSchema());
......@@ -90,12 +91,13 @@ public class BaseRequest {
}
/**
* Creates a new record in a request, making sure the conditions are null,
* and returns it for update by the user.
* Creates a new record in a request, making sure the conditions are null, and
* returns it for update by the user.
*
* @return A new IRecord belonging to the request records collection
*/
public IRecord createRecord() {
IRecord r = this.schema.createRecord();
final IRecord r = this.schema.createRecord();
this.records.add(ConditionUtils.nullifyComparisonConditions(r));
return r;
}
......@@ -124,48 +126,49 @@ public class BaseRequest {
return this.requestRecord;
}
public void setCondition(String conditionId, Object value) {
public void setCondition(final String conditionId, final Object value) {
this.getRequestRecord().setCondition(conditionId, value);
}
private void setType(String type) {
private void setType(final String type) {
this.type = type;
}
private void copySchema(ISchema schema) {
private void copySchema(final ISchema schema) {
this.schema = (ISchema) schema.getCopy();
}
private void copyContainer(IContainer container) {
private void copyContainer(final IContainer container) {
this.container = (IContainer) container.getCopy();
}
private void copyProtocol(IProtocol protocol) {
private void copyProtocol(final IProtocol protocol) {
this.protocol = (IProtocol) protocol.getCopy();
}
protected void copyRecords(List<IRecord> records) {
this.records = Collections.synchronizedList(records.stream().map(r -> r.getCopy()).collect(Collectors.toList()));
protected void copyRecords(final List<IRecord> records) {
this.records = Collections
.synchronizedList(records.stream().map(r -> r.getCopy()).collect(Collectors.toList()));
}
private void setSchema(ISchema schema) {
private void setSchema(final ISchema schema) {
this.schema = schema;
}
private void setContainer(IContainer container) {
private void setContainer(final IContainer container) {
this.container = container;
}
private void setProtocol(IProtocol protocol) {
private void setProtocol(final IProtocol protocol) {
this.protocol = protocol;
}
public void setRecords(List<IRecord> records) {
public void setRecords(final List<IRecord> records) {
this.records = records;
}
private void setRequestRecord(ISchema schema) {
IRecord r = schema.createRecord();
private void setRequestRecord(final ISchema schema) {
final IRecord r = schema.createRecord();
this.requestRecord = r;
}
......
......@@ -16,15 +16,15 @@ import gov.noaa.messageapi.responses.DefaultResponse;
*/
public class DefaultRequest extends BaseRequest implements IRequest {
public DefaultRequest(ISchema schema, IContainer container, IProtocol protocol) {
public DefaultRequest(final ISchema schema, final IContainer container, final IProtocol protocol) {
super("default", schema, container, protocol);
}
public DefaultRequest(IRequest request) {
public DefaultRequest(final IRequest request) {
super(request);
}
public DefaultRequest(IRequest request, List<String> copyComponents) {