fixed issue when person id wouldn't be unique when adding new person on server

This commit is contained in:
Egor 2022-05-16 16:42:21 +03:00
parent d19dd08ec9
commit 34381ddba5
13 changed files with 110 additions and 17 deletions

View file

@ -1,5 +1,23 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<peopleDatabase> <peopleDatabase>
<person>
<name>san</name>
<coordinates>
<x>2.0</x>
<y>2.0</y>
</coordinates>
<creationDate>2022-05-16</creationDate>
<height>321</height>
<passportID>321321321231</passportID>
<eyeColor>BLACK</eyeColor>
<nationality>CHINA</nationality>
<location>
<x>2.0</x>
<y>2.0</y>
<z>2</z>
<name>2</name>
</location>
</person>
<person> <person>
<name>wasd</name> <name>wasd</name>
<coordinates> <coordinates>

View file

@ -126,8 +126,8 @@
<ul> <ul>
<li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable) <li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable)
<ul> <ul>
<li type="circle">common.commandline.<a href="../../common/commandline/LongStrings.html" title="enum in common.commandline"><span class="typeNameLink">LongStrings</span></a></li>
<li type="circle">common.commandline.<a href="../../common/commandline/Executables.html" title="enum in common.commandline"><span class="typeNameLink">Executables</span></a></li> <li type="circle">common.commandline.<a href="../../common/commandline/Executables.html" title="enum in common.commandline"><span class="typeNameLink">Executables</span></a></li>
<li type="circle">common.commandline.<a href="../../common/commandline/LongStrings.html" title="enum in common.commandline"><span class="typeNameLink">LongStrings</span></a></li>
</ul> </ul>
</li> </li>
</ul> </ul>

View file

@ -97,8 +97,8 @@
<ul> <ul>
<li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable) <li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable)
<ul> <ul>
<li type="circle">common.commandline.response.<a href="../../../common/commandline/response/PeopleDatabaseResponse.html" title="enum in common.commandline.response"><span class="typeNameLink">PeopleDatabaseResponse</span></a> (implements common.commandline.response.<a href="../../../common/commandline/response/Response.html" title="interface in common.commandline.response">Response</a>)</li>
<li type="circle">common.commandline.response.<a href="../../../common/commandline/response/DefaultResponse.html" title="enum in common.commandline.response"><span class="typeNameLink">DefaultResponse</span></a> (implements common.commandline.response.<a href="../../../common/commandline/response/Response.html" title="interface in common.commandline.response">Response</a>)</li> <li type="circle">common.commandline.response.<a href="../../../common/commandline/response/DefaultResponse.html" title="enum in common.commandline.response"><span class="typeNameLink">DefaultResponse</span></a> (implements common.commandline.response.<a href="../../../common/commandline/response/Response.html" title="interface in common.commandline.response">Response</a>)</li>
<li type="circle">common.commandline.response.<a href="../../../common/commandline/response/PeopleDatabaseResponse.html" title="enum in common.commandline.response"><span class="typeNameLink">PeopleDatabaseResponse</span></a> (implements common.commandline.response.<a href="../../../common/commandline/response/Response.html" title="interface in common.commandline.response">Response</a>)</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View file

