_id stringlengths 2 7 | title stringlengths 3 140 | partition stringclasses 3
values | text stringlengths 73 34.1k | language stringclasses 1
value | meta_information dict |
|---|---|---|---|---|---|
q171100 | Type.getConstructorDescriptor | test | public static String getConstructorDescriptor(final Constructor<?> constructor) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append('(');
Class<?>[] parameters = constructor.getParameterTypes();
for (Class<?> parameter : parameters) {
appendDescriptor(parameter, stringBuilder);
}
return stringBuilder.append(")V").toString();
} | java | {
"resource": ""
} |
q171101 | Type.getMethodDescriptor | test | public static String getMethodDescriptor(final Type returnType, final Type... argumentTypes) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append('(');
for (Type argumentType : argumentTypes) {
argumentType.appendDescriptor(stringBuilder);
}
stringBuilder.append(')');
returnType.appendDescriptor(stringBuilder);
return stringBuilder.toString();
} | java | {
"resource": ""
} |
q171102 | Type.getMethodDescriptor | test | public static String getMethodDescriptor(final Method method) {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append('(');
Class<?>[] parameters = method.getParameterTypes();
for (Class<?> parameter : parameters) {
appendDescriptor(parameter, stringBuilder);
}
stringBuilder.append(')');
appendDescriptor(method.getReturnType(), stringBuilder);
return stringBuilder.toString();
} | java | {
"resource": ""
} |
q171103 | Type.appendDescriptor | test | private void appendDescriptor(final StringBuilder stringBuilder) {
if (sort == OBJECT) {
stringBuilder.append(valueBuffer, valueBegin - 1, valueEnd + 1);
} else if (sort == INTERNAL) {
stringBuilder.append('L').append(valueBuffer, valueBegin, valueEnd).append(';');
} else {
stringBuilder.append(valueBuffer, valueBegin, valueEnd);
}
} | java | {
"resource": ""
} |
q171104 | Type.getSize | test | public int getSize() {
switch (sort) {
case VOID:
return 0;
case BOOLEAN:
case CHAR:
case BYTE:
case SHORT:
case INT:
case FLOAT:
case ARRAY:
case OBJECT:
case INTERNAL:
return 1;
case LONG:
case DOUBLE:
return 2;
default:
throw new AssertionError();
}
} | java | {
"resource": ""
} |
q171105 | Type.getArgumentsAndReturnSizes | test | public static int getArgumentsAndReturnSizes(final String methodDescriptor) {
int argumentsSize = 1;
// Skip the first character, which is always a '('.
int currentOffset = 1;
int currentChar = methodDescriptor.charAt(currentOffset);
// Parse the argument types and compute their size, one at a each loop iteration.
while (currentChar != ')') {
if (currentChar == 'J' || currentChar == 'D') {
currentOffset++;
argumentsSize += 2;
} else {
while (methodDescriptor.charAt(currentOffset) == '[') {
currentOffset++;
}
if (methodDescriptor.charAt(currentOffset++) == 'L') {
// Skip the argument descriptor content.
currentOffset = methodDescriptor.indexOf(';', currentOffset) + 1;
}
argumentsSize += 1;
}
currentChar = methodDescriptor.charAt(currentOffset);
}
currentChar = methodDescriptor.charAt(currentOffset + 1);
if (currentChar == 'V') {
return argumentsSize << 2;
} else {
int returnSize = (currentChar == 'J' || currentChar == 'D') ? 2 : 1;
return argumentsSize << 2 | returnSize;
}
} | java | {
"resource": ""
} |
q171106 | JtxTransaction.setRollbackOnly | test | public void setRollbackOnly(final Throwable th) {
if (!isNoTransaction()) {
if ((status != STATUS_MARKED_ROLLBACK) && (status != STATUS_ACTIVE)) {
throw new JtxException("TNo active TX that can be marked as rollback only");
}
}
rollbackCause = th;
status = STATUS_MARKED_ROLLBACK;
} | java | {
"resource": ""
} |
q171107 | JtxTransaction.commitOrRollback | test | protected void commitOrRollback(boolean doCommit) {
if (log.isDebugEnabled()) {
if (doCommit) {
log.debug("Commit JTX");
} else {
log.debug("Rollback JTX");
}
}
boolean forcedRollback = false;
if (!isNoTransaction()) {
if (isRollbackOnly()) {
if (doCommit) {
doCommit = false;
forcedRollback = true;
}
} else if (!isActive()) {
if (isCompleted()) {
throw new JtxException("TX is already completed, commit or rollback should be called once per TX");
}
throw new JtxException("No active TX to " + (doCommit ? "commit" : "rollback"));
}
}
if (doCommit) {
commitAllResources();
} else {
rollbackAllResources(forcedRollback);
}
} | java | {
"resource": ""
} |
q171108 | JtxTransaction.rollbackAllResources | test | protected void rollbackAllResources(final boolean wasForced) {
status = STATUS_ROLLING_BACK;
Exception lastException = null;
Iterator<JtxResource> it = resources.iterator();
while (it.hasNext()) {
JtxResource resource = it.next();
try {
resource.rollbackTransaction();
} catch (Exception ex) {
lastException = ex;
} finally {
it.remove();
}
}
txManager.removeTransaction(this);
status = STATUS_ROLLEDBACK;
if (lastException != null) {
status = STATUS_UNKNOWN;
throw new JtxException("Rollback failed: one or more TX resources couldn't rollback a TX", lastException);
}
if (wasForced) {
throw new JtxException("TX rolled back because it has been marked as rollback-only", rollbackCause);
}
} | java | {
"resource": ""
} |
q171109 | JtxTransaction.requestResource | test | public <E> E requestResource(final Class<E> resourceType) {
if (isCompleted()) {
throw new JtxException("TX is already completed, resource are not available after commit or rollback");
}
if (isRollbackOnly()) {
throw new JtxException("TX is marked as rollback only, resource are not available", rollbackCause);
}
if (!isNoTransaction() && !isActive()) {
throw new JtxException("Resources are not available since TX is not active");
}
checkTimeout();
E resource = lookupResource(resourceType);
if (resource == null) {
int maxResources = txManager.getMaxResourcesPerTransaction();
if ((maxResources != -1) && (resources.size() >= maxResources)) {
throw new JtxException("TX already has attached max. number of resources");
}
JtxResourceManager<E> resourceManager = txManager.lookupResourceManager(resourceType);
resource = resourceManager.beginTransaction(mode, isActive());
resources.add(new JtxResource<>(this, resourceManager, resource));
}
return resource;
} | java | {
"resource": ""
} |
q171110 | JsonWriter.popName | test | protected void popName() {
if (isPushed) {
if (pushedComma) {
writeComma();
}
String name = pushedName;
pushedName = null;
isPushed = false;
writeName(name);
}
} | java | {
"resource": ""
} |
q171111 | JsonWriter.writeString | test | public void writeString(final String value) {
popName();
write(StringPool.QUOTE);
int len = value.length();
for (int i = 0; i < len; i++) {
char c = value.charAt(i);
switch (c) {
case '"':
write("\\\"");
break;
case '\\':
write("\\\\");
break;
case '/':
if (strictStringEncoding) {
write("\\/");
}
else {
write(c);
}
break;
case '\b':
write("\\b");
break;
case '\f':
write("\\f");
break;
case '\n':
write("\\n");
break;
case '\r':
write("\\r");
break;
case '\t':
write("\\t");
break;
default:
if (Character.isISOControl(c)) {
unicode(c);
}
else {
write(c);
}
}
}
write(StringPool.QUOTE);
} | java | {
"resource": ""
} |
q171112 | JsonWriter.unicode | test | protected void unicode(final char c) {
write("\\u");
int n = c;
for (int i = 0; i < 4; ++i) {
int digit = (n & 0xf000) >> 12;
char hex = CharUtil.int2hex(digit);
write(hex);
n <<= 4;
}
} | java | {
"resource": ""
} |
q171113 | JsonWriter.write | test | public void write(final CharSequence charSequence) {
popName();
try {
out.append(charSequence);
} catch (IOException ioex) {
throw new JsonException(ioex);
}
} | java | {
"resource": ""
} |
q171114 | LagartoDomBuilderConfig.setParsingErrorLogLevelName | test | public LagartoDomBuilderConfig setParsingErrorLogLevelName(String logLevel) {
logLevel = logLevel.trim().toUpperCase();
parsingErrorLogLevel = Logger.Level.valueOf(logLevel);
return this;
} | java | {
"resource": ""
} |
q171115 | DecoraTag.startRegion | test | public void startRegion(final int start, final int tagLen, final int deepLevel) {
this.regionStart = start + tagLen;
this.regionLength = 0;
this.regionTagStart = start;
this.deepLevel = deepLevel;
} | java | {
"resource": ""
} |
q171116 | Attribute.isContaining | test | public boolean isContaining(final String include) {
if (value == null) {
return false;
}
if (splits == null) {
splits = StringUtil.splitc(value, ' ');
}
for (String s: splits) {
if (s.equals(include)) {
return true;
}
}
return false;
} | java | {
"resource": ""
} |
q171117 | PseudoFunctionSelector.registerPseudoFunction | test | public static void registerPseudoFunction(final Class<? extends PseudoFunction> pseudoFunctionType) {
PseudoFunction pseudoFunction;
try {
pseudoFunction = ClassUtil.newInstance(pseudoFunctionType);
} catch (Exception ex) {
throw new CSSellyException(ex);
}
PSEUDO_FUNCTION_MAP.put(pseudoFunction.getPseudoFunctionName(), pseudoFunction);
} | java | {
"resource": ""
} |
q171118 | PseudoFunctionSelector.lookupPseudoFunction | test | public static PseudoFunction<?> lookupPseudoFunction(final String pseudoFunctionName) {
PseudoFunction pseudoFunction = PSEUDO_FUNCTION_MAP.get(pseudoFunctionName);
if (pseudoFunction == null) {
throw new CSSellyException("Unsupported pseudo function: " + pseudoFunctionName);
}
return pseudoFunction;
} | java | {
"resource": ""
} |
q171119 | ProxettaClassBuilder.visit | test | @Override
public void visit(final int version, int access, final String name, final String signature, final String superName, final String[] interfaces) {
wd.init(name, superName, this.suffix, this.reqProxyClassName);
// change access of destination
access &= ~AsmUtil.ACC_ABSTRACT;
// write destination class
final int v = ProxettaAsmUtil.resolveJavaVersion(version);
wd.dest.visit(v, access, wd.thisReference, signature, wd.superName, null);
wd.proxyAspects = new ProxyAspectData[aspects.length];
for (int i = 0; i < aspects.length; i++) {
wd.proxyAspects[i] = new ProxyAspectData(wd, aspects[i], i);
}
} | java | {
"resource": ""
} |
q171120 | ProxettaClassBuilder.visitAnnotation | test | @Override
public AnnotationVisitor visitAnnotation(final String desc, final boolean visible) {
AnnotationVisitor destAnn = wd.dest.visitAnnotation(desc, visible); // [A3]
return new AnnotationVisitorAdapter(destAnn);
} | java | {
"resource": ""
} |
q171121 | ProxettaClassBuilder.makeStaticInitBlock | test | protected void makeStaticInitBlock() {
if (wd.adviceClinits != null) {
MethodVisitor mv = wd.dest.visitMethod(AsmUtil.ACC_STATIC, CLINIT, DESC_VOID, null, null);
mv.visitCode();
for (String name : wd.adviceClinits) {
mv.visitMethodInsn(
INVOKESTATIC,
wd.thisReference,
name, DESC_VOID,
false);
}
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
}
} | java | {
"resource": ""
} |
q171122 | ProxettaClassBuilder.makeProxyConstructor | test | protected void makeProxyConstructor() {
MethodVisitor mv = wd.dest.visitMethod(AsmUtil.ACC_PRIVATE | AsmUtil.ACC_FINAL, ProxettaNames.initMethodName, DESC_VOID, null, null);
mv.visitCode();
if (wd.adviceInits != null) {
for (String name : wd.adviceInits) {
mv.visitVarInsn(ALOAD, 0);
mv.visitMethodInsn
(INVOKESPECIAL,
wd.thisReference,
name, DESC_VOID,
false);
}
}
mv.visitInsn(RETURN);
mv.visitMaxs(0, 0);
mv.visitEnd();
} | java | {
"resource": ""
} |
q171123 | ProxettaClassBuilder.processSuperMethods | test | protected void processSuperMethods() {
for (ClassReader cr : targetClassInfo.superClassReaders) {
cr.accept(new EmptyClassVisitor() {
String declaredClassName;
@Override
public void visit(final int version, final int access, final String name, final String signature, final String superName, final String[] interfaces) {
declaredClassName = name;
}
@Override
public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) {
if (name.equals(INIT) || name.equals(CLINIT)) {
return null;
}
MethodSignatureVisitor msign = targetClassInfo.lookupMethodSignatureVisitor(access, name, desc, declaredClassName);
if (msign == null) {
return null;
}
return applyProxy(msign);
}
}, 0);
}
} | java | {
"resource": ""
} |
q171124 | BinarySearchBase.findLast | test | public int findLast(int low, int high) {
int ndx = -1;
while (low <= high) {
int mid = (low + high) >>> 1;
int delta = compare(mid);
if (delta > 0) {
high = mid - 1;
} else {
if (delta == 0) {
ndx = mid;
}
low = mid + 1;
}
}
if (ndx == -1) {
return -(low + 1);
}
return ndx;
} | java | {
"resource": ""
} |
q171125 | Chalk.on | test | public String on(final String string) {
if (!enabled) {
return string;
}
final StringBuilder sb = new StringBuilder();
if (prefix != null) {
sb.append(prefix).append("m");
}
sb.append(string);
if (suffix != null) {
sb.append(suffix).append("m");
}
return sb.toString();
} | java | {
"resource": ""
} |
q171126 | ClassWriter.replaceAsmInstructions | test | private byte[] replaceAsmInstructions(final byte[] classFile, final boolean hasFrames) {
final Attribute[] attributes = getAttributePrototypes();
firstField = null;
lastField = null;
firstMethod = null;
lastMethod = null;
lastRuntimeVisibleAnnotation = null;
lastRuntimeInvisibleAnnotation = null;
lastRuntimeVisibleTypeAnnotation = null;
lastRuntimeInvisibleTypeAnnotation = null;
moduleWriter = null;
nestHostClassIndex = 0;
numberOfNestMemberClasses = 0;
nestMemberClasses = null;
firstAttribute = null;
compute = hasFrames ? MethodWriter.COMPUTE_INSERTED_FRAMES : MethodWriter.COMPUTE_NOTHING;
new ClassReader(classFile, 0, /* checkClassVersion = */ false)
.accept(
this,
attributes,
(hasFrames ? ClassReader.EXPAND_FRAMES : 0) | ClassReader.EXPAND_ASM_INSNS);
return toByteArray();
} | java | {
"resource": ""
} |
q171127 | ClassWriter.getAttributePrototypes | test | private Attribute[] getAttributePrototypes() {
Attribute.Set attributePrototypes = new Attribute.Set();
attributePrototypes.addAttributes(firstAttribute);
FieldWriter fieldWriter = firstField;
while (fieldWriter != null) {
fieldWriter.collectAttributePrototypes(attributePrototypes);
fieldWriter = (FieldWriter) fieldWriter.fv;
}
MethodWriter methodWriter = firstMethod;
while (methodWriter != null) {
methodWriter.collectAttributePrototypes(attributePrototypes);
methodWriter = (MethodWriter) methodWriter.mv;
}
return attributePrototypes.toArray();
} | java | {
"resource": ""
} |
q171128 | SqlTypeManager.registerDefaults | test | public void registerDefaults() {
register(Integer.class, IntegerSqlType.class);
register(int.class, IntegerSqlType.class);
register(MutableInteger.class, IntegerSqlType.class);
register(Float.class, FloatSqlType.class);
register(float.class, FloatSqlType.class);
register(MutableFloat.class, FloatSqlType.class);
register(Double.class, DoubleSqlType.class);
register(double.class, DoubleSqlType.class);
register(MutableDouble.class, DoubleSqlType.class);
register(Byte.class, ByteSqlType.class);
register(byte.class, ByteSqlType.class);
register(MutableByte.class, ByteSqlType.class);
register(Boolean.class, BooleanSqlType.class);
register(boolean.class, BooleanSqlType.class);
register(MutableBoolean.class, BooleanSqlType.class);
register(Long.class, LongSqlType.class);
register(long.class, LongSqlType.class);
register(MutableLong.class, LongSqlType.class);
register(Short.class, ShortSqlType.class);
register(short.class, ShortSqlType.class);
register(MutableShort.class, ShortSqlType.class);
register(Character.class, CharacterSqlType.class);
register(char.class, CharacterSqlType.class);
register(BigDecimal.class, BigDecimalSqlType.class);
register(BigInteger.class, BigIntegerSqlType.class);
register(String.class, StringSqlType.class);
register(LocalDateTime.class, LocalDateTimeSqlType.class);
register(LocalDate.class, LocalDateSqlType.class);
register(LocalTime.class, LocalTimeSqlType.class);
register(Date.class, SqlDateSqlType.class);
register(Timestamp.class, TimestampSqlType.class);
register(Time.class, TimeSqlType.class);
register(java.util.Date.class, DateSqlType.class);
register(JulianDate.class, JulianDateSqlType.class);
register(byte[].class, ByteArraySqlType.class);
register(URL.class, URLSqlType.class);
register(Blob.class, BlobSqlType.class);
register(Clob.class, ClobSqlType.class);
register(Array.class, SqlArraySqlType.class);
register(Ref.class, SqlRefSqlType.class);
} | java | {
"resource": ""
} |
q171129 | SqlTypeManager.register | test | public void register(final Class type, final Class<? extends SqlType> sqlTypeClass) {
types.put(type, lookupSqlType(sqlTypeClass));
} | java | {
"resource": ""
} |
q171130 | SqlTypeManager.lookup | test | public SqlType lookup(final Class clazz) {
SqlType sqlType;
for (Class x = clazz; x != null; x = x.getSuperclass()) {
sqlType = types.get(clazz);
if (sqlType != null) {
return sqlType;
}
Class[] interfaces = x.getInterfaces();
for (Class i : interfaces) {
sqlType = types.get(i);
if (sqlType != null) {
return sqlType;
}
}
}
return null;
} | java | {
"resource": ""
} |
q171131 | SqlTypeManager.lookupSqlType | test | public SqlType lookupSqlType(final Class<? extends SqlType> sqlTypeClass) {
SqlType sqlType = sqlTypes.get(sqlTypeClass);
if (sqlType == null) {
try {
sqlType = ClassUtil.newInstance(sqlTypeClass);
} catch (Exception ex) {
throw new DbSqlException("SQL type not found: " + sqlTypeClass.getSimpleName(), ex);
}
sqlTypes.put(sqlTypeClass, sqlType);
}
return sqlType;
} | java | {
"resource": ""
} |
q171132 | ProxyInfo.socks4Proxy | test | public static ProxyInfo socks4Proxy(final String proxyAddress, final int proxyPort, final String proxyUser) {
return new ProxyInfo(ProxyType.SOCKS4, proxyAddress, proxyPort, proxyUser, null);
} | java | {
"resource": ""
} |
q171133 | ProxyInfo.socks5Proxy | test | public static ProxyInfo socks5Proxy(final String proxyAddress, final int proxyPort, final String proxyUser, final String proxyPassword) {
return new ProxyInfo(ProxyType.SOCKS5, proxyAddress, proxyPort, proxyUser, proxyPassword);
} | java | {
"resource": ""
} |
q171134 | ProxyInfo.httpProxy | test | public static ProxyInfo httpProxy(final String proxyAddress, final int proxyPort, final String proxyUser, final String proxyPassword) {
return new ProxyInfo(ProxyType.HTTP, proxyAddress, proxyPort, proxyUser, proxyPassword);
} | java | {
"resource": ""
} |
q171135 | JtxTransactionManager.totalThreadTransactions | test | public int totalThreadTransactions() {
ArrayList<JtxTransaction> txList = txStack.get();
if (txList == null) {
return 0;
}
return txList.size();
} | java | {
"resource": ""
} |
q171136 | JtxTransactionManager.totalThreadTransactionsWithStatus | test | public int totalThreadTransactionsWithStatus(final JtxStatus status) {
ArrayList<JtxTransaction> txlist = txStack.get();
if (txlist == null) {
return 0;
}
int count = 0;
for (JtxTransaction tx : txlist) {
if (tx.getStatus() == status) {
count++;
}
}
return count;
} | java | {
"resource": ""
} |
q171137 | JtxTransactionManager.associateTransaction | test | protected void associateTransaction(final JtxTransaction tx) {
totalTransactions++;
ArrayList<JtxTransaction> txList = txStack.get();
if (txList == null) {
txList = new ArrayList<>();
txStack.set(txList);
}
txList.add(tx); // add last
} | java | {
"resource": ""
} |
q171138 | JtxTransactionManager.continueTx | test | protected void continueTx(final JtxTransaction sourceTx, final JtxTransactionMode destMode) {
if (!validateExistingTransaction) {
return;
}
JtxTransactionMode sourceMode = sourceTx.getTransactionMode();
JtxIsolationLevel destIsolationLevel = destMode.getIsolationLevel();
if (destIsolationLevel != ISOLATION_DEFAULT) {
JtxIsolationLevel currentIsolationLevel = sourceMode.getIsolationLevel();
if (currentIsolationLevel != destIsolationLevel) {
throw new JtxException("Participating TX specifies isolation level: " + destIsolationLevel +
" which is incompatible with existing TX: " + currentIsolationLevel);
}
}
if ((!destMode.isReadOnly()) && (sourceMode.isReadOnly())) {
throw new JtxException("Participating TX is not marked as read-only, but existing TX is");
}
} | java | {
"resource": ""
} |
q171139 | JtxTransactionManager.lookupResourceManager | test | protected <E> JtxResourceManager<E> lookupResourceManager(final Class<E> resourceType) {
//noinspection unchecked
JtxResourceManager<E> resourceManager = this.resourceManagers.get(resourceType);
if (resourceManager == null) {
throw new JtxException("No registered resource manager for resource type: " + resourceType.getSimpleName());
}
return resourceManager;
} | java | {
"resource": ""
} |
q171140 | Pathref.createProxyObject | test | protected C createProxyObject(Class<C> target) {
target = ProxettaUtil.resolveTargetClass(target);
Class proxyClass = cache.get(target);
if (proxyClass == null) {
proxyClass = proxetta.defineProxy(target);
cache.put(target, proxyClass);
}
C proxy;
try {
proxy = (C) ClassUtil.newInstance(proxyClass);
} catch (Exception ex) {
throw new PathrefException(ex);
}
return proxy;
} | java | {
"resource": ""
} |
q171141 | Pathref.append | test | protected void append(final String methodName) {
if (path.length() != 0) {
path += StringPool.DOT;
}
if (methodName.startsWith(StringPool.LEFT_SQ_BRACKET)) {
path = StringUtil.substring(path, 0, -1);
}
path += methodName;
} | java | {
"resource": ""
} |
q171142 | Format.alignLeftAndPad | test | public static String alignLeftAndPad(final String text, final int size) {
int textLength = text.length();
if (textLength > size) {
return text.substring(0, size);
}
final StringBuilder sb = new StringBuilder(size);
sb.append(text);
while (textLength++ < size) {
sb.append(' ');
}
return sb.toString();
} | java | {
"resource": ""
} |
q171143 | Format.toPrettyString | test | public static String toPrettyString(final Object value) {
if (value == null) {
return StringPool.NULL;
}
final Class<?> type = value.getClass();
if (type.isArray()) {
final Class componentType = type.getComponentType();
if (componentType.isPrimitive()) {
final StringBuilder sb = new StringBuilder();
sb.append('[');
if (componentType == int.class) {
sb.append(ArraysUtil.toString((int[]) value));
}
else if (componentType == long.class) {
sb.append(ArraysUtil.toString((long[]) value));
}
else if (componentType == double.class) {
sb.append(ArraysUtil.toString((double[]) value));
}
else if (componentType == float.class) {
sb.append(ArraysUtil.toString((float[]) value));
}
else if (componentType == boolean.class) {
sb.append(ArraysUtil.toString((boolean[]) value));
}
else if (componentType == short.class) {
sb.append(ArraysUtil.toString((short[]) value));
}
else if (componentType == byte.class) {
sb.append(ArraysUtil.toString((byte[]) value));
} else {
throw new IllegalArgumentException();
}
sb.append(']');
return sb.toString();
} else {
final StringBuilder sb = new StringBuilder();
sb.append('[');
final Object[] array = (Object[]) value;
for (int i = 0; i < array.length; i++) {
if (i > 0) {
sb.append(',');
}
sb.append(toPrettyString(array[i]));
}
sb.append(']');
return sb.toString();
}
} else if (value instanceof Iterable) {
final Iterable iterable = (Iterable) value;
final StringBuilder sb = new StringBuilder();
sb.append('{');
int i = 0;
for (final Object o : iterable) {
if (i > 0) {
sb.append(',');
}
sb.append(toPrettyString(o));
i++;
}
sb.append('}');
return sb.toString();
}
return value.toString();
} | java | {
"resource": ""
} |
q171144 | Format.toCamelCase | test | public static String toCamelCase(final String input, final boolean firstCharUppercase, final char separator) {
final int length = input.length();
final StringBuilder sb = new StringBuilder(length);
boolean upperCase = firstCharUppercase;
for (int i = 0; i < length; i++) {
final char ch = input.charAt(i);
if (ch == separator) {
upperCase = true;
} else if (upperCase) {
sb.append(Character.toUpperCase(ch));
upperCase = false;
} else {
sb.append(ch);
}
}
return sb.toString();
} | java | {
"resource": ""
} |
q171145 | Format.formatParagraph | test | public static String formatParagraph(final String src, final int len, final boolean breakOnWhitespace) {
StringBuilder str = new StringBuilder();
int total = src.length();
int from = 0;
while (from < total) {
int to = from + len;
if (to >= total) {
to = total;
} else if (breakOnWhitespace) {
int ndx = StringUtil.lastIndexOfWhitespace(src, to - 1, from);
if (ndx != -1) {
to = ndx + 1;
}
}
int cutFrom = StringUtil.indexOfNonWhitespace(src, from, to);
if (cutFrom != -1) {
int cutTo = StringUtil.lastIndexOfNonWhitespace(src, to - 1, from) + 1;
str.append(src, cutFrom, cutTo);
}
str.append('\n');
from = to;
}
return str.toString();
} | java | {
"resource": ""
} |
q171146 | Format.convertTabsToSpaces | test | public static String convertTabsToSpaces(final String line, final int tabWidth) {
int tab_index, tab_size;
int last_tab_index = 0;
int added_chars = 0;
if (tabWidth == 0) {
return StringUtil.remove(line, '\t');
}
StringBuilder result = new StringBuilder();
while ((tab_index = line.indexOf('\t', last_tab_index)) != -1) {
tab_size = tabWidth - ((tab_index + added_chars) % tabWidth);
if (tab_size == 0) {
tab_size = tabWidth;
}
added_chars += tab_size - 1;
result.append(line, last_tab_index, tab_index);
result.append(StringUtil.repeat(' ', tab_size));
last_tab_index = tab_index+1;
}
if (last_tab_index == 0) {
return line;
}
result.append(line.substring(last_tab_index));
return result.toString();
} | java | {
"resource": ""
} |
q171147 | Format.escapeJava | test | public static String escapeJava(final String string) {
int strLen = string.length();
StringBuilder sb = new StringBuilder(strLen);
for (int i = 0; i < strLen; i++) {
char c = string.charAt(i);
switch (c) {
case '\b' : sb.append("\\b"); break;
case '\t' : sb.append("\\t"); break;
case '\n' : sb.append("\\n"); break;
case '\f' : sb.append("\\f"); break;
case '\r' : sb.append("\\r"); break;
case '\"' : sb.append("\\\""); break;
case '\\' : sb.append("\\\\"); break;
default:
if ((c < 32) || (c > 127)) {
String hex = Integer.toHexString(c);
sb.append("\\u");
for (int k = hex.length(); k < 4; k++) {
sb.append('0');
}
sb.append(hex);
} else {
sb.append(c);
}
}
}
return sb.toString();
} | java | {
"resource": ""
} |
q171148 | Format.unescapeJava | test | public static String unescapeJava(final String str) {
char[] chars = str.toCharArray();
StringBuilder sb = new StringBuilder(str.length());
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (c != '\\') {
sb.append(c);
continue;
}
i++;
c = chars[i];
switch (c) {
case 'b': sb.append('\b'); break;
case 't': sb.append('\t'); break;
case 'n': sb.append('\n'); break;
case 'f': sb.append('\f'); break;
case 'r': sb.append('\r'); break;
case '"': sb.append('\"'); break;
case '\\': sb.append('\\'); break;
case 'u' :
char hex = (char) Integer.parseInt(new String(chars, i + 1, 4), 16);
sb.append(hex);
i += 4;
break;
default:
throw new IllegalArgumentException("Invalid escaping character: " + c);
}
}
return sb.toString();
} | java | {
"resource": ""
} |
q171149 | PetiteContainer.getBean | test | @SuppressWarnings({"unchecked"})
public <T> T getBean(final Class<T> type) {
String name = resolveBeanName(type);
return (T) getBean(name);
} | java | {
"resource": ""
} |
q171150 | PetiteContainer.getBean | test | public <T> T getBean(final String name) {
// Lookup for registered bean definition.
BeanDefinition def = lookupBeanDefinition(name);
if (def == null) {
// try provider
ProviderDefinition providerDefinition = providers.get(name);
if (providerDefinition != null) {
return (T) invokeProvider(providerDefinition);
}
return null;
}
// Find the bean in its scope
Object bean = def.scopeLookup();
if (bean == null) {
// Create new bean in the scope
initBeanDefinition(def);
final BeanData beanData = new BeanData(this, def);
registerBeanAndWireAndInjectParamsAndInvokeInitMethods(beanData);
bean = beanData.bean();
}
return (T) bean;
} | java | {
"resource": ""
} |
q171151 | PetiteContainer.initBeanDefinition | test | protected void initBeanDefinition(final BeanDefinition def) {
// init methods
if (def.initMethods == null) {
def.initMethods = petiteResolvers.resolveInitMethodPoint(def.type);
}
// destroy methods
if (def.destroyMethods == null) {
def.destroyMethods = petiteResolvers.resolveDestroyMethodPoint(def.type);
}
// properties
if (def.properties == null) {
def.properties = petiteResolvers.resolvePropertyInjectionPoint(def.type, def.wiringMode == WiringMode.AUTOWIRE);
}
// methods
if (def.methods == null) {
def.methods = petiteResolvers.resolveMethodInjectionPoint(def.type);
}
// ctors
if (def.ctor == null) {
def.ctor = petiteResolvers.resolveCtorInjectionPoint(def.type);
}
// values
if (def.values == null) {
def.values = paramManager.resolveParamInjectionPoints(def.type);
}
// sets
if (def.sets == null) {
def.sets = petiteResolvers.resolveSetInjectionPoint(def.type, def.wiringMode == WiringMode.AUTOWIRE);
}
// params
if (def.params == null) {
def.params = paramManager.filterParametersForBeanName(def.name, petiteConfig.getResolveReferenceParameters());
}
} | java | {
"resource": ""
} |
q171152 | PetiteContainer.invokeProvider | test | protected Object invokeProvider(final ProviderDefinition provider) {
if (provider.method != null) {
final Object bean;
if (provider.beanName != null) {
// instance factory method
bean = getBean(provider.beanName);
} else {
// static factory method
bean = null;
}
try {
return provider.method.invoke(bean);
} catch (Exception ex) {
throw new PetiteException("Invalid provider method: " + provider.method.getName(), ex);
}
}
throw new PetiteException("Invalid provider");
} | java | {
"resource": ""
} |
q171153 | PetiteContainer.addBean | test | public void addBean(final String name, final Object bean, WiringMode wiringMode) {
wiringMode = petiteConfig.resolveWiringMode(wiringMode);
registerPetiteBean(bean.getClass(), name, SingletonScope.class, wiringMode, false, null);
BeanDefinition def = lookupExistingBeanDefinition(name);
registerBeanAndWireAndInjectParamsAndInvokeInitMethods(new BeanData(this, def, bean));
} | java | {
"resource": ""
} |
q171154 | PetiteContainer.setBeanProperty | test | public void setBeanProperty(final String name, final Object value) {
Object bean = null;
int ndx = name.length();
while (true) {
ndx = name.lastIndexOf('.', ndx);
if (ndx == -1) {
break;
}
String beanName = name.substring(0, ndx);
bean = getBean(beanName);
if (bean != null) {
break;
}
ndx--;
}
if (bean == null) {
throw new PetiteException("Invalid bean property: " + name);
}
try {
BeanUtil.declared.setProperty(bean, name.substring(ndx + 1), value);
} catch (Exception ex) {
throw new PetiteException("Invalid bean property: " + name, ex);
}
} | java | {
"resource": ""
} |
q171155 | PetiteContainer.getBeanProperty | test | public Object getBeanProperty(final String name) {
int ndx = name.indexOf('.');
if (ndx == -1) {
throw new PetiteException("Only bean name is specified, missing property name: " + name);
}
String beanName = name.substring(0, ndx);
Object bean = getBean(beanName);
if (bean == null) {
throw new PetiteException("Bean doesn't exist: " + name);
}
try {
return BeanUtil.declared.getProperty(bean, name.substring(ndx + 1));
} catch (Exception ex) {
throw new PetiteException("Invalid bean property: " + name, ex);
}
} | java | {
"resource": ""
} |
q171156 | PetiteContainer.shutdown | test | public void shutdown() {
scopes.forEachValue(Scope::shutdown);
externalsCache.clear();
beans.clear();
beansAlt.clear();
scopes.clear();
providers.clear();
beanCollections.clear();
} | java | {
"resource": ""
} |
q171157 | Paramo.resolveParameters | test | public static MethodParameter[] resolveParameters(final AccessibleObject methodOrCtor) {
Class[] paramTypes;
Class declaringClass;
String name;
if (methodOrCtor instanceof Method) {
Method method = (Method) methodOrCtor;
paramTypes = method.getParameterTypes();
name = method.getName();
declaringClass = method.getDeclaringClass();
} else {
Constructor constructor = (Constructor) methodOrCtor;
paramTypes = constructor.getParameterTypes();
declaringClass = constructor.getDeclaringClass();
name = CTOR_METHOD;
}
if (paramTypes.length == 0) {
return MethodParameter.EMPTY_ARRAY;
}
InputStream stream;
try {
stream = ClassLoaderUtil.getClassAsStream(declaringClass);
} catch (IOException ioex) {
throw new ParamoException("Failed to read class bytes: " + declaringClass.getName(), ioex);
}
if (stream == null) {
throw new ParamoException("Class not found: " + declaringClass);
}
try {
ClassReader reader = new ClassReader(stream);
MethodFinder visitor = new MethodFinder(declaringClass, name, paramTypes);
reader.accept(visitor, 0);
return visitor.getResolvedParameters();
}
catch (IOException ioex) {
throw new ParamoException(ioex);
}
finally {
StreamUtil.close(stream);
}
} | java | {
"resource": ""
} |
q171158 | FormTag.doAfterBody | test | @Override
public int doAfterBody() throws JspException {
BodyContent body = getBodyContent();
JspWriter out = body.getEnclosingWriter();
String bodytext = populateForm(body.getString(), name -> value(name, pageContext));
try {
out.print(bodytext);
} catch (IOException ioex) {
throw new JspException(ioex);
}
return SKIP_BODY;
} | java | {
"resource": ""
} |
q171159 | PropsEntry.getValue | test | public String getValue(final String... profiles) {
if (hasMacro) {
return propsData.resolveMacros(value, profiles);
}
return value;
} | java | {
"resource": ""
} |
q171160 | LagartoDOMBuilderTagVisitor.end | test | @Override
public void end() {
if (parentNode != rootNode) {
Node thisNode = parentNode;
while (thisNode != rootNode) {
if (domBuilder.config.isImpliedEndTags()) {
if (implRules.implicitlyCloseTagOnEOF(thisNode.getNodeName())) {
thisNode = thisNode.getParentNode();
continue;
}
}
error("Unclosed tag closed: <" + thisNode.getNodeName() + ">");
thisNode = thisNode.getParentNode();
}
}
// remove whitespaces
if (domBuilder.config.isIgnoreWhitespacesBetweenTags()) {
removeLastChildNodeIfEmptyText(parentNode, true);
}
// foster
if (domBuilder.config.isUseFosterRules()) {
HtmlFosterRules fosterRules = new HtmlFosterRules();
fosterRules.fixFosterElements(rootNode);
}
// elapsed
rootNode.end();
if (log.isDebugEnabled()) {
log.debug("LagartoDom tree created in " + rootNode.getElapsedTime() + " ms");
}
} | java | {
"resource": ""
} |
q171161 | LagartoDOMBuilderTagVisitor.createElementNode | test | protected Element createElementNode(final Tag tag) {
boolean hasVoidTags = htmlVoidRules != null;
boolean isVoid = false;
boolean selfClosed = false;
if (hasVoidTags) {
isVoid = htmlVoidRules.isVoidTag(tag.getName());
// HTML and XHTML
if (isVoid) {
// it's void tag, lookup the flag
selfClosed = domBuilder.config.isSelfCloseVoidTags();
}
} else {
// XML, no voids, lookup the flag
selfClosed = domBuilder.config.isSelfCloseVoidTags();
}
return new Element(rootNode, tag, isVoid, selfClosed);
} | java | {
"resource": ""
} |
q171162 | LagartoDOMBuilderTagVisitor.tag | test | @Override
public void tag(final Tag tag) {
if (!enabled) {
return;
}
TagType tagType = tag.getType();
Element node;
switch (tagType) {
case START:
if (domBuilder.config.isIgnoreWhitespacesBetweenTags()) {
removeLastChildNodeIfEmptyText(parentNode, false);
}
node = createElementNode(tag);
if (domBuilder.config.isImpliedEndTags()) {
while (true) {
String parentNodeName = parentNode.getNodeName();
if (!implRules.implicitlyCloseParentTagOnNewTag(parentNodeName, node.getNodeName())) {
break;
}
parentNode = parentNode.getParentNode();
if (log.isDebugEnabled()) {
log.debug("Implicitly closed tag <" + node.getNodeName() + "> ");
}
}
}
parentNode.addChild(node);
if (!node.isVoidElement()) {
parentNode = node;
}
break;
case END:
if (domBuilder.config.isIgnoreWhitespacesBetweenTags()) {
removeLastChildNodeIfEmptyText(parentNode, true);
}
String tagName = tag.getName().toString();
Node matchingParent = findMatchingParentOpenTag(tagName);
if (matchingParent == parentNode) { // regular situation
parentNode = parentNode.getParentNode();
break;
}
if (matchingParent == null) { // matching open tag not found, remove it
error("Orphan closed tag ignored: </" + tagName + "> " + tag.getTagPosition());
break;
}
// try to close it implicitly
if (domBuilder.config.isImpliedEndTags()) {
boolean fixed = false;
while (implRules.implicitlyCloseParentTagOnTagEnd(parentNode.getNodeName(), tagName)) {
parentNode = parentNode.getParentNode();
if (log.isDebugEnabled()) {
log.debug("Implicitly closed tag <" + tagName + ">");
}
if (parentNode == matchingParent) {
parentNode = matchingParent.parentNode;
fixed = true;
break;
}
}
if (fixed) {
break;
}
}
// matching tag found, but it is not a regular situation
// therefore close all unclosed tags in between
fixUnclosedTagsUpToMatchingParent(tag, matchingParent);
break;
case SELF_CLOSING:
if (domBuilder.config.isIgnoreWhitespacesBetweenTags()) {
removeLastChildNodeIfEmptyText(parentNode, false);
}
node = createElementNode(tag);
parentNode.addChild(node);
break;
}
} | java | {
"resource": ""
} |
q171163 | LagartoDOMBuilderTagVisitor.removeLastChildNodeIfEmptyText | test | protected void removeLastChildNodeIfEmptyText(final Node parentNode, final boolean closedTag) {
if (parentNode == null) {
return;
}
Node lastChild = parentNode.getLastChild();
if (lastChild == null) {
return;
}
if (lastChild.getNodeType() != Node.NodeType.TEXT) {
return;
}
if (closedTag) {
if (parentNode.getChildNodesCount() == 1) {
return;
}
}
Text text = (Text) lastChild;
if (text.isBlank()) {
lastChild.detachFromParent();
}
} | java | {
"resource": ""
} |
q171164 | BaseLoggableStatement.getQueryString | test | public String getQueryString() {
if (sqlTemplate == null) {
return toString();
}
if (parameterValues == null) {
return sqlTemplate;
}
final StringBuilder sb = new StringBuilder();
int qMarkCount = 0;
final StringTokenizer tok = new StringTokenizer(sqlTemplate + ' ', "?");
while (tok.hasMoreTokens()) {
final String oneChunk = tok.nextToken();
sb.append(oneChunk);
try {
Object value = null;
if (parameterValues.size() > 1 + qMarkCount) {
value = parameterValues.get(1 + qMarkCount);
qMarkCount++;
} else {
if (!tok.hasMoreTokens()) {
value = "";
}
}
if (value == null) {
value = "?";
}
sb.append(value);
} catch (Throwable th) {
sb.append("--- Building query failed: ").append(th.toString());
}
}
return sb.toString().trim();
} | java | {
"resource": ""
} |
q171165 | I18nInterceptor.getActionClassName | test | protected String getActionClassName(final Object action) {
Class clazz = action.getClass();
clazz = ProxettaUtil.resolveTargetClass(clazz);
return clazz.getName();
} | java | {
"resource": ""
} |
q171166 | IteratorTag.calculateTo | test | protected int calculateTo(final int from, final int count, final int size) {
int to = size;
if (count != -1) {
to = from + count;
if (to > size) {
to = size;
}
}
return to;
} | java | {
"resource": ""
} |
q171167 | IteratorTag.iterateCollection | test | protected void iterateCollection(final Collection collection, final int from, final int count, final PageContext pageContext) throws JspException {
JspFragment body = getJspBody();
Iterator iter = collection.iterator();
int i = 0;
int to = calculateTo(from, count, collection.size());
while (i < to) {
Object item = iter.next();
if (i >= from) {
if (status != null) {
iteratorStatus.next(!iter.hasNext());
}
TagUtil.setScopeAttribute(var, item, scope, pageContext);
TagUtil.invokeBody(body);
}
i++;
}
} | java | {
"resource": ""
} |
q171168 | IteratorTag.iterateArray | test | protected void iterateArray(final Object[] array, final int from, final int count, final PageContext pageContext) throws JspException {
JspFragment body = getJspBody();
int len = array.length;
int to = calculateTo(from, count, len);
int last = to - 1;
for (int i = from; i < to; i++) {
Object item = array[i];
if (status != null) {
iteratorStatus.next(i == last);
}
TagUtil.setScopeAttribute(var, item, scope, pageContext);
TagUtil.invokeBody(body);
}
} | java | {
"resource": ""
} |
q171169 | StringUtil.replace | test | public static String replace(final String s, final String sub, final String with) {
if (sub.isEmpty()) {
return s;
}
int c = 0;
int i = s.indexOf(sub, c);
if (i == -1) {
return s;
}
int length = s.length();
StringBuilder sb = new StringBuilder(length + with.length());
do {
sb.append(s, c, i);
sb.append(with);
c = i + sub.length();
} while ((i = s.indexOf(sub, c)) != -1);
if (c < length) {
sb.append(s, c, length);
}
return sb.toString();
} | java | {
"resource": ""
} |
q171170 | StringUtil.replaceChar | test | public static String replaceChar(final String s, final char sub, final char with) {
int startIndex = s.indexOf(sub);
if (startIndex == -1) {
return s;
}
char[] str = s.toCharArray();
for (int i = startIndex; i < str.length; i++) {
if (str[i] == sub) {
str[i] = with;
}
}
return new String(str);
} | java | {
"resource": ""
} |
q171171 | StringUtil.replaceChars | test | public static String replaceChars(final String s, final char[] sub, final char[] with) {
char[] str = s.toCharArray();
for (int i = 0; i < str.length; i++) {
char c = str[i];
for (int j = 0; j < sub.length; j++) {
if (c == sub[j]) {
str[i] = with[j];
break;
}
}
}
return new String(str);
} | java | {
"resource": ""
} |
q171172 | StringUtil.replaceFirst | test | public static String replaceFirst(final String s, final String sub, final String with) {
int i = s.indexOf(sub);
if (i == -1) {
return s;
}
return s.substring(0, i) + with + s.substring(i + sub.length());
} | java | {
"resource": ""
} |
q171173 | StringUtil.replaceFirst | test | public static String replaceFirst(final String s, final char sub, final char with) {
int index = s.indexOf(sub);
if (index == -1) {
return s;
}
char[] str = s.toCharArray();
str[index] = with;
return new String(str);
} | java | {
"resource": ""
} |
q171174 | StringUtil.replaceLast | test | public static String replaceLast(final String s, final String sub, final String with) {
int i = s.lastIndexOf(sub);
if (i == -1) {
return s;
}
return s.substring(0, i) + with + s.substring(i + sub.length());
} | java | {
"resource": ""
} |
q171175 | StringUtil.replaceLast | test | public static String replaceLast(final String s, final char sub, final char with) {
int index = s.lastIndexOf(sub);
if (index == -1) {
return s;
}
char[] str = s.toCharArray();
str[index] = with;
return new String(str);
} | java | {
"resource": ""
} |
q171176 | StringUtil.remove | test | public static String remove(final String s, final String sub) {
int c = 0;
int sublen = sub.length();
if (sublen == 0) {
return s;
}
int i = s.indexOf(sub, c);
if (i == -1) {
return s;
}
StringBuilder sb = new StringBuilder(s.length());
do {
sb.append(s, c, i);
c = i + sublen;
} while ((i = s.indexOf(sub, c)) != -1);
if (c < s.length()) {
sb.append(s, c, s.length());
}
return sb.toString();
} | java | {
"resource": ""
} |
q171177 | StringUtil.remove | test | public static String remove(final String string, final char ch) {
int stringLen = string.length();
char[] result = new char[stringLen];
int offset = 0;
for (int i = 0; i < stringLen; i++) {
char c = string.charAt(i);
if (c == ch) {
continue;
}
result[offset] = c;
offset++;
}
if (offset == stringLen) {
return string; // no changes
}
return new String(result, 0, offset);
} | java | {
"resource": ""
} |
q171178 | StringUtil.isAllEmpty | test | public static boolean isAllEmpty(final String... strings) {
for (String string : strings) {
if (!isEmpty(string)) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q171179 | StringUtil.isAllBlank | test | public static boolean isAllBlank(final String... strings) {
for (String string : strings) {
if (!isBlank(string)) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q171180 | StringUtil.toStringArray | test | public static String[] toStringArray(final Object value) {
if (value == null) {
return new String[0];
}
Class<?> type = value.getClass();
if (!type.isArray()) {
return new String[] {value.toString()};
}
Class componentType = type.getComponentType();
if (componentType.isPrimitive()) {
if (componentType == int.class) {
return ArraysUtil.toStringArray((int[]) value);
}
else if (componentType == long.class) {
return ArraysUtil.toStringArray((long[]) value);
}
else if (componentType == double.class) {
return ArraysUtil.toStringArray((double[]) value);
}
else if (componentType == float.class) {
return ArraysUtil.toStringArray((float[]) value);
}
else if (componentType == boolean.class) {
return ArraysUtil.toStringArray((boolean[]) value);
}
else if (componentType == short.class) {
return ArraysUtil.toStringArray((short[]) value);
}
else if (componentType == byte.class) {
return ArraysUtil.toStringArray((byte[]) value);
}
else {
throw new IllegalArgumentException();
}
}
else {
return ArraysUtil.toStringArray((Object[]) value);
}
} | java | {
"resource": ""
} |
q171181 | StringUtil.changeFirstCharacterCase | test | private static String changeFirstCharacterCase(final boolean capitalize, final String string) {
int strLen = string.length();
if (strLen == 0) {
return string;
}
char ch = string.charAt(0);
char modifiedCh;
if (capitalize) {
modifiedCh = Character.toUpperCase(ch);
} else {
modifiedCh = Character.toLowerCase(ch);
}
if (modifiedCh == ch) {
// no change, return unchanged string
return string;
}
char[] chars = string.toCharArray();
chars[0] = modifiedCh;
return new String(chars);
} | java | {
"resource": ""
} |
q171182 | StringUtil.title | test | public static String title(final String string) {
char[] chars = string.toCharArray();
boolean wasWhitespace = true;
for (int i = 0; i < chars.length; i++) {
char c = chars[i];
if (CharUtil.isWhitespace(c)) {
wasWhitespace = true;
} else {
if (wasWhitespace) {
chars[i] = Character.toUpperCase(c);
} else {
chars[i] = Character.toLowerCase(c);
}
wasWhitespace = false;
}
}
return new String(chars);
} | java | {
"resource": ""
} |
q171183 | StringUtil.compressChars | test | public static String compressChars(final String s, final char c) {
int len = s.length();
StringBuilder sb = new StringBuilder(len);
boolean wasChar = false;
for (int i = 0; i < len; i++) {
char c1 = s.charAt(i);
if (c1 == c) {
if (wasChar) {
continue;
}
wasChar = true;
} else {
wasChar = false;
}
sb.append(c1);
}
if (sb.length() == len) {
return s;
}
return sb.toString();
} | java | {
"resource": ""
} |
q171184 | StringUtil.startsWithIgnoreCase | test | public static boolean startsWithIgnoreCase(final String src, final String subS, final int startIndex) {
String sub = subS.toLowerCase();
int sublen = sub.length();
if (startIndex + sublen > src.length()) {
return false;
}
int j = 0;
int i = startIndex;
while (j < sublen) {
char source = Character.toLowerCase(src.charAt(i));
if (sub.charAt(j) != source) {
return false;
}
j++; i++;
}
return true;
} | java | {
"resource": ""
} |
q171185 | StringUtil.endsWithChar | test | public static boolean endsWithChar(final String s, final char c) {
if (s.length() == 0) {
return false;
}
return s.charAt(s.length() - 1) == c;
} | java | {
"resource": ""
} |
q171186 | StringUtil.countIgnoreCase | test | public static int countIgnoreCase(final String source, final String sub) {
int count = 0;
int j = 0;
int sublen = sub.length();
if (sublen == 0) {
return 0;
}
while (true) {
int i = indexOfIgnoreCase(source, sub, j);
if (i == -1) {
break;
}
count++;
j = i + sublen;
}
return count;
} | java | {
"resource": ""
} |
q171187 | StringUtil.equalsIgnoreCase | test | public static boolean equalsIgnoreCase(final String[] as, final String[] as1) {
if (as.length != as1.length) {
return false;
}
for (int i = 0; i < as.length; i++) {
if (!as[i].equalsIgnoreCase(as1[i])) {
return false;
}
}
return true;
} | java | {
"resource": ""
} |
q171188 | StringUtil.indexOfWhitespace | test | public static int indexOfWhitespace(final String string, final int startindex, final int endindex) {
for (int i = startindex; i < endindex; i++) {
if (CharUtil.isWhitespace(string.charAt(i))) {
return i;
}
}
return -1;
} | java | {
"resource": ""
} |
q171189 | StringUtil.stripLeadingChar | test | public static String stripLeadingChar(final String string, final char c) {
if (string.length() > 0) {
if (string.charAt(0) == c) {
return string.substring(1);
}
}
return string;
} | java | {
"resource": ""
} |
q171190 | StringUtil.stripTrailingChar | test | public static String stripTrailingChar(final String string, final char c) {
if (string.length() > 0) {
if (string.charAt(string.length() - 1) == c) {
return string.substring(0, string.length() - 1);
}
}
return string;
} | java | {
"resource": ""
} |
q171191 | StringUtil.stripChar | test | public static String stripChar(final String string, final char c) {
if (string.length() == 0) {
return string;
}
if (string.length() == 1) {
if (string.charAt(0) == c) {
return StringPool.EMPTY;
}
return string;
}
int left = 0;
int right = string.length();
if (string.charAt(left) == c) {
left++;
}
if (string.charAt(right - 1) == c) {
right--;
}
return string.substring(left, right);
} | java | {
"resource": ""
} |
q171192 | StringUtil.stripToChar | test | public static String stripToChar(final String string, final char c) {
int ndx = string.indexOf(c);
if (ndx == -1) {
return string;
}
return string.substring(ndx);
} | java | {
"resource": ""
} |
q171193 | StringUtil.stripFromChar | test | public static String stripFromChar(final String string, final char c) {
int ndx = string.indexOf(c);
if (ndx == -1) {
return string;
}
return string.substring(0, ndx);
} | java | {
"resource": ""
} |
q171194 | StringUtil.cropAll | test | public static void cropAll(final String... strings) {
for (int i = 0; i < strings.length; i++) {
String string = strings[i];
if (string != null) {
string = crop(strings[i]);
}
strings[i] = string;
}
} | java | {
"resource": ""
} |
q171195 | StringUtil.trimLeft | test | public static String trimLeft(final String src) {
int len = src.length();
int st = 0;
while ((st < len) && (CharUtil.isWhitespace(src.charAt(st)))) {
st++;
}
return st > 0 ? src.substring(st) : src;
} | java | {
"resource": ""
} |
q171196 | StringUtil.trimRight | test | public static String trimRight(final String src) {
int len = src.length();
int count = len;
while ((len > 0) && (CharUtil.isWhitespace(src.charAt(len - 1)))) {
len--;
}
return (len < count) ? src.substring(0, len) : src;
} | java | {
"resource": ""
} |
q171197 | StringUtil.indexOfRegion | test | public static int[] indexOfRegion(final String string, final String leftBoundary, final String rightBoundary, final int offset) {
int ndx = offset;
int[] res = new int[4];
ndx = string.indexOf(leftBoundary, ndx);
if (ndx == -1) {
return null;
}
res[0] = ndx;
ndx += leftBoundary.length();
res[1] = ndx;
ndx = string.indexOf(rightBoundary, ndx);
if (ndx == -1) {
return null;
}
res[2] = ndx;
res[3] = ndx + rightBoundary.length();
return res;
} | java | {
"resource": ""
} |
q171198 | StringUtil.join | test | public static String join(final Collection collection, final char separator) {
if (collection == null) {
return null;
}
if (collection.size() == 0) {
return StringPool.EMPTY;
}
final StringBuilder sb = new StringBuilder(collection.size() * 16);
final Iterator it = collection.iterator();
for (int i = 0; i < collection.size(); i++) {
if (i > 0) {
sb.append(separator);
}
sb.append(it.next());
}
return sb.toString();
} | java | {
"resource": ""
} |
q171199 | StringUtil.join | test | public static String join(final Object[] array, final String separator) {
if (array == null) {
return null;
}
if (array.length == 0) {
return StringPool.EMPTY;
}
if (array.length == 1) {
return String.valueOf(array[0]);
}
final StringBuilder sb = new StringBuilder(array.length * 16);
for (int i = 0; i < array.length; i++) {
if (i > 0) {
sb.append(separator);
}
sb.append(array[i]);
}
return sb.toString();
} | java | {
"resource": ""
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.