Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c2dc158
Update README.md
eugene-krivosheyev Oct 11, 2021
b42e1be
Add recordings.
eugene-krivosheyev Oct 11, 2021
01c8c2b
Added a new maintainer
teptind Oct 12, 2021
7338bf5
Add new maintainer
tim-papaya Oct 12, 2021
2f74866
Add recordings.
eugene-krivosheyev Oct 12, 2021
2afeb4f
Fix LoggerTest by replacing line endings with System.lineSeparator()
tim-papaya Oct 13, 2021
4c537db
Change sep to private
tim-papaya Oct 13, 2021
95bc9f0
Format maintainers
tim-papaya Oct 13, 2021
202d9d5
Add demo for primitive types.
Oct 13, 2021
4592bf9
Add recordings.
eugene-krivosheyev Oct 14, 2021
9fc8227
Add demo for Type Overflow and FP Precision loss.
Oct 14, 2021
ec31f6b
Add demo for Reference Type.
Oct 14, 2021
8cdcc37
Create logChar
tim-papaya Oct 14, 2021
1b9571e
Create logString
tim-papaya Oct 14, 2021
cfd3b64
Create logBoolean
tim-papaya Oct 14, 2021
7534df2
Create logObject
tim-papaya Oct 14, 2021
cc114cb
Refactor duplications
tim-papaya Oct 14, 2021
0cf77c4
Refactor print
tim-papaya Oct 14, 2021
1e55675
Add demo for String and Wrappers interning.
Oct 14, 2021
ed7961a
Add demo for operators.
Oct 14, 2021
90a89b9
Add recordings.
eugene-krivosheyev Oct 14, 2021
c32c854
Add demo for Wrappers.
Oct 15, 2021
377e430
Add demo for cyclomatic complexity.
Oct 15, 2021
6cb93d7
[LoggerTest] Log int and byte with overflow, count string
tim-papaya Oct 15, 2021
1aadddc
[LoggerTest] Refactor int and byte overflow
tim-papaya Oct 15, 2021
fd159eb
[LoggerTest] Refactor constants
tim-papaya Oct 15, 2021
2ede712
Add demo for code reuse.
Oct 15, 2021
edee97a
Add demo for arrays;
Oct 15, 2021
099b472
Add demo for varargs.
Oct 15, 2021
1d0914e
Add demo for varargs overloading.
Oct 15, 2021
3a55218
Add recordings.
eugene-krivosheyev Oct 15, 2021
47810d1
Fix requirements for iteration 03.
Oct 18, 2021
6a7981d
Add arch hypothesis for iteration 03.
Oct 18, 2021
be53fe4
Merge branch '2021-10-db'
tim-papaya Oct 18, 2021
a43282e
[LoggerTest] Add array and matrix
tim-papaya Oct 18, 2021
df7d165
[LoggerTest] Refactor log(String)
tim-papaya Oct 18, 2021
29a5bca
[LoggerTest] Add accumulation for arrays
tim-papaya Oct 19, 2021
9e857cd
[LoggerTest] Refactor to OOP design
tim-papaya Oct 20, 2021
eeb10c7
[LoggerTest] Refactor to OOP design 1 iteration
tim-papaya Oct 21, 2021
54f0e32
[LoggerTest] Fix String duplication
tim-papaya Oct 21, 2021
5040297
added varargs and matrix log overloading
teptind Oct 21, 2021
673e0cc
Added tests and migrated to JUnit5
teptind Oct 25, 2021
bd45458
Add test coverage report.
Oct 25, 2021
48f83b9
Add mutation testing report.
Oct 25, 2021
5e2c85f
Fix pitest in pom, disable first iterations
Oct 25, 2021
e1ad422
Add exceptions
tim-papaya Oct 26, 2021
771d88d
Refactor append to return a few messages
tim-papaya Oct 27, 2021
c6e1717
Refactor tests
tim-papaya Oct 27, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,16 @@
# Maintainers:
Daniil Teptin, Tagir Minibaev

