package com.framsticks.params.types; import com.framsticks.params.AccessInterface; import com.framsticks.params.CastFailure; import com.framsticks.params.ReassignResult; import com.framsticks.params.UniqueListAccess; import com.framsticks.util.lang.Numbers; import java.util.HashMap; import java.util.Map; /** * @author Piotr Sniegowski */ public class UniqueListParam extends ListParam { final String uidName; public UniqueListParam(String containedTypeName, String uidName) { super(containedTypeName); this.uidName = uidName; } @Override public String computeAccessId() { return "l " + containedTypeName + " " + uidName; } @Override public Class getStorageType() { return Map.class; } @Override public AccessInterface prepareAccessInterface(AccessInterface access) { return new UniqueListAccess(access, uidName); } @Override public ReassignResult> reassign(Object newValue, Object oldValue) throws CastFailure { if (newValue instanceof Map) { return new ReassignResult>((Map) newValue); } Integer size = Numbers.cast(newValue, Integer.class); if (size != null) { //return oldValue; /* the integer value should be ignored, because this may cause, that object is created before information about it's elements is available, which would break resolution flow */ if (oldValue != null) { return new ReassignResult>((Map) oldValue); } return ReassignResult.create(new HashMap()); } throw new CastFailure(); } @Override public String getFramsTypeName() { return "l " + containedTypeName + " " + uidName; } }