Skip to content

Commit

Permalink
Инициализация проекта
Browse files Browse the repository at this point in the history
  • Loading branch information
kalenchukov committed Jun 24, 2022
0 parents commit a3350f4
Show file tree
Hide file tree
Showing 80 changed files with 3,437 additions and 0 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/.idea
/out
/*.iml
/target
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2021 Aleksey Kalenchukov

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
148 changes: 148 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
# Lemna Injection
Внедрение значений в поля классов.

### Поддерживаемые типы данных полей

```java
Integer, Short, Float, Double, Long, String, Character, Boolean, Byte
```
```java
Integer[], Short[], Float[], Double[], Long[], String[], Character[],
Boolean[], Byte[]
```
```java
Collection<Integer>, Collection<Short>, Collection<Float>, Collection<Double>,
Collection<Long>, Collection<String>, Collection<Character>, Collection<Boolean>,
Collection<Byte>
```
```java
List<Integer>, List<Short>, List<Float>, List<Double>, List<Long>, List<String>,
List<Character>, List<Boolean>, List<Byte>
```
```java
Set<Integer>, Set<Short>, Set<Float>, Set<Double>, Set<Long>, Set<String>,
Set<Character>, Set<Boolean>, Set<Byte>
```

Для других типов данных необходимо создавать свои конвертеры.

Примитивные типы данных не поддерживаются.

### Внедрение значений в поля класса
Класс, в поля которого необходимо внедрить значения:
```java
public class Experimental
{
private String varOne;

private Integer varTwo;

public String getVarOne()
{
return this.varOne;
}

public Integer getVarTwo()
{
return this.varTwo;
}
}
```

Данные которые необходимо внедрить в поля.
```java
Map<String, String[]> data = new HashMap<>();
data.put("varOne", new String[]{"Значение первого поля"});
data.put("varTwo", new String[]{"13"});
```

Вызов инжектора:
```java
Experimental experimental = new Experimental();

Injectable injection = new Injection(experimental);
injection.inject(data);

experimental.getVarOne();
/*
Результат выполнения: Значение первого поля
*/

experimental.getVarTwo();
/*
Результат выполнения: 13
*/
```

### Создание конвертера типа данных
Свой тип данных.
```java
public enum Gender
{
M,
F;
}
```

Для создания конвертера типа данных необходимо создать класс реализующий интерфейс "Converting".

```java
import Converting;

public final class GenderConverter implements Converting<Gender>
{
@Override
public @Nullable Gender convert(@Nullable String @Nullable [] value) throws UnableConverterException
{
if (value == null || value[0] == null)
{
return null;
}

try
{
return Gender.valueOf(value[0]);
}
catch (IllegalArgumentException exception)
{
throw new UnableConverterException();
}
}
}
```

Класс для поля которого необходим конвертер:

```java
import Converter;

public class Experimental
{
@Converter(converter = GenderConverter.class)
private Gender gender;

public Gender getGender()
{
return this.gender;
}
}
```

Данные для внедрения:
```java
Map<String, String[]> data = new HashMap<>();
data.put("gender", new String[]{"F"});
```

Вызов инжектора:
```java
Experimental experimental = new Experimental();

Injectable injection = new Injection(experimental);
injection.inject(data);

experimental.getGender();
/*
Результат выполнения: F
*/
```
8 changes: 8 additions & 0 deletions TODO.MD
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
[+] - нужно сделать
[?] - возможно нужно сделать
[>] - перенос в новую версию
[x] - не делать

# CORE
* [>] Сделать настройку чтобы не присваивал значение тем полям, которые не null
*
61 changes: 61 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright © 2022 Алексей Каленчуков
~ GitHub: https://github.com/kalenchukov
~ E-mail: mailto:aleksey.kalenchukov@yandex.ru
-->

<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.kalenchukov</groupId>
<artifactId>lemna-injection</artifactId>
<version>1.0.0</version>

<name>Lemna Injection</name>
<description>Внедрение значений в поля классов</description>
<url>https://github.com/kalenchukov/LemnaInjection</url>

<licenses>
<license>
<name>MIT License</name>
<url>https://opensource.org/licenses/MIT</url>
</license>
</licenses>

<developers>
<developer>
<id>kalenchukov</id>
<name>Алексей Каленчуков</name>
<email>aleksey.kalenchukov@yandex.ru</email>
<url>https://github.com/kalenchukov</url>
</developer>
</developers>

<properties>
<maven.compiler.source>18</maven.compiler.source>
<maven.compiler.target>18</maven.compiler.target>
<encoding>UTF-8</encoding>
</properties>

<dependencies>
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>23.0.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
</dependencies>

</project>
44 changes: 44 additions & 0 deletions src/main/java/dev/kalenchukov/lemna/injection/Injectable.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright © 2022 Алексей Каленчуков
* GitHub: https://github.com/kalenchukov
* E-mail: mailto:aleksey.kalenchukov@yandex.ru
*/

package dev.kalenchukov.lemna.injection;

import dev.kalenchukov.lemna.injection.exceptions.InvalidConverterException;
import dev.kalenchukov.lemna.injection.exceptions.IllegalValueException;
import dev.kalenchukov.lemna.injection.exceptions.UnknownConverterException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.Locale;
import java.util.Map;

/**
* Интерфейс для реализации внедряющего в поля класса данные.
*/
public interface Injectable
{
/**
* Устанавливает локализацию.
*
* @param locale Локализация.
*/
void setLocale(@NotNull Locale locale);

/**
* Внедряет данные в поля класса.
*
* @param data Данные которые необходимо внедрить в поля класса.
* <ul>
* <li><b>key</b> - поле класса.</li>
* <li><b>value</b> - массив значений.</li>
* </ul>
* @throws IllegalValueException Если передано некорректное значение для внедрения в данное поле класса.
* @throws UnknownConverterException Если для типа поля не реализован персональный конвертер.
* @throws InvalidConverterException Если конвертер некорректный.
*/
void inject(@NotNull Map<@NotNull String, @Nullable String @Nullable []> data)
throws IllegalValueException, UnknownConverterException, InvalidConverterException;
}
Loading

0 comments on commit a3350f4

Please # to comment.