use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class NumberFieldActions method convertDistanceUnit.
@AtlasFieldActionInfo(name = "ConvertDistanceUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertDistanceUnit(Action action, Number input) {
if (input == null) {
return 0;
}
if (action == null || !(action instanceof ConvertDistanceUnit) || ((ConvertDistanceUnit) action).getFromUnit() == null || ((ConvertDistanceUnit) action).getToUnit() == null) {
throw new IllegalArgumentException("ConvertDistanceUnit must be specfied with fromUnit and toUnit");
}
DistanceUnitType fromUnit = ((ConvertDistanceUnit) action).getFromUnit();
DistanceUnitType toUnit = ((ConvertDistanceUnit) action).getToUnit();
double rate = distanceConvertionTable.get(fromUnit).get(toUnit);
return doMultiply(input, rate);
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class NumberFieldActions method convertAreaUnit.
@AtlasFieldActionInfo(name = "ConvertAreaUnit", sourceType = FieldType.NUMBER, targetType = FieldType.NUMBER, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static Number convertAreaUnit(Action action, Number input) {
if (input == null) {
return 0;
}
if (action == null || !(action instanceof ConvertAreaUnit) || ((ConvertAreaUnit) action).getFromUnit() == null || ((ConvertAreaUnit) action).getToUnit() == null) {
throw new IllegalArgumentException("ConvertAreaUnit must be specfied with fromUnit and toUnit");
}
AreaUnitType fromUnit = ((ConvertAreaUnit) action).getFromUnit();
AreaUnitType toUnit = ((ConvertAreaUnit) action).getToUnit();
double rate = areaConvertionTable.get(fromUnit).get(toUnit);
return doMultiply(input, rate);
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method append.
@AtlasFieldActionInfo(name = "Append", sourceType = FieldType.ANY, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String append(Action action, Object input) {
if (!(action instanceof Append)) {
throw new IllegalArgumentException("Action must be an Append action");
}
Append append = (Append) action;
String string = append.getString();
if (input == null && string == null) {
return null;
}
if (string == null) {
return input.toString();
}
return input == null ? string : input.toString().concat(string);
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method subStringAfter.
@AtlasFieldActionInfo(name = "SubStringAfter", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String subStringAfter(Action action, String input) {
if (input == null || input.length() == 0) {
return input;
}
if (action == null || !(action instanceof SubStringAfter) || ((SubStringAfter) action).getStartIndex() == null || ((SubStringAfter) action).getStartIndex() < 0 || ((SubStringAfter) action).getMatch() == null || (((SubStringAfter) action).getEndIndex() != null && ((SubStringAfter) action).getEndIndex() < ((SubStringAfter) action).getStartIndex())) {
throw new IllegalArgumentException("SubStringAfter action must be specified with a positive startIndex and a string to match");
}
SubStringAfter subStringAfter = (SubStringAfter) action;
int idx = input.indexOf(subStringAfter.getMatch());
if (idx < 0) {
return input;
}
idx = idx + subStringAfter.getMatch().length();
return doSubString(input.substring(idx), subStringAfter.getStartIndex(), subStringAfter.getEndIndex());
}
use of io.atlasmap.spi.AtlasFieldActionInfo in project atlasmap by atlasmap.
the class StringComplexFieldActions method padStringRight.
@AtlasFieldActionInfo(name = "PadStringRight", sourceType = FieldType.STRING, targetType = FieldType.STRING, sourceCollectionType = CollectionType.NONE, targetCollectionType = CollectionType.NONE)
public static String padStringRight(Action action, String input) {
if (action == null || !(action instanceof PadStringRight) || ((PadStringRight) action).getPadCharacter() == null || ((PadStringRight) action).getPadCount() == null) {
throw new IllegalArgumentException("PadStringRight must be specfied with padCharacter and padCount");
}
PadStringRight padStringRight = (PadStringRight) action;
StringBuilder builder = new StringBuilder();
if (input != null) {
builder.append(input);
}
for (int i = 0; i < padStringRight.getPadCount(); i++) {
builder.append(padStringRight.getPadCharacter());
}
return builder.toString();
}
Aggregations