Class HigsonContext
- All Implemented Interfaces:
ParamContext
- Direct Known Subclasses:
AdhocContext,HigsonSubContext
- Author:
- przemek hertel
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionTries to resolve given path and return object from the context.booleangetBoolean(String path) Tries to resolve path the same way as methodget(String)and then return value as boolean.getBooleanHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into BooleanHolder with some boolean support.static BooleanTypeGet Boolean type instance used by Higson.Tries to resolve path the same way as methodget(String)and then return value as Date with date format.getDateHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into DateHolder with some Date support.getDatetime(String path) Tries to resolve path the same way as methodget(String)and then return value as Date with date and time format.getDatetimeHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into DatetimeHolder with some Date support.static DatetimeTypeGet Datetime type instance used by Higson.static DateTypeGet Date type instance used by Higson.getDecimal(String path) Tries to resolve path the same way as methodget(String)and then return value as BigDecimal.Tries to resolve path the same way as methodget(String), but object under this path must implementIterable.getInteger(String path) Tries to resolve path the same way as methodget(String)and then return value as Integer.getIntegerHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into IntegerHolder with some integer support.static IntegerTypeGet Integer type instance used by Higson.getLocalDate(String path) Tries to resolve path the same way as methodget(String)and then return value as LocalDate with date format.getLocalDateHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into LocalDateHolder with some LocalDate support.getLocalDatetime(String path) Tries to resolve path the same way as methodget(String)and then return value as LocalDateTime with date and time format.getLocalDatetimeHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into LocalDatetimeHolder with some LocalDateTime support.static LocalDateTimeTypeGet LocalDateTime type instance used by Higson.static LocalDateTypeGet LocalDate type instance used by Higson.protected ObjectgetNull()doubleTries to resolve path the same way as methodget(String)and then return value as double.getNumberHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into NumberHolder with some number support.static NumberTypeGet Number type instance used by Higson.Tries to resolve path the same way as methodget(String)and then return value as String.getStringHolder(String path) Tries to resolve path the same way as methodget(String)and then return value wrapped into StringHolder with some String support.static StringTypeGet String type instance used by Higson.static voidinitialize(TypesDto dto) Initialized supported types.Put given value object under specified path.toString()Methods inherited from class io.higson.runtime.engine.core.context.DefaultContext
adhoc, get, get, getLevelValues, getUserContext, has, initialize, modifyKey, set, setLevelValues, with, with, withLevelValues, withLevelValues
-
Field Details
-
SKIP_PARENT
-
-
Constructor Details
-
HigsonContext
-
-
Method Details
-
set
Put given value object under specified path.- Parameters:
path- where object will be storedvalue- any object- Returns:
- the same context instance with stored value under the path
- Throws:
DuplicateContextItemException- if path was already in use
-
get
Tries to resolve given path and return object from the context. If the object is not found at first try, then method is looking for objects by resolving subPath. SubPath is created by stripping given path (between first occurrence of '.' character) into first token and the rest of the path. If stripping was successful and first token is an existing object in context, then algorithm tries to use it as a subContext for the subPath. The more objects exists in depth in context, the longer it might take to resolve them.
Examples:HigsonContext ctx = new HigsonContext("policy.status", "AA"); Object s1 = ctx.get("policy.status"); // found object Object s2 = ctx.get("policy.info"); // s2 is null here, since there is not object with this path defined in cotext // Sample with parent context and subContext HigsonContext policyCtx = new HigsonContext().set("status", "AA"); HigsonContext ctx = new HigsonContext().set("policy", policyCtx); assertThat(ctx.getString("policy.status"), is("AA")); assertThat(ctx.getString("policy.info"), nullValue()); assertThat(ctx.getString("user.name"), nullValue());- Overrides:
getin classDefaultContext- Parameters:
path- to be resolved when looking for object- Returns:
- object if path was successfully resolved, otherwise null
-
getFirst
Tries to resolve path the same way as methodget(String), but object under this path must implementIterable. If it does, then the first object is returned from Iterable, but which first object is returned, that depends on used collection.- Parameters:
path- to be resolved and looking for collection- Returns:
- first object from collection under path if found, null otherwise
-
getNull
-
getStringHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into StringHolder with some String support.HigsonContext ctx = new HigsonContext("policy.status", "AA"); StringHolder s1 = ctx.getStringHolder("policy.status"); assertThat(s1.getString(), is("AA")); assertThat(s1.isBlank(), is(false));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into StringHolder
-
getString
Tries to resolve path the same way as method
Example:get(String)and then return value as String.HigsonContext ctx = new HigsonContext("policy.status", "AA"); assertThat(ctx.getString("policy.status"), is("AA"));- Overrides:
getStringin classDefaultContext- Parameters:
path- to be resolved and looking for value- Returns:
- value as String or null if not found
- See Also:
-
getNumberHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into NumberHolder with some number support.HigsonContext ctx = new HigsonContext("policy.factor", "1.23"); NumberHolder s1 = ctx.getNumberHolder("policy.factor"); assertThat(h1.getBigDecimal(), is(new BigDecimal("1.23"))); assertEquals(1.23, h1.doubleValue(), 1e-6);- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into NumberHolder
-
getDecimal
Tries to resolve path the same way as method
Example:get(String)and then return value as BigDecimal.HigsonContext ctx = new HigsonContext("factor", "1,23"); assertThat(ctx.getDecimal("factor"), is(new BigDecimal("1.23")));- Parameters:
path- to be resolved and looking for value- Returns:
- value as BigDecimal or null if not found
-
getNumber
Tries to resolve path the same way as method
Example:get(String)and then return value as double.HigsonContext ctx = new HigsonContext("factor", "1,23"); assertEquals(1.23, ctx.getNumber("factor"), 1e-6); assertThat(ctx.getNumber("factory"), is(0.0));- Parameters:
path- to be resolved and looking for value- Returns:
- value as double or 0.0 if not found
-
getIntegerHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into IntegerHolder with some integer support.HigsonContext ctx = new HigsonContext("count", "123"); assertThat(ctx.getIntegerHolder("count").intValue(), is(123)); assertThat(ctx.getIntegerHolder("counter").getInteger(), nullValue());- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into IntegerHolder
-
getInteger
Tries to resolve path the same way as method
Example:get(String)and then return value as Integer.HigsonContext ctx = new HigsonContext().set("count", "123"); assertThat(ctx.getInteger("count"), is(123)); assertThat(ctx.getInteger("counter"), nullValue());- Parameters:
path- to be resolved and looking for value- Returns:
- value as Integer or null if not found
-
getDateHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into DateHolder with some Date support.Date rcd = new Date(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); DateHolder h1 = ctx.getDateHolder("policy.rcd"); assertThat(h1.getDate(), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into DateHolder
-
getDate
Tries to resolve path the same way as method
Example:get(String)and then return value as Date with date format.Date rcd = new Date(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); assertThat(ctx.getDate("policy.rcd"), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- value as Date or null if not found
-
getLocalDateHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into LocalDateHolder with some LocalDate support.LocalDate rcd = new LocalDate(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); LocalDateHolder h1 = ctx.getLocalDateHolder("policy.rcd"); assertThat(h1.getLocalDate(), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into LocalDateHolder
-
getLocalDate
Tries to resolve path the same way as method
Example:get(String)and then return value as LocalDate with date format.LocalDate rcd = new LocalDate(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); assertThat(ctx.getLocalDate("policy.rcd"), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- value as LocalDate or null if not found
-
getDatetimeHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into DatetimeHolder with some Date support.Date rcd = new Date(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); DatetimeHolder h1 = ctx.getDatetimeHolder("policy.rcd"); assertThat(h1.getDatetime(), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into DatetimeHolder
-
getDatetime
Tries to resolve path the same way as method
Example:get(String)and then return value as Date with date and time format.Date rcd = new Date(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); assertThat(ctx.getDatetime("policy.rcd"), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- value as Date or null if not found
-
getLocalDatetimeHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into LocalDatetimeHolder with some LocalDateTime support.LocalDateTime rcd = new LocalDateTime(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); LocalDateTimeHolder h1 = ctx.getLocalDatetimeHolder("policy.rcd"); assertThat(h1.getLocalDateTime(), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into LocalDatetimeHolder
-
getLocalDatetime
Tries to resolve path the same way as method
Example:get(String)and then return value as LocalDateTime with date and time format.LocalDateTime rcd = new LocalDateTime(); HigsonContext ctx = new HigsonContext("policy.rcd", rcd); assertThat(ctx.getLocalDateTime("policy.rcd"), sameInstance(rcd));- Parameters:
path- to be resolved and looking for value- Returns:
- value as LocalDateTime or null if not found
-
getBooleanHolder
Tries to resolve path the same way as method
Example:get(String)and then return value wrapped into BooleanHolder with some boolean support.HigsonContext ctx = new HigsonContext().set("flag1", "tak").set("flag2", "no"); assertThat(ctx.getBooleanHolder("flag1").booleanValue(), is(true)); assertThat(ctx.getBooleanHolder("flag1").getBoolean(), is(true)); assertThat(ctx.getBooleanHolder("flag2").getBoolean(), is(false)); assertThat(ctx.getBooleanHolder("flag2").booleanValue(), is(false));- Parameters:
path- to be resolved and looking for value- Returns:
- wrapped value or null if not found into BooleanHolder
-
getBoolean
Tries to resolve path the same way as method
Example:get(String)and then return value as boolean.HigsonContext ctx = new HigsonContext().set("flag1", "tak").set("flag2", "no"); assertThat(ctx.getBoolean("flag1"), is(true)); assertThat(ctx.getBoolean("flag2"), is(false));- Parameters:
path- to be resolved and looking for value- Returns:
- value as boolean or false if not found
-
initialize
Initialized supported types.- Parameters:
dto- with supported types
-
getStringType
Get String type instance used by Higson. It might be used for wrapping String into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Example:StringType type = ctx.getStringType(); StringHolder holder = type.convert(new Integer(17)); // 17 == holder.getValue()- Returns:
- supported StringType with String Holder
-
getNumberType
Get Number type instance used by Higson. It might be used for wrapping Number into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Example:NumberType type = ctx.getNumberType(); NumberHolder holder = type.decode("1143.54");- Returns:
- supported NumberType with Number Holder
-
getIntegerType
Get Integer type instance used by Higson. It might be used for wrapping Integer into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Example:IntegerType type = ctx.getIntegerType(); IntegerHolder holder = type.decode("1143");- Returns:
- supported IntegerType with Integer Holder
-
getBooleanType
Get Boolean type instance used by Higson. It might be used for wrapping Boolean into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Example:BooleanType type = ctx.getBooleanType(); BooleanType holder = type.decode("tak"); BooleanType holder = type.decode("y"); BooleanType holder = type.decode("yes"); BooleanType holder = type.decode("1");- Returns:
- supported BooleanType with Boolean Holder
-
getDateType
Get Date type instance used by Higson. It might be used for wrapping Date into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Supported formats:- yyyy-MM-dd - default
- dd-MM-yyyy
- dd.MM.yyyy
- dd/MM/yyyy
- yyyy-MM-dd
- yyyy.MM.dd
- yyyy/MM/dd
DateType type = ctx.getDateType(); DateHolder holder = type.decode("2018-10-29");- Returns:
- supported DateType with Date Holder
-
getLocalDateType
Get LocalDate type instance used by Higson. It might be used for wrapping LocalDate into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Supported formats:- yyyy-MM-dd - default
- dd-MM-yyyy
- dd.MM.yyyy
- dd/MM/yyyy
- yyyy-MM-dd
- yyyy.MM.dd
- yyyy/MM/dd
LocalDate type = ctx.getLocalDateType(); LocalDateHolder holder = type.decode("2018-10-29");- Returns:
- supported LocalDateType with LocalDate Holder
-
getDatetimeType
Get Datetime type instance used by Higson. It might be used for wrapping Date into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Supported formats:- yyyy-MM-dd HH:mm:ss.SSS - default
- dd-MM-yyyy HH:mm:ss.SSS
- dd.MM.yyyy HH:mm:ss.SSS
- dd/MM/yyyy HH:mm:ss.SSS
- yyyy-MM-dd HH:mm:ss.SSS
- yyyy.MM.dd HH:mm:ss.SSS
- yyyy/MM/dd HH:mm:ss.SSS
DatetimeType type = ctx.getDatetimeType(); DatetimeHolder holder = type.decode("2018-07-31 14:56:07.627");- Returns:
- supported DatetimeType with Datetime Holder
-
getLocalDateTimeType
Get LocalDateTime type instance used by Higson. It might be used for wrapping LocalDateTime into recognizable type by Higson, trying out conversions, encoding and decoding supported by engine.
Supported formats:- yyyy-MM-dd HH:mm:ss.SSS - default
- dd-MM-yyyy HH:mm:ss.SSS
- dd.MM.yyyy HH:mm:ss.SSS
- dd/MM/yyyy HH:mm:ss.SSS
- yyyy-MM-dd HH:mm:ss.SSS
- yyyy.MM.dd HH:mm:ss.SSS
- yyyy/MM/dd HH:mm:ss.SSS
- DateTimeFormatter.ISO_LOCAL_DATE_TIME
- DateTimeFormatter.ISO_OFFSET_DATE_TIME
- DateTimeFormatter.ISO_ZONED_DATE_TIME
- DateTimeFormatter.ISO_DATE_TIME
- DateTimeFormatter.RFC_1123_DATE_TIME
LocalDateTimeType type = ctx.getLocalDateTimeType(); LocalDateTimeHolder holder = type.decode("2018-07-31 14:56:07.627");- Returns:
- supported LocalDateTimeType with LocalDateTime Holder
-
toString
- Overrides:
toStringin classDefaultContext
-