Skip to content
This repository has been archived by the owner on Mar 11, 2019. It is now read-only.

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
None.
  • Loading branch information
Unknown committed May 12, 2018
1 parent 81f1be0 commit c8c2fc4
Show file tree
Hide file tree
Showing 16 changed files with 346 additions and 304 deletions.
328 changes: 156 additions & 172 deletions .idea/workspace.xml

Large diffs are not rendered by default.

80 changes: 79 additions & 1 deletion main.nzprofile
Original file line number Diff line number Diff line change
@@ -1 +1,79 @@
{"color_settings":{"color_4":{"color_G":0,"color_R":0,"color_B":0},"color_5":{"color_G":0,"color_R":0,"color_B":0},"color_6":{"color_G":0,"color_R":0,"color_B":0},"color_7":{"color_G":0,"color_R":0,"color_B":0},"color_mode":0,"color_8":{"color_G":0,"color_R":0,"color_B":0},"color_0":{"color_G":1,"color_R":0,"color_B":0},"color_1":{"color_G":2,"color_R":255,"color_B":0},"color_2":{"color_G":0,"color_R":0,"color_B":0},"color_3":{"color_G":0,"color_R":0,"color_B":0}},"pump_settings":{"100_degrees":100,"50_degrees":25,"20_degrees":25,"70_degrees":50,"0_degrees":25,"90_degrees":50,"60_degrees":50,"30_degrees":25,"10_degrees":25,"40_degrees":25,"80_degrees":50},"fan_settings":{"100_degrees":100,"50_degrees":60,"20_degrees":60,"70_degrees":60,"0_degrees":60,"90_degrees":60,"60_degrees":60,"30_degrees":60,"10_degrees":100,"40_degrees":100,"80_degrees":100},"id":2222,"nzreal_class_version":4,"temperature_warning":89}
{
"color_settings":{
"color_4":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_5":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_6":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_7":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_mode":0,
"color_8":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_0":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_1":{
"color_G":2,
"color_R":255,
"color_B":255
},
"color_2":{
"color_G":255,
"color_R":255,
"color_B":255
},
"color_3":{
"color_G":255,
"color_R":255,
"color_B":255
}
},
"pump_settings":{
"100_degrees":100,
"50_degrees":100,
"20_degrees":100,
"70_degrees":100,
"0_degrees":100,
"90_degrees":100,
"60_degrees":100,
"30_degrees":100,
"10_degrees":100,
"40_degrees":100,
"80_degrees":100
},
"fan_settings":{
"100_degrees":100,
"50_degrees":100,
"20_degrees":100,
"70_degrees":100,
"0_degrees":100,
"90_degrees":100,
"60_degrees":100,
"30_degrees":100,
"10_degrees":100,
"40_degrees":100,
"80_degrees":100
},
"id":1002,
"nzreal_class_version":3,
"temperature_warning":89
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>com.project.pcmr</groupId>
<artifactId>nzos</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0.2</version>
<packaging>jar</packaging>

<name>nzOS</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import com.profesorfalken.jsensors.model.sensors.Load;
import com.profesorfalken.jsensors.model.sensors.Temperature;
import com.project.pcmr.nzos.json_reader.FileManagement;
import org.json.simple.JSONObject;


import java.util.List;

Expand Down
107 changes: 56 additions & 51 deletions src/main/java/com/project/pcmr/nzos/json_reader/FileManagement.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,19 @@
import org.apache.logging.log4j.Logger;
import org.json.simple.JSONObject;
import org.json.simple.parser.JSONParser;
import org.junit.Assert;

import java.io.*;
import java.lang.reflect.Array;
import java.nio.ByteBuffer;
import java.nio.LongBuffer;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;


Expand All @@ -27,15 +31,15 @@ public class FileManagement<T> implements InterfaceFileManagment<T> {
/**
* Metoda służaca do czytania pojedynczych obiektów.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa pojedynczego obiektu do odczytu.
* @return Zwraca wartość zapisaną w obiekcie.
*/
@Override
public T readingFile(String FILENAME, String OBJECT) {
public T readingFile(String filename, String OBJECT) {
T name = null;
try {
Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
name = (T) jsonObject.get(OBJECT);

Expand All @@ -49,17 +53,17 @@ public T readingFile(String FILENAME, String OBJECT) {
/**
* Metoda służaca do czytania obiektu w obiekcie.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do odczytu.
* @param ALTOBJECT Nazwa obiektu do odczytu.
* @return Zwraca wartość zapisaną w obiekcie.
*/
@Override
public T readingFile(String FILENAME, String OBJECT, String ALTOBJECT) {
public T readingFile(String filename, String OBJECT, String ALTOBJECT) {
T name = null;
try {

Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonObject1 = (JSONObject) jsonObject.get(OBJECT);
name = (T) jsonObject1.get(ALTOBJECT);
Expand All @@ -74,18 +78,18 @@ public T readingFile(String FILENAME, String OBJECT, String ALTOBJECT) {
/**
* Metoda służaca do czytania obiektu w obiekcie w obiekcie (Obiekto incepcja).
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do odczytu.
* @param ALTOBJECT Nazwa obiektu do odczytu.
* @param ALTALTOBJECT Nazwa obiektu do odczytu.
* @return Zwraca wartość zapisaną w obiekcie.
*/
@Override
public T readingFile(String FILENAME, String OBJECT, String ALTOBJECT, String ALTALTOBJECT) {
public T readingFile(String filename, String OBJECT, String ALTOBJECT, String ALTALTOBJECT) {
T name = null;
try {

Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonObject1 = (JSONObject) jsonObject.get(OBJECT);
JSONObject jsonObject2 = (JSONObject) jsonObject1.get(ALTOBJECT);
Expand All @@ -101,17 +105,17 @@ public T readingFile(String FILENAME, String OBJECT, String ALTOBJECT, String AL
/**
* Metoda służaca do zapisania obiektu.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do zapisu.
* @param VALUE Wartość do zapisu.
*/
@Override
public void writingFile(String FILENAME, String OBJECT, T VALUE) {
public void writingFile(String filename, String OBJECT, T VALUE) {
try {
Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
jsonObject.put(OBJECT, VALUE);
writingFile(FILENAME, jsonObject);
writingFile(filename, jsonObject);
} catch (Exception e) {
logger.error("File saving problem or no search value in the file: " + e);
e.printStackTrace();
Expand All @@ -121,19 +125,19 @@ public void writingFile(String FILENAME, String OBJECT, T VALUE) {
/**
* Metoda służaca do zapisania obiektu w obiekcie.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do zapisu.
* @param ALTOBJECT Nazwa obiektu do odczytu.
* @param VALUE Wartość do zapisu.
*/
@Override
public void writingFile(String FILENAME, String OBJECT, String ALTOBJECT, T VALUE) {
public void writingFile(String filename, String OBJECT, String ALTOBJECT, T VALUE) {
try {
Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonObject1 = (JSONObject) jsonObject.get(OBJECT);
jsonObject1.put(ALTOBJECT, VALUE);
writingFile(FILENAME, jsonObject);
writingFile(filename, jsonObject);
} catch (Exception e) {
logger.error("File saving problem or no search value in the file: " + e);
e.printStackTrace();
Expand All @@ -143,21 +147,21 @@ public void writingFile(String FILENAME, String OBJECT, String ALTOBJECT, T VALU
/**
* Metoda służaca do zapisania obiektu w obiekcie w obiekcie.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do zapisu.
* @param ALTOBJECT Nazwa obiektu do odczytu.
* @param ALTALTOBJECT Nazwa obiektu do odczytu.
* @param VALUE Wartość do zapisu.
*/
@Override
public void writingFile(String FILENAME, String OBJECT, String ALTOBJECT, String ALTALTOBJECT, T VALUE) {
public void writingFile(String filename, String OBJECT, String ALTOBJECT, String ALTALTOBJECT, T VALUE) {
try {
Object obj = parser.parse(new FileReader(DIR + "\\" + FILENAME));
Object obj = parser.parse(new FileReader(DIR + "\\" + filename));
JSONObject jsonObject = (JSONObject) obj;
JSONObject jsonObject1 = (JSONObject) jsonObject.get(OBJECT);
JSONObject jsonObject2 = (JSONObject) jsonObject1.get(ALTOBJECT);
jsonObject2.put(ALTALTOBJECT, VALUE);
writingFile(FILENAME, jsonObject);
writingFile(filename, jsonObject);

} catch (Exception e) {
logger.error("File saving problem or no search value in the file: " + e);
Expand All @@ -168,13 +172,13 @@ public void writingFile(String FILENAME, String OBJECT, String ALTOBJECT, String
/**
* Metoda służaca do zapisu pliku.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param JSON_OBJECT Wskaźnik na obiekt Json.
*/
@Override
public void writingFile(String FILENAME, JSONObject JSON_OBJECT) {
public void writingFile(String filename, JSONObject JSON_OBJECT) {
try {
FileWriter file = new FileWriter(DIR + "\\" + FILENAME);
FileWriter file = new FileWriter(DIR + "\\" + filename);
try {
file.write(JSON_OBJECT.toJSONString());

Expand All @@ -194,35 +198,32 @@ public void writingFile(String FILENAME, JSONObject JSON_OBJECT) {
/**
* Metoda służaca do zapisu pliku.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param TEXT Tekst do zapisu.
* @param filename Nazwa pliku do odczytu.
* @param TEXT Tekst do zapisu.
*/
public void writingFile(String FILENAME, String TEXT)
{
final String DIR = System.getProperty("user.dir");
public void writingFile(String filename, String TEXT) {
final String DIR = System.getProperty("user.dir");
try (Writer writer = new BufferedWriter(new OutputStreamWriter(
new FileOutputStream(DIR + "\\" + FILENAME), "utf-8"))) {
new FileOutputStream(DIR + "\\" + filename), "utf-8"))) {
writer.write(TEXT);
}
catch (Exception e)
{
} catch (Exception e) {
logger.error("Problem with creating a file: " + e);
}
}

/**
* Metoda służąca do odczytu barw i zapisu jej do tablicy.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
*/
public byte[] colorArray(String FILENAME) {
public byte[] colorArray(String filename) {
byte[] CALLBACK = new byte[27];
ByteBuffer byteBuffer = ByteBuffer.allocate(216);
LongBuffer intBuffer = byteBuffer.asLongBuffer();
String[] temp = {"G", "R", "B"};
for (int i = 0; i < 9; i++) {
for (String s : temp) {
intBuffer.put((Long) readingFile(FILENAME, "color_settings", "color_" + i, "color_" + s));
intBuffer.put((Long) readingFile(filename, "color_settings", "color_" + i, "color_" + s));
}
}
byte[] array = byteBuffer.array();
Expand All @@ -235,48 +236,52 @@ public byte[] colorArray(String FILENAME) {
}


public long[] colorLongArray(String FILENAME) {
public long[] colorLongArray(String filename) {
LongBuffer byteBuffer = LongBuffer.allocate(27);
String[] temp = {"G", "R", "B"};
for (int i = 0; i < 9; i++) {
for (String s : temp) {
byteBuffer.put((Long) readingFile(FILENAME, "color_settings", "color_" + i, "color_" + s));
byteBuffer.put((Long) readingFile(filename, "color_settings", "color_" + i, "color_" + s));
}
}
return byteBuffer.array();
}

/**
* Metoda służaca do zamiany tablicy na listę.
*
* @param FILENAME Nazwa pliku do odczytu.
* @param filename Nazwa pliku do odczytu.
* @param OBJECT Nazwa obiektu do pobrania.
* @param ALTOBJECT Nazwa obiektu do pobrania.
* @return Lista z obiektami.
*/
public List<T> arrayToList(String FILENAME, String OBJECT, String ALTOBJECT) {
public List<T> arrayToList(String filename, String OBJECT, String ALTOBJECT) {
List<T> List = new ArrayList();
String AltObject;

for (int i = 0; i <= 100; i = i + 10) {
AltObject = i + ALTOBJECT;
List.add(readingFile(FILENAME, OBJECT, AltObject));
List.add(readingFile(filename, OBJECT, AltObject));
}

return List;
}


public void showLogFile(String FILENAME)
{
String fileName = DIR + "\\logs\\" + FILENAME;

//read file into stream, try-with-resources
try (Stream<String> stream = Files.lines(Paths.get(fileName))) {
public ArrayList<String> showLogFile(String filename) {
String fileName = DIR + "\\logs\\" + filename;
ArrayList<String> al = new ArrayList<>();

stream.forEach(System.out::println);

} catch (IOException e) {
e.printStackTrace();
try {
BufferedReader lineReader = new BufferedReader(new FileReader(fileName));
String lineText = null;
while ((lineText = lineReader.readLine()) != null) {
al.add(lineText);
}
lineReader.close();
} catch (IOException ex) {
logger.error("Problem with log reading: " + ex);
}
return al;
}
}
Loading

0 comments on commit c8c2fc4

Please sign in to comment.