public MetaData getMetaData(int index) { if (indexMap == null || indexMap.length < index + 1) { int startFrom = 0; int lastIndex = index; if (indexMap != null) { startFrom = indexMap.length; indexMap = Arrays.copyOf(indexMap, index + 1); } else { String[] headers = context.headers(); if (headers != null && lastIndex < headers.length) { lastIndex = headers.length; } int[] indexes = context.extractedFieldIndexes(); if (indexes != null) { for (int i = 0; i < indexes.length; i++) { if (lastIndex < indexes[i]) { lastIndex = indexes[i]; } } } indexMap = new MetaData[lastIndex + 1]; } for (int i = startFrom; i < lastIndex + 1; i++) { indexMap[i] = new MetaData(i); } } return indexMap[index]; }
private MetaData getMetaData(String name) { int index = context.indexOf(name); if (index == -1) { getValidatedHeaders(); throw new IllegalArgumentException( "Header name '" + name + "' not found. Available columns are: " + Arrays.asList(headers())); } return getMetaData(index); }
<T> Annotation buildAnnotation(Class<T> type, final String args1, final String... args2) { Integer hash = (type.hashCode() * 31) + String.valueOf(args1).hashCode() + (31 * Arrays.toString(args2).hashCode()); Annotation out = annotationHashes.get(hash); if (out == null) { if (type == Boolean.class || type == boolean.class) { out = buildBooleanStringAnnotation(args1 == null ? null : new String[] {args1}, args2); } else { out = newFormatAnnotation(args1, args2); } annotationHashes.put(hash, out); } return out; }
/** Calculates a MD5 digest of the class. */ public String getDigest() { try { if (_className == null || "".equals(_className)) return ""; DynamicClassLoader loader = (DynamicClassLoader) Thread.currentThread().getContextClassLoader(); ClassLoader tmpLoader = loader.getNewTempClassLoader(); Class cl = Class.forName(_className, false, tmpLoader); if (cl == null) return ""; MessageDigest digest = MessageDigest.getInstance("MD5"); addDigest(digest, cl.getName()); addDigest(digest, cl.getModifiers()); Class superClass = cl.getSuperclass(); if (superClass != null) addDigest(digest, superClass.getName()); Class[] interfaces = cl.getInterfaces(); for (int i = 0; i < interfaces.length; i++) addDigest(digest, interfaces[i].getName()); Field[] fields = cl.getDeclaredFields(); Arrays.sort(fields, new FieldComparator()); if (_checkFields) { for (Field field : fields) { if (Modifier.isPrivate(field.getModifiers()) && !_checkPrivate) continue; if (Modifier.isProtected(field.getModifiers()) && !_checkProtected) continue; addDigest(digest, field.getName()); addDigest(digest, field.getModifiers()); addDigest(digest, field.getType().getName()); addDigest(digest, field.getAnnotations()); } } Method[] methods = cl.getDeclaredMethods(); Arrays.sort(methods, new MethodComparator()); for (int i = 0; i < methods.length; i++) { Method method = methods[i]; if (Modifier.isPrivate(method.getModifiers()) && !_checkPrivate) continue; if (Modifier.isProtected(method.getModifiers()) && !_checkProtected) continue; if (Modifier.isStatic(method.getModifiers()) && !_checkStatic) continue; addDigest(digest, method.getName()); addDigest(digest, method.getModifiers()); addDigest(digest, method.getName()); Class[] param = method.getParameterTypes(); for (int j = 0; j < param.length; j++) addDigest(digest, param[j].getName()); addDigest(digest, method.getReturnType().getName()); Class[] exn = method.getExceptionTypes(); for (int j = 0; j < exn.length; j++) addDigest(digest, exn[j].getName()); addDigest(digest, method.getAnnotations()); } byte[] digestBytes = new byte[256]; int len = digest.digest(digestBytes, 0, digestBytes.length); return digestToBase64(digestBytes, len); } catch (Exception e) { log.log(Level.FINER, e.toString(), e); return ""; } }