Skip to content

Kochnev Roman lab2#9

Open
poma12390 wants to merge 4 commits intomasterfrom
master
Open

Kochnev Roman lab2#9
poma12390 wants to merge 4 commits intomasterfrom
master

Conversation

@poma12390
Copy link

No description provided.

Choose a reason for hiding this comment

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

Будто честнее было бы брать случайный

Copy link
Author

Choose a reason for hiding this comment

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

Поправил

ctor.setAccessible(true);
Class<?>[] ptypes = ctor.getParameterTypes();
Object[] args = new Object[ptypes.length];
for (int i = 0; i < ptypes.length; i++) {

Choose a reason for hiding this comment

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

Мб туплю, но не увидел ветви для создания Generatable класса. Как у вас работает создание дерева через конструктор?

Copy link
Author

Choose a reason for hiding this comment

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

Логика такая:

resolveConcrete выбирает реализацию для интерфейсов/абстрактных классов на основе @Generatable(implementations=...)

instantiateShell создаёт объект через конструктор, но ссылочные параметры на этом этапе ставятся пустые
граф строится не конструктором, а на шаге populateFields рефлексией обходим поля и уже там генерируем/переиспользуем ссылки

} else if (Optional.class.isAssignableFrom(p)) {
args[i] = Optional.empty();
} else if (Collection.class.isAssignableFrom(p)) {
args[i] = instantiateCollectionClass(p);

Choose a reason for hiding this comment

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

Просто пустые коллекции?

Copy link
Author

Choose a reason for hiding this comment

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

На этапе оболочки — да, дальше в populateFields вызывается maybeFillCollection/maybeFillMap, где случайно добавляется 0-2 элемента

return (T) generateGraphForClass(clazz, st);
}

private static final class State {

Choose a reason for hiding this comment

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

Расскажите пж вашу идею с пулом и как ограничивается глубина рекурсии

Copy link
Author

Choose a reason for hiding this comment

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

Есть pool всех уже созданных экземпляров

Для каждого ссылочного поля случайный выбор: null (10%) / переиспользовать из пула (50%) / создать новый (40%).

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

Comments