Skip to content

Commit

Permalink
Applied new code style to all classes
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonDan committed Mar 21, 2020
1 parent b7d384c commit a173bb7
Show file tree
Hide file tree
Showing 115 changed files with 718 additions and 604 deletions.
16 changes: 15 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@
@EncapsulatedData
abstract class AbstractEncapsulatedData<ELEMENT, DATASOURCE extends IDataSource> implements IEncapsulatedData<ELEMENT, DATASOURCE>
{
private final Map<IEncapsulatedBeanData, Set<BeanReference>> weakReferencesMapping =
Collections.synchronizedMap(new WeakHashMap<>());
private final Map<IEncapsulatedBeanData, Set<BeanReference>> weakReferencesMapping = Collections.synchronizedMap(new WeakHashMap<>());
private final Map<Class<? extends IEvent>, PublishSubject<? extends IEvent>> eventSubjects = new ConcurrentHashMap<>();
private DATASOURCE datasource;

Expand All @@ -52,8 +51,8 @@ public void setDataSource(@NotNull DATASOURCE pDataSource)
@Override
public Set<BeanReference> getDirectReferences()
{
return weakReferencesMapping.values().stream()
.flatMap(Collection::stream)
return weakReferencesMapping.values().stream() //
.flatMap(Collection::stream) //
.collect(Collectors.toSet());
}

Expand All @@ -69,6 +68,7 @@ public void removeReference(IBean pBean, IField<?> pField)
{
final IEncapsulatedBeanData encapsulatedData = requestEncapsulatedDataForField(pBean, pField);
boolean removed = false;

if (weakReferencesMapping.containsKey(encapsulatedData))
{
final Set<BeanReference> references = weakReferencesMapping.get(encapsulatedData);
Expand All @@ -86,6 +86,7 @@ public void removeReference(IBean pBean, IField<?> pField)
}
}
}

if (!removed)
throw new OJInternalException("Unable to remove reference! bean: " + pBean + " field: " + pField);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,9 @@ public IEncapsulatedBeanContainerData<BEAN> getEncapsulatedData()
@Override
public String toString()
{
return getClass().getSimpleName() + "{beanType: " + getBeanType().getSimpleName() + ", count: " + size() + "}\nbeans:\n" +
stream()
.map(Objects::toString)
.collect(Collectors.joining("\n"));
return getClass().getSimpleName() + "{beanType: " + getBeanType().getSimpleName() + ", count: " + size() + "}\nbeans:\n" + stream() //
.map(Objects::toString) //
.collect(Collectors.joining("\n"));
}

@Override
Expand All @@ -78,8 +77,8 @@ public boolean equals(Object pOther)
//noinspection unchecked
final BeanContainer<BEAN> otherContainer = (BeanContainer<BEAN>) pOther;
final int size = size();
return size == otherContainer.size() &&
IntStream.range(0, size).allMatch(pIndex -> Objects.equals(getBean(pIndex), otherContainer.getBean(pIndex)));
return size == otherContainer.size() && IntStream.range(0, size).allMatch(
pIndex -> Objects.equals(getBean(pIndex), otherContainer.getBean(pIndex)));
}

