@Override public void put(Double d, String v) { if (d == null || v == null) { throw new NullPointerException("Null values are not allowed in this mapping."); } if (parameter instanceof StringLiteral) { if (Double.isInfinite(d) && d < 0) { ((StringLiteral) parameter).setValue(v); } else { try { String current = parameter.getValue(null); Categorize2String c2s = new Categorize2String( new StringLiteral(current), new StringLiteral(current), new RealAttribute(getField())); c2s.put(new RealLiteral(d), new StringLiteral(v)); parameter = c2s; fireTypeChanged(); } catch (ParameterException pe) { throw new IllegalStateException( "We've failed at retrieved the value of a literal. " + "Something is going really wrong here."); } } } else { ((Categorize2String) parameter).put(new RealLiteral(d), new StringLiteral(v)); } }
/** * Sets the value obtained when the input data can't be processed for whatever reason. * * @param value The new fallback value. */ public void setFallbackValue(String value) { if (parameter instanceof StringLiteral) { ((StringLiteral) parameter).setValue(value); } else { ((Categorize2String) parameter).setFallbackValue(new StringLiteral(value)); } }
@Override public String getFromLower(Double d) { if (d == null) { throw new NullPointerException("The input threshold must not be null"); } if (parameter instanceof StringLiteral) { return ((StringLiteral) parameter).getValue(null); } else { String col = get(d); if (col == null) { Categorize2String c2s = (Categorize2String) parameter; Map<String, Value> inp = new HashMap<String, Value>(); inp.put(getField(), ValueFactory.createValue(d)); return c2s.getValue(inp); } else { return col; } } }
@Override public String remove(Double d) { if (d == null) { throw new NullPointerException("The input threshold must not be null"); } if (parameter instanceof StringLiteral) { return null; } else { Categorize2String c2s = (Categorize2String) parameter; StringParameter ret = c2s.remove(new RealLiteral(d)); if (ret == null) { return null; } else if (c2s.getNumClasses() == 1 && c2s.getFallbackValue().equals(c2s.get(0))) { parameter = new StringLiteral(c2s.getFallbackValue().getValue(null)); } if (ret instanceof StringLiteral) { try { return ret.getValue(null); } catch (ParameterException pe) { throw new IllegalStateException( "We've failed at retrieved the value of a literal. " + "Something is going really wrong here."); } } else { throw new IllegalStateException( "We're not supposed to have values that are not StringLiteral in this categorize."); } } }