hadoop-mapreduce-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Johannes.Lichtenberger" <Johannes.Lichtenber...@uni-konstanz.de>
Subject Re: NullPointerException
Date Fri, 08 Oct 2010 12:39:52 GMT
Just in case it matters, my DateWritable key class:

package com.treetank.wikipedia.hadoop;

import java.io.DataInput;
import java.io.DataOutput;
import java.io.IOException;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

import org.apache.hadoop.io.WritableComparable;
import org.slf4j.LoggerFactory;

import com.treetank.service.xml.shredder.XMLShredder;
import com.treetank.utils.LogWrapper;

/**
 * <h1>DateWritable</h1>
 *
 * <p>
 * Simple date wrapper which implements {@link WritableComparable}, as
such it can be used as a key.
 * </p>
 *
 * @author Johannes Lichtenberger, University of Konstanz
 *
 */
public final class DateWritable implements
WritableComparable<DateWritable> {

    /**
     * {@link LogWrapper} used for logging.
     */
    private static final LogWrapper LOGWRAPPER = new
LogWrapper(LoggerFactory.getLogger(XMLShredder.class));

    /** {@link DateFormat}. */
    private final DateFormat mFormatter = new
SimpleDateFormat("yyyy.MM.dd HH.mm.ss", Locale.ENGLISH);

    /** {@link Date} used as the key. */
    private Date mTimestamp;

    /**
     * Constructor.
     */
    public DateWritable() {

    }

    /**
     * Constructor.
     *
     * @param paramTimestamp
     *                  The {@link Date} to use as the key.
     */
    public DateWritable(final Date paramTimestamp) {
        mTimestamp = paramTimestamp;
    }

    /**
     * Set timestamp.
     *
     * @param paramTimestamp
     *            The Timestamp to set.
     */
    public void setTimestamp(final Date paramTimestamp) {
        mTimestamp = paramTimestamp;
    }

    @Override
    public void readFields(final DataInput paramIn) throws IOException {
        try {
            mTimestamp = mFormatter.parse(paramIn.readUTF());
        } catch (final ParseException e) {
            LOGWRAPPER.error(e.getMessage(), e);
        }
    }

    @Override
    public void write(final DataOutput paramOut) throws IOException {
        paramOut.writeUTF(mFormatter.format(mTimestamp));
    }

    @Override
    public int compareTo(final DateWritable paramDate) {
        int retVal = 0;

        if (paramDate.mTimestamp.before(this.mTimestamp)) {
            retVal = -1;
        } else if (paramDate.mTimestamp.after(this.mTimestamp)) {
            retVal = 1;
        }

        return retVal;
    }
}


Mime
View raw message