@Override
Expand Down
28 changes: 15 additions & 13 deletions ojcms-beans/src/main/java/de/adito/ojcms/beans/BeanCopies.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ static IBean doCreateCopy(IBean pOriginal, ECopyMode pMode, CustomFieldCopy<?>..
final Class<? extends IBean> beanType = BeanReflector.requiresDeclaredBeanType(pOriginal.getClass());
final List<IField<?>> fieldOrder = pOriginal.streamFields().collect(Collectors.toList());

final IBean copyInstance = _createBeanPerDefaultConstructorAndSetDataSource(beanType)
final IBean copyInstance = _createBeanPerDefaultConstructorAndSetDataSource(beanType) //
.orElse(_createBeanSneakyAndInjectEncapsulatedData(beanType, fieldOrder));

return _setValues(pOriginal, copyInstance, pMode, pCustomCopies);
Expand All @@ -64,7 +64,8 @@ static IBean doCreateCopy(IBean pOriginal, ECopyMode pMode, CustomFieldCopy<?>..
*
* @param pOriginal the original bean to create the copy of
* @param pMode the copy mode
* @param pCustomConstructorCall a custom constructor call defined as function (the input is the existing bean, the function should create the copy)
* @param pCustomConstructorCall a custom constructor call defined as function (the input is the existing bean, the function should
* create the copy)
* @param pCustomCopies a collection of custom copy mechanisms for specific bean fields
* @return a copy of the bean
*/
Expand Down Expand Up @@ -138,15 +139,17 @@ private static IBean _setValues(IBean pOriginal, IBean pCopy, ECopyMode pMode, C
{
final _BeanValueCopyCreator beanValueCopyCreator = new _BeanValueCopyCreator(pMode, pCustomCopies);
//noinspection unchecked,RedundantCast
requestEncapsulatedData(pOriginal).streamFields()
.forEach(pField -> pCopy.setValue((IField) pField, beanValueCopyCreator.copyFieldValue((IField) pField, pOriginal.getValue(pField))));
requestEncapsulatedData(pOriginal).streamFields() //
.forEach(
pField -> pCopy.setValue((IField) pField, beanValueCopyCreator.copyFieldValue((IField) pField, pOriginal.getValue(pField))));

//If required set non bean values as well
if (pMode.shouldCopyAllFields())
{
final _NonBeanValueCopyCreator copyCreator = new _NonBeanValueCopyCreator(pMode);
BeanReflector.reflectDeclaredNonBeanFields(pOriginal.getClass())
.forEach(pField -> {
BeanReflector.reflectDeclaredNonBeanFields(pOriginal.getClass()) //
.forEach(pField ->
{
try
{
if (!pField.isAccessible())
Expand Down Expand Up @@ -182,8 +185,8 @@ private _BeanValueCopyCreator(ECopyMode pMode, CustomFieldCopy<?>[] pCustomCopie
{
mode = pMode;
customCopies = pCustomCopies;
fieldCustomCopyMapping = Arrays.stream(pCustomCopies)
.collect(Collectors.toMap(CustomFieldCopy::getField, CustomFieldCopy::getCopyCreator));
fieldCustomCopyMapping = Arrays.stream(pCustomCopies).collect(
Collectors.toMap(CustomFieldCopy::getField, CustomFieldCopy::getCopyCreator));
}

/**
Expand All @@ -202,9 +205,8 @@ <VALUE> VALUE copyFieldValue(IField<VALUE> pField, VALUE pValue)
try
{
//noinspection unchecked
return (VALUE) Optional.ofNullable(fieldCustomCopyMapping.get(pField))
.map(pCreator -> pCreator.apply(pValue))
.orElse(pField.copyValue(pValue, mode, customCopies));
return (VALUE) Optional.ofNullable(fieldCustomCopyMapping.get(pField)).map(pCreator -> pCreator.apply(pValue)).orElse(
pField.copyValue(pValue, mode, customCopies));
}
catch (BeanCopyNotSupportedException pE)
{
Expand Down Expand Up @@ -244,8 +246,8 @@ Object copyValue(Field pDeclaredField, Object pValue)

final Class<?> dataType = pDeclaredField.getType();
final Type genericType = pDeclaredField.getGenericType();
final Type[] genericTypes = genericType instanceof ParameterizedType ?
((ParameterizedType) genericType).getActualTypeArguments() : new Type[0];
final Type[] genericTypes =
genericType instanceof ParameterizedType ? ((ParameterizedType) genericType).getActualTypeArguments() : new Type[0];
try
{
return SneakyCopyUtils.createDeepCopy(pValue, dataType, genericTypes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@
public final class BeanCreationEvents
{
private static final Map<Class<? extends IBean>, PublishSubject<IBean>> PUBLISHERS_BY_TYPE = new ConcurrentHashMap<>();
private static final Map<Class<? extends Annotation>, PublishSubject<? extends BeanCreationEvent<?>>> PUBLISHERS_BY_ANNOTATION = new ConcurrentHashMap<>();
private static final Map<Class<? extends Annotation>, PublishSubject<? extends BeanCreationEvent<?>>> PUBLISHERS_BY_ANNOTATION =
new ConcurrentHashMap<>();

private BeanCreationEvents()
{
Expand All @@ -39,7 +40,7 @@ public static <BEAN extends IBean> Observable<BEAN> observeCreationByBeanType(Cl
{
_getObservableAnnotation(pBeanType); //check, if annotation is present
//noinspection unchecked
return (Observable<BEAN>) PUBLISHERS_BY_TYPE.computeIfAbsent(pBeanType, pType -> PublishSubject.create())
return (Observable<BEAN>) PUBLISHERS_BY_TYPE.computeIfAbsent(pBeanType, pType -> PublishSubject.create()) //
.observeOn(Schedulers.newThread());
}

Expand All @@ -55,8 +56,8 @@ public static <ANNOTATION extends Annotation> Observable<BeanCreationEvent<ANNOT
if (!_isObservableAnnotation(pAnnotationType))
throw new BeanCreationNotObservableException(pAnnotationType.getName() + " is not a valid creation observer annotation.");
//noinspection unchecked
return (Observable<BeanCreationEvent<ANNOTATION>>) PUBLISHERS_BY_ANNOTATION.computeIfAbsent(pAnnotationType, pType -> PublishSubject.create())
.observeOn(Schedulers.newThread());
return (Observable<BeanCreationEvent<ANNOTATION>>) PUBLISHERS_BY_ANNOTATION.computeIfAbsent(pAnnotationType,
pType -> PublishSubject.create()).observeOn(Schedulers.newThread());
}

/**
Expand Down Expand Up @@ -89,7 +90,9 @@ static void fireCreation(IBean pCreatedBean)
if (PUBLISHERS_BY_ANNOTATION.containsKey(annotationType))
{
//noinspection unchecked
final PublishSubject<BeanCreationEvent<?>> publisher = (PublishSubject<BeanCreationEvent<?>>) PUBLISHERS_BY_ANNOTATION.get(annotationType);
final PublishSubject<BeanCreationEvent<?>> publisher = (PublishSubject<BeanCreationEvent<?>>) PUBLISHERS_BY_ANNOTATION.get(
annotationType);

publisher.onNext(new BeanCreationEvent<>(pCreatedBean, beanType.getAnnotation(annotationType)));
}
}
Expand All @@ -112,7 +115,7 @@ static boolean hasObservableAnnotation(Class<? extends IBean> pBeanType)
*/
private static boolean _observersPresent()
{
return Stream.concat(PUBLISHERS_BY_TYPE.values().stream(), PUBLISHERS_BY_ANNOTATION.values().stream())
return Stream.concat(PUBLISHERS_BY_TYPE.values().stream(), PUBLISHERS_BY_ANNOTATION.values().stream()) //
.anyMatch(PublishSubject::hasObservers);
}

Expand All @@ -126,8 +129,7 @@ private static boolean _observersPresent()
*/
private static Class<? extends Annotation> _getObservableAnnotation(Class<? extends IBean> pBeanType)
{
return _searchObservableAnnotation(pBeanType)
.orElseThrow(() -> new BeanCreationNotObservableException(pBeanType));
return _searchObservableAnnotation(pBeanType).orElseThrow(() -> new BeanCreationNotObservableException(pBeanType));
}

/**
Expand All @@ -139,10 +141,10 @@ private static Class<? extends Annotation> _getObservableAnnotation(Class<? exte
*/
private static Optional<Class<? extends Annotation>> _searchObservableAnnotation(Class<? extends IBean> pBeanType)
{
return Stream.of(pBeanType.getDeclaredAnnotations())
.map(Annotation::annotationType)
.filter(BeanCreationEvents::_isObservableAnnotation)
.findAny()
return Stream.of(pBeanType.getDeclaredAnnotations()) //
.map(Annotation::annotationType) //
.filter(BeanCreationEvents::_isObservableAnnotation) //
.findAny() //
.map(pAnnotationType -> (Class<? extends Annotation>) pAnnotationType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ static <VALUE, FIELD extends IField<VALUE>> FIELD createField(Class<FIELD> pFiel
{
final Optional<Class<?>> optionalGenericType = _getGenericType(pFieldType, pGenericTypeSupplier);
final boolean isOptional = pActiveCondition != null;

//Constructor argument distinction between generic and non generic values (generic types provide their type additionally)
final Class[] constructorArgumentTypes = optionalGenericType
.map(pType -> new Class[]{Class.class, String.class, Collection.class, boolean.class, boolean.class})
final Class[] constructorArgumentTypes = optionalGenericType //
.map(pType -> new Class[]{Class.class, String.class, Collection.class, boolean.class, boolean.class}) //
.orElseGet(() -> new Class[]{String.class, Collection.class, boolean.class, boolean.class});

final Object[] constructorArguments = optionalGenericType
.map(pClass -> new Object[]{pClass, pName, pAnnotations, isOptional, pIsPrivate})
final Object[] constructorArguments = optionalGenericType //
.map(pClass -> new Object[]{pClass, pName, pAnnotations, isOptional, pIsPrivate}) //
.orElseGet(() -> new Object[]{pName, pAnnotations, isOptional, pIsPrivate});

//Create the field by using the reflected constructor
Expand Down
Loading

0 comments on commit a173bb7

Please sign in to comment.