@ -17,8 +17,8 @@
catch(err) { catch(err) {
} }
//--> //-->
var methods = {"i0":10,"i1":10,"i2":10,"i3":10,"i4":10,"i5":10}; var methods = {"i0":10,"i1":10,"i2":9,"i3":10,"i4":10,"i5":10,"i6":10};
var tabs = {65535:["t0","All Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]}; var tabs = {65535:["t0","All Methods"],1:["t1","Static Methods"],2:["t2","Instance Methods"],8:["t4","Concrete Methods"]};
var altColor = "altColor"; var altColor = "altColor";
var rowColor = "rowColor"; var rowColor = "rowColor";
var tableTab = "tableTab"; var tableTab = "tableTab";
@ -158,7 +158,7 @@ implements java.lang.Comparable&lt;<a href="../../common/data/Person.html" title
</a> </a>
<h3>Method Summary</h3> <h3>Method Summary</h3>
<table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation"> <table class="memberSummary" border="0" cellpadding="3" cellspacing="0" summary="Method Summary table, listing methods, and an explanation">
<caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption> <caption><span id="t0" class="activeTableTab"><span>All Methods</span><span class="tabEnd">&nbsp;</span></span><span id="t1" class="tableTab"><span><a href="javascript:show(1);">Static Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t2" class="tableTab"><span><a href="javascript:show(2);">Instance Methods</a></span><span class="tabEnd">&nbsp;</span></span><span id="t4" class="tableTab"><span><a href="javascript:show(8);">Concrete Methods</a></span><span class="tabEnd">&nbsp;</span></span></caption>
<tr> <tr>
<th class="colFirst" scope="col">Modifier and Type</th> <th class="colFirst" scope="col">Modifier and Type</th>
<th class="colLast" scope="col">Method and Description</th> <th class="colLast" scope="col">Method and Description</th>
@ -176,24 +176,28 @@ implements java.lang.Comparable&lt;<a href="../../common/data/Person.html" title
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#formatted--">formatted</a></span>()</code>&nbsp;</td> <td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#formatted--">formatted</a></span>()</code>&nbsp;</td>
</tr> </tr>
<tr id="i2" class="altColor"> <tr id="i2" class="altColor">
<td class="colFirst"><code>static void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#incrementExistingPeople--">incrementExistingPeople</a></span>()</code>&nbsp;</td>
</tr>
<tr id="i3" class="rowColor">
<td class="colFirst"><code>void</code></td> <td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setHeight-java.lang.Integer-">setHeight</a></span>(java.lang.Integer&nbsp;height)</code> <td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setHeight-java.lang.Integer-">setHeight</a></span>(java.lang.Integer&nbsp;height)</code>
<div class="block">Сеттер для поля height</div> <div class="block">Сеттер для поля height</div>
</td> </td>
</tr> </tr>
<tr id="i3" class="rowColor"> <tr id="i4" class="altColor">
<td class="colFirst"><code>void</code></td> <td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setName-java.lang.String-">setName</a></span>(java.lang.String&nbsp;name)</code> <td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setName-java.lang.String-">setName</a></span>(java.lang.String&nbsp;name)</code>
<div class="block">Сеттер для поля name</div> <div class="block">Сеттер для поля name</div>
</td> </td>
</tr> </tr>
<tr id="i4" class="altColor"> <tr id="i5" class="rowColor">
<td class="colFirst"><code>void</code></td> <td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setPassportID-java.lang.String-">setPassportID</a></span>(java.lang.String&nbsp;passportID)</code> <td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#setPassportID-java.lang.String-">setPassportID</a></span>(java.lang.String&nbsp;passportID)</code>
<div class="block">Сеттер для поля passportID</div> <div class="block">Сеттер для поля passportID</div>
</td> </td>
</tr> </tr>
<tr id="i5" class="rowColor"> <tr id="i6" class="altColor">
<td class="colFirst"><code>void</code></td> <td class="colFirst"><code>void</code></td>
<td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#update-common.data.Person-">update</a></span>(<a href="../../common/data/Person.html" title="class in common.data">Person</a>&nbsp;newPerson)</code> <td class="colLast"><code><span class="memberNameLink"><a href="../../common/data/Person.html#update-common.data.Person-">update</a></span>(<a href="../../common/data/Person.html" title="class in common.data">Person</a>&nbsp;newPerson)</code>
<div class="block">Метод, меняющий все значения полей человека (кроме <a href="../../common/data/Person.html#id"><code>id</code></a> и <a href="../../common/data/Person.html#creationDate"><code>creationDate</code></a>) в соответствии <div class="block">Метод, меняющий все значения полей человека (кроме <a href="../../common/data/Person.html#id"><code>id</code></a> и <a href="../../common/data/Person.html#creationDate"><code>creationDate</code></a>) в соответствии
@ -277,6 +281,15 @@ implements java.lang.Comparable&lt;<a href="../../common/data/Person.html" title
</dl> </dl>
</li> </li>
</ul> </ul>
<a name="incrementExistingPeople--">
<!-- -->
</a>
<ul class="blockList">
<li class="blockList">
<h4>incrementExistingPeople</h4>
<pre>public static&nbsp;void&nbsp;incrementExistingPeople()</pre>
</li>
</ul>
<a name="setName-java.lang.String-"> <a name="setName-java.lang.String-">
<!-- --> <!-- -->
</a> </a>

View file

@ -91,8 +91,8 @@
<ul> <ul>
<li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable) <li type="circle">java.lang.Enum&lt;E&gt; (implements java.lang.Comparable&lt;T&gt;, java.io.Serializable)
<ul> <ul>
<li type="circle">common.data.<a href="../../common/data/Country.html" title="enum in common.data"><span class="typeNameLink">Country</span></a> (implements java.io.Serializable)</li>
<li type="circle">common.data.<a href="../../common/data/Color.html" title="enum in common.data"><span class="typeNameLink">Color</span></a> (implements java.io.Serializable)</li> <li type="circle">common.data.<a href="../../common/data/Color.html" title="enum in common.data"><span class="typeNameLink">Color</span></a> (implements java.io.Serializable)</li>
<li type="circle">common.data.<a href="../../common/data/Country.html" title="enum in common.data"><span class="typeNameLink">Country</span></a> (implements java.io.Serializable)</li>
</ul> </ul>
</li> </li>
</ul> </ul>

View file

@ -380,6 +380,8 @@
</a> </a>
<h2 class="title">I</h2> <h2 class="title">I</h2>
<dl> <dl>
<dt><span class="memberNameLink"><a href="common/data/Person.html#incrementExistingPeople--">incrementExistingPeople()</a></span> - Static method in class common.data.<a href="common/data/Person.html" title="class in common.data">Person</a></dt>
<dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="common/collection/PeopleDatabase.html#info--">info()</a></span> - Method in class common.collection.<a href="common/collection/PeopleDatabase.html" title="class in common.collection">PeopleDatabase</a></dt> <dt><span class="memberNameLink"><a href="common/collection/PeopleDatabase.html#info--">info()</a></span> - Method in class common.collection.<a href="common/collection/PeopleDatabase.html" title="class in common.collection">PeopleDatabase</a></dt>
<dd>&nbsp;</dd> <dd>&nbsp;</dd>
<dt><span class="memberNameLink"><a href="common/commandline/CommandLineHandler.html#input--">input()</a></span> - Method in class common.commandline.<a href="common/commandline/CommandLineHandler.html" title="class in common.commandline">CommandLineHandler</a></dt> <dt><span class="memberNameLink"><a href="common/commandline/CommandLineHandler.html#input--">input()</a></span> - Method in class common.commandline.<a href="common/commandline/CommandLineHandler.html" title="class in common.commandline">CommandLineHandler</a></dt>

View file

@ -15,7 +15,12 @@ public enum Executables {
PeopleDatabase peopleDatabase = (PeopleDatabase) args[0]; PeopleDatabase peopleDatabase = (PeopleDatabase) args[0];
Person person = (Person) args[1]; Person person = (Person) args[1];
boolean success = peopleDatabase.getCollection().add(person); boolean success = peopleDatabase.getCollection().add(person);
Response response = success ? DefaultResponse.OK : PeopleDatabaseResponse.FAILED_TO_ADD; Response response = PeopleDatabaseResponse.FAILED_TO_ADD;
if (success) {
Person.incrementExistingPeople();
person.setId(Person.getExistingPeople());
response = DefaultResponse.OK;
}
return new CommandResult(response.getMsg(), response); return new CommandResult(response.getMsg(), response);
}), }),

