Skip to content

Home work1#1

Open
GeorgyMironov2001 wants to merge 4 commits intomainfrom
HomeWork1
Open

Home work1#1
GeorgyMironov2001 wants to merge 4 commits intomainfrom
HomeWork1

Conversation

@GeorgyMironov2001
Copy link
Copy Markdown
Owner

No description provided.

Copy link
Copy Markdown
Collaborator

@vladkats vladkats left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пока принять не готов


public enum ClientType {
INDIVIDUAL("INDIVIDUAL") {
private List<Object> parseClient(MyJsonObject client) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

вот этого тут быть не должно, не надо все поля разных типов складывать в List. Как ты потом будешь по индексу искать что ль. А если там не в том порядке что ты хочешь. Надо складывать в Map, а потом искать по ключу, а не по индексу

return new HoldingClient(parseClient(client));
}
};
public final String type;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

это необязательно. У тебя название экземпляров enum не отличается строкового типа

};
public final String type;

/*List<Object> parseClient(JSONObject client) {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мертвый код убираем

import ru.sber.mironov.ClientType.ClientType;

public class Client {
public final String name;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

почему все public. Заменить на private

}

public HoldingClient(List<Object> client) {
super((String) client.get(0), (String) client.get(1), ClientType.HOLDING);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

кастование может плохим закончиться, ты даже не проверяешь на тип. Схватишь ClassCastException.
Ведь в задании нужно было поддерживать все примитивы

import java.util.ArrayList;

public class ClientsJsonParser {
public static ArrayList<Client> parseClientsJson(String filePath) throws IOException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Парсить в map

String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ресурсы закрываем в finally либо используем try-with-resources

//System.out.println(clients);
ArrayList<Client> people = new ArrayList<>();
for (var o : clients) {
//System.out.println(o);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

мертвый код убираем


public MyJsonArray(String content) {
ArrayList<MyJsonObject> clients = new ArrayList<>();
Pattern pattern = Pattern.compile("\\{.+?}");
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя решение явно завязано на то что json в одну строку идет, но это не так. Он может подаваться на вход в любом, отформатированным или нет. И он не обязательно будет подаваться в виде массива

private ArrayList<Client> people;

@Before
public void setUpPeople() throws IOException {
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

тестов мало. Нет тестов на примитивы. Значением в json может быть как boolean, int, double, float. И они будут без кавычек и должны все парситься

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants