public short getTerminologyComponentIdAsShort(final String terminologyComponentId) { Preconditions.checkNotNull(terminologyComponentId, "Terminology component identifier argument cannot be null."); Preconditions.checkArgument(!StringUtils.isEmpty(terminologyComponentId), "Terminology component identifier argument cannot be empty string."); Short componentId = ID_TO_SHORT_CACHE.get(terminologyComponentId); if (null != componentId) { return componentId.shortValue(); } final int asInt = getTerminologyComponentIdAsInt(terminologyComponentId); if (asInt < Integer.MIN_VALUE || asInt > Integer.MAX_VALUE) throw new NumberFormatException("Value out of range. Value:\"" + asInt); componentId = Short.valueOf((short) asInt); ID_TO_SHORT_CACHE.put(terminologyComponentId, componentId); return (short) asInt; }
public short getTerminologyComponentIdAsShort(final Object object) { Preconditions.checkNotNull(object, "Object argument cannot be null."); Short id = CLASS_TO_SHORT_CACHE.get(object.getClass()); if (null != id) { return id.shortValue(); } else if (object instanceof ExtendedComponent) { return ((ExtendedComponent) object).getTerminologyComponentId(); } final int asInt = getTerminologyComponentIdAsInt(object); if (asInt < Integer.MIN_VALUE || asInt > Integer.MAX_VALUE) throw new NumberFormatException("Value out of range. Value:\"" + asInt); id = Short.valueOf((short) asInt); CLASS_TO_SHORT_CACHE.put(object.getClass(), id); return (short) asInt; }
public int getTerminologyComponentIdAsInt(final Object object) { Preconditions.checkNotNull(object, "Object argument cannot be null."); final Integer componentId = CLASS_TO_INT_CACHE.get(object.getClass()); if (null != componentId) { return componentId.intValue(); } else if (object instanceof ExtendedComponent) { return (int) ((ExtendedComponent) object).getTerminologyComponentId(); } for (final IConfigurationElement element : Platform.getExtensionRegistry().getConfigurationElementsFor(REPRESENTATION_EXTENSION_POINT_ID)) { final String representationClass = element.getAttribute(CLASS_ATTRIBUTE); if (ClassUtils.isClassAssignableFrom(object.getClass(), representationClass)) { final int idAsInt = getTerminologyComponentIdAsInt(element.getAttribute(TERMINOLOGY_COMPONENT_ID_ATTRIBUTE)); CLASS_TO_INT_CACHE.put(object.getClass(), Integer.valueOf(idAsInt)); return idAsInt; } } throw new IllegalArgumentException("No terminology component extension has been registered for the passed in object: " + object.getClass()); }