View file

@ -1,9 +1,6 @@
package common.data; package common.data;
import lombok.Data; import lombok.*;
import lombok.EqualsAndHashCode;
import lombok.NonNull;
import lombok.ToString;
import common.parser.Adapters; import common.parser.Adapters;
import javax.xml.bind.annotation.*; import javax.xml.bind.annotation.*;
@ -24,13 +21,13 @@ public class Person implements Comparable<Person>, Serializable {
* Количество созданных людей, используется для задания * Количество созданных людей, используется для задания
* уникального id для каждого объекта данного класса * уникального id для каждого объекта данного класса
*/ */
@XmlTransient @XmlTransient @Getter
private static long existingPeople = 0; private static long existingPeople = 0;
/** /**
* Id человека, не может быть null, значение поля должно быть больше 0, * Id человека, не может быть null, значение поля должно быть больше 0,
* значение этого поля должно быть уникальным, значение этого поля должно генерироваться автоматически * значение этого поля должно быть уникальным, значение этого поля должно генерироваться автоматически
*/ */
@XmlTransient @XmlTransient @Setter
private Long id; private Long id;
/** /**
* Имя человека, не может быть null, строка не может быть пустой * Имя человека, не может быть null, строка не может быть пустой
@ -103,7 +100,7 @@ public class Person implements Comparable<Person>, Serializable {
*/ */
public Person(@NonNull String name, @NonNull Coordinates coordinates, Integer height, String passportID, public Person(@NonNull String name, @NonNull Coordinates coordinates, Integer height, String passportID,
@NonNull Color eyeColor, @NonNull Country nationality, Location location) { @NonNull Color eyeColor, @NonNull Country nationality, Location location) {
this.id = ++existingPeople; this.id = existingPeople;
this.creationDate = LocalDate.now(); this.creationDate = LocalDate.now();
this.location = location; this.location = location;
this.coordinates = coordinates; this.coordinates = coordinates;
@ -130,6 +127,10 @@ public class Person implements Comparable<Person>, Serializable {
this.setPassportID(newPerson.passportID); this.setPassportID(newPerson.passportID);
} }
public static void incrementExistingPeople() {
existingPeople++;
}
/** /**
* Сеттер для поля name * Сеттер для поля name
* *

View file

@ -1,4 +1,58 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<peopleDatabase> <peopleDatabase>
<person>
<name>pop</name>
<coordinates>
<x>2.0</x>
<y>2.0</y>
</coordinates>
<creationDate>2022-05-16</creationDate>
<height>1321</height>
<passportID>321312321312</passportID>
<eyeColor>BLACK</eyeColor>
<nationality>CHINA</nationality>
<location>
<x>2.0</x>
<y>2.0</y>
<z>2</z>
<name>2</name>
</location>
</person>
<person>
<name>san</name>
<coordinates>
<x>2.0</x>
<y>2.0</y>
</coordinates>
<creationDate>2022-05-16</creationDate>
<height>3123</height>
<passportID>3213213321</passportID>
<eyeColor>BLACK</eyeColor>
<nationality>CHINA</nationality>
<location>
<x>2.0</x>
<y>2.0</y>
<z>2</z>
<name>2</name>
</location>
</person>
<person>
<name>wasd</name>
<coordinates>
<x>2.0</x>
<y>2.0</y>
</coordinates>
<creationDate>2022-05-16</creationDate>
<height>321</height>
<passportID>321312321321</passportID>
<eyeColor>BLACK</eyeColor>
<nationality>CHINA</nationality>
<location>
<x>2.0</x>
<y>2.0</y>
<z>2</z>
<name>2</name>
</location>
</person>
<initDate>2022-05-10</initDate> <initDate>2022-05-10</initDate>
</peopleDatabase> </peopleDatabase>