MCPcopy Create free account
hub / github.com/PCGen/pcgen / evaluate

Method evaluate

code/src/java/plugin/function/LookupFunction.java:142–186  ·  view source on GitHub ↗
(EvaluateVisitor visitor, Node[] args, EvaluationManager manager)

Source from the content-addressed store, hash-verified

140 }
141
142 @Override
143 public Object evaluate(EvaluateVisitor visitor, Node[] args, EvaluationManager manager)
144 {
145 LoadContext context = manager.get(ManagerKey.CONTEXT);
146 AbstractReferenceContext refContext = context.getReferenceContext();
147 DataTable dataTable = (DataTable) args[0].jjtAccept(visitor,
148 manager.getWith(EvaluationManager.ASSERTED, Optional.of(refContext.getManufacturer(DATATABLE_CLASS))));
149
150 FormatManager<?> lookupFormat = dataTable.getFormat(0);
151
152 //Lookup value (format based on the table)
153 Object lookupValue =
154 args[1].jjtAccept(visitor, manager.getWith(EvaluationManager.ASSERTED, Optional.of(lookupFormat)));
155
156 //Result Column
157 TableColumn column = (TableColumn) args[2].jjtAccept(visitor,
158 manager.getWith(EvaluationManager.ASSERTED, Optional.of(refContext.getManufacturer(COLUMN_CLASS))));
159
160 String columnName = column.getName();
161 if (!dataTable.isColumn(columnName))
162 {
163 FormatManager<?> fmt = column.getFormatManager();
164 System.out.println("Lookup called on invalid column: '" + columnName + "' is not present on table '"
165 + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
166 FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
167 return fm.getDefault(fmt);
168 }
169 String lookupRule = "EXACT";
170 if (args.length == 4)
171 {
172 lookupRule = (String) args[3].jjtAccept(visitor,
173 manager.getWith(EvaluationManager.ASSERTED, Optional.of(FormatUtilities.STRING_MANAGER)));
174 }
175 LookupType lookupType = DataTable.LookupType.valueOf(lookupRule);
176 if (!dataTable.hasRow(lookupType, lookupValue))
177 {
178 FormatManager<?> fmt = column.getFormatManager();
179 System.out.println(
180 "Lookup called on invalid item: '" + lookupValue + "' is not present in the first row of table '"
181 + dataTable.getName() + "' assuming default for " + fmt.getIdentifierType());
182 FormulaManager fm = manager.get(EvaluationManager.FMANAGER);
183 return fm.getDefault(fmt);
184 }
185 return dataTable.lookup(lookupType, lookupValue, columnName);
186 }
187
188 @Override
189 public Optional<FormatManager<?>> getDependencies(DependencyVisitor visitor, DependencyManager manager, Node[] args)

Callers

nothing calls this directly

Calls 15

getReferenceContextMethod · 0.95
getManufacturerMethod · 0.95
getFormatMethod · 0.95
getNameMethod · 0.95
isColumnMethod · 0.95
getFormatManagerMethod · 0.95
getNameMethod · 0.95
hasRowMethod · 0.95
lookupMethod · 0.95
ofMethod · 0.80
getMethod · 0.65
getIdentifierTypeMethod · 0.65

Tested by

no test coverage detected