看下定义,继承了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. 记录Flex布局的属性
  2. (转)JS正则表达式元字符
  3. P2P平台选择网关支付、第三方托管、第三方+银行联合托管有什么区别?
  4. js原型和原型链_JS里的原型和原型链
  5. servlet实现用户登录
  6. css:实现文本两行或多行文本溢出显示省略号
  7. 迈向电商认知智能时代的基石:阿里电商认知图谱揭秘
  8. Android UI开发第八篇——ViewFlipper 左右滑动效果
  9. C语言之文件读写探究(三):fputs、fgets、feof(一次读写一行字符(文本操作))
  10. Nginx反向代理及简单负载均衡配置
  11. bzoj 1685: [Usaco2005 Oct]Allowance 津贴(贪心)
  12. java string简单例子_java从字符串中提取数字的简单实例
  13. mockserver
  14. 保研夏令营、考研复试个人升学简历模板与制作注意事项
  15. 芜湖计算机专业学校录取分数线,芜湖市各类高中2018年中考录取分数线是多少...
  16. [开发证书] Apple PKI
  17. 儿童护眼灯哪个品牌最好?儿童护眼灯十大排行榜
  18. 解决D3DCompiler_47.dll文件丢失找不到问题
  19. 利用ajax从jsp中返回的字符串时出现回车符号解决办法
  20. 华为耳机5根线怎么接线图解_【技能】小白耳机维修入门--各种耳机插头接线图--耳机维修汇总贴...

热门文章

  1. hdfs java操作_hdfs java操作
  2. ios 怎么判断字符串的字节数_如何用IOS判断字符串是不是纯数字
  3. oracle+快速客户端安装方法,ORACLE简易客户端安装与使用方法
  4. ubuntu linux配置bond 网卡绑定 多个bond配置多网关
  5. neo4j 查询同一节点的两个上级_链表的魅力:两个单向链表的第一个交点
  6. Linux实现删除撤回的方法。
  7. springboot2.0 图片收集
  8. java final 详解_java中Final详解
  9. html头部协议,TCP/IP协议头部结构体
  10. webstorm设置注释颜色_PDF中的注释怎么用?这里有方法