id stringlengths 7 14 | text stringlengths 1 106k |
|---|---|
1484463_2 | @Override
public void handle(final Event event)
{
try {
final ProducerData<String, String> data = new ProducerData<String, String>(event.getEventType(), eventToMessage(event));
producer.send(data);
eventsSent.incrementAndGet();
}
catch (IOException e) {
log.warn(e);
eventsDiscarded.getAndIncrement();
}
} |
1484463_3 | public List<HostSamplesForTimestamp> readAll()
{
final List<HostSamplesForTimestamp> samples = new ArrayList<HostSamplesForTimestamp>();
readAll(true, null, new Function<HostSamplesForTimestamp, Void>()
{
@Override
public Void apply(@Nullable final HostSamplesForTimestamp input)
{
if (input != null) {
samples.add(input);
}
return null;
}
});
return samples;
} |
1484463_4 | public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes)
{
// Extract the chunk
final byte[] sampleBytes = getEncodedSamples().getEncodedBytes();
log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount());
final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount());
// Reset this current accumulator
reset();
return chunk;
} |
1484463_5 | public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes)
{
// Extract the chunk
final byte[] sampleBytes = getEncodedSamples().getEncodedBytes();
log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount());
final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount());
// Reset this current accumulator
reset();
return chunk;
} |
1484463_6 | public synchronized TimelineChunk extractTimelineChunkAndReset(final DateTime startTime, final DateTime endTime, final byte[] timeBytes)
{
// Extract the chunk
final byte[] sampleBytes = getEncodedSamples().getEncodedBytes();
log.debug("Creating TimelineChunk for sampleKindId %d, sampleCount %d", sampleKindId, getSampleCount());
final TimelineChunk chunk = new TimelineChunk(sampleCoder, 0, hostId, sampleKindId, startTime, endTime, timeBytes, sampleBytes, getSampleCount());
// Reset this current accumulator
reset();
return chunk;
} |
1484463_7 | public void addSampleKind(final String sampleKind)
{
sampleKinds.add(sampleKind);
} |
1484463_8 | @Override
public Object process(Object value)
{
Long time = System.currentTimeMillis();
if (this.lastValue == null) {
this.lastUpdate = time;
this.lastValue = value;
return null; // no value at this time
}
if (!(value instanceof Number)) {
throw new IllegalArgumentException(String.format("Rate requested, but value '%s' of type '%s' is not a number", value.toString(),value.getClass().getName()));
}
double diff = ((Number) value).doubleValue() - ((Number) this.lastValue).doubleValue();
double timeChangeInSeconds = ((double)(time - this.lastUpdate)) / 1000.0;
double rate;
if(timeChangeInSeconds == 0.0)
rate = Double.NaN;
else {
rate = diff / timeChangeInSeconds;
if(Math.abs(rate) < EPS) {
rate = 0.0;
}
}
// overflow guards. Note that these use Double because the Numbers passed in are converted to doubles.
if (Double.isNaN(rate) || rate == Double.POSITIVE_INFINITY || rate == Double.NEGATIVE_INFINITY) {
log.warn("Overflow in rate calculation: val=%f, last val=%f; time=%tc, last time=%tc", ((Number) value).doubleValue(), ((Number) this.lastValue).doubleValue(), time, this.lastUpdate);
this.lastUpdate = time;
this.lastValue = value;
return null; // no value at this time
}
// success. update last values before returning
this.lastUpdate = time;
this.lastValue = value;
return rate;
} |
1484463_9 | @Override
public Object process(Object value)
{
Long time = System.currentTimeMillis();
if (this.lastValue == null) {
this.lastUpdate = time;
this.lastValue = value;
return null; // no value at this time
}
if (!(value instanceof Number)) {
throw new IllegalArgumentException(String.format("Rate requested, but value '%s' of type '%s' is not a number", value.toString(),value.getClass().getName()));
}
double diff = ((Number) value).doubleValue() - ((Number) this.lastValue).doubleValue();
double timeChangeInSeconds = ((double)(time - this.lastUpdate)) / 1000.0;
double rate;
if(timeChangeInSeconds == 0.0)
rate = Double.NaN;
else {
rate = diff / timeChangeInSeconds;
if(Math.abs(rate) < EPS) {
rate = 0.0;
}
}
// overflow guards. Note that these use Double because the Numbers passed in are converted to doubles.
if (Double.isNaN(rate) || rate == Double.POSITIVE_INFINITY || rate == Double.NEGATIVE_INFINITY) {
log.warn("Overflow in rate calculation: val=%f, last val=%f; time=%tc, last time=%tc", ((Number) value).doubleValue(), ((Number) this.lastValue).doubleValue(), time, this.lastUpdate);
this.lastUpdate = time;
this.lastValue = value;
return null; // no value at this time
}
// success. update last values before returning
this.lastUpdate = time;
this.lastValue = value;
return rate;
} |
1493029_0 | public void loadResource(URL url) {
try {
// Is Local
loadResource( new File( url.toURI() ), "" );
} catch (IllegalArgumentException iae) {
// Is Remote
loadRemoteResource( url );
} catch (URISyntaxException e) {
throw new JclException( "URISyntaxException", e );
}
} |
1493029_1 | @SuppressWarnings("rawtypes")
public Class loadClass(String className, boolean resolveIt) {
Class result;
try {
result = delegate.loadClass(className, resolveIt);
} catch (ClassNotFoundException e) {
return null;
}
return result;
} |
149511_10 | public boolean isUnderRevisionControl() {
return true;
} |
149511_11 | public boolean isCheckedIn() {
return true;
} |
149511_12 | public boolean isCheckedOut() {
return true;
} |
1495584_0 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_1 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_2 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_3 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_4 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_5 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_6 | @Override
public String getClassSimpleName() {
return constructor.getDeclaringClass().getSimpleName();
} |
1495584_7 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_8 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1495584_9 | public T execute() {
try {
return constructor.newInstance(constructionArguments);
} catch (InvocationTargetException e) {
Throwable cause = e.getCause();
/*
* Due to constraints on the constructor, cause can only be an
* unchecked exception.
*/
if (cause instanceof Error) {
throw ((Error) cause);
} else {
throw ((RuntimeException) cause);
}
} catch (Exception e) {
throw new IllegalStateException("This should never happen. Due to previously checked constraints (see extractConstructor()), no exception may actually be caught here.", e);
}
} |
1502367_0 | public ConstructedMessage getConstructedMessage(int messageId) {
return keyValue.get("M-" + messageId);
} |
1502367_1 | public static XMLModel getProtocolConfiguration(String protocolLocation) throws JAXBException, IOException {
JAXBContext context = JAXBContext.newInstance(XMLModel.class);
Unmarshaller um = context.createUnmarshaller();
return (XMLModel) um.unmarshal(new ClassPathResource(protocolLocation).getInputStream());
} |
1502367_2 | public void put(Request request) throws InterruptedException {
Node node = new Node(executor, new NodeCallable(handler, request));
queue.put(node);
} |
1502367_3 | public void loadDBSchema(DataSource dataSource, String schemaName) throws DataAccessException,
FileNotFoundException {
JdbcTemplate template = new JdbcTemplate(dataSource);
InputStream is = null;
try {
is = new ClassPathResource(schemaName).getInputStream();
contents = IOUtils.toString(is);
} catch (IOException e) {
throw new FileNotFoundException("schema[" + schemaName + "]" + "is not found");
}
template.execute(new StatementCallback<Boolean>() {
@Override
public Boolean doInStatement(Statement stmt) throws SQLException, DataAccessException {
return stmt.execute(contents);
}
});
} |
1502367_4 | public void sendEmail(SendBoxInfo sendBoxInfo, EmailContent sendContent, String[] to) throws MessagingException,
MailException {
JavaMailSenderImpl senderImpl = new JavaMailSenderImpl();
// 设定mail server
senderImpl.setHost(sendBoxInfo.getHost());
senderImpl.setPort(sendBoxInfo.getPort());
senderImpl.setUsername(sendBoxInfo.getUserName()); // 根据自己的情况,设置username
senderImpl.setPassword(sendBoxInfo.getPwd()); // 根据自己的情况, 设置password
senderImpl.setDefaultEncoding(sendBoxInfo.getDefaultEncoding());
senderImpl.setJavaMailProperties(sendBoxInfo.getProperties());
// 建立邮件消息
MimeMessage mimeMessage = senderImpl.createMimeMessage();
MimeMessageHelper helper = new MimeMessageHelper(mimeMessage);
helper.setTo(to);
helper.setFrom(sendBoxInfo.getFrom());
helper.setSubject(sendContent.getSubject());
helper.setText(sendContent.getContent(), sendContent.isHtml());
// 发送邮件
senderImpl.send(mimeMessage);
logger.debug("邮件发送成功,email:{}", Arrays.toString(to));
} |
1502367_5 | public void batchInsertEmailOutbox(List<Object[]> batchArgs) {
super.batchUpdate(INSERT_EMAIL_OUTBOX, batchArgs);
} |
1502367_6 | public void batchInsertEmailInbox(List<Object[]> batchArgs) {
super.batchUpdate(INSERT_EMAIL_INBOX, batchArgs);
} |
1502367_7 | public List<EmailInbox> queryInboxToSend(int amount) {
return pageByProperty(Collections.singletonMap("state", (Object) EmailInbox.STATE_TO_SEND), 0, amount, "id",
false);
} |
1502367_8 | public Software querySoftware(String softwareName) throws DataAccessException {
return (Software) getSqlSession().selectOne(STMT_QUERY_SOFTWARE_BY_NAME, softwareName);
} |
1502367_9 | public int insertSoftware(Software software) throws DataAccessException {
return getSqlSession().insert(STMT_INSERT_SOFTWARE, software);
} |
1511246_0 | public static Object getDefaultValue(Class<?> c) {
if (!c.isPrimitive()) {
return null;
}
if (c == boolean.class) {
return false;
} else if (c == byte.class) {
return (byte) 0;
} else if (c == char.class) {
return (char) 0;
} else if (c == short.class) {
return (short) 0;
} else if (c == int.class) {
return 0;
} else if (c == long.class) {
return 0L;
} else if (c == float.class) {
return 0F;
} else if (c == double.class) {
return 0D;
}
return null;
} |
1511246_1 | public static Class<?> getNonPrimitiveClass(Class<?> c) {
if (!c.isPrimitive()) {
return c;
} else if (c == boolean.class) {
return Boolean.class;
} else if (c == byte.class) {
return Byte.class;
} else if (c == char.class) {
return Character.class;
} else if (c == double.class) {
return Double.class;
} else if (c == float.class) {
return Float.class;
} else if (c == int.class) {
return Integer.class;
} else if (c == long.class) {
return Long.class;
} else if (c == short.class) {
return Short.class;
} else if (c == void.class) {
return Void.class;
}
return c;
} |
1511246_2 | public static String getPackageName(Class<?> c) {
Package p = c.getPackage();
if (p != null) {
return p.getName();
}
if (c.isPrimitive()) {
return "";
}
String s = c.getName();
int lastDot = s.lastIndexOf('.');
if (lastDot < 0) {
return "";
}
return s.substring(0, lastDot);
} |
1511246_3 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_4 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_5 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_6 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_7 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_8 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1511246_9 | @SuppressWarnings("unchecked")
public <T> T createProxy(T obj, final InvocationHandler handler) {
Class<?> c = obj.getClass();
Class<?> pc = getClassProxy(c);
Constructor<?> cons;
try {
cons = pc.getConstructor(new Class<?>[] { InvocationHandler.class });
return (T) cons.newInstance(new Object[] { handler });
} catch (Exception e) {
IllegalArgumentException ia = new IllegalArgumentException(
"Could not create a new instance of the class " +
pc.getName());
ia.initCause(e);
throw ia;
}
} |
1516026_0 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_1 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_2 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_3 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_4 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_5 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_6 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_7 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_8 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1516026_9 | public static Date parseDate(final Object value) {
Date date = null;
if (value instanceof String) {
if (StringUtils.isNotBlank((String) value)) {
try {
date = org.apache.commons.lang3.time.DateUtils.parseDateStrictly((String) value, new String[] {
DateUtils.L_DATE_TIME_FORMAT, DateUtils.L_DATE_FORMAT });
} catch (ParseException e) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value), e);
}
}
} else if (value instanceof Date) {
// Date is mutable, make defensive copy to disallow implicit ('silent') modifications of the original one
date = new Date(((Date) value).getTime());
} else if (value instanceof Number) {
date = new Date(((Number) value).longValue());
} else if (value != null) {
throw new IllegalArgumentException(String.format(PARSE_EXCEPTION_MSG, value));
}
return date;
} |
1520524_0 | public TimeManager() {
dateFormat = new SimpleDateFormat("HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
startTime = System.currentTimeMillis();
} |
1520524_1 | public synchronized double getElapsedTimeInHours() {
double currentTime = System.currentTimeMillis();
return (currentTime - startTime) / (60 * 60 * 1000);
} |
1520524_2 | public synchronized double getElapsedTimeInMinutes() {
double currentTime = System.currentTimeMillis();
return (currentTime - startTime) / (60 * 1000);
} |
1520524_3 | public synchronized double getElapsedTimeInSeconds() {
double currentTime = System.currentTimeMillis();
return ((currentTime - startTime) / 1000);
} |
1520524_4 | public synchronized double getElapsedTimeInMilliSeconds() {
double currentTime = System.currentTimeMillis();
return (currentTime - startTime);
} |
1520524_5 | public synchronized static BondEnergies getInstance()
throws CDKException {
if (null == instance) {
instance = new BondEnergies();
}
return instance;
} |
1520524_6 | public synchronized int getEnergies(IAtom sourceAtom, IAtom targetAtom, Order bondOrder) {
String sourceAtomSymbol = null;
if (!(sourceAtom instanceof IQueryAtom)) {
sourceAtomSymbol = sourceAtom.getSymbol();
} else {
return 0;
}
String targetAtomSymbol = targetAtom.getSymbol();
return getEnergies(sourceAtomSymbol, targetAtomSymbol, bondOrder);
} |
1520524_7 | public synchronized String getSymbolFirstAtom() {
return symbol1;
} |
1520524_8 | public synchronized String getSymbolSecondAtom() {
return symbol2;
} |
1520524_9 | public synchronized IBond.Order getBondOrder() {
return bondOrder;
} |
152134_10 | @SuppressWarnings("unchecked")
public List<Person> findAll() {
return getJdbcTemplate().query("SELECT * FROM employee",
new Object[0], new PersonRowMapper());
} |
152134_11 | public static byte[] readIntoByteArray(InputStream in) throws IOException {
ByteArrayOutputStream content = new ByteArrayOutputStream();
pipe(in, content);
return content.toByteArray();
} |
152134_12 | public static String readIntoString(Reader reader) throws IOException {
StringWriter writer = new StringWriter();
pipe(reader, writer);
return writer.toString();
} |
152134_13 | public static void pipe(InputStream source, OutputStream destination)
throws IOException {
int r = -1;
byte[] buffer = new byte[8096];
while ((r = source.read(buffer, 0, buffer.length)) != -1) {
destination.write(buffer, 0, r);
}
} |
152134_14 | public static void pipe(InputStream source, OutputStream destination)
throws IOException {
int r = -1;
byte[] buffer = new byte[8096];
while ((r = source.read(buffer, 0, buffer.length)) != -1) {
destination.write(buffer, 0, r);
}
} |
152134_15 | public void writeFile(String path, byte[] content) throws IOException {
writeFile(path, new ByteArrayInputStream(content));
} |
152134_16 | public void writeFile(String path, byte[] content) throws IOException {
writeFile(path, new ByteArrayInputStream(content));
} |
152134_17 | public double add(double left, double right) {
addToHistory(left, '+', right);
return left + right;
} |
152134_18 | public double subtract(double left, double right) {
addToHistory(left, '-', right);
return left - right;
} |
152134_19 | public double multiply(double left, double right) {
addToHistory(left, '*', right);
return left * right;
} |
152134_20 | public double divide(double left, double right) {
addToHistory(left, '/', right);
if (right == 0.0d) {
throw new IllegalArgumentException(
"Can't divide with zero");
}
return left / right;
} |
152134_21 | public void buyTicket() throws InterruptedException {
tickets.acquire();
} |
152134_22 | public int add(int a, int b) {
notifyJmsQueue(a, b);
return a + b;
} |
152134_23 | public int add(int a, int b) {
notifyJmsQueue(a, b);
return a + b;
} |
152134_24 | public Price discountedPrice(Product product, Account account) {
try {
DiscountService discounts = getDiscountService();
int discount = discounts.getDiscountPercentage(account);
float discountMultiplier = ((100 - discount) / 100.0f);
return new Price((int) (product.getPrice() * discountMultiplier));
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
152134_25 | public Price discountedPrice(Product product, Account account) {
try {
DiscountService discounts = getDiscountService();
int discount = discounts.getDiscountPercentage(account);
float discountMultiplier = ((100 - discount) / 100.0f);
return new Price((int) (product.getPrice() * discountMultiplier));
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
152134_26 | public Price discountedPrice(Product product, Account account) {
try {
DiscountService discounts = getDiscountService();
int discount = discounts.getDiscountPercentage(account);
float discountMultiplier = ((100 - discount) / 100.0f);
return new Price((int) (product.getPrice() * discountMultiplier));
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
152134_27 | public void onMessage(Message message) {
try {
ObjectMessage searchRequest = (ObjectMessage) message;
String[] keywords = (String[]) searchRequest.getObject();
String[] results = searchService.search(keywords);
QueueConnection connection = connectionFactory
.createQueueConnection();
QueueSession session = connection.createQueueSession(
false, Session.AUTO_ACKNOWLEDGE);
QueueSender sender = session.createSender(resultsQueue);
Message resultsMessage = session
.createObjectMessage(results);
sender.send(resultsMessage);
connection.close();
} catch (Exception e) {
throw new RuntimeException(e);
}
} |
152134_28 | public User findByUsername(String username) {
Query query = em.createNamedQuery("findUserByUsername");
query.setParameter("username", username);
return (User) query.getSingleResult();
} |
152134_29 | @Override
public Class<? extends Page> getHomePage() {
return MyHomePage.class;
} |
152134_30 | public String format(HttpServletRequest request, int httpStatus,
int contentLength) {
StringBuffer line = new StringBuffer();
line.append(request.getRemoteAddr());
line.append(" - ");
line.append(request.getRemoteUser());
line.append(" [");
line.append(dateFormat.format(SystemTime.asDate()));
line.append("] \"").append(request.getMethod());
line.append(" ").append(request.getRequestURI());
line.append(" ").append(request.getProtocol());
line.append("\" ").append(httpStatus);
line.append(" ").append(contentLength);
return line.toString();
} |
152134_31 | public String format(HttpServletRequest request, int httpStatus,
int contentLength) {
StringBuffer line = new StringBuffer();
line.append(request.getRemoteAddr());
line.append(" - ");
line.append(request.getRemoteUser());
line.append(" [");
line.append(dateFormat.format(SystemTime.asDate()));
line.append("] \"").append(request.getMethod());
line.append(" ").append(request.getRequestURI());
line.append(" ").append(request.getProtocol());
line.append("\" ").append(httpStatus);
line.append(" ").append(contentLength);
return line.toString();
} |
152134_32 | public List<String> parse(String template) {
List<String> segments = new ArrayList<String>();
int index = collectSegments(template, segments, 0);
addTail(segments, template, index);
return segments;
} |
152134_33 | public List<String> parse(String template) {
List<String> segments = new ArrayList<String>();
int index = collectSegments(template, segments, 0);
addTail(segments, template, index);
return segments;
} |
152134_34 | public List<String> parse(String template) {
List<String> segments = new ArrayList<String>();
int index = collectSegments(template, segments, 0);
addTail(segments, template, index);
return segments;
} |
152134_35 | public List<Segment> parseSegments(String template) {
List<Segment> segments = new ArrayList<Segment>();
List<String> strings = parse(template);
for (String s : strings) {
if (isVariable(s)) {
String name = s.substring(2, s.length() - 1);
segments.add(new Variable(name));
} else {
segments.add(new PlainText(s));
}
}
return segments;
} |
152134_36 | public void set(String name, String value) {
this.variables.put(name, value);
} |
152134_37 | public void set(String name, String value) {
this.variables.put(name, value);
} |
152134_38 | public String evaluate() {
TemplateParse p = new TemplateParse();
List<Segment> segments = p.parseSegments(templateText);
return concatenate(segments);
} |
152134_39 | public String evaluate() {
TemplateParse p = new TemplateParse();
List<Segment> segments = p.parseSegments(templateText);
return concatenate(segments);
} |
152134_40 | public Prompt join(final String nickname, Client user) {
clients.put(nickname, user);
return new Prompt() {
@Override
public void say(String message) {
deliverMessage(nickname, message);
}
};
} |
152134_41 | @Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String user = request.getParameter("j_username");
String pass = request.getParameter("j_password");
if (getAuthenticator().isValidLogin(user, pass)) {
request.getSession().setAttribute("username", user);
response.sendRedirect("/frontpage");
} else {
forwardTo("/invalidlogin", request, response);
}
} |
152134_42 | @Override
protected void service(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
String user = request.getParameter("j_username");
String pass = request.getParameter("j_password");
if (getAuthenticator().isValidLogin(user, pass)) {
request.getSession().setAttribute("username", user);
response.sendRedirect("/frontpage");
} else {
forwardTo("/invalidlogin", request, response);
}
} |
152134_43 | public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String user = request.getParameter("j_username");
String pass = request.getParameter("j_password");
if (authenticator.isValidLogin(user, pass)) {
return new ModelAndView("frontpage");
}
return new ModelAndView("wrongpassword");
} |
152134_44 | public ModelAndView handleRequest(HttpServletRequest request,
HttpServletResponse response) throws Exception {
String user = request.getParameter("j_username");
String pass = request.getParameter("j_password");
if (authenticator.isValidLogin(user, pass)) {
return new ModelAndView("frontpage");
}
return new ModelAndView("wrongpassword");
} |
152134_45 | public void parse (Reader input, Writer output) throws Exception {
this.input = input;
this.output = output;
int i;
while (-1 != (i = input.read())) {
this.c = (char)i;
this.cnt++;
switch (this.state) {
case IN_TAG:
this.handleInTag();
break;
default:
this.handleUnknown();
break;
}
}
} |
152134_46 | public void parse (Reader input, Writer output) throws Exception {
this.input = input;
this.output = output;
int i;
while (-1 != (i = input.read())) {
this.c = (char)i;
this.cnt++;
switch (this.state) {
case IN_TAG:
this.handleInTag();
break;
default:
this.handleUnknown();
break;
}
}
} |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.