Skip to content

Commit

Permalink
KAA-1279: Fixed about 100 warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
sashadidukh committed Sep 29, 2016
1 parent d9dabbb commit f773096
Show file tree
Hide file tree
Showing 30 changed files with 138 additions and 115 deletions.
Expand Up @@ -86,8 +86,6 @@ public class DefaultDeltaCalculationAlgorithm implements DeltaCalculationAlgorit
*/
private AvroBinaryDelta resultDelta;

/* FieldAttribute */

/**
* Instantiates a new default delta calculator.
*
Expand All @@ -99,8 +97,6 @@ public DefaultDeltaCalculationAlgorithm(Schema deltaSchema, Schema baseSchema) {
this.baseSchema = baseSchema;
}

/* RecordTuple */

/**
* Gets the full name.
*
Expand Down Expand Up @@ -174,7 +170,8 @@ private static Schema getSchemaByFullName(Schema arraySchema, String fullName) {
List<Schema> itemTypes = arraySchema.getElementType().getTypes();
return getSchemaByFullName(itemTypes, fullName);
} else {
return arraySchema.getElementType().getFullName().equals(fullName) ? arraySchema.getElementType() : null;
return arraySchema.getElementType().getFullName().equals(
fullName) ? arraySchema.getElementType() : null;
}
}

Expand All @@ -185,8 +182,10 @@ private static Schema getSchemaByFullName(Schema arraySchema, String fullName) {
* @param field the field
* @throws DeltaCalculatorException the delta calculator exception
*/
private static void putUnchanged(GenericRecord delta, String field) throws DeltaCalculatorException {
Schema unchangedSchema = getSchemaByFullName(delta, field, KAA_NAMESPACE + "." + UNCHANGED + "T");
private static void putUnchanged(GenericRecord delta, String field)
throws DeltaCalculatorException {
Schema unchangedSchema = getSchemaByFullName(
delta, field, KAA_NAMESPACE + "." + UNCHANGED + "T");
if (unchangedSchema != null) {
GenericEnumSymbol unchanged = new GenericData.EnumSymbol(unchangedSchema, UNCHANGED);
delta.put(field, unchanged);
Expand All @@ -210,8 +209,9 @@ private static void putReset(GenericRecord delta, String field) throws DeltaCalc
GenericEnumSymbol reset = new GenericData.EnumSymbol(resetSchema, RESET);
delta.put(field, reset);
} else {
throw new DeltaCalculatorException(new StringBuilder().append("Failed to find schema for \"reset\" type ")
.append(" in ").append(delta.getSchema().getFullName()).append(" field ").append(field).toString());
throw new DeltaCalculatorException(new StringBuilder().append(
"Failed to find schema for \"reset\" type ").append(" in ").append(
delta.getSchema().getFullName()).append(" field ").append(field).toString());
}
}

Expand All @@ -223,7 +223,8 @@ private static void putReset(GenericRecord delta, String field) throws DeltaCalc
* @param record the record
* @return the generic record
*/
private static GenericRecord createSubDelta(GenericRecord delta, String field, GenericRecord record) {
private static GenericRecord createSubDelta(
GenericRecord delta, String field, GenericRecord record) {
Schema recordType = getSchemaByFullName(delta, field, getFullName(record));
return recordType == null ? null : new GenericData.Record(recordType);
}
Expand All @@ -238,7 +239,9 @@ private static GenericRecord createSubDelta(GenericRecord delta, String field, G
* @throws DeltaCalculatorException the delta calculator exception
*/
private static void fillDeltaArrayFields(GenericRecord delta, Set<String> resetFields,
Map<String, List<byte[]>> uuidFields, Queue<FieldAttribute> fieldQueue) throws DeltaCalculatorException {
Map<String, List<byte[]>> uuidFields,
Queue<FieldAttribute> fieldQueue)
throws DeltaCalculatorException {
List<Schema.Field> fields = delta.getSchema().getFields();

if (fieldQueue.isEmpty()) {
Expand Down Expand Up @@ -299,7 +302,8 @@ private Schema getDeltaSchemaByFullName(String fullName) {
* @param array the array
* @throws DeltaCalculatorException the delta calculator exception
*/
private void addComplexItemToArray(GenericContainer container, GenericArray array) throws DeltaCalculatorException {
private void addComplexItemToArray(GenericContainer container, GenericArray array)
throws DeltaCalculatorException {
Schema itemSchema = getSchemaByFullName(array.getSchema(), getFullName(container));
if (itemSchema.getType() == Type.RECORD) {
GenericRecord subDelta = new GenericData.Record(itemSchema);
Expand All @@ -320,20 +324,23 @@ private void addComplexItemToArray(GenericContainer container, GenericArray arra
* @param fieldQueue the field queue
* @throws DeltaCalculatorException the delta calculator exception
*/
private void processComplexField(GenericRecord delta, String field, GenericContainer newRecordValue,
GenericContainer oldRecordValue, Queue<FieldAttribute> fieldQueue) throws DeltaCalculatorException {
private void processComplexField(
GenericRecord delta, String field, GenericContainer newRecordValue,
GenericContainer oldRecordValue, Queue<FieldAttribute> fieldQueue)
throws DeltaCalculatorException {
boolean fieldChanged = false;
if (newRecordValue.getSchema().getType() == Type.RECORD) {
GenericRecord subDelta = createSubDelta(delta, field, (GenericRecord) newRecordValue);
if (subDelta != null) {
boolean hasChanges = false;
if (oldRecordValue != null && oldRecordValue.getSchema().getFullName().equals(newRecordValue.getSchema().getFullName())) {
if (oldRecordValue != null && oldRecordValue.getSchema().getFullName().equals(
newRecordValue.getSchema().getFullName())) {
FieldAttribute fieldPair = new FieldAttribute(getSchemaByFullName(delta, field,
getFullName(newRecordValue)), field);
Queue<FieldAttribute> newFieldQueue = new LinkedList<FieldAttribute>(fieldQueue);
newFieldQueue.offer(fieldPair);
hasChanges = fillDelta(subDelta, (GenericRecord) oldRecordValue, (GenericRecord) newRecordValue,
newFieldQueue);
hasChanges = fillDelta(subDelta, (GenericRecord) oldRecordValue,
(GenericRecord) newRecordValue, newFieldQueue);
} else {
fillDeltaWithoutMerge(subDelta, (GenericRecord) newRecordValue);
hasChanges = true;
Expand All @@ -343,7 +350,8 @@ private void processComplexField(GenericRecord delta, String field, GenericConta
fieldChanged = true;
}
} else {
throw new DeltaCalculatorException(new StringBuilder().append("Failed to find subdelta schema \"")
throw new DeltaCalculatorException(
new StringBuilder().append("Failed to find subdelta schema \"")
.append(getFullName(newRecordValue)).append("\"").toString());
}
} else if (oldRecordValue == null || field.equals(UUID_FIELD)
Expand All @@ -363,7 +371,8 @@ private void processComplexField(GenericRecord delta, String field, GenericConta
* @param root the root
* @throws DeltaCalculatorException the delta calculator exception
*/
private void fillDeltaWithoutMerge(GenericRecord delta, GenericRecord root) throws DeltaCalculatorException {
private void fillDeltaWithoutMerge(GenericRecord delta, GenericRecord root)
throws DeltaCalculatorException {
Schema rootSchema = root.getSchema();
for (Field field : rootSchema.getFields()) {
Object value = root.get(field.name());
Expand Down Expand Up @@ -425,7 +434,8 @@ private boolean fillDelta(GenericRecord delta, GenericRecord oldRoot, GenericRec
if (!newArrayItems.isEmpty()) {
if (newArrayItems.get(0) instanceof GenericRecord) {
// Item is a complex type
if (oldArrayItems != null && !oldArrayItems.isEmpty() && oldArrayItems.get(0) instanceof GenericRecord) {
if (oldArrayItems != null && !oldArrayItems.isEmpty()
&& oldArrayItems.get(0) instanceof GenericRecord) {
for (Object oldItem : oldArrayItems) {
GenericRecord oldItemRecord = (GenericRecord) oldItem;
Schema oldItemSchema = oldItemRecord.getSchema();
Expand Down Expand Up @@ -513,7 +523,8 @@ private boolean fillDelta(GenericRecord delta, GenericRecord oldRoot, GenericRec
}
}
} else if (oldArrayItems == null) {
delta.put(newField.name(), new GenericData.Array(0, getArraySchema(delta, newField.name())));
delta.put(newField.name(),
new GenericData.Array(0, getArraySchema(delta, newField.name())));
hasChanges = true;
} else if (!oldArrayItems.isEmpty()) {
resetFields.add(newField.name());
Expand All @@ -533,7 +544,8 @@ private boolean fillDelta(GenericRecord delta, GenericRecord oldRoot, GenericRec
}
} else if (newValue instanceof GenericContainer) {
GenericContainer newRecordValue = (GenericContainer) newValue;
GenericContainer oldRecordValue = (oldValue instanceof GenericContainer) ? (GenericContainer) oldValue : null;
GenericContainer oldRecordValue =
(oldValue instanceof GenericContainer) ? (GenericContainer) oldValue : null;
processComplexField(delta, newField.name(), newRecordValue, oldRecordValue, fieldQueue);
} else if ((newValue == null && oldValue != null)
|| (newValue != null && !newValue.equals(oldValue))) {
Expand Down Expand Up @@ -598,7 +610,8 @@ private void processDifferences(GenericRecord oldRoot, GenericRecord newRoot)

hasDifferences = !(oldArray.size() == newArray.size());
if (!hasDifferences) {
if (!newArray.isEmpty() && newArray.get(0) instanceof GenericRecord && oldArray.get(0) instanceof GenericRecord) {
if (!newArray.isEmpty() && newArray.get(0) instanceof GenericRecord
&& oldArray.get(0) instanceof GenericRecord) {
GenericRecord uuidCheckRecord = (GenericRecord) newArray.get(0);
Schema uuidCheckSchema = uuidCheckRecord.getSchema();
if (uuidCheckSchema.getField(UUID_FIELD) != null) {
Expand Down Expand Up @@ -647,7 +660,8 @@ private void processDifferences(GenericRecord oldRoot, GenericRecord newRoot)
if (hasDifferences && !processedRecords.contains(lastUuidRecords)) {
Schema deltaSubSchema = getDeltaSchemaByFullName(lastUuidRecordName);
if (deltaSubSchema == null) {
throw new DeltaCalculatorException(new StringBuilder().append("Failed to find schema for \"")
throw new DeltaCalculatorException(
new StringBuilder().append("Failed to find schema for \"")
.append(lastUuidRecordName).append("\"").toString());
}
GenericRecord delta = new GenericData.Record(deltaSubSchema);
Expand Down Expand Up @@ -675,12 +689,14 @@ public RawBinaryDelta calculate(BaseData endpointConfiguration, BaseData newConf
}

@Override
public RawBinaryDelta calculate(BaseData newConfigurationBody) throws IOException, DeltaCalculatorException {
public RawBinaryDelta calculate(BaseData newConfigurationBody)
throws IOException, DeltaCalculatorException {
GenericRecord newRoot = getRootNode(newConfigurationBody, baseSchema);
return calculate(newRoot);
}

public RawBinaryDelta calculate(GenericRecord oldConfig, GenericRecord newConfig) throws DeltaCalculatorException {
public RawBinaryDelta calculate(GenericRecord oldConfig, GenericRecord newConfig)
throws DeltaCalculatorException {
resultDelta = new AvroBinaryDelta(deltaSchema);
processedRecords = new HashSet<>();
processDifferences(oldConfig, newConfig);
Expand Down
Expand Up @@ -17,8 +17,8 @@
package org.kaaproject.kaa.common.channels.communication;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public class HttpLongPollParameters extends IPParameters {
public class HttpLongPollParameters extends IpParameters {

}
Expand Up @@ -17,7 +17,7 @@
package org.kaaproject.kaa.common.channels.communication;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public class HttpParameters extends IPParameters {
public class HttpParameters extends IpParameters {
}
Expand Up @@ -17,13 +17,13 @@
package org.kaaproject.kaa.common.channels.communication;

/**
* IPParameters Class.
* Base type for IP oriented Channels - IPParameters consists
* IpParameters Class.
* Base type for IP oriented Channels - IpParameters consists
* HostName String and Integer port
*
* @author Andrey Panasenko
*/
public class IPParameters {
public class IpParameters {
private String hostName;
private int port;

Expand Down Expand Up @@ -68,7 +68,7 @@ public void setPort(int port) {
*/
@Override
public String toString() {
return "IPParameters [hostName=" + hostName + ", port=" + port + "]";
return "IpParameters [hostName=" + hostName + ", port=" + port + "]";
}

/* (non-Javadoc)
Expand Down Expand Up @@ -97,7 +97,7 @@ public boolean equals(Object obj) {
if (getClass() != obj.getClass()) {
return false;
}
IPParameters other = (IPParameters) obj;
IpParameters other = (IpParameters) obj;
if (hostName == null) {
if (other.hostName != null) {
return false;
Expand Down
Expand Up @@ -16,7 +16,7 @@

package org.kaaproject.kaa.common.channels.communication;

public class KaaTcpParameters extends IPParameters {
public class KaaTcpParameters extends IpParameters {


}
Expand Up @@ -16,7 +16,7 @@

/**
* Provides Communications parameters implementations for all types of Channels
* Base type for IP oriented Channels - IPParameters consists
* Base type for IP oriented Channels - IpParameters consists
* HostName String and Integer port
*
* @author Andrey Panasenko
Expand Down
Expand Up @@ -44,12 +44,12 @@ public class Framer {
.getLogger(Framer.class);

/**
* Mqtt frame listeners list
* Mqtt frame listeners list.
*/
private final List<MqttFramelistener> listeners;

/**
* Current processing frame
* Current processing frame.
*/
private MqttFrame currentFrame;

Expand Down Expand Up @@ -108,7 +108,7 @@ public int pushBytes(byte[] bytes) throws KaaTcpProtocolException {
}

/**
* Notify all listeners on new Frame
* Notify all listeners on new Frame.
*/
private void callListeners(MqttFrame frame) {
for (MqttFramelistener listener : listeners) {
Expand All @@ -117,7 +117,7 @@ private void callListeners(MqttFrame frame) {
}

/**
* Creates specific Kaatcp message by MessageType
* Creates specific Kaatcp message by MessageType.
*
* @param type - MessageType of mqttFrame
* @return mqttFrame
Expand Down
Expand Up @@ -24,13 +24,10 @@
*/
public class KaaTcpProtocolException extends Exception {

/**
*
*/
private static final long serialVersionUID = 4989380711384492851L;

/**
* Default constructor with error message
* Default constructor with error message.
*
* @param string the string
*/
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.MqttFrame;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface MqttFramelistener {
public void onMqttFrame(MqttFrame frame);
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.ConnAck;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface ConnAckListener extends MessageListener<ConnAck> {

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.Connect;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface ConnectListener extends MessageListener<Connect> {

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.Disconnect;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface DisconnectListener extends MessageListener<Disconnect> {

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.KaaSync;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface KaaSyncListener extends MessageListener<KaaSync> {

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.MqttFrame;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface MessageListener<T extends MqttFrame> {
public void onMessage(T message);
Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.PingRequest;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface PingRequestListener extends MessageListener<PingRequest> {

Expand Down
Expand Up @@ -19,7 +19,7 @@
import org.kaaproject.kaa.common.channels.protocols.kaatcp.messages.PingResponse;

/**
* @author Andrey Panasenko
* @author Andrey Panasenko.
*/
public interface PingResponseListener extends MessageListener<PingResponse> {

Expand Down

0 comments on commit f773096

Please sign in to comment.