private FixedWidthFields()

in src/main/java/com/univocity/parsers/fixed/FixedWidthFields.java [144:196]


	private FixedWidthFields(Class beanClass, MethodFilter methodFilter) {
		if (beanClass == null) {
			throw new IllegalArgumentException("Class must not be null.");
		}

		List<TransformedHeader> fieldSequence = AnnotationHelper.getFieldSequence(beanClass, true, null, methodFilter);
		if (fieldSequence.isEmpty()) {
			throw new IllegalArgumentException("Can't derive fixed-width fields from class '" + beanClass.getName() + "'. No @Parsed annotations found.");
		}

		Set<String> fieldNamesWithoutConfig = new LinkedHashSet<String>();

		for (TransformedHeader field : fieldSequence) {
			if (field == null) {
				continue;
			}
			String fieldName = field.getHeaderName();

			FixedWidth fw = AnnotationHelper.findAnnotation(field.getTarget(), FixedWidth.class);
			if (fw == null) {
				fieldNamesWithoutConfig.add(field.getTargetName());
				continue;
			}

			int length = AnnotationRegistry.getValue(field.getTarget(), fw, "value", fw.value());
			int from = AnnotationRegistry.getValue(field.getTarget(), fw, "from", fw.from());
			int to = AnnotationRegistry.getValue(field.getTarget(), fw, "to", fw.to());


			FieldAlignment alignment = AnnotationRegistry.getValue(field.getTarget(), fw, "alignment", fw.alignment());
			char padding = AnnotationRegistry.getValue(field.getTarget(), fw, "padding", fw.padding());

			if (length != -1) {
				if (from != -1 || to != -1) {
					throw new IllegalArgumentException("Can't initialize fixed-width field from " + field.describe() + ". " +
							"Can't have field length (" + length + ") defined along with position from (" + from + ") and to (" + to + ")");

				}

				addField(fieldName, length, alignment, padding);
			} else if (from != -1 && to != -1) {
				addField(fieldName, from, to, alignment, padding);
			} else {
				throw new IllegalArgumentException("Can't initialize fixed-width field from " + field.describe() + "'. " +
						"Field length/position undefined defined");
			}
		}

		if (fieldNamesWithoutConfig.size() > 0) {
			throw new IllegalArgumentException("Can't derive fixed-width fields from class '" + beanClass.getName() + "'. " +
					"The following fields don't have a @FixedWidth annotation: " + fieldNamesWithoutConfig);
		}
	}