-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor basic types with several corrections (#48)
* Refactor basic types with several corrections * Corrections imports for codacy * Corrections for codacy * Corrections code in byte set in pactDslJsonBody --------- Co-authored-by: Tiago Simoes <[email protected]>
- Loading branch information
Showing
12 changed files
with
160 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
src/main/java/com/sngular/annotation/processor/mapping/BigDecimalMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.sngular.annotation.processor.mapping; | ||
|
||
import java.util.Objects; | ||
|
||
import com.sngular.annotation.processor.model.FieldValidations; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.rng.UniformRandomProvider; | ||
import org.apache.commons.rng.simple.RandomSource; | ||
|
||
public class BigDecimalMapping implements TypeMapping<Number> { | ||
|
||
private final UniformRandomProvider uniformRandomProvider = RandomSource.XO_RO_SHI_RO_128_PP.create(); | ||
|
||
@Override | ||
public final String getFieldType() { | ||
return "BigDecimal"; | ||
} | ||
|
||
@Override | ||
public final String getFunctionType() { | ||
return "decimalType"; | ||
} | ||
|
||
@Override | ||
public final String getFunctionOnlyValue() { | ||
return "decimalValue"; | ||
} | ||
|
||
@Override | ||
public final Number getRandomDefaultValue(final FieldValidations fieldValidations) { | ||
final Number randomDefaultValue; | ||
|
||
if (Objects.nonNull(fieldValidations) && ObjectUtils.anyNotNull(fieldValidations.getMin(), fieldValidations.getMax())) { | ||
final int minValue = ObjectUtils.defaultIfNull(fieldValidations.getMin(), 0); | ||
final int maxValue = ObjectUtils.defaultIfNull(fieldValidations.getMax(), (int) Double.MAX_VALUE); | ||
|
||
randomDefaultValue = uniformRandomProvider.nextDouble(minValue, maxValue); | ||
} else { | ||
randomDefaultValue = uniformRandomProvider.nextDouble(Double.MIN_VALUE, Double.MAX_VALUE); | ||
} | ||
|
||
return randomDefaultValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
src/main/java/com/sngular/annotation/processor/mapping/FloatMapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
/* | ||
* This Source Code Form is subject to the terms of the Mozilla Public | ||
* * License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* * file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
*/ | ||
|
||
package com.sngular.annotation.processor.mapping; | ||
|
||
import java.util.Objects; | ||
|
||
import com.sngular.annotation.processor.model.FieldValidations; | ||
import org.apache.commons.lang3.ObjectUtils; | ||
import org.apache.commons.rng.UniformRandomProvider; | ||
import org.apache.commons.rng.simple.RandomSource; | ||
|
||
public class FloatMapping implements TypeMapping<Number> { | ||
|
||
private final UniformRandomProvider uniformRandomProvider = RandomSource.XO_RO_SHI_RO_128_PP.create(); | ||
|
||
@Override | ||
public final String getFieldType() { | ||
return "float"; | ||
} | ||
|
||
@Override | ||
public final String getFunctionType() { | ||
return "decimalType"; | ||
} | ||
|
||
@Override | ||
public final String getFunctionOnlyValue() { | ||
return "decimalValue"; | ||
} | ||
|
||
@Override | ||
public final Number getRandomDefaultValue(final FieldValidations fieldValidations) { | ||
final Number randomDefaultValue; | ||
|
||
if (Objects.nonNull(fieldValidations) && ObjectUtils.anyNotNull(fieldValidations.getMin(), fieldValidations.getMax())) { | ||
final int minValue = ObjectUtils.defaultIfNull(fieldValidations.getMin(), 0); | ||
final int maxValue = ObjectUtils.defaultIfNull(fieldValidations.getMax(), (int) Float.MAX_VALUE); | ||
|
||
randomDefaultValue = uniformRandomProvider.nextDouble(minValue, maxValue); | ||
} else { | ||
randomDefaultValue = uniformRandomProvider.nextDouble(0, Float.MAX_VALUE); | ||
} | ||
|
||
return randomDefaultValue; | ||
} | ||
|
||
@Override | ||
public final String getSuffixValue() { | ||
return "F"; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters