mirror of
https://github.com/Example-uPagge/debugger.git
synced 2024-06-14 11:22:32 +03:00
Добавил примеры для дебага
This commit is contained in:
commit
aec1f4f0b4
85
.gitignore
vendored
Normal file
85
.gitignore
vendored
Normal file
@ -0,0 +1,85 @@
|
||||
*.class
|
||||
*.log
|
||||
*.ctxt
|
||||
.mtj.tmp/
|
||||
*.jar
|
||||
*.war
|
||||
*.nar
|
||||
*.ear
|
||||
*.zip
|
||||
*.tar.gz
|
||||
*.rar
|
||||
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
|
||||
.mvn/wrapper/maven-wrapper.jar
|
||||
.idea/**/workspace.xml
|
||||
.idea/**/tasks.xml
|
||||
.idea/**/usage.statistics.xml
|
||||
.idea/**/dictionaries
|
||||
.idea/**/shelf
|
||||
.idea/**/contentModel.xml
|
||||
.idea/**/dataSources/
|
||||
.idea/**/dataSources.ids
|
||||
.idea/**/dataSources.local.xml
|
||||
.idea/**/sqlDataSources.xml
|
||||
.idea/**/dynamic.xml
|
||||
.idea/**/uiDesigner.xml
|
||||
.idea/**/dbnavigator.xml
|
||||
.idea/**/gradle.xml
|
||||
.idea/**/libraries
|
||||
cmake-build-*/
|
||||
.idea/**/mongoSettings.xml
|
||||
*.iws
|
||||
out/
|
||||
.idea_modules/
|
||||
atlassian-ide-plugin.xml
|
||||
.idea/replstate.xml
|
||||
com_crashlytics_export_strings.xml
|
||||
crashlytics.properties
|
||||
crashlytics-build.properties
|
||||
fabric.properties
|
||||
.idea/httpRequests
|
||||
.idea/caches/build_file_checksums.ser
|
||||
*~
|
||||
.fuse_hidden*
|
||||
.directory
|
||||
.Trash-*
|
||||
.nfs*
|
||||
Thumbs.db
|
||||
Thumbs.db:encryptable
|
||||
ehthumbs.db
|
||||
ehthumbs_vista.db
|
||||
*.stackdump
|
||||
[Dd]esktop.ini
|
||||
$RECYCLE.BIN/
|
||||
*.cab
|
||||
*.msi
|
||||
*.msix
|
||||
*.msm
|
||||
*.msp
|
||||
*.lnk
|
||||
.DS_Store
|
||||
.AppleDouble
|
||||
.LSOverride
|
||||
Icon
|
||||
._*
|
||||
.DocumentRevisions-V100
|
||||
.fseventsd
|
||||
.Spotlight-V100
|
||||
.TemporaryItems
|
||||
.Trashes
|
||||
.VolumeIcon.icns
|
||||
.com.apple.timemachine.donotpresent
|
||||
.AppleDB
|
||||
.AppleDesktop
|
||||
Network Trash Folder
|
||||
Temporary Items
|
||||
.apdisk
|
24
pom.xml
Normal file
24
pom.xml
Normal file
@ -0,0 +1,24 @@
|
||||
<?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>dev.struchkov</groupId>
|
||||
<artifactId>debugger</artifactId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
|
||||
<properties>
|
||||
<maven.compiler.source>17</maven.compiler.source>
|
||||
<maven.compiler.target>17</maven.compiler.target>
|
||||
</properties>
|
||||
|
||||
<dependencies>
|
||||
<dependency>
|
||||
<groupId>dev.struchkov.haiti</groupId>
|
||||
<artifactId>haiti-utils</artifactId>
|
||||
<version>0.0.3</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -0,0 +1,11 @@
|
||||
package dev.struchkov.example.debugger.box;
|
||||
|
||||
public class SurpriseBox {
|
||||
|
||||
public static void surpriseOne(int i) {
|
||||
if (i == 896) {
|
||||
throw new SurpriseException("Сюрприииииииз");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.struchkov.example.debugger.box;
|
||||
|
||||
public class SurpriseException extends RuntimeException {
|
||||
|
||||
public SurpriseException(String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.struchkov.example.debugger.five;
|
||||
|
||||
public class Calculator {
|
||||
|
||||
public boolean process(long a, long b) {
|
||||
return Math.max(a, b) % 2 == 0;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.struchkov.example.debugger.five;
|
||||
|
||||
public class FiveExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final Calculator calculator = new Calculator();
|
||||
System.out.println();
|
||||
System.out.println(calculator.process(10L, 2L));
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
package dev.struchkov.example.debugger.four;
|
||||
|
||||
public class Entity {
|
||||
|
||||
private String field;
|
||||
|
||||
public Entity(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
public String getField() {
|
||||
return field;
|
||||
}
|
||||
|
||||
public void setField(String field) {
|
||||
this.field = field;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return field;
|
||||
}
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dev.struchkov.example.debugger.four;
|
||||
|
||||
public class ExampleFour {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final ThirdService thirdService = new ThirdService();
|
||||
final SecondService secondService = new SecondService(thirdService);
|
||||
final FirstService firstService = new FirstService(secondService);
|
||||
|
||||
final Entity entity = new Entity("Dasha");
|
||||
firstService.processing(entity);
|
||||
|
||||
System.out.println();
|
||||
System.out.println(entity);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
package dev.struchkov.example.debugger.four;
|
||||
|
||||
import dev.struchkov.example.debugger.box.SurpriseException;
|
||||
|
||||
public class FirstService {
|
||||
|
||||
private final SecondService secondService;
|
||||
|
||||
public FirstService(SecondService secondService) {
|
||||
this.secondService = secondService;
|
||||
}
|
||||
|
||||
public void processing(Entity entity) {
|
||||
valid(entity.getField());
|
||||
secondService.processing(entity);
|
||||
final String newField = entity.getField();
|
||||
entity.setField("\033[31;1;4m" + newField + "!\033[0m");
|
||||
}
|
||||
|
||||
private void valid(String field) {
|
||||
if (field.equals("Masha")) {
|
||||
throw new SurpriseException("Ошибочка вышла");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
package dev.struchkov.example.debugger.four;
|
||||
|
||||
public class SecondService {
|
||||
|
||||
private final ThirdService thirdService;
|
||||
|
||||
public SecondService(ThirdService thirdService) {
|
||||
this.thirdService = thirdService;
|
||||
}
|
||||
|
||||
public void processing(Entity entity) {
|
||||
thirdService.processing(entity);
|
||||
final String field = entity.getField();
|
||||
entity.setField("Nice to " + field);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,9 @@
|
||||
package dev.struchkov.example.debugger.four;
|
||||
|
||||
public class ThirdService {
|
||||
|
||||
public void processing(Entity entity) {
|
||||
entity.setField("meet you " + entity.getField());
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,24 @@
|
||||
package dev.struchkov.example.debugger.one;
|
||||
|
||||
public class ExampleOne {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final PersonService personService = new PersonService();
|
||||
|
||||
demoOne(personService);
|
||||
// demoTwo(personService);
|
||||
}
|
||||
|
||||
private static void demoOne(PersonService personService) {
|
||||
personService.showAllPerson();
|
||||
personService.deleteAllByLastName("Иванов");
|
||||
personService.showAllPerson();
|
||||
}
|
||||
|
||||
private static void demoTwo(PersonService personService) {
|
||||
personService.showAllPerson();
|
||||
personService.correctDeleteAllByLastName("Скворцова");
|
||||
personService.showAllPerson();
|
||||
}
|
||||
|
||||
}
|
47
src/main/java/dev/struchkov/example/debugger/one/Person.java
Normal file
47
src/main/java/dev/struchkov/example/debugger/one/Person.java
Normal file
@ -0,0 +1,47 @@
|
||||
package dev.struchkov.example.debugger.one;
|
||||
|
||||
public class Person {
|
||||
|
||||
private Long id;
|
||||
private String firstName;
|
||||
private String lastName;
|
||||
|
||||
public Person(Long id, String firstName, String lastName) {
|
||||
this.id = id;
|
||||
this.firstName = firstName;
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
public Long getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public void setId(Long id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
||||
public String getFirstName() {
|
||||
return firstName;
|
||||
}
|
||||
|
||||
public void setFirstName(String firstName) {
|
||||
this.firstName = firstName;
|
||||
}
|
||||
|
||||
public String getLastName() {
|
||||
return lastName;
|
||||
}
|
||||
|
||||
public void setLastName(String lastName) {
|
||||
this.lastName = lastName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Person{" +
|
||||
"id=" + id +
|
||||
", firstName='" + firstName + '\'' +
|
||||
", lastName='" + lastName + '\'' +
|
||||
'}';
|
||||
}
|
||||
}
|
@ -0,0 +1,51 @@
|
||||
package dev.struchkov.example.debugger.one;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
public class PersonService {
|
||||
|
||||
private final Map<Long, Person> names = new HashMap<>();
|
||||
|
||||
public PersonService() {
|
||||
init();
|
||||
}
|
||||
|
||||
public void deleteAllByLastName(String lastName) {
|
||||
for (Person person : names.values()) {
|
||||
if (lastName.equals(person.getLastName())) {
|
||||
names.remove(person.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showAllPerson() {
|
||||
System.out.println("\nПользователи системы:");
|
||||
names.values().forEach(System.out::println);
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
public void init() {
|
||||
names.putAll(
|
||||
Map.of(
|
||||
1L, new Person(1L, "Алексей", "Кашемиров"),
|
||||
2L, new Person(2L, "Никита", "Иванов"),
|
||||
3L, new Person(3L, "Иван", "Сизов"),
|
||||
4L, new Person(4L, "Михаил", "Иванов"),
|
||||
5L, new Person(5L, "Ксения", "Cкорцова")
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
public void correctDeleteAllByLastName(String lastName) {
|
||||
final Iterator<Person> iterator = names.values().iterator();
|
||||
while (iterator.hasNext()) {
|
||||
final Person person = iterator.next();
|
||||
if (lastName.equals(person.getLastName())) {
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,15 @@
|
||||
/**
|
||||
* <p>Первый пакет, который вводит в общую суть дебага</p>
|
||||
* <p></p>
|
||||
* <p>Пример строится на исключении ConcurrentModificationException при попытке удаления сщуности из Map во время ее обхода.</p>
|
||||
* <p></p>
|
||||
* <h2><b>Что тут можно показать:</b></h2>
|
||||
* <ol>
|
||||
* <li>Как поставить брекпойнт. На примере PersonService</li>
|
||||
* <li></li>
|
||||
* </ol>
|
||||
* <h2>Сценарий</h2>
|
||||
* <p>Первым делом просто запускаем ExampleOne. Видим, что происходит исключение. Рассказываем из-за чего оно произошло. И напоминаем что такое stack trace и что по нему можно навигироваться.</p>
|
||||
* <p>Далее ставим точку останова в PersonService#deleteAllByLastName. В этот момент мы показываем, как ставиться точка останова.</p>
|
||||
*/
|
||||
package dev.struchkov.example.debugger.one;
|
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* <h2>Проект для демонстрации возможностей дебага IDE</h2>
|
||||
* <p>Проект разделен на пакеты, каждый пакет иллюстрирует какие-то возможности дебага.</p>
|
||||
* <p>Начинать следует с пакета one, потом two и так далее. В каждом пакете есть package-info.java со сценарием проведения демострации</p>
|
||||
*
|
||||
* @author upagge
|
||||
*/
|
||||
package dev.struchkov.example.debugger;
|
@ -0,0 +1,7 @@
|
||||
package dev.struchkov.example.debugger.six;
|
||||
|
||||
public abstract class AbstractService {
|
||||
|
||||
abstract int processing(int arg);
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.struchkov.example.debugger.six;
|
||||
|
||||
public class FirstChild extends AbstractService {
|
||||
|
||||
@Override
|
||||
int processing(int arg) {
|
||||
final int result = arg + 1;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.struchkov.example.debugger.six;
|
||||
|
||||
public class SecondChild extends AbstractService {
|
||||
|
||||
@Override
|
||||
int processing(int arg) {
|
||||
final int result = arg + 2;
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,21 @@
|
||||
package dev.struchkov.example.debugger.six;
|
||||
|
||||
public class SixExample {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final AbstractService firstChild = new FirstChild();
|
||||
final AbstractService secondChild = new SecondChild();
|
||||
|
||||
demoOne(secondChild);
|
||||
demoTwo(firstChild);
|
||||
}
|
||||
|
||||
private static int demoTwo(AbstractService firstChild) {
|
||||
return firstChild.processing(5);
|
||||
}
|
||||
|
||||
private static int demoOne(AbstractService secondChild) {
|
||||
return secondChild.processing(10);
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,18 @@
|
||||
package dev.struchkov.example.debugger.three;
|
||||
|
||||
public class ThreadExample implements Runnable {
|
||||
|
||||
private final String name;
|
||||
|
||||
public ThreadExample(String name) {
|
||||
this.name = name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = 0; i < 10; i++) {
|
||||
System.out.println(name + ": " + i);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package dev.struchkov.example.debugger.three;
|
||||
|
||||
public class TreadMain {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final ThreadExample one = new ThreadExample("Первый");
|
||||
final ThreadExample two = new ThreadExample("Второй");
|
||||
|
||||
new Thread(one).start();
|
||||
new Thread(two).start();
|
||||
}
|
||||
|
||||
}
|
@ -0,0 +1,19 @@
|
||||
package dev.struchkov.example.debugger.two;
|
||||
|
||||
import dev.struchkov.example.debugger.box.SurpriseBox;
|
||||
|
||||
public class ForExample {
|
||||
|
||||
public void example() {
|
||||
for (int i = 0; i < 1000; i++) {
|
||||
SurpriseBox.surpriseOne(i);
|
||||
|
||||
// try {
|
||||
// SurpriseBox.surpriseOne(i);
|
||||
// } catch (SurpriseException e) {
|
||||
// System.err.println(e.getMessage());
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
10
src/main/java/dev/struchkov/example/debugger/two/Main.java
Normal file
10
src/main/java/dev/struchkov/example/debugger/two/Main.java
Normal file
@ -0,0 +1,10 @@
|
||||
package dev.struchkov.example.debugger.two;
|
||||
|
||||
public class Main {
|
||||
|
||||
public static void main(String[] args) {
|
||||
final ForExample forExample = new ForExample();
|
||||
forExample.example();
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user