Skip to content

Commit

Permalink
format Java exercises (only whitespace change), rename 3 fields to co…
Browse files Browse the repository at this point in the history
…nform to Java conventions
  • Loading branch information
codecop committed Sep 12, 2015
1 parent 45e7f7f commit d720aa2
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,92 +9,89 @@ public class TelemetryClient
// Because the focus of the exercise is on the other class.
//

public static final String DIAGNOSTIC_MESSAGE = "AT#UD";
public static final String DIAGNOSTIC_MESSAGE = "AT#UD";

private boolean onlineStatus;
private boolean onlineStatus;
private boolean diagnosticMessageJustSent = false;

private final Random connectionEventsSimulator = new Random();
private final Random randomMessageSimulator = new Random();

public boolean getOnlineStatus()
{
return onlineStatus;
}
public boolean getOnlineStatus()
{
return onlineStatus;
}

public void connect(String telemetryServerConnectionString)
{
if (telemetryServerConnectionString == null || "".equals(telemetryServerConnectionString))
{
throw new IllegalArgumentException();
}
public void connect(String telemetryServerConnectionString)
{
if (telemetryServerConnectionString == null || "".equals(telemetryServerConnectionString))
{
throw new IllegalArgumentException();
}

// Fake the connection with 20% chances of success
boolean success = connectionEventsSimulator.nextInt(10) <= 2;
boolean success = connectionEventsSimulator.nextInt(10) <= 2;

onlineStatus = success;
}
onlineStatus = success;
}

public void disconnect()
{
onlineStatus = false;
}
public void disconnect()
{
onlineStatus = false;
}

public void send(String message)
{
if (message == null || "".equals(message))
{
throw new IllegalArgumentException();
}
public void send(String message)
{
if (message == null || "".equals(message))
{
throw new IllegalArgumentException();
}

// The simulation of Send() actually just remember if the last message sent was a diagnostic message.
// This information will be used to simulate the Receive(). Indeed there is no real server listening.
if (message == DIAGNOSTIC_MESSAGE)
{
diagnosticMessageJustSent = true;
}
else
} else
{
diagnosticMessageJustSent = false;
}
}

public String receive()
{
String message;
public String receive()
{
String message;

if (diagnosticMessageJustSent)
{
// Simulate the reception of the diagnostic message
message = "LAST TX rate................ 100 MBPS\r\n"
+ "HIGHEST TX rate............. 100 MBPS\r\n"
+ "LAST RX rate................ 100 MBPS\r\n"
+ "HIGHEST RX rate............. 100 MBPS\r\n"
+ "BIT RATE.................... 100000000\r\n"
+ "WORD LEN.................... 16\r\n"
+ "WORD/FRAME.................. 511\r\n"
+ "BITS/FRAME.................. 8192\r\n"
+ "MODULATION TYPE............. PCM/FM\r\n"
+ "TX Digital Los.............. 0.75\r\n"
+ "RX Digital Los.............. 0.10\r\n"
+ "BEP Test.................... -5\r\n"
+ "Local Rtrn Count............ 00\r\n"
message = "LAST TX rate................ 100 MBPS\r\n" //
+ "HIGHEST TX rate............. 100 MBPS\r\n" //
+ "LAST RX rate................ 100 MBPS\r\n" //
+ "HIGHEST RX rate............. 100 MBPS\r\n" //
+ "BIT RATE.................... 100000000\r\n" //
+ "WORD LEN.................... 16\r\n" //
+ "WORD/FRAME.................. 511\r\n" //
+ "BITS/FRAME.................. 8192\r\n" //
+ "MODULATION TYPE............. PCM/FM\r\n" //
+ "TX Digital Los.............. 0.75\r\n" //
+ "RX Digital Los.............. 0.10\r\n" //
+ "BEP Test.................... -5\r\n" //
+ "Local Rtrn Count............ 00\r\n" //
+ "Remote Rtrn Count........... 00";

diagnosticMessageJustSent = false;
}
else
} else
{
// Simulate the reception of a response message returning a random message.
message = "";
int messageLength = randomMessageSimulator.nextInt(50) + 60;
for(int i = messageLength; i > 0; --i)
for (int i = messageLength; i > 0; --i)
{
message += (char)randomMessageSimulator.nextInt(40) + 86;
message += (char) randomMessageSimulator.nextInt(40) + 86;
}
}

return message;
}
return message;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class TelemetryDiagnosticControls
{
private final static String DIAGNOSTIC_CHANNEL_CONNECTION_STRING = "*111#";
private static final String DIAGNOSTIC_CHANNEL_CONNECTION_STRING = "*111#";

private final TelemetryClient telemetryClient;
private String diagnosticInfo = "";

Expand All @@ -29,13 +29,13 @@ public void checkTransmission() throws Exception
telemetryClient.disconnect();

int retryLeft = 3;
while (telemetryClient.getOnlineStatus() == false && retryLeft > 0)
while (!telemetryClient.getOnlineStatus() && retryLeft > 0)
{
telemetryClient.connect(DIAGNOSTIC_CHANNEL_CONNECTION_STRING);
retryLeft -= 1;
}

if(telemetryClient.getOnlineStatus() == false)
if (!telemetryClient.getOnlineStatus())
{
throw new Exception("Unable to connect.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,21 @@ public UnicodeFileToHtmlTextConverter(String fullFilenameWithPath)
this.fullFilenameWithPath = fullFilenameWithPath;
}

public String convertToHtml() throws IOException{

BufferedReader reader = new BufferedReader(new FileReader(fullFilenameWithPath));

String line = reader.readLine();
String html = "";
while (line != null)
{
html += StringEscapeUtils.escapeHtml4(line);
html += "<br />";
line = reader.readLine();
}
return html;
public String convertToHtml() throws IOException
{
try (BufferedReader reader = new BufferedReader(new FileReader(fullFilenameWithPath)))
{

String line = reader.readLine();
String html = "";
while (line != null)
{
html += StringEscapeUtils.escapeHtml4(line);
html += "<br />";
line = reader.readLine();
}
return html;

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

public class Alarm
{
private final double LowPressureThreshold = 17;
private final double HighPressureThreshold = 21;
private final double lowPressureThreshold = 17;
private final double highPressureThreshold = 21;

private Sensor sensor = new Sensor();

Expand All @@ -13,14 +13,14 @@ public void check()
{
double psiPressureValue = sensor.popNextPressurePsiValue();

if (psiPressureValue < LowPressureThreshold || HighPressureThreshold < psiPressureValue)
if (psiPressureValue < lowPressureThreshold || highPressureThreshold < psiPressureValue)
{
alarmOn = true;
}
}

public boolean isAlarmOn()
{
return alarmOn;
return alarmOn;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class Sensor
public double popNextPressurePsiValue()
{
double pressureTelemetryValue;
pressureTelemetryValue = samplePressure( );
pressureTelemetryValue = samplePressure();

return OFFSET + pressureTelemetryValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class TicketDispenser
{

public TurnTicket getTurnTicket()
{
int newTurnNumber = TurnNumberSequence.getNextTurnNumber();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public class TurnNumberSequence
{
private static int _turnNumber = 0;
private static int turnNumber = 0;

public static int getNextTurnNumber()
{
return _turnNumber++;
return turnNumber++;
}
}

0 comments on commit d720aa2

Please sign in to comment.