# Java Junior Developer Training Course.
88 hours training + 32 hours work project = 120 hr.

# Recordings
- [11.10](https://us02web.zoom.us/rec/share/4K_bvC_0q8nvkzo26fSbcMVPM2uWzlQ9kqT2BbdbcQe-qeAdinWuF-rPfFBA0Pyp.R2IQ39ujDDEZjv1C)
- [12.10](https://us02web.zoom.us/rec/share/IwiS9NXzVEhoBHgAwCJX6SIVhnfKfq2YeTctQMByD4n_UrFCdeaEkGXDxzPBgxZy.4wsHSeX8T1s4IYNk)
- [13.10](https://us02web.zoom.us/rec/share/_OVUvUZVlz2vRyM2nXZKOp9dPsbeEZhevRc1iuU-YMyfIhaAJ_mjjQ8sAcM_P6_V.IsA920-72jNMeF5i)
- [14.10](https://us02web.zoom.us/rec/share/FLno-ISY6mZZDbzwtfZ0DUWKSlUPNwTOK-hFO5jrd3ed1hSOzGaOHLbl3yFX7yEu.b-uJykoOquFRQCY0)
- [15.10](https://us02web.zoom.us/rec/share/9ZC-sDNnL9VtDWp6JcfTa0BxeEURuszfEUva7rHm7DEUXgNqy0CHXckKltTQUAyu.iNA5x7BXdlq_VfWc)

---

# Introduction to Java and Java Technology (*1* hour theory / *including 0.5* hour practice)
Expand Down Expand Up @@ -633,3 +643,8 @@ assertMessageEquals("3")
- PM and Business Customers accept product with six demo sessions

---

# Парковка
- Spring: Core, MVC, Boot
- DB: JDBC, Templates, JPA
- CI: Jenkins, Sonar
88 changes: 83 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,96 @@
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<source>11</source>
<target>11</target>
</configuration>
</plugin>

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M5</version>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>report</id>
<phase>verify</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.pitest</groupId>
<artifactId>pitest-maven</artifactId>
<version>1.7.2</version>
<dependencies>
<dependency>
<groupId>org.pitest</groupId>
<artifactId>pitest-junit5-plugin</artifactId>
<version>0.15</version>
</dependency>
</dependencies>
<configuration>
<targetClasses>
<param>com.acme.edu.*</param>
</targetClasses>
<targetTests>
<param>com.acme.edu.*</param>
</targetTests>
<verbose>true</verbose>
</configuration>
<executions>
<execution>
<id>mutation-coverage</id>
<goals>
<goal>mutationCoverage</goal>
</goals>
</execution>
<execution>
<id>mutation-report</id>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>

<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.21.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.0.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
57 changes: 55 additions & 2 deletions src/main/java/com/acme/edu/Logger.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,64 @@
package com.acme.edu;

import com.acme.edu.controller.Controller;
import com.acme.edu.message.*;
import com.acme.edu.saver.ConsoleSaver;

public class Logger {

private static final Controller controller = new Controller(new ConsoleSaver());

private static void arrayLog(int message) {
controller.log(new ArrayNumberMessage(Integer.MAX_VALUE, Integer.MIN_VALUE, message));
}

public static void log(int... message) {
for (int i : message) {
arrayLog(i);
}
}

public static void log(int[][] message) {
for (int[] arr : message) {
log(arr);
}
}

public static void log(int message) {
System.out.println("primitive: " + message);
controller.log(new SingleNumberMessage(Integer.MAX_VALUE, Integer.MIN_VALUE, message));
}

public static void log(byte message) {
System.out.println("primitive: " + message);
controller.log(new SingleNumberMessage(Byte.MAX_VALUE, Byte.MIN_VALUE, message));
}

public static void flush() {
controller.flush();
}

public static void log(String... message) {
for (String str : message) {
log(str);
}
}

public static void log(String message) {
controller.log(new StringMessage(message));
}

public static void log(char message) {
controller.log(new CharMessage(message));
}

public static void log(boolean message) {
controller.log(new BooleanMessage(message));
}

public static void log(Object message) {
controller.log(new ReferenceMessage(message));
}

private Logger() {
}

}
15 changes: 15 additions & 0 deletions src/main/java/com/acme/edu/Utils.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.acme.edu;

import java.util.Arrays;
import java.util.stream.Stream;

public class Utils {
private static Stream<Object> flatten(Object[] array) {
return Arrays.stream(array)
.flatMap(o -> o instanceof Object[] ? flatten((Object[])o) : Stream.of(o));
}

public static Object[] getFlatArray(Object[] array) {
return flatten(array).toArray();
}
}
43 changes: 43 additions & 0 deletions src/main/java/com/acme/edu/controller/Controller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.acme.edu.controller;

import com.acme.edu.exception.LogException;
import com.acme.edu.message.Message;
import com.acme.edu.saver.Saver;

public class Controller {

private final Saver saver;

private Message messageBuffer;

public Controller(Saver saver) {
this.saver = saver;
}

public void log(Message message) {
if (message == null) throw new IllegalArgumentException("Received message is null");

if (messageBuffer == null) {
messageBuffer = message;
} else if (messageBuffer.canAppend(message)) {
Message[] messageArray = messageBuffer.append(message);
flushAllOverflowingMessages(messageArray);
messageBuffer = messageArray[messageArray.length - 1];
} else {
flush();
messageBuffer = message;
}
}

public void flush() {
saver.save(messageBuffer.getBody());
messageBuffer = null;
}

private void flushAllOverflowingMessages(Message[] messageArray) {
for (int i = 0; i < messageArray.length - 1; i++) {
messageBuffer = messageArray[i];
flush();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.acme.edu.exception;

public class IllegalMessageStateException extends LogException {
public IllegalMessageStateException(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/acme/edu/exception/LogException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.acme.edu.exception;

public class LogException extends RuntimeException {
public LogException(String message) {
super(message);
}
}
7 changes: 7 additions & 0 deletions src/main/java/com/acme/edu/exception/SavingException.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.acme.edu.exception;

public class SavingException extends LogException {
public SavingException(String message) {
super(message);
}
}
18 changes: 18 additions & 0 deletions src/main/java/com/acme/edu/message/ArrayNumberMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.acme.edu.message;

public class ArrayNumberMessage extends OverflowingMessage {

public ArrayNumberMessage(long maxLimit, long minLimit, long number) {
super(maxLimit, minLimit, number);
}

@Override
protected OverflowingMessage createSpecificMessage(long number) {
return new ArrayNumberMessage(maxLimit, minLimit, number);
}

@Override
public boolean canAppend(Message message) {
return message instanceof ArrayNumberMessage && checkLimits((ArrayNumberMessage) message);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/acme/edu/message/BooleanMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.acme.edu.message;

public class BooleanMessage implements Message {

protected static final String BOOLEAN_PREFIX = "primitive: ";

private final boolean accumulator;

public BooleanMessage(boolean bool) {
this.accumulator = bool;
}

@Override
public Message[] append(Message message) {
return new Message[]{ message };
}

@Override
public String getBody() {
return BOOLEAN_PREFIX + accumulator;
}

@Override
public boolean canAppend(Message message) {
return false;
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/acme/edu/message/CharMessage.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.acme.edu.message;

public class CharMessage implements Message {

protected static final String CHAR_PREFIX = "char: ";

private final char accumulator;

public CharMessage(char ch) {
this.accumulator = ch;
}

@Override
public Message[] append(Message message) {
return new Message[]{message};
}

@Override
public String getBody() {
return CHAR_PREFIX + accumulator;
}

@Override
public boolean canAppend(Message message) {
return false;
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/acme/edu/message/Message.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.acme.edu.message;

public interface Message {
/**
* @return First messages of the array contain data about overflow.
* The last one message (with index = Message[].lenght - 1) contains remainder of
* append operation.
* If there is no overflow, it returns an array with one message.
*/
Message[] append(Message message);

String getBody();

boolean canAppend(Message message);
}
Loading