看下定义,继承了WritableComparable接口.这个说明什么呢?

public class LongWritable
extends Object
implements org.apache.hadoop.io.WritableComparable<LongWritable>

属性

就一个 value

private long value;

然后get set方法,常规操作

/** Set the value of this LongWritable. */public void set(long value) { this.value = value; }/** Return the value of this LongWritable. */public long get() { return value; }

构造方法

比较简单

  public LongWritable() {}public LongWritable(long value) { set(value); }

WritableComparable接口

public interface WritableComparable<T> extends Writable, Comparable<T> {}

继续追根溯源. Writable里面有两个方法,一个序列化,一个反序列化.那么为何要序列化以及反序列化呢?

public interface Writable {/** * Serialize the fields of this object to <code>out</code>.* * @param out <code>DataOuput</code> to serialize this object into.* @throws IOException*/void write(DataOutput out) throws IOException;/** * Deserialize the fields of this object from <code>in</code>.  * * <p>For efficiency, implementations should attempt to re-use storage in the * existing object where possible.</p>* * @param in <code>DataInput</code> to deseriablize this object from.* @throws IOException*/void readFields(DataInput in) throws IOException;
}再看看Comparable接口
```sql
public interface Comparable<T> {/*** Compares this object with the specified object for order.  Returns a* negative integer, zero, or a positive integer as this object is less* than, equal to, or greater than the specified object.** <p>The implementor must ensure <tt>sgn(x.compareTo(y)) ==* -sgn(y.compareTo(x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This* implies that <tt>x.compareTo(y)</tt> must throw an exception iff* <tt>y.compareTo(x)</tt> throws an exception.)** <p>The implementor must also ensure that the relation is transitive:* <tt>(x.compareTo(y)&gt;0 &amp;&amp; y.compareTo(z)&gt;0)</tt> implies* <tt>x.compareTo(z)&gt;0</tt>.** <p>Finally, the implementor must ensure that <tt>x.compareTo(y)==0</tt>* implies that <tt>sgn(x.compareTo(z)) == sgn(y.compareTo(z))</tt>, for* all <tt>z</tt>.** <p>It is strongly recommended, but <i>not</i> strictly required that* <tt>(x.compareTo(y)==0) == (x.equals(y))</tt>.  Generally speaking, any* class that implements the <tt>Comparable</tt> interface and violates* this condition should clearly indicate this fact.  The recommended* language is "Note: this class has a natural ordering that is* inconsistent with equals."** <p>In the foregoing description, the notation* <tt>sgn(</tt><i>expression</i><tt>)</tt> designates the mathematical* <i>signum</i> function, which is defined to return one of <tt>-1</tt>,* <tt>0</tt>, or <tt>1</tt> according to whether the value of* <i>expression</i> is negative, zero or positive.** @param   o the object to be compared.* @return  a negative integer, zero, or a positive integer as this object*          is less than, equal to, or greater than the specified object.** @throws NullPointerException if the specified object is null* @throws ClassCastException if the specified object's type prevents it*         from being compared to this object.*/public int compareTo(T o);
}

总结下来,就是要定义一个hadoop的类型,需要实现write,readFields,以及compareTo方法.

LongWritable是如何实现这几个方法的呢?

/** Compares two LongWritables. */@Overridepublic int compareTo(LongWritable o) {long thisValue = this.value;long thatValue = o.value;return (thisValue<thatValue ? -1 : (thisValue==thatValue ? 0 : 1));}
@Overridepublic void readFields(DataInput in) throws IOException {value = in.readLong();}@Overridepublic void write(DataOutput out) throws IOException {out.writeLong(value);}

hadoop longwritable类相关推荐

  1. Hadoop——Configuration类详解

    转自:http://blog.csdn.net/ghuilee/article/details/45771003 1.configuration类简介 Hadoop没有使用java.util.Prop ...

  2. 如何高效阅读 Spark 和 Hadoop 这类大型开源项目源代码?

    我自己看过HDFS以及HDFS Raid的源码,其他的偶尔也看一下. 个人感觉大致以下一些步骤吧: 看官方网站的描述,知道项目的定位.功能.常见用例. 搜集文档,与项目相关的论文.整体架构文档.某些重 ...

  3. (2)Hadoop核心 -- java代码对MapReduce的例子1

    案例一:wordcount字数统计功能 1.1 先准备两个txt文件,并上传到hdfs上 test1.txt hello zhangsan lisi nihao hai zhangsan nihao ...

  4. hadoop系列三:mapreduce的使用(一)

    一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的一些内容,如hadoop,spark,storm,机器学习等. 当前使用的hadoop版本为2.6.4 上一篇:hadoop系列二: ...

  5. hadoop系列四:mapreduce的使用(二)

    转载请在页首明显处注明作者与出处 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据的一些内容,如hadoop,spark,storm,机器学习等. 当前使用的hadoop版本为2.6 ...

  6. hadoop存储与分析

    Apache Hadoop ## 背景 随着信息化互联网|物联网发展要求,万物互联趋势势在必行.随之引发架构的演变由单一架构向高并发分布式架构演变.数据的存储也开始由原始的单机存储演变为分布式存储. ...

  7. Apache Hadoop

    作者:jiangzz 电话:15652034180 微信:jiangzz_wx 微信公众账号:jiangzz_wy 大数据(Big Data) 随着信息化互联网|物联网发展要求,万物互联趋势势在必行. ...

  8. 使用Hadoop MapReduce进行大数据分析

    Google在2001年推出图片搜索功能时,拥有2.5亿张索引图片. 不到十年后,这家搜索巨头就索引了超过100亿张图片. 每分钟有35个小时的内容上传到YouTube. 据说Twitter平均每天处 ...

  9. Hadoop与Alpach Spark的区别

    Hadoop与Alpach Spark的区别 1.概述 2.解决问题的层面不一样 3.两者可合可分 4.Spark数据处理速度秒杀MapReduce 5.数据恢复 6.二者的区别总结: 1.概述    ...

最新文章

  1. rpm安装mysql报错_【CentOS-65】通过rpm包安装mysql57解决了server报错和mysqld启动报错的问题...
  2. 一个页面是否应该全部组件化
  3. (转).NET框架下使用双缓冲技术绘图
  4. mysql权限层级体系_MySQL权限体系介绍
  5. Kubernetes 入门教程
  6. mvc5控制器修改html,ASP.NET MVC Razor:如何在控制器动作中呈现Razor局部视图的HTML...
  7. linux中node跨服务执行文件,linux部署node.js服务并启动服务
  8. 【动态规划】牛客网:把数字翻译成字符串
  9. 海康摄像头使用网线连接电脑后无法访问摄像头ip
  10. selenium--下载与安装
  11. uniapp:广告API使用总结
  12. 嵌入式系统基础——Unbuntu的初步使用
  13. 开源公告|更可信的人脸识别,腾讯优图TFace正式开源!
  14. 医学影像工作站 v2.2 官方
  15. 有什么适合新手学习的3D建模软件?
  16. 二次规划问题的KKT 条件求解方法
  17. 春季出游将至 Bingdata大数据详解春季踏青游趋势
  18. 那年,我在亚马逊被骂成狗
  19. BLEU 评价 NLP 文本输出质量
  20. 前端向--BLOB文件处理及常用输入校验

热门文章

  1. python继承中的参数_python 继承中的super
  2. Linux网络配置与远程连接
  3. 车子前进档为什么往后退_「前推倒车·后拉加速」自动挡的档杆为什么设计的这么奇怪?...
  4. 每日总结 神州数码DCWS
  5. The application could not be installed: INSTALL_FAILED_INSUFFICIENT_STORAGE
  6. python的主要内容_请教,python基础班主要学哪些内容?
  7. linux不同机器之间的拷贝,Linux下不同机器之间的文件拷贝
  8. php对象合并,【面向对象的PHP】之模式:组合
  9. 前格式 直接将转换为当_如何将word转化为PDF格式?1分钟学会文档转换
  10. c语言如何调用三个子程序,哪位师傅知道51单片机怎样编写子程序?C语言的。在主程序里调...