File |
Line |
org\djutils\exceptions\Throw.java |
206 |
org\djutils\exceptions\Try.java |
598 |
{
// create a clear message
List<StackTraceElement> steList = new ArrayList<>(Arrays.asList(new Throwable().getStackTrace()));
steList.remove(0); // remove the throwMessage(...) call
steList.remove(0); // remove the when(...) call
StackTraceElement[] ste = steList.toArray(new StackTraceElement[steList.size()]);
String where = ste[0].getClassName() + "." + ste[0].getMethodName() + " (" + ste[0].getLineNumber() + "): ";
Object[] args = argList.toArray();
String formattedMessage;
try
{
formattedMessage = where + String.format(message, args);
}
catch (IllegalFormatException exception)
{
formattedMessage = where + message + " [FormatException; args=" + argList + "]";
}
// throw all other exceptions through reflection
T exception;
try
{
@SuppressWarnings("unchecked")
Constructor<T> constructor =
(Constructor<T>) ClassUtil.resolveConstructor(throwableClass, new Class<?>[] {String.class}); |
File |
Line |
org\djutils\decoderdumper\CharDecoder.java |
35 |
org\djutils\decoderdumper\HexDecoder.java |
38 |
String format = String.format("%%%ds", fieldsPerLine + (fieldsPerLine - 1) / this.extraSpaceAfterEvery);
this.prototypeLine = String.format(format, "");
}
/** String builder for current output line. */
private StringBuilder buffer = new StringBuilder();
/** {@inheritDoc} */
@Override
public String getResult()
{
String result = this.buffer.toString();
this.buffer.setLength(0);
return result;
}
/** {@inheritDoc} */
@Override
public int getMaximumWidth()
{
return this.prototypeLine.length();
}
/** {@inheritDoc} */
@Override
public boolean append(int address, byte theByte) throws IOException
{
if (this.buffer.length() == 0)
{
this.buffer.append(this.prototypeLine);
}
int lineByte = address % this.fieldsPerLine;
int index = lineByte + lineByte / this.extraSpaceAfterEvery; |
File |
Line |
org\djutils\reflection\ClassUtil.java |
791 |
org\djutils\reflection\ClassUtil.java |
837 |
private static Constructor<?> getSpecificConstructor(final Constructor<?>[] methods) throws NoSuchMethodException
{
if (methods.length == 0)
{
throw new NoSuchMethodException();
}
if (methods.length == 1)
{
return methods[0];
}
// Apply generic algorithm
int resultID = 0; // Assume first method to be most specific
while (resultID < methods.length)
{
// Verify assumption
boolean success = true;
for (int i = 0; i < methods.length; i++)
{
if (resultID == i)
{
continue;
}
if (!isMoreSpecific(methods[resultID], methods[i]))
{
success = false;
}
}
// Assumption verified
if (success)
{
return methods[resultID];
}
resultID++;
}
// No method is most specific, thus:
throw new NoSuchMethodException();
}
/**
* Determines & returns the most specific method as defined in the Java Language Specification par 15.12. The current
* algorithm is simple and reliable, but probably slow.
* @param methods Method[]; which are the methods to be searched. They are assumed to have the same name and number of
* parameters, as determined by the method matchSignature.
* @return The most specific method.
* @throws NoSuchMethodException when no method is found that's more specific than the others.
*/
private static Method getSpecificMethod(final Method[] methods) throws NoSuchMethodException |