_id
stringlengths 2
7
| title
stringlengths 3
140
| partition
stringclasses 3
values | text
stringlengths 73
34.1k
| language
stringclasses 1
value | meta_information
dict |
---|---|---|---|---|---|
q2700
|
PerformanceMonitorBeanDefinitionDecorator.registerProxyCreator
|
train
|
private void registerProxyCreator(Node source,
BeanDefinitionHolder holder,
ParserContext context) {
String beanName = holder.getBeanName();
String proxyName = beanName + "Proxy";
String interceptorName = beanName + "PerformanceMonitorInterceptor";
BeanDefinitionBuilder initializer =
BeanDefinitionBuilder.rootBeanDefinition(BeanNameAutoProxyCreator.class);
initializer.addPropertyValue("beanNames", beanName);
initializer.addPropertyValue("interceptorNames", interceptorName);
BeanDefinitionRegistry registry = context.getRegistry();
registry.registerBeanDefinition(proxyName, initializer.getBeanDefinition());
}
|
java
|
{
"resource": ""
}
|
q2701
|
CircuitBreakerFactory.getIntegerPropertyOverrideValue
|
train
|
private Integer getIntegerPropertyOverrideValue(String name, String key) {
if (properties != null) {
String propertyName = getPropertyName(name, key);
String propertyOverrideValue = properties.getProperty(propertyName);
if (propertyOverrideValue != null) {
try {
return Integer.parseInt(propertyOverrideValue);
}
catch (NumberFormatException e) {
logger.error("Could not parse property override key={}, value={}",
key, propertyOverrideValue);
}
}
}
return null;
}
|
java
|
{
"resource": ""
}
|
q2702
|
SingleServiceWrapperInterceptor.shouldWrapMethodCall
|
train
|
private boolean shouldWrapMethodCall(String methodName) {
if (methodList == null) {
return true; // Wrap all by default
}
if (methodList.contains(methodName)) {
return true; //Wrap a specific method
}
// If I get to this point, I should not wrap the call.
return false;
}
|
java
|
{
"resource": ""
}
|
q2703
|
MBeanOperationInvoker.invokeOperation
|
train
|
public Object invokeOperation(Map<String, String[]> parameterMap) throws JMException {
MBeanParameterInfo[] parameterInfoArray = operationInfo.getSignature();
Object[] values = new Object[parameterInfoArray.length];
String[] types = new String[parameterInfoArray.length];
MBeanValueConverter valueConverter = createMBeanValueConverter(parameterMap);
for (int parameterNum = 0; parameterNum < parameterInfoArray.length; parameterNum++) {
MBeanParameterInfo parameterInfo = parameterInfoArray[parameterNum];
String type = parameterInfo.getType();
types[parameterNum] = type;
values[parameterNum] = valueConverter.convertParameterValue(parameterInfo.getName(), type);
}
return mBeanServer.invoke(objectName, operationInfo.getName(), values, types);
}
|
java
|
{
"resource": ""
}
|
q2704
|
MonitorMethodInterceptorDefinitionDecorator.registerInterceptor
|
train
|
private void registerInterceptor(Node source,
String beanName,
BeanDefinitionRegistry registry) {
List<String> methodList = buildMethodList(source);
BeanDefinitionBuilder initializer =
BeanDefinitionBuilder.rootBeanDefinition(SingleServiceWrapperInterceptor.class);
initializer.addPropertyValue("methods", methodList);
String perfMonitorName = beanName + "PerformanceMonitor";
initializer.addPropertyReference("serviceWrapper", perfMonitorName);
String interceptorName = beanName + "PerformanceMonitorInterceptor";
registry.registerBeanDefinition(interceptorName, initializer.getBeanDefinition());
}
|
java
|
{
"resource": ""
}
|
q2705
|
MonitorMethodInterceptorDefinitionDecorator.parseMethodList
|
train
|
public List<String> parseMethodList(String methods) {
String[] methodArray = StringUtils.delimitedListToStringArray(methods, ",");
List<String> methodList = new ArrayList<String>();
for (String methodName : methodArray) {
methodList.add(methodName.trim());
}
return methodList;
}
|
java
|
{
"resource": ""
}
|
q2706
|
MonitorMethodInterceptorDefinitionDecorator.registerPerformanceMonitor
|
train
|
private void registerPerformanceMonitor(String beanName,
BeanDefinitionRegistry registry) {
String perfMonitorName = beanName + "PerformanceMonitor";
if (!registry.containsBeanDefinition(perfMonitorName)) {
BeanDefinitionBuilder initializer =
BeanDefinitionBuilder.rootBeanDefinition(PerformanceMonitorBean.class);
registry.registerBeanDefinition(perfMonitorName, initializer.getBeanDefinition());
}
}
|
java
|
{
"resource": ""
}
|
q2707
|
Files.forceDelete
|
train
|
public static void forceDelete(final Path path) throws IOException {
if (!java.nio.file.Files.isDirectory(path)) {
java.nio.file.Files.delete(path);
} else {
java.nio.file.Files.walkFileTree(path, DeleteDirVisitor.getInstance());
}
}
|
java
|
{
"resource": ""
}
|
q2708
|
SelectCreator.count
|
train
|
public PreparedStatementCreator count(final Dialect dialect) {
return new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection con)
throws SQLException {
return getPreparedStatementCreator()
.setSql(dialect.createCountSelect(builder.toString()))
.createPreparedStatement(con);
}
};
}
|
java
|
{
"resource": ""
}
|
q2709
|
SelectCreator.page
|
train
|
public PreparedStatementCreator page(final Dialect dialect, final int limit, final int offset) {
return new PreparedStatementCreator() {
public PreparedStatement createPreparedStatement(Connection con) throws SQLException {
return getPreparedStatementCreator()
.setSql(dialect.createPageSelect(builder.toString(), limit, offset))
.createPreparedStatement(con);
}
};
}
|
java
|
{
"resource": ""
}
|
q2710
|
Column.toColumnName
|
train
|
private static String toColumnName(String fieldName) {
int lastDot = fieldName.indexOf('.');
if (lastDot > -1) {
return fieldName.substring(lastDot + 1);
} else {
return fieldName;
}
}
|
java
|
{
"resource": ""
}
|
q2711
|
Predicates.anyBitsSet
|
train
|
public static Predicate anyBitsSet(final String expr, final long bits) {
return new Predicate() {
private String param;
public void init(AbstractSqlCreator creator) {
param = creator.allocateParameter();
creator.setParameter(param, bits);
}
public String toSql() {
return String.format("(%s & :%s) > 0", expr, param);
}
};
}
|
java
|
{
"resource": ""
}
|
q2712
|
Predicates.is
|
train
|
public static Predicate is(final String sql) {
return new Predicate() {
public String toSql() {
return sql;
}
public void init(AbstractSqlCreator creator) {
}
};
}
|
java
|
{
"resource": ""
}
|
q2713
|
Predicates.join
|
train
|
private static Predicate join(final String joinWord, final List<Predicate> preds) {
return new Predicate() {
public void init(AbstractSqlCreator creator) {
for (Predicate p : preds) {
p.init(creator);
}
}
public String toSql() {
StringBuilder sb = new StringBuilder()
.append("(");
boolean first = true;
for (Predicate p : preds) {
if (!first) {
sb.append(" ").append(joinWord).append(" ");
}
sb.append(p.toSql());
first = false;
}
return sb.append(")").toString();
}
};
}
|
java
|
{
"resource": ""
}
|
q2714
|
Mapping.addFields
|
train
|
public Mapping<T> addFields() {
if (idColumn == null) {
throw new RuntimeException("Map ID column before adding class fields");
}
for (Field f : ReflectionUtils.getDeclaredFieldsInHierarchy(clazz)) {
if (!Modifier.isStatic(f.getModifiers())
&& !isFieldMapped(f.getName())
&& !ignoredFields.contains(f.getName())) {
addColumn(f.getName());
}
}
return this;
}
|
java
|
{
"resource": ""
}
|
q2715
|
Mapping.createInstance
|
train
|
protected T createInstance() {
try {
Constructor<T> ctor = clazz.getDeclaredConstructor();
ctor.setAccessible(true);
return ctor.newInstance();
} catch (InstantiationException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
} catch (SecurityException e) {
throw new RuntimeException(e);
} catch (NoSuchMethodException e) {
throw new RuntimeException(e);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (InvocationTargetException e) {
throw new RuntimeException(e);
}
}
|
java
|
{
"resource": ""
}
|
q2716
|
Mapping.deleteById
|
train
|
public void deleteById(Object id) {
int count = beginDelete().whereEquals(idColumn.getColumnName(), id).delete();
if (count == 0) {
throw new RowNotFoundException(table, id);
}
}
|
java
|
{
"resource": ""
}
|
q2717
|
Mapping.findById
|
train
|
public T findById(Object id) throws RowNotFoundException, TooManyRowsException {
return findWhere(eq(idColumn.getColumnName(), id)).getSingleResult();
}
|
java
|
{
"resource": ""
}
|
q2718
|
Mapping.insert
|
train
|
public T insert(T entity) {
if (!hasPrimaryKey(entity)) {
throw new RuntimeException(String.format("Tried to insert entity of type %s with null or zero primary key",
entity.getClass().getSimpleName()));
}
InsertCreator insert = new InsertCreator(table);
insert.setValue(idColumn.getColumnName(), getPrimaryKey(entity));
if (versionColumn != null) {
insert.setValue(versionColumn.getColumnName(), 0);
}
for (Column column : columns) {
if (!column.isReadOnly()) {
insert.setValue(column.getColumnName(), getFieldValueAsColumn(entity, column));
}
}
new JdbcTemplate(ormConfig.getDataSource()).update(insert);
if (versionColumn != null) {
ReflectionUtils.setFieldValue(entity, versionColumn.getFieldName(), 0);
}
return entity;
}
|
java
|
{
"resource": ""
}
|
q2719
|
Mapping.hasPrimaryKey
|
train
|
private boolean hasPrimaryKey(T entity) {
Object pk = getPrimaryKey(entity);
if (pk == null) {
return false;
} else {
if (pk instanceof Number && ((Number) pk).longValue() == 0) {
return false;
}
}
return true;
}
|
java
|
{
"resource": ""
}
|
q2720
|
Mapping.update
|
train
|
public T update(T entity) throws RowNotFoundException, OptimisticLockException {
if (!hasPrimaryKey(entity)) {
throw new RuntimeException(String.format("Tried to update entity of type %s without a primary key", entity
.getClass().getSimpleName()));
}
UpdateCreator update = new UpdateCreator(table);
update.whereEquals(idColumn.getColumnName(), getPrimaryKey(entity));
if (versionColumn != null) {
update.set(versionColumn.getColumnName() + " = " + versionColumn.getColumnName() + " + 1");
update.whereEquals(versionColumn.getColumnName(), getVersion(entity));
}
for (Column column : columns) {
if (!column.isReadOnly()) {
update.setValue(column.getColumnName(), getFieldValueAsColumn(entity, column));
}
}
int rows = new JdbcTemplate(ormConfig.getDataSource()).update(update);
if (rows == 1) {
if (versionColumn != null) {
ReflectionUtils.setFieldValue(entity, versionColumn.getFieldName(), getVersion(entity) + 1);
}
return entity;
} else if (rows > 1) {
throw new RuntimeException(
String.format("Updating table %s with id %s updated %d rows. There must be a mapping problem. Is column %s really the primary key?",
table, getPrimaryKey(entity), rows, idColumn));
} else {
//
// Updated zero rows. This could be because our ID is wrong, or
// because our object is out-of date. Let's try querying just by ID.
//
SelectCreator selectById = new SelectCreator()
.column("count(*)")
.from(table)
.whereEquals(idColumn.getColumnName(), getPrimaryKey(entity));
rows = new JdbcTemplate(ormConfig.getDataSource()).query(selectById, new ResultSetExtractor<Integer>() {
@Override
public Integer extractData(ResultSet rs) throws SQLException, DataAccessException {
rs.next();
return rs.getInt(1);
}
});
if (rows == 0) {
throw new RowNotFoundException(table, getPrimaryKey(entity));
} else {
throw new OptimisticLockException(table, getPrimaryKey(entity));
}
}
}
|
java
|
{
"resource": ""
}
|
q2721
|
AbstractSqlCreator.setParameter
|
train
|
public AbstractSqlCreator setParameter(String name, Object value) {
ppsc.setParameter(name, value);
return this;
}
|
java
|
{
"resource": ""
}
|
q2722
|
InsertBuilder.set
|
train
|
public InsertBuilder set(String column, String value) {
columns.add(column);
values.add(value);
return this;
}
|
java
|
{
"resource": ""
}
|
q2723
|
SelectBuilder.orderBy
|
train
|
public SelectBuilder orderBy(String name, boolean ascending) {
if (ascending) {
orderBys.add(name + " asc");
} else {
orderBys.add(name + " desc");
}
return this;
}
|
java
|
{
"resource": ""
}
|
q2724
|
StringListFlattener.split
|
train
|
public List<String> split(String s) {
List<String> result = new ArrayList<String>();
if (s == null) {
return result;
}
boolean seenEscape = false;
// Used to detect if the last char was a separator,
// in which case we append an empty string
boolean seenSeparator = false;
StringBuilder sb = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
seenSeparator = false;
char c = s.charAt(i);
if (seenEscape) {
if (c == escapeChar || c == separator) {
sb.append(c);
} else {
sb.append(escapeChar).append(c);
}
seenEscape = false;
} else {
if (c == escapeChar) {
seenEscape = true;
} else if (c == separator) {
if (sb.length() == 0 && convertEmptyToNull) {
result.add(null);
} else {
result.add(sb.toString());
}
sb.setLength(0);
seenSeparator = true;
} else {
sb.append(c);
}
}
}
// Clean up
if (seenEscape) {
sb.append(escapeChar);
}
if (sb.length() > 0 || seenSeparator) {
if (sb.length() == 0 && convertEmptyToNull) {
result.add(null);
} else {
result.add(sb.toString());
}
}
return result;
}
|
java
|
{
"resource": ""
}
|
q2725
|
StringListFlattener.join
|
train
|
public String join(List<String> list) {
if (list == null) {
return null;
}
StringBuilder sb = new StringBuilder();
boolean first = true;
for (String s : list) {
if (s == null) {
if (convertEmptyToNull) {
s = "";
} else {
throw new IllegalArgumentException("StringListFlattener does not support null strings in the list. Consider calling setConvertEmptyToNull(true).");
}
}
if (!first) {
sb.append(separator);
}
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == escapeChar || c == separator) {
sb.append(escapeChar);
}
sb.append(c);
}
first = false;
}
return sb.toString();
}
|
java
|
{
"resource": ""
}
|
q2726
|
AbstractSqlBuilder.appendList
|
train
|
protected void appendList(StringBuilder sql, List<?> list, String init, String sep) {
boolean first = true;
for (Object s : list) {
if (first) {
sql.append(init);
} else {
sql.append(sep);
}
sql.append(s);
first = false;
}
}
|
java
|
{
"resource": ""
}
|
q2727
|
EnumStringConverter.create
|
train
|
public static <E extends Enum<E>> EnumStringConverter<E> create(Class<E> enumType) {
return new EnumStringConverter<E>(enumType);
}
|
java
|
{
"resource": ""
}
|
q2728
|
ReflectionUtils.getDeclaredFieldsInHierarchy
|
train
|
public static Field[] getDeclaredFieldsInHierarchy(Class<?> clazz) {
if (clazz.isPrimitive()) {
throw new IllegalArgumentException("Primitive types not supported.");
}
List<Field> result = new ArrayList<Field>();
while (true) {
if (clazz == Object.class) {
break;
}
result.addAll(Arrays.asList(clazz.getDeclaredFields()));
clazz = clazz.getSuperclass();
}
return result.toArray(new Field[result.size()]);
}
|
java
|
{
"resource": ""
}
|
q2729
|
ReflectionUtils.getDeclaredFieldWithPath
|
train
|
public static Field getDeclaredFieldWithPath(Class<?> clazz, String path) {
int lastDot = path.lastIndexOf('.');
if (lastDot > -1) {
String parentPath = path.substring(0, lastDot);
String fieldName = path.substring(lastDot + 1);
Field parentField = getDeclaredFieldWithPath(clazz, parentPath);
return getDeclaredFieldInHierarchy(parentField.getType(), fieldName);
} else {
return getDeclaredFieldInHierarchy(clazz, path);
}
}
|
java
|
{
"resource": ""
}
|
q2730
|
ReflectionUtils.getFieldValue
|
train
|
public static Object getFieldValue(Object object, String fieldName) {
try {
return getDeclaredFieldInHierarchy(object.getClass(), fieldName).get(object);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
|
java
|
{
"resource": ""
}
|
q2731
|
ReflectionUtils.setFieldValue
|
train
|
public static void setFieldValue(Object object, String fieldName, Object value) {
try {
getDeclaredFieldInHierarchy(object.getClass(), fieldName).set(object, value);
} catch (IllegalArgumentException e) {
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
throw new RuntimeException(e);
}
}
|
java
|
{
"resource": ""
}
|
q2732
|
LMinMax.checkPreconditions
|
train
|
private static void checkPreconditions(final long min, final long max) {
if( max < min ) {
throw new IllegalArgumentException(String.format("max (%d) should not be < min (%d)", max, min));
}
}
|
java
|
{
"resource": ""
}
|
q2733
|
ReflectionUtils.findGetter
|
train
|
public static Method findGetter(final Object object, final String fieldName) {
if( object == null ) {
throw new NullPointerException("object should not be null");
} else if( fieldName == null ) {
throw new NullPointerException("fieldName should not be null");
}
final Class<?> clazz = object.getClass();
// find a standard getter
final String standardGetterName = getMethodNameForField(GET_PREFIX, fieldName);
Method getter = findGetterWithCompatibleReturnType(standardGetterName, clazz, false);
// if that fails, try for an isX() style boolean getter
if( getter == null ) {
final String booleanGetterName = getMethodNameForField(IS_PREFIX, fieldName);
getter = findGetterWithCompatibleReturnType(booleanGetterName, clazz, true);
}
if( getter == null ) {
throw new SuperCsvReflectionException(
String
.format(
"unable to find getter for field %s in class %s - check that the corresponding nameMapping element matches the field name in the bean",
fieldName, clazz.getName()));
}
return getter;
}
|
java
|
{
"resource": ""
}
|
q2734
|
Util.filterListToMap
|
train
|
public static <T> void filterListToMap(final Map<String, T> destinationMap, final String[] nameMapping,
final List<? extends T> sourceList) {
if( destinationMap == null ) {
throw new NullPointerException("destinationMap should not be null");
} else if( nameMapping == null ) {
throw new NullPointerException("nameMapping should not be null");
} else if( sourceList == null ) {
throw new NullPointerException("sourceList should not be null");
} else if( nameMapping.length != sourceList.size() ) {
throw new SuperCsvException(
String
.format(
"the nameMapping array and the sourceList should be the same size (nameMapping length = %d, sourceList size = %d)",
nameMapping.length, sourceList.size()));
}
destinationMap.clear();
for( int i = 0; i < nameMapping.length; i++ ) {
final String key = nameMapping[i];
if( key == null ) {
continue; // null's in the name mapping means skip column
}
// no duplicates allowed
if( destinationMap.containsKey(key) ) {
throw new SuperCsvException(String.format("duplicate nameMapping '%s' at index %d", key, i));
}
destinationMap.put(key, sourceList.get(i));
}
}
|
java
|
{
"resource": ""
}
|
q2735
|
Util.filterMapToList
|
train
|
public static List<Object> filterMapToList(final Map<String, ?> map, final String[] nameMapping) {
if( map == null ) {
throw new NullPointerException("map should not be null");
} else if( nameMapping == null ) {
throw new NullPointerException("nameMapping should not be null");
}
final List<Object> result = new ArrayList<Object>(nameMapping.length);
for( final String key : nameMapping ) {
result.add(map.get(key));
}
return result;
}
|
java
|
{
"resource": ""
}
|
q2736
|
Util.filterMapToObjectArray
|
train
|
public static Object[] filterMapToObjectArray(final Map<String, ?> values, final String[] nameMapping) {
if( values == null ) {
throw new NullPointerException("values should not be null");
} else if( nameMapping == null ) {
throw new NullPointerException("nameMapping should not be null");
}
final Object[] targetArray = new Object[nameMapping.length];
int i = 0;
for( final String name : nameMapping ) {
targetArray[i++] = values.get(name);
}
return targetArray;
}
|
java
|
{
"resource": ""
}
|
q2737
|
IsIncludedIn.checkPreconditions
|
train
|
private static void checkPreconditions(final Set<Object> possibleValues) {
if( possibleValues == null ) {
throw new NullPointerException("possibleValues Set should not be null");
} else if( possibleValues.isEmpty() ) {
throw new IllegalArgumentException("possibleValues Set should not be empty");
}
}
|
java
|
{
"resource": ""
}
|
q2738
|
Truncate.checkPreconditions
|
train
|
private static void checkPreconditions(final int maxSize, final String suffix) {
if( maxSize <= 0 ) {
throw new IllegalArgumentException(String.format("maxSize should be > 0 but was %d", maxSize));
}
if( suffix == null ) {
throw new NullPointerException("suffix should not be null");
}
}
|
java
|
{
"resource": ""
}
|
q2739
|
AbstractCsvWriter.writeRow
|
train
|
protected void writeRow(final String... columns) throws IOException {
if( columns == null ) {
throw new NullPointerException(String.format("columns to write should not be null on line %d", lineNumber));
} else if( columns.length == 0 ) {
throw new IllegalArgumentException(String.format("columns to write should not be empty on line %d",
lineNumber));
}
StringBuilder builder = new StringBuilder();
for( int i = 0; i < columns.length; i++ ) {
columnNumber = i + 1; // column no used by CsvEncoder
if( i > 0 ) {
builder.append((char) preference.getDelimiterChar()); // delimiter
}
final String csvElement = columns[i];
if( csvElement != null ) {
final CsvContext context = new CsvContext(lineNumber, rowNumber, columnNumber);
final String escapedCsv = encoder.encode(csvElement, context, preference);
builder.append(escapedCsv);
lineNumber = context.getLineNumber(); // line number can increment when encoding multi-line columns
}
}
builder.append(preference.getEndOfLineSymbols()); // EOL
writer.write(builder.toString());
}
|
java
|
{
"resource": ""
}
|
q2740
|
HashMapper.checkPreconditions
|
train
|
private static void checkPreconditions(final Map<Object, Object> mapping) {
if( mapping == null ) {
throw new NullPointerException("mapping should not be null");
} else if( mapping.isEmpty() ) {
throw new IllegalArgumentException("mapping should not be empty");
}
}
|
java
|
{
"resource": ""
}
|
q2741
|
ParseDateTimeAbstract.checkPreconditions
|
train
|
private static void checkPreconditions(final String dateFormat, final Locale locale) {
if( dateFormat == null ) {
throw new NullPointerException("dateFormat should not be null");
} else if( locale == null ) {
throw new NullPointerException("locale should not be null");
}
}
|
java
|
{
"resource": ""
}
|
q2742
|
StrReplace.checkPreconditions
|
train
|
private static void checkPreconditions(final String regex, final String replacement) {
if( regex == null ) {
throw new NullPointerException("regex should not be null");
} else if( regex.length() == 0 ) {
throw new IllegalArgumentException("regex should not be empty");
}
if( replacement == null ) {
throw new NullPointerException("replacement should not be null");
}
}
|
java
|
{
"resource": ""
}
|
q2743
|
TwoDHashMap.get
|
train
|
public V get(final K1 firstKey, final K2 secondKey) {
// existence check on inner map
final HashMap<K2, V> innerMap = map.get(firstKey);
if( innerMap == null ) {
return null;
}
return innerMap.get(secondKey);
}
|
java
|
{
"resource": ""
}
|
q2744
|
MethodCache.getGetMethod
|
train
|
public Method getGetMethod(final Object object, final String fieldName) {
if( object == null ) {
throw new NullPointerException("object should not be null");
} else if( fieldName == null ) {
throw new NullPointerException("fieldName should not be null");
}
Method method = getCache.get(object.getClass().getName(), fieldName);
if( method == null ) {
method = ReflectionUtils.findGetter(object, fieldName);
getCache.set(object.getClass().getName(), fieldName, method);
}
return method;
}
|
java
|
{
"resource": ""
}
|
q2745
|
MethodCache.getSetMethod
|
train
|
public <T> Method getSetMethod(final Object object, final String fieldName, final Class<?> argumentType) {
if( object == null ) {
throw new NullPointerException("object should not be null");
} else if( fieldName == null ) {
throw new NullPointerException("fieldName should not be null");
} else if( argumentType == null ) {
throw new NullPointerException("argumentType should not be null");
}
Method method = setMethodsCache.get(object.getClass(), argumentType, fieldName);
if( method == null ) {
method = ReflectionUtils.findSetter(object, fieldName, argumentType);
setMethodsCache.set(object.getClass(), argumentType, fieldName, method);
}
return method;
}
|
java
|
{
"resource": ""
}
|
q2746
|
CsvBeanReader.invokeSetter
|
train
|
private static void invokeSetter(final Object bean, final Method setMethod, final Object fieldValue) {
try {
setMethod.setAccessible(true);
setMethod.invoke(bean, fieldValue);
}
catch(final Exception e) {
throw new SuperCsvReflectionException(String.format("error invoking method %s()", setMethod.getName()), e);
}
}
|
java
|
{
"resource": ""
}
|
q2747
|
CsvBeanReader.populateBean
|
train
|
private <T> T populateBean(final T resultBean, final String[] nameMapping) {
// map each column to its associated field on the bean
for( int i = 0; i < nameMapping.length; i++ ) {
final Object fieldValue = processedColumns.get(i);
// don't call a set-method in the bean if there is no name mapping for the column or no result to store
if( nameMapping[i] == null || fieldValue == null ) {
continue;
}
// invoke the setter on the bean
Method setMethod = cache.getSetMethod(resultBean, nameMapping[i], fieldValue.getClass());
invokeSetter(resultBean, setMethod, fieldValue);
}
return resultBean;
}
|
java
|
{
"resource": ""
}
|
q2748
|
CsvBeanReader.readIntoBean
|
train
|
private <T> T readIntoBean(final T bean, final String[] nameMapping, final CellProcessor[] processors)
throws IOException {
if( readRow() ) {
if( nameMapping.length != length() ) {
throw new IllegalArgumentException(String.format(
"the nameMapping array and the number of columns read "
+ "should be the same size (nameMapping length = %d, columns = %d)", nameMapping.length,
length()));
}
if( processors == null ) {
processedColumns.clear();
processedColumns.addAll(getColumns());
} else {
executeProcessors(processedColumns, processors);
}
return populateBean(bean, nameMapping);
}
return null; // EOF
}
|
java
|
{
"resource": ""
}
|
q2749
|
Strlen.checkAndAddLengths
|
train
|
private void checkAndAddLengths(final int... requiredLengths) {
for( final int length : requiredLengths ) {
if( length < 0 ) {
throw new IllegalArgumentException(String.format("required length cannot be negative but was %d",
length));
}
this.requiredLengths.add(length);
}
}
|
java
|
{
"resource": ""
}
|
q2750
|
RequireSubStr.checkPreconditions
|
train
|
private static void checkPreconditions(List<String> requiredSubStrings) {
if( requiredSubStrings == null ) {
throw new NullPointerException("requiredSubStrings List should not be null");
} else if( requiredSubStrings.isEmpty() ) {
throw new IllegalArgumentException("requiredSubStrings List should not be empty");
}
}
|
java
|
{
"resource": ""
}
|
q2751
|
RequireSubStr.checkAndAddRequiredSubStrings
|
train
|
private void checkAndAddRequiredSubStrings(final List<String> requiredSubStrings) {
for( String required : requiredSubStrings ) {
if( required == null ) {
throw new NullPointerException("required substring should not be null");
}
this.requiredSubStrings.add(required);
}
}
|
java
|
{
"resource": ""
}
|
q2752
|
ForbidSubStr.checkPreconditions
|
train
|
private static void checkPreconditions(final List<String> forbiddenSubStrings) {
if( forbiddenSubStrings == null ) {
throw new NullPointerException("forbiddenSubStrings list should not be null");
} else if( forbiddenSubStrings.isEmpty() ) {
throw new IllegalArgumentException("forbiddenSubStrings list should not be empty");
}
}
|
java
|
{
"resource": ""
}
|
q2753
|
ForbidSubStr.checkAndAddForbiddenStrings
|
train
|
private void checkAndAddForbiddenStrings(final List<String> forbiddenSubStrings) {
for( String forbidden : forbiddenSubStrings ) {
if( forbidden == null ) {
throw new NullPointerException("forbidden substring should not be null");
}
this.forbiddenSubStrings.add(forbidden);
}
}
|
java
|
{
"resource": ""
}
|
q2754
|
ThreeDHashMap.get
|
train
|
public HashMap<K2, HashMap<K3, V>> get(final K1 firstKey) {
return map.get(firstKey);
}
|
java
|
{
"resource": ""
}
|
q2755
|
ThreeDHashMap.getAs2d
|
train
|
public TwoDHashMap<K2, K3, V> getAs2d(final K1 firstKey) {
final HashMap<K2, HashMap<K3, V>> innerMap1 = map.get(firstKey);
if( innerMap1 != null ) {
return new TwoDHashMap<K2, K3, V>(innerMap1);
} else {
return new TwoDHashMap<K2, K3, V>();
}
}
|
java
|
{
"resource": ""
}
|
q2756
|
ThreeDHashMap.size
|
train
|
public int size(final K1 firstKey) {
// existence check on inner map
final HashMap<K2, HashMap<K3, V>> innerMap = map.get(firstKey);
if( innerMap == null ) {
return 0;
}
return innerMap.size();
}
|
java
|
{
"resource": ""
}
|
q2757
|
ThreeDHashMap.size
|
train
|
public int size(final K1 firstKey, final K2 secondKey) {
// existence check on inner map
final HashMap<K2, HashMap<K3, V>> innerMap1 = map.get(firstKey);
if( innerMap1 == null ) {
return 0;
}
// existence check on inner map1
final HashMap<K3, V> innerMap2 = innerMap1.get(secondKey);
if( innerMap2 == null ) {
return 0;
}
return innerMap2.size();
}
|
java
|
{
"resource": ""
}
|
q2758
|
BeanInterfaceProxy.createProxy
|
train
|
public static <T> T createProxy(final Class<T> proxyInterface) {
if( proxyInterface == null ) {
throw new NullPointerException("proxyInterface should not be null");
}
return proxyInterface.cast(Proxy.newProxyInstance(proxyInterface.getClassLoader(),
new Class[] { proxyInterface }, new BeanInterfaceProxy()));
}
|
java
|
{
"resource": ""
}
|
q2759
|
SuperCsvCellProcessorException.getUnexpectedTypeMessage
|
train
|
private static String getUnexpectedTypeMessage(final Class<?> expectedType, final Object actualValue) {
if( expectedType == null ) {
throw new NullPointerException("expectedType should not be null");
}
String expectedClassName = expectedType.getName();
String actualClassName = (actualValue != null) ? actualValue.getClass().getName() : "null";
return String.format("the input value should be of type %s but is %s", expectedClassName, actualClassName);
}
|
java
|
{
"resource": ""
}
|
q2760
|
AbstractCsvReader.executeProcessors
|
train
|
protected List<Object> executeProcessors(final List<Object> processedColumns, final CellProcessor[] processors) {
Util.executeCellProcessors(processedColumns, getColumns(), processors, getLineNumber(), getRowNumber());
return processedColumns;
}
|
java
|
{
"resource": ""
}
|
q2761
|
MongoServer.stopListenting
|
train
|
public void stopListenting() {
if (channel != null) {
log.info("closing server channel");
channel.close().syncUninterruptibly();
channel = null;
}
}
|
java
|
{
"resource": ""
}
|
q2762
|
AbstractMongoCollection.convertSelectorToDocument
|
train
|
Document convertSelectorToDocument(Document selector) {
Document document = new Document();
for (String key : selector.keySet()) {
if (key.startsWith("$")) {
continue;
}
Object value = selector.get(key);
if (!Utils.containsQueryExpression(value)) {
Utils.changeSubdocumentValue(document, key, value, (AtomicReference<Integer>) null);
}
}
return document;
}
|
java
|
{
"resource": ""
}
|
q2763
|
BsonDecoder.decodeCString
|
train
|
String decodeCString(ByteBuf buffer) throws IOException {
int length = buffer.bytesBefore(BsonConstants.STRING_TERMINATION);
if (length < 0)
throw new IOException("string termination not found");
String result = buffer.toString(buffer.readerIndex(), length, StandardCharsets.UTF_8);
buffer.skipBytes(length + 1);
return result;
}
|
java
|
{
"resource": ""
}
|
q2764
|
InstantDeserializer._countPeriods
|
train
|
protected int _countPeriods(String str)
{
int commas = 0;
for (int i = 0, end = str.length(); i < end; ++i) {
int ch = str.charAt(i);
if (ch < '0' || ch > '9') {
if (ch == '.') {
++commas;
} else {
return -1;
}
}
}
return commas;
}
|
java
|
{
"resource": ""
}
|
q2765
|
JSR310DeserializerBase._peelDTE
|
train
|
protected DateTimeException _peelDTE(DateTimeException e) {
while (true) {
Throwable t = e.getCause();
if (t != null && t instanceof DateTimeException) {
e = (DateTimeException) t;
continue;
}
break;
}
return e;
}
|
java
|
{
"resource": ""
}
|
q2766
|
InstantSerializerBase._acceptTimestampVisitor
|
train
|
@Override
protected void _acceptTimestampVisitor(JsonFormatVisitorWrapper visitor, JavaType typeHint)
throws JsonMappingException
{
SerializerProvider prov = visitor.getProvider();
if ((prov != null) && useNanoseconds(prov)) {
JsonNumberFormatVisitor v2 = visitor.expectNumberFormat(typeHint);
if (v2 != null) {
v2.numberType(NumberType.BIG_DECIMAL);
}
} else {
JsonIntegerFormatVisitor v2 = visitor.expectIntegerFormat(typeHint);
if (v2 != null) {
v2.numberType(NumberType.LONG);
}
}
}
|
java
|
{
"resource": ""
}
|
q2767
|
HyperLinkUtil.applyHyperLinkToElement
|
train
|
public static void applyHyperLinkToElement(DynamicJasperDesign design, DJHyperLink djlink, JRDesignChart chart, String name) {
JRDesignExpression hlpe = ExpressionUtils.createAndRegisterExpression(design, name, djlink.getExpression());
chart.setHyperlinkReferenceExpression(hlpe);
chart.setHyperlinkType( HyperlinkTypeEnum.REFERENCE ); //FIXME Should this be a parameter in the future?
if (djlink.getTooltip() != null){
JRDesignExpression tooltipExp = ExpressionUtils.createAndRegisterExpression(design, "tooltip_" + name, djlink.getTooltip());
chart.setHyperlinkTooltipExpression(tooltipExp);
}
}
|
java
|
{
"resource": ""
}
|
q2768
|
Dj2JrCrosstabBuilder.setCrosstabOptions
|
train
|
private void setCrosstabOptions() {
if (djcross.isUseFullWidth()){
jrcross.setWidth(layoutManager.getReport().getOptions().getPrintableWidth());
} else {
jrcross.setWidth(djcross.getWidth());
}
jrcross.setHeight(djcross.getHeight());
jrcross.setColumnBreakOffset(djcross.getColumnBreakOffset());
jrcross.setIgnoreWidth(djcross.isIgnoreWidth());
}
|
java
|
{
"resource": ""
}
|
q2769
|
Dj2JrCrosstabBuilder.setExpressionForPrecalculatedTotalValue
|
train
|
private void setExpressionForPrecalculatedTotalValue(
DJCrosstabColumn[] auxCols, DJCrosstabRow[] auxRows, JRDesignExpression measureExp, DJCrosstabMeasure djmeasure,
DJCrosstabColumn crosstabColumn, DJCrosstabRow crosstabRow, String meausrePrefix) {
String rowValuesExp = "new Object[]{";
String rowPropsExp = "new String[]{";
for (int i = 0; i < auxRows.length; i++) {
if (auxRows[i].getProperty()== null)
continue;
rowValuesExp += "$V{" + auxRows[i].getProperty().getProperty() +"}";
rowPropsExp += "\"" + auxRows[i].getProperty().getProperty() +"\"";
if (i+1<auxRows.length && auxRows[i+1].getProperty()!= null){
rowValuesExp += ", ";
rowPropsExp += ", ";
}
}
rowValuesExp += "}";
rowPropsExp += "}";
String colValuesExp = "new Object[]{";
String colPropsExp = "new String[]{";
for (int i = 0; i < auxCols.length; i++) {
if (auxCols[i].getProperty()== null)
continue;
colValuesExp += "$V{" + auxCols[i].getProperty().getProperty() +"}";
colPropsExp += "\"" + auxCols[i].getProperty().getProperty() +"\"";
if (i+1<auxCols.length && auxCols[i+1].getProperty()!= null){
colValuesExp += ", ";
colPropsExp += ", ";
}
}
colValuesExp += "}";
colPropsExp += "}";
String measureProperty = meausrePrefix + djmeasure.getProperty().getProperty();
String expText = "((("+DJCRosstabMeasurePrecalculatedTotalProvider.class.getName()+")$P{crosstab-measure__"+measureProperty+"_totalProvider}).getValueFor( "
+ colPropsExp +", "
+ colValuesExp +", "
+ rowPropsExp
+ ", "
+ rowValuesExp
+" ))";
if (djmeasure.getValueFormatter() != null){
String fieldsMap = ExpressionUtils.getTextForFieldsFromScriptlet();
String parametersMap = ExpressionUtils.getTextForParametersFromScriptlet();
String variablesMap = ExpressionUtils.getTextForVariablesFromScriptlet();
String stringExpression = "((("+DJValueFormatter.class.getName()+")$P{crosstab-measure__"+measureProperty+"_vf}).evaluate( "
+ "("+expText+"), " + fieldsMap +", " + variablesMap + ", " + parametersMap +" ))";
measureExp.setText(stringExpression);
measureExp.setValueClassName(djmeasure.getValueFormatter().getClassName());
} else {
// String expText = "((("+DJCRosstabMeasurePrecalculatedTotalProvider.class.getName()+")$P{crosstab-measure__"+djmeasure.getProperty().getProperty()+"_totalProvider}).getValueFor( "
// + colPropsExp +", "
// + colValuesExp +", "
// + rowPropsExp
// + ", "
// + rowValuesExp
// +" ))";
//
log.debug("text for crosstab total provider is: " + expText);
measureExp.setText(expText);
// measureExp.setValueClassName(djmeasure.getValueFormatter().getClassName());
String valueClassNameForOperation = ExpressionUtils.getValueClassNameForOperation(djmeasure.getOperation(),djmeasure.getProperty());
measureExp.setValueClassName(valueClassNameForOperation);
}
}
|
java
|
{
"resource": ""
}
|
q2770
|
Dj2JrCrosstabBuilder.getRowTotalStyle
|
train
|
private Style getRowTotalStyle(DJCrosstabRow crosstabRow) {
return crosstabRow.getTotalStyle() == null ? this.djcross.getRowTotalStyle(): crosstabRow.getTotalStyle();
}
|
java
|
{
"resource": ""
}
|
q2771
|
Dj2JrCrosstabBuilder.registerRows
|
train
|
private void registerRows() {
for (int i = 0; i < rows.length; i++) {
DJCrosstabRow crosstabRow = rows[i];
JRDesignCrosstabRowGroup ctRowGroup = new JRDesignCrosstabRowGroup();
ctRowGroup.setWidth(crosstabRow.getHeaderWidth());
ctRowGroup.setName(crosstabRow.getProperty().getProperty());
JRDesignCrosstabBucket rowBucket = new JRDesignCrosstabBucket();
//New in JR 4.1+
rowBucket.setValueClassName(crosstabRow.getProperty().getValueClassName());
ctRowGroup.setBucket(rowBucket);
JRDesignExpression bucketExp = ExpressionUtils.createExpression("$F{"+crosstabRow.getProperty().getProperty()+"}", crosstabRow.getProperty().getValueClassName());
rowBucket.setExpression(bucketExp);
JRDesignCellContents rowHeaderContents = new JRDesignCellContents();
JRDesignTextField rowTitle = new JRDesignTextField();
JRDesignExpression rowTitExp = new JRDesignExpression();
rowTitExp.setValueClassName(crosstabRow.getProperty().getValueClassName());
rowTitExp.setText("$V{"+crosstabRow.getProperty().getProperty()+"}");
rowTitle.setExpression(rowTitExp);
rowTitle.setWidth(crosstabRow.getHeaderWidth());
//The width can be the sum of the with of all the rows starting from the current one, up to the inner most one.
int auxHeight = getRowHeaderMaxHeight(crosstabRow);
// int auxHeight = crosstabRow.getHeight(); //FIXME getRowHeaderMaxHeight() must be FIXED because it breaks when 1rs row shows total and 2nd doesn't
rowTitle.setHeight(auxHeight);
Style headerstyle = crosstabRow.getHeaderStyle() == null ? this.djcross.getRowHeaderStyle(): crosstabRow.getHeaderStyle();
if (headerstyle != null){
layoutManager.applyStyleToElement(headerstyle, rowTitle);
rowHeaderContents.setBackcolor(headerstyle.getBackgroundColor());
}
rowHeaderContents.addElement(rowTitle);
rowHeaderContents.setMode( ModeEnum.OPAQUE );
boolean fullBorder = i <= 0; //Only outer most will have full border
applyCellBorder(rowHeaderContents, false, fullBorder);
ctRowGroup.setHeader(rowHeaderContents );
if (crosstabRow.isShowTotals())
createRowTotalHeader(ctRowGroup,crosstabRow,fullBorder);
try {
jrcross.addRowGroup(ctRowGroup);
} catch (JRException e) {
log.error(e.getMessage(),e);
}
}
}
|
java
|
{
"resource": ""
}
|
q2772
|
Dj2JrCrosstabBuilder.registerColumns
|
train
|
private void registerColumns() {
for (int i = 0; i < cols.length; i++) {
DJCrosstabColumn crosstabColumn = cols[i];
JRDesignCrosstabColumnGroup ctColGroup = new JRDesignCrosstabColumnGroup();
ctColGroup.setName(crosstabColumn.getProperty().getProperty());
ctColGroup.setHeight(crosstabColumn.getHeaderHeight());
JRDesignCrosstabBucket bucket = new JRDesignCrosstabBucket();
bucket.setValueClassName(crosstabColumn.getProperty().getValueClassName());
JRDesignExpression bucketExp = ExpressionUtils.createExpression("$F{"+crosstabColumn.getProperty().getProperty()+"}", crosstabColumn.getProperty().getValueClassName());
bucket.setExpression(bucketExp);
ctColGroup.setBucket(bucket);
JRDesignCellContents colHeaerContent = new JRDesignCellContents();
JRDesignTextField colTitle = new JRDesignTextField();
JRDesignExpression colTitleExp = new JRDesignExpression();
colTitleExp.setValueClassName(crosstabColumn.getProperty().getValueClassName());
colTitleExp.setText("$V{"+crosstabColumn.getProperty().getProperty()+"}");
colTitle.setExpression(colTitleExp);
colTitle.setWidth(crosstabColumn.getWidth());
colTitle.setHeight(crosstabColumn.getHeaderHeight());
//The height can be the sum of the heights of all the columns starting from the current one, up to the inner most one.
int auxWidth = calculateRowHeaderMaxWidth(crosstabColumn);
colTitle.setWidth(auxWidth);
Style headerstyle = crosstabColumn.getHeaderStyle() == null ? this.djcross.getColumnHeaderStyle(): crosstabColumn.getHeaderStyle();
if (headerstyle != null){
layoutManager.applyStyleToElement(headerstyle,colTitle);
colHeaerContent.setBackcolor(headerstyle.getBackgroundColor());
}
colHeaerContent.addElement(colTitle);
colHeaerContent.setMode( ModeEnum.OPAQUE );
boolean fullBorder = i <= 0; //Only outer most will have full border
applyCellBorder(colHeaerContent, fullBorder, false);
ctColGroup.setHeader(colHeaerContent);
if (crosstabColumn.isShowTotals())
createColumTotalHeader(ctColGroup,crosstabColumn,fullBorder);
try {
jrcross.addColumnGroup(ctColGroup);
} catch (JRException e) {
log.error(e.getMessage(),e);
}
}
}
|
java
|
{
"resource": ""
}
|
q2773
|
Dj2JrCrosstabBuilder.calculateRowHeaderMaxWidth
|
train
|
private int calculateRowHeaderMaxWidth(DJCrosstabColumn crosstabColumn) {
int auxWidth = 0;
boolean firstTime = true;
List<DJCrosstabColumn> auxList = new ArrayList<DJCrosstabColumn>(djcross.getColumns());
Collections.reverse(auxList);
for (DJCrosstabColumn col : auxList) {
if (col.equals(crosstabColumn)){
if (auxWidth == 0)
auxWidth = col.getWidth();
break;
}
if (firstTime){
auxWidth += col.getWidth();
firstTime = false;
}
if (col.isShowTotals()) {
auxWidth += col.getWidth();
}
}
return auxWidth;
}
|
java
|
{
"resource": ""
}
|
q2774
|
AbstractDataset.getExpressionFromVariable
|
train
|
protected static JRDesignExpression getExpressionFromVariable(JRDesignVariable var){
JRDesignExpression exp = new JRDesignExpression();
exp.setText("$V{" + var.getName() + "}");
exp.setValueClass(var.getValueClass());
return exp;
}
|
java
|
{
"resource": ""
}
|
q2775
|
DynamicJasperHelper.generateJasperPrint
|
train
|
public static JasperPrint generateJasperPrint(DynamicReport dr, LayoutManager layoutManager, JRDataSource ds, Map<String, Object> _parameters) throws JRException {
log.info("generating JasperPrint");
JasperPrint jp;
JasperReport jr = DynamicJasperHelper.generateJasperReport(dr, layoutManager, _parameters);
jp = JasperFillManager.fillReport(jr, _parameters, ds);
return jp;
}
|
java
|
{
"resource": ""
}
|
q2776
|
DynamicJasperHelper.generateJasperPrint
|
train
|
public static JasperPrint generateJasperPrint(DynamicReport dr, LayoutManager layoutManager, Connection con, Map<String, Object> _parameters) throws JRException {
log.info("generating JasperPrint");
JasperPrint jp;
if (_parameters == null)
_parameters = new HashMap<String, Object>();
visitSubreports(dr, _parameters);
compileOrLoadSubreports(dr, _parameters, "r");
DynamicJasperDesign jd = generateJasperDesign(dr);
Map<String, Object> params = new HashMap<String, Object>();
if (!_parameters.isEmpty()) {
registerParams(jd, _parameters);
params.putAll(_parameters);
}
registerEntities(jd, dr, layoutManager);
layoutManager.applyLayout(jd, dr);
JRPropertiesUtil.getInstance(DefaultJasperReportsContext.getInstance()).setProperty(JRCompiler.COMPILER_PREFIX, DJCompilerFactory.getCompilerClassName());
//JRProperties.setProperty(JRCompiler.COMPILER_PREFIX, DJCompilerFactory.getCompilerClassName());
JasperReport jr = JasperCompileManager.compileReport(jd);
params.putAll(jd.getParametersWithValues());
jp = JasperFillManager.fillReport(jr, params, con);
return jp;
}
|
java
|
{
"resource": ""
}
|
q2777
|
DynamicJasperHelper.generateJRXML
|
train
|
public static void generateJRXML(DynamicReport dr, LayoutManager layoutManager, Map _parameters, String xmlEncoding, OutputStream outputStream) throws JRException {
JasperReport jr = generateJasperReport(dr, layoutManager, _parameters);
if (xmlEncoding == null)
xmlEncoding = DEFAULT_XML_ENCODING;
JRXmlWriter.writeReport(jr, outputStream, xmlEncoding);
}
|
java
|
{
"resource": ""
}
|
q2778
|
DynamicJasperHelper.registerParams
|
train
|
public static void registerParams(DynamicJasperDesign jd, Map _parameters) {
for (Object key : _parameters.keySet()) {
if (key instanceof String) {
try {
Object value = _parameters.get(key);
if (jd.getParametersMap().get(key) != null) {
log.warn("Parameter \"" + key + "\" already registered, skipping this one: " + value);
continue;
}
JRDesignParameter parameter = new JRDesignParameter();
if (value == null) //There are some Map implementations that allows nulls values, just go on
continue;
// parameter.setValueClassName(value.getClass().getCanonicalName());
Class clazz = value.getClass().getComponentType();
if (clazz == null)
clazz = value.getClass();
parameter.setValueClass(clazz); //NOTE this is very strange
//when using an array as subreport-data-source, I must pass the parameter class name like this: value.getClass().getComponentType()
parameter.setName((String) key);
jd.addParameter(parameter);
} catch (JRException e) {
//nothing to do
}
}
}
}
|
java
|
{
"resource": ""
}
|
q2779
|
DynamicJasperHelper.visitSubreports
|
train
|
@SuppressWarnings("unchecked")
protected static void visitSubreports(DynamicReport dr, Map _parameters) {
for (DJGroup group : dr.getColumnsGroups()) {
//Header Subreports
for (Subreport subreport : group.getHeaderSubreports()) {
if (subreport.getDynamicReport() != null) {
visitSubreport(dr, subreport);
visitSubreports(subreport.getDynamicReport(), _parameters);
}
}
//Footer Subreports
for (Subreport subreport : group.getFooterSubreports()) {
if (subreport.getDynamicReport() != null) {
visitSubreport(dr, subreport);
visitSubreports(subreport.getDynamicReport(), _parameters);
}
}
}
}
|
java
|
{
"resource": ""
}
|
q2780
|
ExpressionUtils.getDataSourceExpression
|
train
|
public static JRDesignExpression getDataSourceExpression(DJDataSource ds) {
JRDesignExpression exp = new JRDesignExpression();
exp.setValueClass(JRDataSource.class);
String dsType = getDataSourceTypeStr(ds.getDataSourceType());
String expText = null;
if (ds.getDataSourceOrigin() == DJConstants.DATA_SOURCE_ORIGIN_FIELD) {
expText = dsType + "$F{" + ds.getDataSourceExpression() + "})";
} else if (ds.getDataSourceOrigin() == DJConstants.DATA_SOURCE_ORIGIN_PARAMETER) {
expText = dsType + REPORT_PARAMETERS_MAP + ".get( \"" + ds.getDataSourceExpression() + "\" ) )";
} else if (ds.getDataSourceOrigin() == DJConstants.DATA_SOURCE_TYPE_SQL_CONNECTION) {
expText = dsType + REPORT_PARAMETERS_MAP + ".get( \"" + ds.getDataSourceExpression() + "\" ) )";
} else if (ds.getDataSourceOrigin() == DJConstants.DATA_SOURCE_ORIGIN_REPORT_DATASOURCE) {
expText = "((" + JRDataSource.class.getName() + ") $P{REPORT_DATA_SOURCE})";
}
exp.setText(expText);
return exp;
}
|
java
|
{
"resource": ""
}
|
q2781
|
ExpressionUtils.getReportConnectionExpression
|
train
|
public static JRDesignExpression getReportConnectionExpression() {
JRDesignExpression connectionExpression = new JRDesignExpression();
connectionExpression.setText("$P{" + JRDesignParameter.REPORT_CONNECTION + "}");
connectionExpression.setValueClass(Connection.class);
return connectionExpression;
}
|
java
|
{
"resource": ""
}
|
q2782
|
ExpressionUtils.getVariablesMapExpression
|
train
|
public static String getVariablesMapExpression(Collection variables) {
StringBuilder variablesMap = new StringBuilder("new " + PropertiesMap.class.getName() + "()");
for (Object variable : variables) {
JRVariable jrvar = (JRVariable) variable;
String varname = jrvar.getName();
variablesMap.append(".with(\"").append(varname).append("\",$V{").append(varname).append("})");
}
return variablesMap.toString();
}
|
java
|
{
"resource": ""
}
|
q2783
|
ExpressionUtils.createCustomExpressionInvocationText
|
train
|
public static String createCustomExpressionInvocationText(CustomExpression customExpression, String customExpName, boolean usePreviousFieldValues) {
String stringExpression;
if (customExpression instanceof DJSimpleExpression) {
DJSimpleExpression varexp = (DJSimpleExpression) customExpression;
String symbol;
switch (varexp.getType()) {
case DJSimpleExpression.TYPE_FIELD:
symbol = "F";
break;
case DJSimpleExpression.TYPE_VARIABLE:
symbol = "V";
break;
case DJSimpleExpression.TYPE_PARAMATER:
symbol = "P";
break;
default:
throw new DJException("Invalid DJSimpleExpression, type must be FIELD, VARIABLE or PARAMETER");
}
stringExpression = "$" + symbol + "{" + varexp.getVariableName() + "}";
} else {
String fieldsMap = "((" + DJDefaultScriptlet.class.getName() + ")$P{REPORT_SCRIPTLET}).getCurrentFields()";
if (usePreviousFieldValues) {
fieldsMap = "((" + DJDefaultScriptlet.class.getName() + ")$P{REPORT_SCRIPTLET}).getPreviousFields()";
}
String parametersMap = "((" + DJDefaultScriptlet.class.getName() + ")$P{REPORT_SCRIPTLET}).getCurrentParams()";
String variablesMap = "((" + DJDefaultScriptlet.class.getName() + ")$P{REPORT_SCRIPTLET}).getCurrentVariables()";
stringExpression = "((" + CustomExpression.class.getName() + ")$P{REPORT_PARAMETERS_MAP}.get(\"" + customExpName + "\"))."
+ CustomExpression.EVAL_METHOD_NAME + "( " + fieldsMap + ", " + variablesMap + ", " + parametersMap + " )";
}
return stringExpression;
}
|
java
|
{
"resource": ""
}
|
q2784
|
ReflectiveReportBuilder.addProperties
|
train
|
private void addProperties(final PropertyDescriptor[] _properties) throws ColumnBuilderException, ClassNotFoundException {
for (final PropertyDescriptor property : _properties) {
if (isValidProperty(property)) {
addColumn(getColumnTitle(property), property.getName(), property.getPropertyType().getName(), getColumnWidth(property));
}
}
setUseFullPageWidth(true);
}
|
java
|
{
"resource": ""
}
|
q2785
|
ReflectiveReportBuilder.getColumnTitle
|
train
|
private static String getColumnTitle(final PropertyDescriptor _property) {
final StringBuilder buffer = new StringBuilder();
final String name = _property.getName();
buffer.append(Character.toUpperCase(name.charAt(0)));
for (int i = 1; i < name.length(); i++) {
final char c = name.charAt(i);
if (Character.isUpperCase(c)) {
buffer.append(' ');
}
buffer.append(c);
}
return buffer.toString();
}
|
java
|
{
"resource": ""
}
|
q2786
|
ReflectiveReportBuilder.isValidPropertyClass
|
train
|
private static boolean isValidPropertyClass(final PropertyDescriptor _property) {
final Class type = _property.getPropertyType();
return Number.class.isAssignableFrom(type) || type == String.class || Date.class.isAssignableFrom(type) || type == Boolean.class;
}
|
java
|
{
"resource": ""
}
|
q2787
|
ReflectiveReportBuilder.getColumnWidth
|
train
|
private static int getColumnWidth(final PropertyDescriptor _property) {
final Class type = _property.getPropertyType();
if (Float.class.isAssignableFrom(type) || Double.class.isAssignableFrom(type)) {
return 70;
} else if (type == Boolean.class) {
return 10;
} else if (Number.class.isAssignableFrom(type)) {
return 60;
} else if (type == String.class) {
return 100;
} else if (Date.class.isAssignableFrom(type)) {
return 50;
} else {
return 50;
}
}
|
java
|
{
"resource": ""
}
|
q2788
|
XYDataset.addSerie
|
train
|
public void addSerie(AbstractColumn column, StringExpression labelExpression) {
series.add(column);
seriesLabels.put(column, labelExpression);
}
|
java
|
{
"resource": ""
}
|
q2789
|
DynamicReportBuilder.build
|
train
|
public DynamicReport build() {
if (built) {
throw new DJBuilderException("DynamicReport already built. Cannot use more than once.");
} else {
built = true;
}
report.setOptions(options);
if (!globalVariablesGroup.getFooterVariables().isEmpty() || !globalVariablesGroup.getHeaderVariables().isEmpty() || !globalVariablesGroup.getVariables().isEmpty() || hasPercentageColumn()) {
report.getColumnsGroups().add(0, globalVariablesGroup);
}
createChartGroups();
addGlobalCrosstabs();
addSubreportsToGroups();
concatenateReports();
report.setAutoTexts(autoTexts);
return report;
}
|
java
|
{
"resource": ""
}
|
q2790
|
DynamicReportBuilder.concatenateReports
|
train
|
protected void concatenateReports() {
if (!concatenatedReports.isEmpty()) { // dummy group for page break if needed
DJGroup globalGroup = createDummyGroup();
report.getColumnsGroups().add(0, globalGroup);
}
for (Subreport subreport : concatenatedReports) {
DJGroup globalGroup = createDummyGroup();
globalGroup.getFooterSubreports().add(subreport);
report.getColumnsGroups().add(0, globalGroup);
}
}
|
java
|
{
"resource": ""
}
|
q2791
|
DynamicReportBuilder.setTemplateFile
|
train
|
public DynamicReportBuilder setTemplateFile(String path, boolean importFields, boolean importVariables, boolean importParameters, boolean importDatasets) {
report.setTemplateFileName(path);
report.setTemplateImportFields(importFields);
report.setTemplateImportParameters(importParameters);
report.setTemplateImportVariables(importVariables);
report.setTemplateImportDatasets(importDatasets);
return this;
}
|
java
|
{
"resource": ""
}
|
q2792
|
DynamicReportBuilder.addStyle
|
train
|
public DynamicReportBuilder addStyle(Style style) throws DJBuilderException {
if (style.getName() == null) {
throw new DJBuilderException("Invalid style. The style must have a name");
}
report.addStyle(style);
return this;
}
|
java
|
{
"resource": ""
}
|
q2793
|
DynamicReportBuilder.setQuery
|
train
|
public DynamicReportBuilder setQuery(String text, String language) {
this.report.setQuery(new DJQuery(text, language));
return this;
}
|
java
|
{
"resource": ""
}
|
q2794
|
DynamicReportBuilder.setProperty
|
train
|
public DynamicReportBuilder setProperty(String name, String value) {
this.report.setProperty(name, value);
return this;
}
|
java
|
{
"resource": ""
}
|
q2795
|
DynamicReportBuilder.setColspan
|
train
|
public DynamicReportBuilder setColspan(int colNumber, int colQuantity, String colspanTitle) {
this.setColspan(colNumber, colQuantity, colspanTitle, null);
return this;
}
|
java
|
{
"resource": ""
}
|
q2796
|
CrossTabColorShema.setTotalColorForColumn
|
train
|
public void setTotalColorForColumn(int column, Color color){
int map = (colors.length-1) - column;
colors[map][colors[0].length-1]=color;
}
|
java
|
{
"resource": ""
}
|
q2797
|
CrossTabColorShema.setColorForTotal
|
train
|
public void setColorForTotal(int row, int column, Color color){
int mapC = (colors.length-1) - column;
int mapR = (colors[0].length-1) - row;
colors[mapC][mapR]=color;
}
|
java
|
{
"resource": ""
}
|
q2798
|
StreamUtils.copyThenClose
|
train
|
public static void copyThenClose(InputStream input, OutputStream output)
throws IOException {
copy(input, output);
input.close();
output.close();
}
|
java
|
{
"resource": ""
}
|
q2799
|
SubReportBuilder.setParameterMapPath
|
train
|
public SubReportBuilder setParameterMapPath(String path) {
subreport.setParametersExpression(path);
subreport.setParametersMapOrigin(DJConstants.SUBREPORT_PARAMETER_MAP_ORIGIN_PARAMETER);
return this;
}
|
java
|
{
"resource": ""
}
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.