Update CRCAlgorithm.java

This commit is contained in:
Libin Yang
2019-02-17 20:56:47 +08:00
committed by GitHub
parent 31bf10f29f
commit d434e4a4f1

View File

@ -1,11 +1,10 @@
package crcalgorithm;
package Others;
import java.util.ArrayList;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;
/**
*
* @author dimgrichr
*/
public class CRCAlgorithm {
@ -37,6 +36,7 @@ public class CRCAlgorithm {
* The algorithm's main constructor.
* The most significant variables, used in the algorithm,
* are set in their initial values.
*
* @param str The binary number P, in a string form, which is used by the CRC algorithm
* @param size The size of every transmitted message
* @param ber The Bit Error Rate
@ -61,6 +61,7 @@ public class CRCAlgorithm {
/**
* Returns the counter wrongMess
*
* @return wrongMess, the number of Wrong Messages
*/
public int getWrongMess() {
@ -69,6 +70,7 @@ public class CRCAlgorithm {
/**
* Returns the counter wrongMessCaught
*
* @return wrongMessCaught, the number of wrong messages, which are caught by the CRC algoriithm
*/
public int getWrongMessCaught() {
@ -77,6 +79,7 @@ public class CRCAlgorithm {
/**
* Returns the counter wrongMessNotCaught
*
* @return wrongMessNotCaught, the number of wrong messages, which are not caught by the CRC algorithm
*/
public int getWrongMessNotCaught() {
@ -85,6 +88,7 @@ public class CRCAlgorithm {
/**
* Returns the counter correctMess
*
* @return correctMess, the number of the Correct Messages
*/
public int getCorrectMess() {
@ -120,6 +124,7 @@ public class CRCAlgorithm {
* If it does, the message is considered to be wrong by the receiver,so the variable wrongMessCaught changes.
* If it does not, it is accepted, so one of the variables correctMess, wrongMessNotCaught, changes.
* If check == false, the diviided Message is added at the end of the ArrayList<integer> message.
*
* @param check the variable used to determine, if the message is going to be checked from the receiver
* if true, it is checked
* otherwise, it is not
@ -141,8 +146,7 @@ public class CRCAlgorithm {
for (int i = 0; i < p.size(); i++) {
if (x.get(i) == p.get(i)) {
x.set(i, 0);
}
else{
} else {
x.set(i, 1);
}
}
@ -156,15 +160,12 @@ public class CRCAlgorithm {
for (int z : dividedMessage) {
message.add(z);
}
}
else{
} else {
if (dividedMessage.contains(1) && messageChanged) {
wrongMessCaught++;
}
else if(!dividedMessage.contains(1) && messageChanged){
} else if (!dividedMessage.contains(1) && messageChanged) {
wrongMessNotCaught++;
}
else if(!messageChanged){
} else if (!messageChanged) {
correctMess++;
}
}
@ -190,8 +191,7 @@ public class CRCAlgorithm {
messageChanged = true;
if (y == 1) {
message.set(message.indexOf(y), 0);
}
else{
} else {
message.set(message.indexOf(y), 1);
}
}
@ -200,5 +200,4 @@ public class CRCAlgorithm {
wrongMess++;
}
}
}