@Override protected void checkParameterSet( final ConfigGroup module ) { switch ( module.getName() ) { case ModeRoutingParams.SET_TYPE: if ( !(module instanceof ModeRoutingParams) ) { throw new RuntimeException( "unexpected class for module "+module ); } break; default: throw new IllegalArgumentException( module.getName() ); } }
@Override protected void checkParameterSet(final ConfigGroup set) { switch ( set.getName() ) { case StrategySettings.SET_NAME: if ( !(set instanceof StrategySettings) ) { throw new RuntimeException( set+" is not an instance of StrategySettings" ); } break; default: throw new IllegalArgumentException( "unknown set type "+set.getName() ); } }
@Override protected void checkParameterSet( final ConfigGroup module ) { switch ( module.getName() ) { case RouteDesignScoreParams.SET_TYPE: if ( !(module instanceof RouteDesignScoreParams) ) { throw new RuntimeException( "unexpected class for module "+module ); } break; default: throw new IllegalArgumentException( module.getName() ); } }
public boolean removeParameterSet( final ConfigGroup set ) { final Collection<ConfigGroup> parameterSets = parameterSetsPerType.get( set.getName() ); return parameterSets != null ? parameterSets.remove( set ) : false; }
public void addParameterSet(final ConfigGroup set) { checkParameterSet( set ); Collection<ConfigGroup> parameterSets = parameterSetsPerType.get( set.getName() ); if ( parameterSets == null ) { parameterSets = new ArrayList<>(); parameterSetsPerType.put( set.getName() , parameterSets ); } parameterSets.add( set ); }
@Override public void checkConsistency(Config config) { for (ConfigGroup configGroup : config.getModules().values()) { if (configGroup.getClass().equals(ConfigGroup.class)) { throw new RuntimeException("Unmaterialized config group: "+configGroup.getName()); } } } }
@Override public void addParameterSet( final ConfigGroup set ) { switch ( set.getName() ) { case ActivityParams.SET_TYPE: addActivityParams( (ActivityParams) set ); break; case ModeParams.SET_TYPE: addModeParams( (ModeParams) set ); break; default: throw new IllegalArgumentException( set.getName() ); } }
@Override public final String toString() { StringBuilder str = new StringBuilder(); for ( Entry<String, String> entry : this.getParams().entrySet() ) { str.append('['); str.append(entry.getKey()); str.append('='); str.append(entry.getValue()); str.append(']'); } return "[name=" + this.getName() + "]" + "[nOfParams=" + this.getParams().size() + "]" + str.toString(); }
@Override protected void checkParameterSet(final ConfigGroup module) { switch (module.getName()) { case ScoringParameterSet.SET_TYPE: if (!(module instanceof ScoringParameterSet)) { throw new RuntimeException("wrong class for " + module); } final String s = ((ScoringParameterSet) module).getSubpopulation(); if (getScoringParameters(s) != null) { throw new IllegalStateException("already a parameter set for subpopulation " + s); } break; default: throw new IllegalArgumentException(module.getName()); } }
public static <C extends ConfigGroup & Modal> void checkSingleOrMultiModeConsistency(C cfg, MultiModal<C> multiModeCfg, Consumer<C> consistencyChecker) { if (cfg != null) { if (multiModeCfg != null) { throw new RuntimeException("Either single or multi-mode " + cfg.getName() + " must be defined"); } consistencyChecker.accept(cfg); } else { if (multiModeCfg == null) { throw new RuntimeException("Either single or multi-mode " + cfg.getName() + " must be defined"); } multiModeCfg.getModalElements().stream().forEach(consistencyChecker); if (!areModesUnique(multiModeCfg)) { throw new RuntimeException("Modes in multi-mode config are not unique"); } } }
/** * Convenience method to all addOrGetModule with only two arguments. * <br/> * Notes:<ul> * <li>Seems to be really slow, so don't use in inner loop.</li> * </ul> * @param config * @param moduleClass * @return instance of moduleClass inside config */ public static <T extends ConfigGroup> T addOrGetModule( Config config, Class<T> moduleClass ) { String groupName; try { groupName = moduleClass.newInstance().getName(); } catch (InstantiationException | IllegalAccessException e) { throw new RuntimeException(e) ; } return addOrGetModule( config, groupName, moduleClass ) ; }
@Override public void checkConsistency(Config config) { Set<ConstraintViolation<ConfigGroup>> violations = new HashSet<>(); List<String> messages = new ArrayList<>(); for (ConfigGroup group : config.getModules().values()) { Set<ConstraintViolation<ConfigGroup>> groupViolations = validator.validate(group); violations.addAll(groupViolations); for (ConstraintViolation<ConfigGroup> v : groupViolations) { messages.add(group.getName() + "." + v.getPropertyPath() + ": " + v.getMessage()); } } if (!violations.isEmpty()) { String message = "Errors in config:\n" + messages.stream().collect(Collectors.joining("\n")); throw new ConstraintViolationException(message, violations); } } }
@Override public void addParameterSet(final ConfigGroup set) { switch (set.getName()) { case ActivityParams.SET_TYPE: addActivityParams((ActivityParams) set); break; case ModeParams.SET_TYPE: addModeParams((ModeParams) set); break; case ScoringParameterSet.SET_TYPE: addScoringParameters((ScoringParameterSet) set); break; default: throw new IllegalArgumentException(set.getName()); } }
@Override public void addParameterSet(final ConfigGroup set) { if ( set.getName().equals( ModeRoutingParams.SET_TYPE ) && !this.acceptModeParamsWithoutClearing ) { clearParameterSetsForType( set.getName() ); this.acceptModeParamsWithoutClearing = true; } ModeRoutingParams pars = (ModeRoutingParams) set ; // for the time being pushing the "global" factor into the local ones if they are not initialized by // themselves. Necessary for some tests; maybe we should eventually disable them. kai, feb'15 if ( pars.getBeelineDistanceFactor()== null ) { pars.setBeelineDistanceFactor( this.beelineDistanceFactor ); } super.addParameterSet( set ); }
@Override void writeModule( final ConfigGroup module, final BufferedWriter out) { if ( ! (module instanceof ChangeLegModeConfigGroup) ) { // yyyy special case to provide error message; may be removed eventually. kai, may'16 ConfigGroup comparisonConfig = null ; if ( verbosity==Verbosity.minimal) { comparisonConfig = ConfigUtils.createConfig().getModules().get(module.getName()); // preference to generate this here multiple times to avoid having it as a field. kai, may'18 } writeModule( out, "", MODULE, NAME, module.getName(), module, comparisonConfig ); } }
out.write(" name=\"" + module.getName() + "\" >"); out.write(this.newline);
@Override protected void checkParameterSet( final ConfigGroup module ) { switch ( module.getName() ) { case ActivityParams.SET_TYPE: if ( !(module instanceof ActivityParams) ) { throw new RuntimeException( "wrong class for "+module ); } final String t = ((ActivityParams) module).getActivityType(); if ( getActivityParams( t ) != null ) { throw new IllegalStateException( "already a parameter set for activity type "+t ); } break; case ModeParams.SET_TYPE: if ( !(module instanceof ModeParams) ) { throw new RuntimeException( "wrong class for "+module ); } final String m = ((ModeParams) module).getMode(); if ( getModes().get( m ) != null ) { throw new IllegalStateException( "already a parameter set for mode "+m ); } break; default: throw new IllegalArgumentException( module.getName() ); } }
@Override protected void checkParameterSet(final ConfigGroup module) { switch (module.getName()) { case ActivityParams.SET_TYPE: if (!(module instanceof ActivityParams)) { throw new RuntimeException("wrong class for " + module); } final String t = ((ActivityParams) module).getActivityType(); if (getActivityParams(t) != null) { throw new IllegalStateException("already a parameter set for activity type " + t); } break; case ModeParams.SET_TYPE: if (!(module instanceof ModeParams)) { throw new RuntimeException("wrong class for " + module); } final String m = ((ModeParams) module).getMode(); if (getModes().get(m) != null) { throw new IllegalStateException("already a parameter set for mode " + m); } break; default: throw new IllegalArgumentException(module.getName()); } }
private static boolean sameType(ConfigGroup pSet, ConfigGroup cg) { if ( ! ( pSet.getName().equals( cg.getName() ) ) ) { return false; } if ( pSet instanceof ModeRoutingParams ) { // (these are the "teleportedRouteParameters" in config.xml) if ( ((ModeRoutingParams)pSet).getMode().equals( ((ModeRoutingParams)cg).getMode() ) ) { return true ; } } if ( pSet instanceof ScoringParameterSet ) { return true ; } if ( pSet instanceof ModeParams ) { if ( ((ModeParams)pSet).getMode().equals( ((ModeParams)cg).getMode() ) ) { return true ; } } if ( pSet instanceof ActivityParams ) { if ( ((ActivityParams)pSet).getActivityType().equals( ((ActivityParams)cg).getActivityType() ) ) { return true ; } } if ( pSet instanceof StrategySettings ) { return true ; // yy this will not work since there is no corresponding default entry! kai, may'18 } return false ; }