14#include "keyple/core/util/KeypleAssert.hpp"
19#include "keyple/core/util/HexUtil.hpp"
25const char* Assert::ARGUMENT =
"Argument [";
26const char* Assert::CONDITION =
"Condition [";
27const char* Assert::HAS_A_VALUE =
"] has a value [";
28const char* Assert::LESS_THAN =
"] less than [";
29const char* Assert::GREATER_THAN =
"] greater than [";
30const char* Assert::IS_NULL =
"] is null.";
31const char* Assert::IS_EMPTY =
"] is empty.";
32const char* Assert::IS_FALSE =
"] is false.";
33const char* Assert::IS_NOT_HEX =
"] is not a hex string.";
34const char* Assert::NOT_EQUAL_TO =
"] not equal to [";
35const char* Assert::CLOSING_BRACKET =
"].";
44 static Assert INSTANCE;
50Assert::notEmpty(
const std::string& obj,
const std::string& name)
53 throw IllegalArgumentException(ARGUMENT + name + IS_EMPTY);
60Assert::notEmpty(
const std::vector<uint8_t>& obj,
const std::string& name)
62 if (obj.size() == 0) {
63 throw IllegalArgumentException(ARGUMENT + name + IS_EMPTY);
70Assert::isTrue(
const bool condition,
const std::string& name)
73 throw IllegalArgumentException(CONDITION + name + IS_FALSE);
80Assert::greaterOrEqual(
81 const size_t number,
const size_t minValue,
const std::string& name)
83 if (number < minValue) {
84 throw IllegalArgumentException(
85 ARGUMENT + name + HAS_A_VALUE + std::to_string(number) + LESS_THAN
86 + std::to_string(minValue) + CLOSING_BRACKET);
94 const size_t number,
const size_t value,
const std::string& name)
96 if (number != value) {
97 throw IllegalArgumentException(
98 ARGUMENT + name + HAS_A_VALUE + std::to_string(number)
99 + NOT_EQUAL_TO + std::to_string(value) + CLOSING_BRACKET);
108 const size_t minValue,
109 const size_t maxValue,
110 const std::string& name)
112 if (number < minValue) {
113 throw IllegalArgumentException(
114 ARGUMENT + name + HAS_A_VALUE + std::to_string(number) + LESS_THAN
115 + std::to_string(minValue) + CLOSING_BRACKET);
116 }
else if (number > maxValue) {
117 throw IllegalArgumentException(
118 ARGUMENT + name + HAS_A_VALUE + std::to_string(number)
119 + GREATER_THAN + std::to_string(maxValue) + CLOSING_BRACKET);
126Assert::isHexString(
const std::string& hex,
const std::string& name)
128 if (!HexUtil::isValid(hex)) {
129 throw IllegalArgumentException(ARGUMENT + name + IS_NOT_HEX);