Skip to content

Commit

Permalink
Merge pull request #4 from bruch-alex/maven-integration
Browse files Browse the repository at this point in the history
add maven and JLine
  • Loading branch information
bruch-alex authored Jul 13, 2024
2 parents 35e9114 + d3315ec commit a5ae1c1
Show file tree
Hide file tree
Showing 13 changed files with 316 additions and 68 deletions.
23 changes: 22 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,25 @@
*.ear
*.zip
*.tar.gz
*.rar
*.rar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

target/
pom.xml.tag
pom.xml.releaseBackup
pom.xml.versionsBackup
pom.xml.next
release.properties
dependency-reduced-pom.xml
buildNumber.properties
.mvn/timing.properties
# https://github.com/takari/maven-wrapper#usage-without-binary-jar
.mvn/wrapper/maven-wrapper.jar

# Eclipse m2e generated files
# Eclipse Core
.project
# JDT-specific (Eclipse Java Development Tools)
.classpath
13 changes: 13 additions & 0 deletions .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions .idea/encodings.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions .idea/hamming-code.iml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 20 additions & 0 deletions .idea/jarRepositories.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 9 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

124 changes: 124 additions & 0 deletions .idea/uiDesigner.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 63 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>hamming-code</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
Main
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>Main</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>

</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.jline</groupId>
<artifactId>jline</artifactId>
<version>3.26.2</version>
</dependency>
</dependencies>

</project>
12 changes: 1 addition & 11 deletions src/main/Coder.java → src/main/java/Coder.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,5 @@
package main;

import java.util.Scanner;

public class Coder {
public static String startCoder(Scanner s) {
System.out.println("Enter the message you want to encode: ");
String message = s.nextLine();
//Helpers.clearConsole();
//System.out.println("You entered: " + message);

public static String startCoder(String message) {
StringBuilder result = new StringBuilder();

for (char c : message.toCharArray()){
Expand All @@ -18,7 +9,6 @@ public static String startCoder(Scanner s) {
result.append(binaryCharWithCalculatedParityBits);
}
return result.toString();
//System.out.println("Your encoded text: \n\n" + result);
}

/**
Expand Down
16 changes: 6 additions & 10 deletions src/main/Decoder.java → src/main/java/Decoder.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,14 @@
package main;
import org.jline.reader.LineReader;

import java.util.Scanner;

public class Decoder {
public static void startDecoder() {
Scanner s = new Scanner(System.in);
System.out.println("Enter the message you want to decode: ");
String messageWithParityBits = s.nextLine();

public static String startDecoder(String message) {
boolean withErrors = false;
StringBuilder sb = new StringBuilder(messageWithParityBits);
StringBuilder sb = new StringBuilder(message);
StringBuilder result = new StringBuilder();

for (int i = 0; i < messageWithParityBits.length(); i+=12) {
for (int i = 0; i < message.length(); i+=12) {
String binaryCharWithParityBits = sb.substring(i , i+12);
int positionOfDamagedBit = checkAllControlBits(binaryCharWithParityBits);
if (positionOfDamagedBit != 0) {
Expand All @@ -25,7 +21,7 @@ public static void startDecoder() {
if (!withErrors){
System.out.println("!!!Received without errors!!!");
}
System.out.println("Your message: \n\n" + result);
return result.toString();
}

private static char decode(String messageWithControlBits){
Expand Down Expand Up @@ -56,7 +52,7 @@ private static int checkAllControlBits(String messageWithControlBits){
for (int i = 0; i < messageWithControlBits.length(); i++) {
if (Helpers.checkPosition(i)) {
sb.replace(i,i+1, "0");
int controlBitValue = Helpers.calculateParityBitValue(sb, i);
int controlBitValue = Helpers.calculateParityBitValue(i, sb);
if (Character.digit(messageWithControlBits.charAt(i),10) != controlBitValue)
{
positionsOfWrongBits += (i +1);
Expand Down
Loading

0 comments on commit a5ae1c1

Please sign in to comment.