_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q171600 | ArraysUtil.resize | test | public static <T> T[] resize(T[] buffer, int newSize) {
Class<T> componentType = (Class<T>) buffer.getClass().getComponentType();
T[] temp = (T[]) Array.newInstance(componentType, newSize);
System.arraycopy(buffer, 0, temp, 0, buffer.length >= newSize ? newSize : buffer.length);
return temp;
} | java | {
"resource": ""
} |
q171601 | ArraysUtil.append | test | public static <T> T[] append(T[] buffer, T newElement) {
T[] t = resize(buffer, buffer.length + 1);
t[buffer.length] = newElement;
return t;
} | java | {
"resource": ""
} |
q171602 | ArraysUtil.remove | test | @SuppressWarnings({"unchecked"})
public static <T> T[] remove(T[] buffer, int offset, int length, Class<T> componentType) {
int len2 = buffer.length - length;
T[] temp = (T[]) Array.newInstance(componentType, len2);
System.arraycopy(buffer, 0, temp, 0, offset);
System.arraycopy(buffer, offset + length, temp, offset, len2 - offset);
return temp;
} | java | {
"resource": ""
} |
q171603 | ArraysUtil.indexOf | test | public static int indexOf(char[] array, char value) {
for (int i = 0; i < array.length; i++) {
if (array[i] == value) {
return i;
}
}
return -1;
} | java | {
"resource": ""
} |
q171604 | ArraysUtil.indexOf | test | public static int indexOf(Object[] array, Object value) {
for (int i = 0; i < array.length; i++) {
if (array[i].equals(value)) {
return i;
}
}
return -1;
} | java | {
"resource": ""
} |
q171605 | ArraysUtil.indexOf | test | public static int indexOf(byte[] array, byte[] sub, int startIndex) {
return indexOf(array, sub, startIndex, array.length);
} | java | {
"resource": ""
} |
q171606 | LagartoDOMBuilder.enableXhtmlMode | test | public LagartoDOMBuilder enableXhtmlMode() {
config.ignoreWhitespacesBetweenTags = false; // collect all whitespaces
config.setCaseSensitive(true); // XHTML is case sensitive
config.setEnableRawTextModes(false); // all tags are parsed in the same way
config.enabledVoidTags = true; // list of void tags
config.selfCloseVoidTags = true; // self close void tags
config.impliedEndTags = false; // no implied tag ends
config.setEnableConditionalComments(false); // don't enable IE conditional comments
config.setParseXmlTags(false); // enable XML mode in parsing
return this;
} | java | {
"resource": ""
} |
q171607 | LagartoDOMBuilder.parse | test | @Override
public Document parse(final char[] content) {
LagartoParser lagartoParser = new LagartoParser(content);
return doParse(lagartoParser);
} | java | {
"resource": ""
} |
q171608 | LagartoDOMBuilder.doParse | test | protected Document doParse(final LagartoParser lagartoParser) {
lagartoParser.setConfig(config);
LagartoDOMBuilderTagVisitor domBuilderTagVisitor =
new LagartoDOMBuilderTagVisitor(this);
lagartoParser.parse(domBuilderTagVisitor);
return domBuilderTagVisitor.getDocument();
} | java | {
"resource": ""
} |
q171609 | MethodWriter.computeMaxStackAndLocal | test | private void computeMaxStackAndLocal() {
// Complete the control flow graph with exception handler blocks.
Handler handler = firstHandler;
while (handler != null) {
Label handlerBlock = handler.handlerPc;
Label handlerRangeBlock = handler.startPc;
Label handlerRangeEnd = handler.endPc;
// Add handlerBlock as a successor of all the basic blocks in the exception handler range.
while (handlerRangeBlock != handlerRangeEnd) {
if ((handlerRangeBlock.flags & Label.FLAG_SUBROUTINE_CALLER) == 0) {
handlerRangeBlock.outgoingEdges =
new Edge(Edge.EXCEPTION, handlerBlock, handlerRangeBlock.outgoingEdges);
} else {
// If handlerRangeBlock is a JSR block, add handlerBlock after the first two outgoing
// edges to preserve the hypothesis about JSR block successors order (see
// {@link #visitJumpInsn}).
handlerRangeBlock.outgoingEdges.nextEdge.nextEdge =
new Edge(
Edge.EXCEPTION, handlerBlock, handlerRangeBlock.outgoingEdges.nextEdge.nextEdge);
}
handlerRangeBlock = handlerRangeBlock.nextBasicBlock;
}
handler = handler.nextHandler;
}
// Complete the control flow graph with the successor blocks of subroutines, if needed.
if (hasSubroutines) {
// First step: find the subroutines. This step determines, for each basic block, to which
// subroutine(s) it belongs. Start with the main "subroutine":
short numSubroutines = 1;
firstBasicBlock.markSubroutine(numSubroutines);
// Then, mark the subroutines called by the main subroutine, then the subroutines called by
// those called by the main subroutine, etc.
for (short currentSubroutine = 1; currentSubroutine <= numSubroutines; ++currentSubroutine) {
Label basicBlock = firstBasicBlock;
while (basicBlock != null) {
if ((basicBlock.flags & Label.FLAG_SUBROUTINE_CALLER) != 0
&& basicBlock.subroutineId == currentSubroutine) {
Label jsrTarget = basicBlock.outgoingEdges.nextEdge.successor;
if (jsrTarget.subroutineId == 0) {
// If this subroutine has not been marked yet, find its basic blocks.
jsrTarget.markSubroutine(++numSubroutines);
}
}
basicBlock = basicBlock.nextBasicBlock;
}
}
// Second step: find the successors in the control flow graph of each subroutine basic block
// 'r' ending with a RET instruction. These successors are the virtual successors of the basic
// blocks ending with JSR instructions (see {@link #visitJumpInsn)} that can reach 'r'.
Label basicBlock = firstBasicBlock;
while (basicBlock != null) {
if ((basicBlock.flags & Label.FLAG_SUBROUTINE_CALLER) != 0) {
// By construction, jsr targets are stored in the second outgoing edge of basic blocks
// that ends with a jsr instruction (see {@link #FLAG_SUBROUTINE_CALLER}).
Label subroutine = basicBlock.outgoingEdges.nextEdge.successor;
subroutine.addSubroutineRetSuccessors(basicBlock);
}
basicBlock = basicBlock.nextBasicBlock;
}
}
// Data flow algorithm: put the first basic block in a list of blocks to process (i.e. blocks
// whose input stack size has changed) and, while there are blocks to process, remove one
// from the list, update the input stack size of its successor blocks in the control flow
// graph, and add these blocks to the list of blocks to process (if not already done).
Label listOfBlocksToProcess = firstBasicBlock;
listOfBlocksToProcess.nextListElement = Label.EMPTY_LIST;
int maxStackSize = maxStack;
while (listOfBlocksToProcess != Label.EMPTY_LIST) {
// Remove a basic block from the list of blocks to process. Note that we don't reset
// basicBlock.nextListElement to null on purpose, to make sure we don't reprocess already
// processed basic blocks.
Label basicBlock = listOfBlocksToProcess;
listOfBlocksToProcess = listOfBlocksToProcess.nextListElement;
// Compute the (absolute) input stack size and maximum stack size of this block.
int inputStackTop = basicBlock.inputStackSize;
int maxBlockStackSize = inputStackTop + basicBlock.outputStackMax;
// Update the absolute maximum stack size of the method.
if (maxBlockStackSize > maxStackSize) {
maxStackSize = maxBlockStackSize;
}
// Update the input stack size of the successor blocks of basicBlock in the control flow
// graph, and add these blocks to the list of blocks to process, if not already done.
Edge outgoingEdge = basicBlock.outgoingEdges;
if ((basicBlock.flags & Label.FLAG_SUBROUTINE_CALLER) != 0) {
// Ignore the first outgoing edge of the basic blocks ending with a jsr: these are virtual
// edges which lead to the instruction just after the jsr, and do not correspond to a
// possible execution path (see {@link #visitJumpInsn} and
// {@link Label#FLAG_SUBROUTINE_CALLER}).
outgoingEdge = outgoingEdge.nextEdge;
}
while (outgoingEdge != null) {
Label successorBlock = outgoingEdge.successor;
if (successorBlock.nextListElement == null) {
successorBlock.inputStackSize =
(short) (outgoingEdge.info == Edge.EXCEPTION ? 1 : inputStackTop + outgoingEdge.info);
successorBlock.nextListElement = listOfBlocksToProcess;
listOfBlocksToProcess = successorBlock;
}
outgoingEdge = outgoingEdge.nextEdge;
}
}
this.maxStack = maxStackSize;
} | java | {
"resource": ""
} |
q171610 | MethodWriter.endCurrentBasicBlockWithNoSuccessor | test | private void endCurrentBasicBlockWithNoSuccessor() {
if (compute == COMPUTE_ALL_FRAMES) {
Label nextBasicBlock = new Label();
nextBasicBlock.frame = new Frame(nextBasicBlock);
nextBasicBlock.resolve(code.data, code.length);
lastBasicBlock.nextBasicBlock = nextBasicBlock;
lastBasicBlock = nextBasicBlock;
currentBasicBlock = null;
} else if (compute == COMPUTE_MAX_STACK_AND_LOCAL) {
currentBasicBlock.outputStackMax = (short) maxRelativeStackSize;
currentBasicBlock = null;
}
} | java | {
"resource": ""
} |
q171611 | MethodWriter.collectAttributePrototypes | test | final void collectAttributePrototypes(final Attribute.Set attributePrototypes) {
attributePrototypes.addAttributes(firstAttribute);
attributePrototypes.addAttributes(firstCodeAttribute);
} | java | {
"resource": ""
} |
q171612 | ContextInjectorComponent.injectContext | test | public void injectContext(final Object targetObject) {
final Class targetType = targetObject.getClass();
final ScopeData scopeData = scopeDataInspector.inspectClassScopesWithCache(targetType);
final Targets targets = new Targets(targetObject, scopeData);
// inject no context
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(targets));
// inject special case
scopeResolver.forScope(ParamsScope.class, scope -> scope.inject(targets));
// inject servlet context
final ServletContext servletContext = madvocController.getApplicationContext();
if (servletContext != null) {
scopeResolver.forEachScope(madvocScope -> madvocScope.inject(servletContext, targets));
}
} | java | {
"resource": ""
} |
q171613 | PseudoClassSelector.registerPseudoClass | test | public static void registerPseudoClass(final Class<? extends PseudoClass> pseudoClassType) {
PseudoClass pseudoClass;
try {
pseudoClass = ClassUtil.newInstance(pseudoClassType);
} catch (Exception ex) {
throw new CSSellyException(ex);
}
PSEUDO_CLASS_MAP.put(pseudoClass.getPseudoClassName(), pseudoClass);
} | java | {
"resource": ""
} |
q171614 | PseudoClassSelector.lookupPseudoClass | test | public static PseudoClass lookupPseudoClass(final String pseudoClassName) {
PseudoClass pseudoClass = PSEUDO_CLASS_MAP.get(pseudoClassName);
if (pseudoClass == null) {
throw new CSSellyException("Unsupported pseudo class: " + pseudoClassName);
}
return pseudoClass;
} | java | {
"resource": ""
} |
q171615 | AsyncActionExecutor.invoke | test | public void invoke(final ActionRequest actionRequest) {
if (executorService == null) {
throw new MadvocException("No action is marked as async!");
}
final HttpServletRequest servletRequest = actionRequest.getHttpServletRequest();
log.debug(() -> "Async call to: " + actionRequest);
final AsyncContext asyncContext = servletRequest.startAsync();
executorService.submit(() -> {
try {
actionRequest.invoke();
} catch (Exception ex) {
log.error("Invoking async action path failed: " , ExceptionUtil.unwrapThrowable(ex));
} finally {
asyncContext.complete();
}
});
} | java | {
"resource": ""
} |
q171616 | BeanVisitor.getAllBeanPropertyNames | test | protected String[] getAllBeanPropertyNames(final Class type, final boolean declared) {
ClassDescriptor classDescriptor = ClassIntrospector.get().lookup(type);
PropertyDescriptor[] propertyDescriptors = classDescriptor.getAllPropertyDescriptors();
ArrayList<String> names = new ArrayList<>(propertyDescriptors.length);
for (PropertyDescriptor propertyDescriptor : propertyDescriptors) {
MethodDescriptor getter = propertyDescriptor.getReadMethodDescriptor();
if (getter != null) {
if (getter.matchDeclared(declared)) {
names.add(propertyDescriptor.getName());
}
}
else if (includeFields) {
FieldDescriptor field = propertyDescriptor.getFieldDescriptor();
if (field != null) {
if (field.matchDeclared(declared)) {
names.add(field.getName());
}
}
}
}
return names.toArray(new String[0]);
} | java | {
"resource": ""
} |
q171617 | BeanVisitor.visit | test | public void visit() {
String[] properties = resolveProperties(source, declared);
for (String name : properties) {
if (name == null) {
continue;
}
if (!rules.match(name, blacklist)) {
continue;
}
Object value;
String propertyName = name;
if (isSourceMap) {
propertyName = LEFT_SQ_BRACKET + name + RIGHT_SQ_BRACKET;
}
if (declared) {
value = BeanUtil.declared.getProperty(source, propertyName);
} else {
value = BeanUtil.pojo.getProperty(source, propertyName);
}
if (value == null && ignoreNullValues) {
continue;
}
if (value instanceof String && StringUtil.isEmpty((String) value)) {
continue;
}
visitProperty(name, value);
}
} | java | {
"resource": ""
} |
q171618 | BeanVisitor.accept | test | @Override
public boolean accept(final String propertyName, final String rule, final boolean include) {
return propertyName.equals(rule);
} | java | {
"resource": ""
} |
q171619 | MethodResolver.resolve | test | public MethodInjectionPoint[] resolve(final Class type) {
// lookup methods
ClassDescriptor cd = ClassIntrospector.get().lookup(type);
List<MethodInjectionPoint> list = new ArrayList<>();
MethodDescriptor[] allMethods = cd.getAllMethodDescriptors();
for (MethodDescriptor methodDescriptor : allMethods) {
Method method = methodDescriptor.getMethod();
if (ClassUtil.isBeanPropertySetter(method)) {
// ignore setters
continue;
}
if (method.getParameterTypes().length == 0) {
// ignore methods with no argument
continue;
}
BeanReferences[] references = referencesResolver.readAllReferencesFromAnnotation(method);
if (references != null) {
MethodInjectionPoint methodInjectionPoint = new MethodInjectionPoint(method, references);
list.add(methodInjectionPoint);
}
}
final MethodInjectionPoint[] methodInjectionPoints;
if (list.isEmpty()) {
methodInjectionPoints = MethodInjectionPoint.EMPTY;
} else {
methodInjectionPoints = list.toArray(new MethodInjectionPoint[0]);
}
return methodInjectionPoints;
} | java | {
"resource": ""
} |
q171620 | HtmlStaplerFilter.readFilterConfigParameters | test | protected void readFilterConfigParameters(final FilterConfig filterConfig, final Object target, final String... parameters) {
for (String parameter : parameters) {
String value = filterConfig.getInitParameter(parameter);
if (value != null) {
BeanUtil.declared.setProperty(target, parameter, value);
}
}
} | java | {
"resource": ""
} |
q171621 | HtmlStaplerFilter.sendBundleFile | test | protected void sendBundleFile(final HttpServletResponse resp, final File bundleFile) throws IOException {
OutputStream out = resp.getOutputStream();
FileInputStream fileInputStream = new FileInputStream(bundleFile);
try {
StreamUtil.copy(fileInputStream, out);
}
finally {
StreamUtil.close(fileInputStream);
}
} | java | {
"resource": ""
} |
q171622 | HtmlStaplerBundlesManager.lookupBundleFile | test | public File lookupBundleFile(String bundleId) {
if ((mirrors != null) && (!mirrors.isEmpty())) {
String realBundleId = mirrors.remove(bundleId);
if (realBundleId != null) {
bundleId = realBundleId;
}
}
return createBundleFile(bundleId);
} | java | {
"resource": ""
} |
q171623 | HtmlStaplerBundlesManager.lookupGzipBundleFile | test | public File lookupGzipBundleFile(final File file) throws IOException {
String path = file.getPath() + ZipUtil.GZIP_EXT;
File gzipFile = new File(path);
if (!gzipFile.exists()) {
if (log.isDebugEnabled()) {
log.debug("gzip bundle to " + path);
}
ZipUtil.gzip(file);
}
return gzipFile;
} | java | {
"resource": ""
} |
q171624 | HtmlStaplerBundlesManager.registerBundle | test | public synchronized String registerBundle(final String contextPath, final String actionPath, final String tempBundleId, final String bundleContentType, final List<String> sources) {
if (tempBundleId == null || sources.isEmpty()) {
if (strategy == Strategy.ACTION_MANAGED) {
// page does not include any resource source file
actionBundles.put(actionPath, StringPool.EMPTY);
}
return null;
}
// create unique digest from the collected sources
String[] sourcesArray = sources.toArray(new String[0]);
for (int i = 0, sourcesArrayLength = sourcesArray.length; i < sourcesArrayLength; i++) {
sourcesArray[i] = sourcesArray[i].trim().toLowerCase();
}
if (sortResources) {
Arrays.sort(sourcesArray);
}
StringBand sb = new StringBand(sourcesArray.length);
for (String src : sourcesArray) {
sb.append(src);
}
String sourcesString = sb.toString();
String bundleId = createDigest(sourcesString);
bundleId += '.' + bundleContentType;
// bundle appears for the first time, create the bundle
if (strategy == Strategy.ACTION_MANAGED) {
actionBundles.put(actionPath, bundleId);
mirrors.put(tempBundleId, bundleId);
}
try {
createBundle(contextPath, actionPath, bundleId, sources);
} catch (IOException ioex) {
throw new HtmlStaplerException("Can't create bundle", ioex);
}
return bundleId;
} | java | {
"resource": ""
} |
q171625 | HtmlStaplerBundlesManager.createDigest | test | protected String createDigest(final String source) {
final DigestEngine digestEngine = DigestEngine.sha256();
final byte[] bytes = digestEngine.digest(CharUtil.toSimpleByteArray(source));
String digest = Base32.encode(bytes);
if (uniqueDigestKey != null) {
digest += uniqueDigestKey;
}
return digest;
} | java | {
"resource": ""
} |
q171626 | HtmlStaplerBundlesManager.createBundle | test | protected void createBundle(final String contextPath, final String actionPath, final String bundleId, final List<String>sources) throws IOException {
final File bundleFile = createBundleFile(bundleId);
if (bundleFile.exists()) {
return;
}
StringBand sb = new StringBand(sources.size() * 2);
for (String src : sources) {
if (sb.length() != 0) {
sb.append(StringPool.NEWLINE);
}
String content;
if (isExternalResource(src)) {
content = downloadString(src);
} else {
if (!downloadLocal) {
// load local resource from file system
String localFile = webRoot;
if (src.startsWith(contextPath + '/')) {
src = src.substring(contextPath.length());
}
if (src.startsWith(StringPool.SLASH)) {
// absolute path
localFile += src;
} else {
// relative path
localFile += '/' + FileNameUtil.getPathNoEndSeparator(actionPath) + '/' + src;
}
// trim link parameters, if any
int qmndx = localFile.indexOf('?');
if (qmndx != -1) {
localFile = localFile.substring(0, qmndx);
}
try {
content = FileUtil.readString(localFile);
} catch (IOException ioex) {
if (notFoundExceptionEnabled) {
throw ioex;
}
if (log.isWarnEnabled()) {
log.warn(ioex.getMessage());
}
content = null;
}
} else {
// download local resource
String localUrl = localAddressAndPort;
if (src.startsWith(StringPool.SLASH)) {
localUrl += contextPath + src;
} else {
localUrl += contextPath + FileNameUtil.getPath(actionPath) + '/' + src;
}
content = downloadString(localUrl);
}
if (content != null) {
if (isCssResource(src)) {
content = fixCssRelativeUrls(content, src);
}
}
}
if (content != null) {
content = onResourceContent(content);
sb.append(content);
}
}
FileUtil.writeString(bundleFile, sb.toString());
if (log.isInfoEnabled()) {
log.info("Bundle created: " + bundleId);
}
} | java | {
"resource": ""
} |
q171627 | HtmlStaplerBundlesManager.reset | test | public synchronized void reset() {
if (strategy == Strategy.ACTION_MANAGED) {
actionBundles.clear();
mirrors.clear();
}
final FindFile ff = new FindFile();
ff.includeDirs(false);
ff.searchPath(new File(bundleFolder, staplerPath));
File f;
int count = 0;
while ((f = ff.nextFile()) != null) {
f.delete();
count++;
}
if (log.isInfoEnabled()) {
log.info("reset: " + count + " bundle files deleted.");
}
} | java | {
"resource": ""
} |
q171628 | HtmlStaplerBundlesManager.fixCssRelativeUrls | test | protected String fixCssRelativeUrls(final String content, final String src) {
final String path = FileNameUtil.getPath(src);
final Matcher matcher = CSS_URL_PATTERN.matcher(content);
final StringBuilder sb = new StringBuilder(content.length());
int start = 0;
while (matcher.find()) {
sb.append(content, start, matcher.start());
final String matchedUrl = StringUtil.removeChars(matcher.group(1), "'\"");
final String url;
if (matchedUrl.startsWith("https://") || matchedUrl.startsWith("http://") || matchedUrl.startsWith("data:")) {
url = "url('" + matchedUrl + "')";
}
else {
url = fixRelativeUrl(matchedUrl, path);
}
sb.append(url);
start = matcher.end();
}
sb.append(content.substring(start));
return sb.toString();
} | java | {
"resource": ""
} |
q171629 | DbEntitySql.updateColumn | test | public DbSqlBuilder updateColumn(final Object entity, final String columnRef) {
final Object value = BeanUtil.pojo.getProperty(entity, columnRef);
return updateColumn(entity, columnRef, value);
} | java | {
"resource": ""
} |
q171630 | DbEntitySql.createTableRefName | test | protected static String createTableRefName(final Object entity) {
Class type = entity.getClass();
type = (type == Class.class ? (Class) entity : type);
return (type.getSimpleName() + '_');
} | java | {
"resource": ""
} |
q171631 | DbJtxSessionProvider.getDbSession | test | @Override
public DbSession getDbSession() {
log.debug("Requesting db TX manager session");
final DbJtxTransaction jtx = (DbJtxTransaction) jtxTxManager.getTransaction();
if (jtx == null) {
throw new DbSqlException(
"No transaction is in progress and DbSession can't be provided. " +
"It seems that transaction manager is not used to begin a transaction.");
}
return jtx.requestResource();
} | java | {
"resource": ""
} |
q171632 | ArrayConverter.convertToSingleElementArray | test | protected T[] convertToSingleElementArray(final Object value) {
T[] singleElementArray = createArray(1);
singleElementArray[0] = convertType(value);
return singleElementArray;
} | java | {
"resource": ""
} |
q171633 | GenericsReader.parseSignatureForGenerics | test | public Map<String, String> parseSignatureForGenerics(final String signature, final boolean isInterface) {
if (signature == null) {
return Collections.emptyMap();
}
final Map<String, String> genericsMap = new HashMap<>();
SignatureReader sr = new SignatureReader(signature);
StringBuilder sb = new StringBuilder();
TraceSignatureVisitor v = new TraceSignatureVisitor(sb, isInterface) {
String genericName;
@Override
public void visitFormalTypeParameter(final String name) {
genericName = name;
super.visitFormalTypeParameter(name);
}
@Override
public void visitClassType(final String name) {
if (genericName != null) {
genericsMap.put(genericName, 'L' + name + ';');
genericName = null;
}
super.visitClassType(name);
}
};
sr.accept(v);
return genericsMap;
} | java | {
"resource": ""
} |
q171634 | SetResolver.resolve | test | public SetInjectionPoint[] resolve(final Class type, final boolean autowire) {
ClassDescriptor cd = ClassIntrospector.get().lookup(type);
List<SetInjectionPoint> list = new ArrayList<>();
PropertyDescriptor[] allProperties = cd.getAllPropertyDescriptors();
for (PropertyDescriptor propertyDescriptor : allProperties) {
if (propertyDescriptor.isGetterOnly()) {
continue;
}
Class propertyType = propertyDescriptor.getType();
if (!ClassUtil.isTypeOf(propertyType, Collection.class)) {
continue;
}
MethodDescriptor writeMethodDescriptor = propertyDescriptor.getWriteMethodDescriptor();
FieldDescriptor fieldDescriptor = propertyDescriptor.getFieldDescriptor();
PetiteInject ref = null;
if (writeMethodDescriptor != null) {
ref = writeMethodDescriptor.getMethod().getAnnotation(PetiteInject.class);
}
if (ref == null && fieldDescriptor != null) {
ref = fieldDescriptor.getField().getAnnotation(PetiteInject.class);
}
if ((!autowire) && (ref == null)) {
continue;
}
list.add(new SetInjectionPoint(propertyDescriptor));
}
SetInjectionPoint[] fields;
if (list.isEmpty()) {
fields = SetInjectionPoint.EMPTY;
} else {
fields = list.toArray(new SetInjectionPoint[0]);
}
return fields;
} | java | {
"resource": ""
} |
q171635 | JsonContext.matchIgnoredPropertyTypes | test | public boolean matchIgnoredPropertyTypes(final Class propertyType, final boolean excludeMaps, final boolean include) {
if (!include) {
return false;
}
if (propertyType != null) {
if (!jsonSerializer.deep) {
ClassDescriptor propertyTypeClassDescriptor = ClassIntrospector.get().lookup(propertyType);
if (propertyTypeClassDescriptor.isArray()) {
return false;
}
if (propertyTypeClassDescriptor.isCollection()) {
return false;
}
if (excludeMaps) {
if (propertyTypeClassDescriptor.isMap()) {
return false;
}
}
}
// still not excluded, continue with excluded types and type names
// + excluded types
if (jsonSerializer.excludedTypes != null) {
for (Class excludedType : jsonSerializer.excludedTypes) {
if (ClassUtil.isTypeOf(propertyType, excludedType)) {
return false;
}
}
}
// + exclude type names
final String propertyTypeName = propertyType.getName();
if (jsonSerializer.excludedTypeNames != null) {
for (String excludedTypeName : jsonSerializer.excludedTypeNames) {
if (Wildcard.match(propertyTypeName, excludedTypeName)) {
return false;
}
}
}
}
return true;
} | java | {
"resource": ""
} |
q171636 | DbSession.openConnectionForQuery | test | protected void openConnectionForQuery() {
if (connection == null) {
connection = connectionProvider.getConnection();
txActive = false; // txAction should already be false
try {
connection.setAutoCommit(true);
} catch (SQLException sex) {
throw new DbSqlException("Failed to open non-TX connection", sex);
}
}
} | java | {
"resource": ""
} |
q171637 | DbSession.openTx | test | protected void openTx() {
if (connection == null) {
connection = connectionProvider.getConnection();
}
txActive = true;
try {
connection.setAutoCommit(false);
if (txMode.getIsolation() != DbTransactionMode.ISOLATION_DEFAULT) {
connection.setTransactionIsolation(txMode.getIsolation());
}
connection.setReadOnly(txMode.isReadOnly());
} catch (SQLException sex) {
throw new DbSqlException("Open TX failed", sex);
}
} | java | {
"resource": ""
} |
q171638 | DbSession.closeTx | test | protected void closeTx() {
txActive = false;
try {
connection.setAutoCommit(true);
} catch (SQLException sex) {
throw new DbSqlException("Close TX failed", sex);
}
} | java | {
"resource": ""
} |
q171639 | DbSession.commitTransaction | test | public void commitTransaction() {
log.debug("Committing transaction");
assertTxIsActive();
try {
connection.commit();
} catch (SQLException sex) {
throw new DbSqlException("Commit TX failed", sex);
} finally {
closeTx();
}
} | java | {
"resource": ""
} |
q171640 | DbSession.rollbackTransaction | test | public void rollbackTransaction() {
log.debug("Rolling-back transaction");
assertTxIsActive();
try {
connection.rollback();
} catch (SQLException sex) {
throw new DbSqlException("Rollback TX failed", sex);
} finally {
closeTx();
}
} | java | {
"resource": ""
} |
q171641 | PropertiesUtil.createFromFile | test | public static Properties createFromFile(final File file) throws IOException {
Properties prop = new Properties();
loadFromFile(prop, file);
return prop;
} | java | {
"resource": ""
} |
q171642 | PropertiesUtil.createFromString | test | public static Properties createFromString(final String data) throws IOException {
Properties p = new Properties();
loadFromString(p, data);
return p;
} | java | {
"resource": ""
} |
q171643 | PropertiesUtil.loadFromString | test | public static void loadFromString(final Properties p, final String data) throws IOException {
try (ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes(StringPool.ISO_8859_1))) {
p.load(is);
}
} | java | {
"resource": ""
} |
q171644 | PropertiesUtil.subset | test | public static Properties subset(final Properties p, String prefix, final boolean stripPrefix) {
if (StringUtil.isBlank(prefix)) {
return p;
}
if (!prefix.endsWith(StringPool.DOT)) {
prefix += '.';
}
Properties result = new Properties();
int baseLen = prefix.length();
for (Object o : p.keySet()) {
String key = (String) o;
if (key.startsWith(prefix)) {
result.setProperty(stripPrefix ? key.substring(baseLen) : key, p.getProperty(key));
}
}
return result;
} | java | {
"resource": ""
} |
q171645 | PropertiesUtil.createFromClasspath | test | public static Properties createFromClasspath(final String... rootTemplate) {
Properties p = new Properties();
return loadFromClasspath(p, rootTemplate);
} | java | {
"resource": ""
} |
q171646 | PropertiesUtil.getProperty | test | public static String getProperty(final Map map, final String key, final String defaultValue) {
Object val = map.get(key);
return (val instanceof String) ? (String) val : defaultValue;
} | java | {
"resource": ""
} |
q171647 | PropertiesUtil.resolveAllVariables | test | public static void resolveAllVariables(final Properties prop) {
for (Object o : prop.keySet()) {
String key = (String) o;
String value = resolveProperty(prop, key);
prop.setProperty(key, value);
}
} | java | {
"resource": ""
} |
q171648 | PropertiesUtil.resolveProperty | test | public static String resolveProperty(final Map map, final String key) {
String value = getProperty(map, key);
if (value == null) {
return null;
}
value = stp.parse(value, macroName -> getProperty(map, macroName));
return value;
} | java | {
"resource": ""
} |
q171649 | AnnotationTxAdviceManager.resolveScope | test | public String resolveScope(final Class type, final String methodName) {
if (scopePattern == null) {
return null;
}
String ctx = scopePattern;
ctx = StringUtil.replace(ctx, JTXCTX_PATTERN_CLASS, type.getName());
ctx = StringUtil.replace(ctx, JTXCTX_PATTERN_METHOD, methodName);
return ctx;
} | java | {
"resource": ""
} |
q171650 | AnnotationTxAdviceManager.getTxMode | test | public synchronized JtxTransactionMode getTxMode(final Class type, final String methodName, final Class[] methodArgTypes, final String unique) {
String signature = type.getName() + '#' + methodName + '%' + unique;
JtxTransactionMode txMode = txmap.get(signature);
if (txMode == null) {
if (!txmap.containsKey(signature)) {
final Method m;
try {
m = type.getMethod(methodName, methodArgTypes);
} catch (NoSuchMethodException nsmex) {
throw new ProxettaException(nsmex);
}
final TransactionAnnotationValues txAnn = readTransactionAnnotation(m);
if (txAnn != null) {
txMode = new JtxTransactionMode(
txAnn.propagation(),
txAnn.isolation(),
txAnn.readOnly(),
txAnn.timeout()
);
} else {
txMode = defaultTransactionMode;
}
txmap.put(signature, txMode);
}
}
return txMode;
} | java | {
"resource": ""
} |
q171651 | AnnotationTxAdviceManager.registerAnnotations | test | @SuppressWarnings( {"unchecked"})
public void registerAnnotations(final Class<? extends Annotation>[] annotations) {
this.annotations = annotations;
this.annotationParsers = new AnnotationParser[annotations.length];
for (int i = 0; i < annotations.length; i++) {
annotationParsers[i] = TransactionAnnotationValues.parserFor(annotations[i]);
}
} | java | {
"resource": ""
} |
q171652 | AnnotationTxAdviceManager.readTransactionAnnotation | test | protected TransactionAnnotationValues readTransactionAnnotation(final Method method) {
for (AnnotationParser annotationParser : annotationParsers) {
TransactionAnnotationValues tad = TransactionAnnotationValues.of(annotationParser, method);
if (tad != null) {
return tad;
}
}
return null;
} | java | {
"resource": ""
} |
q171653 | CssSelector.accept | test | @Override
public boolean accept(final Node node) {
// match element name with node name
if (!matchElement(node)) {
return false;
}
// match attributes
int totalSelectors = selectorsCount();
for (int i = 0; i < totalSelectors; i++) {
Selector selector = getSelector(i);
// just attr name existence
switch (selector.getType()) {
case ATTRIBUTE:
if (!((AttributeSelector) selector).accept(node)) {
return false;
}
break;
case PSEUDO_CLASS:
if (!((PseudoClassSelector) selector).accept(node)) {
return false;
}
break;
case PSEUDO_FUNCTION:
if (!((PseudoFunctionSelector) selector).accept(node)) {
return false;
}
break;
}
}
return true;
} | java | {
"resource": ""
} |
q171654 | CssSelector.matchElement | test | protected boolean matchElement(final Node node) {
if (node.getNodeType() != Node.NodeType.ELEMENT) {
return false;
}
String element = getElement();
String nodeName = node.getNodeName();
return element.equals(StringPool.STAR) || element.equals(nodeName);
} | java | {
"resource": ""
} |
q171655 | CssSelector.accept | test | public boolean accept(final List<Node> currentResults, final Node node, final int index) {
// match attributes
int totalSelectors = selectorsCount();
for (int i = 0; i < totalSelectors; i++) {
Selector selector = getSelector(i);
// just attr name existence
switch (selector.getType()) {
case PSEUDO_FUNCTION:
if (!((PseudoFunctionSelector) selector).accept(currentResults, node, index)) {
return false;
}
break;
case PSEUDO_CLASS:
if (!((PseudoClassSelector) selector).accept(currentResults, node, index)) {
return false;
}
break;
default:
}
}
return true;
} | java | {
"resource": ""
} |
q171656 | CssSelector.unescape | test | protected String unescape(final String value) {
if (value.indexOf('\\') == -1) {
return value;
}
return StringUtil.remove(value, '\\');
} | java | {
"resource": ""
} |
q171657 | JavaInfo.buildJrePackages | test | private String[] buildJrePackages(final int javaVersionNumber) {
final ArrayList<String> packages = new ArrayList<>();
switch (javaVersionNumber) {
case 9:
case 8:
case 7:
case 6:
case 5:
// in Java1.5, the apache stuff moved
packages.add("com.sun.org.apache");
// fall through...
case 4:
if (javaVersionNumber == 4) {
packages.add("org.apache.crimson");
packages.add("org.apache.xalan");
packages.add("org.apache.xml");
packages.add("org.apache.xpath");
}
packages.add("org.ietf.jgss");
packages.add("org.w3c.dom");
packages.add("org.xml.sax");
// fall through...
case 3:
packages.add("org.omg");
packages.add("com.sun.corba");
packages.add("com.sun.jndi");
packages.add("com.sun.media");
packages.add("com.sun.naming");
packages.add("com.sun.org.omg");
packages.add("com.sun.rmi");
packages.add("sunw.io");
packages.add("sunw.util");
// fall through...
case 2:
packages.add("com.sun.java");
packages.add("com.sun.image");
// fall through...
case 1:
default:
// core stuff
packages.add("sun");
packages.add("java");
packages.add("javax");
break;
}
return packages.toArray(new String[0]);
} | java | {
"resource": ""
} |
q171658 | Node.cloneTo | test | protected <T extends Node> T cloneTo(final T dest) {
// dest.nodeValue = nodeValue; // already in clone implementations!
dest.parentNode = parentNode;
if (attributes != null) {
dest.attributes = new ArrayList<>(attributes.size());
for (int i = 0, attributesSize = attributes.size(); i < attributesSize; i++) {
Attribute attr = attributes.get(i);
dest.attributes.add(attr.clone());
}
}
if (childNodes != null) {
dest.childNodes = new ArrayList<>(childNodes.size());
for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) {
Node child = childNodes.get(i);
Node childClone = child.clone();
childClone.parentNode = dest; // fix parent!
dest.childNodes.add(childClone);
}
}
return dest;
} | java | {
"resource": ""
} |
q171659 | Node.detachFromParent | test | public void detachFromParent() {
if (parentNode == null) {
return;
}
if (parentNode.childNodes != null) {
parentNode.childNodes.remove(siblingIndex);
parentNode.reindexChildren();
}
parentNode = null;
} | java | {
"resource": ""
} |
q171660 | Node.addChild | test | public void addChild(final Node... nodes) {
if (nodes.length == 0) {
return; // nothing to add
}
for (Node node : nodes) {
node.detachFromParent();
node.parentNode = this;
initChildNodes(node);
childNodes.add(node);
}
reindexChildrenOnAdd(nodes.length);
} | java | {
"resource": ""
} |
q171661 | Node.insertChild | test | public void insertChild(final Node node, final int index) {
node.detachFromParent();
node.parentNode = this;
try {
initChildNodes(node);
childNodes.add(index, node);
} catch (IndexOutOfBoundsException ignore) {
throw new LagartoDOMException("Invalid node index: " + index);
}
reindexChildren();
} | java | {
"resource": ""
} |
q171662 | Node.insertBefore | test | public void insertBefore(final Node newChild, final Node refChild) {
int siblingIndex = refChild.getSiblingIndex();
refChild.parentNode.insertChild(newChild, siblingIndex);
} | java | {
"resource": ""
} |
q171663 | Node.insertBefore | test | public void insertBefore(final Node[] newChilds, final Node refChild) {
if (newChilds.length == 0) {
return;
}
int siblingIndex = refChild.getSiblingIndex();
refChild.parentNode.insertChild(newChilds, siblingIndex);
} | java | {
"resource": ""
} |
q171664 | Node.insertAfter | test | public void insertAfter(final Node newChild, final Node refChild) {
int siblingIndex = refChild.getSiblingIndex() + 1;
if (siblingIndex == refChild.parentNode.getChildNodesCount()) {
refChild.parentNode.addChild(newChild);
} else {
refChild.parentNode.insertChild(newChild, siblingIndex);
}
} | java | {
"resource": ""
} |
q171665 | Node.insertAfter | test | public void insertAfter(final Node[] newChilds, final Node refChild) {
if (newChilds.length == 0) {
return;
}
int siblingIndex = refChild.getSiblingIndex() + 1;
if (siblingIndex == refChild.parentNode.getChildNodesCount()) {
refChild.parentNode.addChild(newChilds);
} else {
refChild.parentNode.insertChild(newChilds, siblingIndex);
}
} | java | {
"resource": ""
} |
q171666 | Node.removeAllChilds | test | public void removeAllChilds() {
List<Node> removedNodes = childNodes;
childNodes = null;
childElementNodes = null;
childElementNodesCount = 0;
if (removedNodes != null) {
for (int i = 0, removedNodesSize = removedNodes.size(); i < removedNodesSize; i++) {
Node removedNode = removedNodes.get(i);
removedNode.detachFromParent();
}
}
} | java | {
"resource": ""
} |
q171667 | Node.findChildNodeWithName | test | public Node findChildNodeWithName(final String name) {
if (childNodes == null) {
return null;
}
for (final Node childNode : childNodes) {
if (childNode.getNodeName().equals(name)) {
return childNode;
}
}
return null;
} | java | {
"resource": ""
} |
q171668 | Node.filterChildNodes | test | public Node[] filterChildNodes(final Predicate<Node> nodePredicate) {
if (childNodes == null) {
return new Node[0];
}
return childNodes.stream()
.filter(nodePredicate)
.toArray(Node[]::new);
} | java | {
"resource": ""
} |
q171669 | Node.check | test | public boolean check() {
if (childNodes == null) {
return true;
}
// children
int siblingElementIndex = 0;
for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) {
Node childNode = childNodes.get(i);
if (childNode.siblingIndex != i) {
return false;
}
if (childNode.getNodeType() == NodeType.ELEMENT) {
if (childNode.siblingElementIndex != siblingElementIndex) {
return false;
}
siblingElementIndex++;
}
}
if (childElementNodesCount != siblingElementIndex) {
return false;
}
// child element nodes
if (childElementNodes != null) {
if (childElementNodes.length != childElementNodesCount) {
return false;
}
int childCount = getChildNodesCount();
for (int i = 0; i < childCount; i++) {
Node child = getChild(i);
if (child.siblingElementIndex >= 0) {
if (childElementNodes[child.siblingElementIndex] != child) {
return false;
}
}
}
}
// sibling names
if (siblingNameIndex != -1) {
List<Node> siblings = parentNode.childNodes;
int index = 0;
for (int i = 0, siblingsSize = siblings.size(); i < siblingsSize; i++) {
Node sibling = siblings.get(i);
if (sibling.siblingNameIndex == -1
&& nodeType == NodeType.ELEMENT
&& nodeName.equals(sibling.getNodeName())) {
if (sibling.siblingNameIndex != index++) {
return false;
}
}
}
}
// process children
for (Node childNode : childNodes) {
if (!childNode.check()) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q171670 | Node.initChildElementNodes | test | protected void initChildElementNodes() {
if (childElementNodes == null) {
childElementNodes = new Element[childElementNodesCount];
int childCount = getChildNodesCount();
for (int i = 0; i < childCount; i++) {
Node child = getChild(i);
if (child.siblingElementIndex >= 0) {
childElementNodes[child.siblingElementIndex] = (Element) child;
}
}
}
} | java | {
"resource": ""
} |
q171671 | Node.initSiblingNames | test | protected void initSiblingNames() {
if (siblingNameIndex == -1) {
List<Node> siblings = parentNode.childNodes;
int index = 0;
for (int i = 0, siblingsSize = siblings.size(); i < siblingsSize; i++) {
Node sibling = siblings.get(i);
if (sibling.siblingNameIndex == -1
&& nodeType == NodeType.ELEMENT
&& nodeName.equals(sibling.getNodeName())) {
sibling.siblingNameIndex = index++;
}
}
}
} | java | {
"resource": ""
} |
q171672 | Node.initChildNodes | test | protected void initChildNodes(final Node newNode) {
if (childNodes == null) {
childNodes = new ArrayList<>();
}
if (ownerDocument != null) {
if (newNode.ownerDocument != ownerDocument) {
changeOwnerDocument(newNode, ownerDocument);
}
}
} | java | {
"resource": ""
} |
q171673 | Node.changeOwnerDocument | test | protected void changeOwnerDocument(final Node node, final Document ownerDocument) {
node.ownerDocument = ownerDocument;
int childCount = node.getChildNodesCount();
for (int i = 0; i < childCount; i++) {
Node child = node.getChild(i);
changeOwnerDocument(child, ownerDocument);
}
} | java | {
"resource": ""
} |
q171674 | Node.getPreviousSiblingName | test | public Node getPreviousSiblingName() {
if (nodeName == null) {
return null;
}
initSiblingNames();
int index = siblingNameIndex -1;
for (int i = siblingIndex; i >= 0; i--) {
Node sibling = parentNode.childNodes.get(i);
if ((index == sibling.siblingNameIndex) && nodeName.equals(sibling.getNodeName())) {
return sibling;
}
}
return null;
} | java | {
"resource": ""
} |
q171675 | Node.getTextContent | test | public String getTextContent() {
StringBuilder sb = new StringBuilder(getChildNodesCount() + 1);
appendTextContent(sb);
return sb.toString();
} | java | {
"resource": ""
} |
q171676 | Node.getHtml | test | public String getHtml() {
LagartoDomBuilderConfig lagartoDomBuilderConfig;
if (ownerDocument == null) {
lagartoDomBuilderConfig = ((Document) this).getConfig();
} else {
lagartoDomBuilderConfig = ownerDocument.getConfig();
}
LagartoHtmlRenderer lagartoHtmlRenderer =
lagartoDomBuilderConfig.getLagartoHtmlRenderer();
return lagartoHtmlRenderer.toHtml(this, new StringBuilder());
} | java | {
"resource": ""
} |
q171677 | Node.getInnerHtml | test | public String getInnerHtml() {
LagartoDomBuilderConfig lagartoDomBuilderConfig;
if (ownerDocument == null) {
lagartoDomBuilderConfig = ((Document) this).getConfig();
} else {
lagartoDomBuilderConfig = ownerDocument.getConfig();
}
LagartoHtmlRenderer lagartoHtmlRenderer =
lagartoDomBuilderConfig.getLagartoHtmlRenderer();
return lagartoHtmlRenderer.toInnerHtml(this, new StringBuilder());
} | java | {
"resource": ""
} |
q171678 | Node.visitChildren | test | protected void visitChildren(final NodeVisitor nodeVisitor) {
if (childNodes != null) {
for (int i = 0, childNodesSize = childNodes.size(); i < childNodesSize; i++) {
Node childNode = childNodes.get(i);
childNode.visit(nodeVisitor);
}
}
} | java | {
"resource": ""
} |
q171679 | Node.getCssPath | test | public String getCssPath() {
StringBuilder path = new StringBuilder();
Node node = this;
while (node != null) {
String nodeName = node.getNodeName();
if (nodeName != null) {
StringBuilder sb = new StringBuilder();
sb.append(' ').append(nodeName);
String id = node.getAttribute("id");
if (id != null) {
sb.append('#').append(id);
}
path.insert(0, sb);
}
node = node.getParentNode();
}
if (path.charAt(0) == ' ') {
return path.substring(1);
}
return path.toString();
} | java | {
"resource": ""
} |
q171680 | DecoratorTagVisitor.onDecoraTag | test | protected void onDecoraTag(final Tag tag) {
String tagName = tag.getName().toString();
if (tag.getType() == TagType.SELF_CLOSING) {
checkNestedDecoraTags();
decoraTagName = tagName.substring(7);
decoraTagStart = tag.getTagPosition();
decoraTagEnd = tag.getTagPosition() + tag.getTagLength();
defineDecoraTag();
return;
}
if (tag.getType() == TagType.START) {
checkNestedDecoraTags();
decoraTagName = tagName.substring(7);
decoraTagStart = tag.getTagPosition();
decoraTagDefaultValueStart = tag.getTagPosition() + tag.getTagLength();
return;
}
// closed tag type
decoraTagEnd = tag.getTagPosition() + tag.getTagLength();
decoraTagDefaultValueEnd = tag.getTagPosition();
defineDecoraTag();
} | java | {
"resource": ""
} |
q171681 | DecoratorTagVisitor.onIdAttrStart | test | protected void onIdAttrStart(final Tag tag) {
String id = tag.getId().toString().substring(7);
String tagName;
String idName;
int dashIndex = id.indexOf('-');
if (dashIndex == -1) {
tagName = id;
idName = null;
} else {
tagName = id.substring(0, dashIndex);
idName = id.substring(dashIndex + 1);
}
if (tag.getType() == TagType.SELF_CLOSING) {
checkNestedDecoraTags();
decoraTagName = tagName;
decoraIdName = idName;
decoraTagStart = tag.getTagPosition();
decoraTagEnd = tag.getTagPosition() + tag.getTagLength();
defineDecoraTag();
return;
}
if (tag.getType() == TagType.START) {
checkNestedDecoraTags();
decoraTagName = tagName;
decoraIdName = idName;
decoraTagStart = tag.getTagPosition();
decoraTagDefaultValueStart = tag.getTagPosition() + tag.getTagLength();
closingTagName = tag.getName().toString();
closingTagDeepLevel = tag.getDeepLevel();
}
} | java | {
"resource": ""
} |
q171682 | DecoratorTagVisitor.defineDecoraTag | test | protected void defineDecoraTag() {
DecoraTag decoraTag =
decoraTagDefaultValueStart == 0 ?
new DecoraTag(decoraTagName, decoraIdName, decoraTagStart, decoraTagEnd) :
new DecoraTag(
decoraTagName, decoraIdName,
decoraTagStart, decoraTagEnd,
decoraTagDefaultValueStart, decoraTagDefaultValueEnd - decoraTagDefaultValueStart);
decoraTags.add(decoraTag);
decoraTagName = null;
decoraIdName = null;
closingTagName = null;
decoraTagDefaultValueStart = 0;
} | java | {
"resource": ""
} |
q171683 | JoyProxetta.addProxyAspect | test | @Override
public JoyProxetta addProxyAspect(final ProxyAspect proxyAspect) {
requireNotStarted(proxetta);
this.proxyAspects.add(proxyAspect);
return this;
} | java | {
"resource": ""
} |
q171684 | RootPackages.addRootPackage | test | public void addRootPackage(final String rootPackage, String mapping) {
if (packages == null) {
packages = new String[0];
}
if (mappings == null) {
mappings = new String[0];
}
// fix mapping
if (mapping.length() > 0) {
// mapping must start with the slash
if (!mapping.startsWith(StringPool.SLASH)) {
mapping = StringPool.SLASH + mapping;
}
// mapping must NOT end with the slash
if (mapping.endsWith(StringPool.SLASH)) {
mapping = StringUtil.substring(mapping, 0, -1);
}
}
// detect duplicates
for (int i = 0; i < packages.length; i++) {
if (packages[i].equals(rootPackage)) {
if (mappings[i].equals(mapping)) {
// both package and the mappings are the same
return;
}
throw new MadvocException("Different mappings for the same root package: " + rootPackage);
}
}
packages = ArraysUtil.append(packages, rootPackage);
mappings = ArraysUtil.append(mappings, mapping);
} | java | {
"resource": ""
} |
q171685 | RootPackages.addRootPackageOf | test | public void addRootPackageOf(final Class actionClass, final String mapping) {
addRootPackage(actionClass.getPackage().getName(), mapping);
} | java | {
"resource": ""
} |
q171686 | RootPackages.findRootPackageForActionPath | test | public String findRootPackageForActionPath(final String actionPath) {
if (mappings == null) {
return null;
}
int ndx = -1;
int delta = Integer.MAX_VALUE;
for (int i = 0; i < mappings.length; i++) {
String mapping = mappings[i];
boolean found = false;
if (actionPath.equals(mapping)) {
found = true;
} else {
mapping += StringPool.SLASH;
if (actionPath.startsWith(mapping)) {
found = true;
}
}
if (found) {
int distance = actionPath.length() - mapping.length();
if (distance < delta) {
ndx = i;
delta = distance;
}
}
}
if (ndx == -1) {
return null;
}
return packages[ndx];
} | java | {
"resource": ""
} |
q171687 | VtorUtil.resolveValidationMessage | test | public static String resolveValidationMessage(final HttpServletRequest request, final Violation violation) {
ValidationConstraint vc = violation.getConstraint();
String key = vc != null ? vc.getClass().getName() : violation.getName();
String msg = LocalizationUtil.findMessage(request, key);
if (msg != null) {
return beanTemplateParser.parseWithBean(msg, violation);
}
return null;
} | java | {
"resource": ""
} |
q171688 | BeanReferences.removeDuplicateNames | test | public BeanReferences removeDuplicateNames() {
if (names.length < 2) {
return this;
}
int nullCount = 0;
for (int i = 1; i < names.length; i++) {
String thisRef = names[i];
if (thisRef == null) {
nullCount++;
continue;
}
for (int j = 0; j < i; j++) {
if (names[j] == null) {
continue;
}
if (thisRef.equals(names[j])) {
names[i] = null;
break;
}
}
}
if (nullCount == 0) {
return this;
}
String[] newRefs = new String[names.length - nullCount];
int ndx = 0;
for (String name : names) {
if (name == null) {
continue;
}
newRefs[ndx] = name;
ndx++;
}
return new BeanReferences(newRefs);
} | java | {
"resource": ""
} |
q171689 | JoyProps.addPropsFile | test | @Override
public JoyProps addPropsFile(final String namePattern) {
requireNotStarted(props);
this.propsNamePatterns.add(namePattern);
return this;
} | java | {
"resource": ""
} |
q171690 | Targets.forEachTarget | test | public void forEachTarget(final Consumer<Target> targetConsumer) {
for (final Target target : targets) {
targetConsumer.accept(target);
}
} | java | {
"resource": ""
} |
q171691 | Targets.forEachTargetAndIn | test | public void forEachTargetAndIn(final MadvocScope scope, final BiConsumer<Target, InjectionPoint> biConsumer) {
for (final Target target : targets) {
final ScopeData scopeData = target.scopeData();
if (scopeData.in() == null) {
continue;
}
for (final InjectionPoint in : scopeData.in()) {
if (in.scope() != scope) {
continue;
}
biConsumer.accept(target, in);
}
}
} | java | {
"resource": ""
} |
q171692 | Targets.forEachTargetAndOut | test | public void forEachTargetAndOut(final MadvocScope scope, final BiConsumer<Target, InjectionPoint> biConsumer) {
for (final Target target : targets) {
final ScopeData scopeData = target.scopeData();
if (scopeData.out() == null) {
continue;
}
for (final InjectionPoint out : scopeData.out()) {
if (out.scope() != scope) {
continue;
}
biConsumer.accept(target, out);
}
}
} | java | {
"resource": ""
} |
q171693 | Targets.extractParametersValues | test | public Object[] extractParametersValues() {
final Object[] values = new Object[targets.length - 1];
for (int i = 1; i < targets.length; i++) {
values[i - 1] = targets[i].value();
}
return values;
} | java | {
"resource": ""
} |
q171694 | Targets.makeTargets | test | protected Target[] makeTargets(final Target actionTarget, final MethodParam[] methodParams) {
if (methodParams == null) {
// action does not have method parameters, so there is just one target
return new Target[]{actionTarget};
}
// action has method arguments, so there is more then one target
final Target[] target = new Target[methodParams.length + 1];
target[0] = actionTarget;
final Object action = actionTarget.value();
for (int i = 0; i < methodParams.length; i++) {
final MethodParam methodParam = methodParams[i];
final Class paramType = methodParam.type();
final Target paramTarget;
if (methodParam.annotationType() == null) {
// parameter is NOT annotated, create new value for the target
// the class itself will be a base class, and should be scanned
final ScopeData newScopeData = methodParam.scopeData().inspector().inspectClassScopesWithCache(paramType);
paramTarget = Target.ofValue(createActionMethodArgument(paramType, action), newScopeData);
}
else if (methodParam.annotationType() == Out.class) {
// parameter is annotated with *only* OUT annotation
// create the output value now AND to save the type
paramTarget = Target.ofMethodParam(methodParam, createActionMethodArgument(paramType, action));
}
else {
// parameter is annotated with any IN annotation
// create target with NO value, as the value will be created later
paramTarget = Target.ofMethodParam(methodParam, type -> createActionMethodArgument(type, action));
}
target[i + 1] = paramTarget;
}
return target;
} | java | {
"resource": ""
} |
q171695 | Targets.createActionMethodArgument | test | @SuppressWarnings({"unchecked", "NullArgumentToVariableArgMethod"})
protected Object createActionMethodArgument(final Class type, final Object action) {
try {
if (type.getEnclosingClass() == null || Modifier.isStatic(type.getModifiers())) {
// regular or static class
return ClassUtil.newInstance(type);
} else {
// member class
Constructor ctor = type.getDeclaredConstructor(type.getDeclaringClass());
ctor.setAccessible(true);
return ctor.newInstance(action);
}
} catch (Exception ex) {
throw new MadvocException(ex);
}
} | java | {
"resource": ""
} |
q171696 | SessionMonitor.sessionCreated | test | @Override
public void sessionCreated(final HttpSessionEvent httpSessionEvent) {
HttpSession session = httpSessionEvent.getSession();
sessionMap.putIfAbsent(session.getId(), session);
for (HttpSessionListener listener : listeners) {
listener.sessionCreated(httpSessionEvent);
}
} | java | {
"resource": ""
} |
q171697 | SessionMonitor.sessionDestroyed | test | @Override
public void sessionDestroyed(final HttpSessionEvent httpSessionEvent) {
HttpSession session = httpSessionEvent.getSession();
sessionMap.remove(session.getId());
for (HttpSessionListener listener : listeners) {
listener.sessionDestroyed(httpSessionEvent);
}
} | java | {
"resource": ""
} |
q171698 | JsonArray.add | test | public JsonArray add(Object value) {
Objects.requireNonNull(value);
value = JsonObject.resolveValue(value);
list.add(value);
return this;
} | java | {
"resource": ""
} |
q171699 | JsonArray.addAll | test | public JsonArray addAll(final JsonArray array) {
Objects.requireNonNull(array);
list.addAll(array.list);
return this;
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.