Type[] types = segment.getField( n ); for ( int t = 0; t < types.length; t++ ) { int nrComponents = Terser.numComponents( types[t] ); for ( int c = 1; c <= nrComponents; c++ ) { int nrSub = Terser.numSubComponents( types[t], c );
/** * Returns the number of sub-components in the specified component, i.e. the number of standard * sub-components (e.g. 6 for CE) plus any extra components that that have been added at * runtime. * * @param type composite type * @param component numbered from 1 * @return number of sub-components in the specified component */ public static int numSubComponents(Type type, int component) { if (component == 1 && Primitive.class.isAssignableFrom(type.getClass())) { // note that getComponent(primitive, 1) below returns the primitive // itself -- if we do numComponents on it, we'll end up with the // number of components in the field, not the number of subcomponents return 1; } Type comp = getComponent(type, component); return numComponents(comp); }
/** * Returns the number of sub-components in the specified component, i.e. the number of standard * sub-components (e.g. 6 for CE) plus any extra components that that have been added at * runtime. * * @param type composite type * @param component numbered from 1 * @return number of sub-components in the specified component */ public static int numSubComponents(Type type, int component) { if (component == 1 && Primitive.class.isAssignableFrom(type.getClass())) { // note that getComponent(primitive, 1) below returns the primitive // itself -- if we do numComponents on it, we'll end up with the // number of components in the field, not the number of subcomponents return 1; } Type comp = getComponent(type, component); return numComponents(comp); }
/** * Encodes the given Type, using the given encoding characters. * It is assumed that the Type represents a complete field rather than a component. */ public static String encode(Type source, EncodingCharacters encodingChars) { StringBuffer field = new StringBuffer(); for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuffer comp = new StringBuffer(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.append(encodePrimitive(p, encodingChars)); comp.append(encodingChars.getSubcomponentSeparator()); } field.append(stripExtraDelimiters(comp.toString(), encodingChars.getSubcomponentSeparator())); field.append(encodingChars.getComponentSeparator()); } return stripExtraDelimiters(field.toString(), encodingChars.getComponentSeparator()); //return encode(source, encodingChars, false); }
/** * Encodes the given Type, using the given encoding characters. * It is assumed that the Type represents a complete field rather than a component. */ public static String encode(Type source, EncodingCharacters encodingChars) { StringBuffer field = new StringBuffer(); for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuffer comp = new StringBuffer(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) { Primitive p = Terser.getPrimitive(source, i, j); comp.append(encodePrimitive(p, encodingChars)); comp.append(encodingChars.getSubcomponentSeparator()); } field.append(stripExtraDelimiters(comp.toString(), encodingChars.getSubcomponentSeparator())); field.append(encodingChars.getComponentSeparator()); } return stripExtraDelimiters(field.toString(), encodingChars.getComponentSeparator()); //return encode(source, encodingChars, false); }
/** * Returns the number of components in the given type, i.e. the number of standard components * (e.g. 6 for CE) plus any extra components that have been added at runtime. * * @param t composite type * @return the number of components in the given type */ public static int numComponents(Type t) { if (!(t instanceof Varies)) { return numStandardComponents(t) + t.getExtraComponents().numComponents(); } return numComponents(((Varies) t).getData()); }
for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuilder comp = new StringBuilder(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) {
/** * Returns the number of components in the given type, i.e. the number of standard components * (e.g. 6 for CE) plus any extra components that have been added at runtime. * * @param t composite type * @return the number of components in the given type */ public static int numComponents(Type t) { if (!(t instanceof Varies)) { return numStandardComponents(t) + t.getExtraComponents().numComponents(); } return numComponents(((Varies) t).getData()); }
for (int i = 1; i <= Terser.numComponents(source); i++) { StringBuilder comp = new StringBuilder(); for (int j = 1; j <= Terser.numSubComponents(source, i); j++) {
/** * Copies data from the "from" Type into the "to" Type. Either Type may be * a Primitive, Composite, or Varies. If a Varies is provided, the operation is * performed on the result of calling its getData() method. A Primitive may be * copied into a Composite, in which case the value is copied into the first * component of the Composite. A Composite may be copied into a Primitive, * in which case the first component is copied. Given Composites with different * numbers of components, the first components are copied, up to the length * of the smaller one. * * @param from type to copy from * @param to type to copy to * @throws DataTypeException if the types are not compatible */ public static void copy(Type from, Type to) throws DataTypeException { for (int i = 1; i <= Terser.numComponents(from); i++) { for (int j = 1; j <= Terser.numSubComponents(from, i); j++) { String val = Terser.getPrimitive(from, i, j).getValue(); Terser.getPrimitive(to, i, j).setValue(val); } } }
/** * Copies data from the "from" Type into the "to" Type. Either Type may be * a Primitive, Composite, or Varies. If a Varies is provided, the operation is * performed on the result of calling its getData() method. A Primitive may be * copied into a Composite, in which case the value is copied into the first * component of the Composite. A Composite may be copied into a Primitive, * in which case the first component is copied. Given Composites with different * numbers of components, the first components are copied, up to the length * of the smaller one. * * @param from type to copy from * @param to type to copy to * @throws DataTypeException if the types are not compatible */ public static void copy(Type from, Type to) throws DataTypeException { for (int i = 1; i <= Terser.numComponents(from); i++) { for (int j = 1; j <= Terser.numSubComponents(from, i); j++) { String val = Terser.getPrimitive(from, i, j).getValue(); Terser.getPrimitive(to, i, j).setValue(val); } } }