add data_ptr return for datablock

This commit is contained in:
lionsoul 2016-06-30 16:02:11 +08:00
parent 72ca42f54f
commit 32ad842926
3 changed files with 77 additions and 47 deletions

View File

@ -9,7 +9,7 @@
<property name="jars" value="${basedir}"/> <property name="jars" value="${basedir}"/>
<property name="sources" value="${basedir}/src"/> <property name="sources" value="${basedir}/src"/>
<property name="classes" value="${basedir}/classes"/> <property name="classes" value="${basedir}/classes"/>
<property name="version" value="1.0"/> <property name="version" value="1.2"/>
<property name="api" value="${basedir}/doc"/> <property name="api" value="${basedir}/doc"/>
<mkdir dir="${classes}"/> <mkdir dir="${classes}"/>
<mkdir dir="${api}"/> <mkdir dir="${api}"/>

View File

@ -3,54 +3,84 @@ package org.lionsoul.ip2region;
/** /**
* data block class * data block class
* *
* @author chenxin<chenxin619315@gmail.com> * @author chenxin<chenxin619315@gmail.com>
*/ */
public class DataBlock public class DataBlock
{ {
/** /**
* city id * city id
*/ */
private int city_id; private int city_id;
/** /**
* region address * region address
*/ */
private String region; private String region;
public DataBlock( int city_id, String region ) /**
{ * region ptr in the db file
this.city_id = city_id; */
this.region = region; private int dataPtr;
}
/**
* construct method
*
* @param city_id
* @param region region string
* @param ptr data ptr
*/
public DataBlock( int city_id, String region, int dataPtr )
{
this.city_id = city_id;
this.region = region;
this.dataPtr = dataPtr;
}
public DataBlock(int city_id, String region)
{
this(city_id, region, 0);
}
public int getCityId() public int getCityId()
{ {
return city_id; return city_id;
} }
public DataBlock setCityId(int city_id) public DataBlock setCityId(int city_id)
{ {
this.city_id = city_id; this.city_id = city_id;
return this; return this;
} }
public String getRegion() public String getRegion()
{ {
return region; return region;
} }
public DataBlock setRegion(String region)
{
this.region = region;
return this;
}
public int getDataPtr()
{
return dataPtr;
}
public DataBlock setDataPtr(int dataPtr)
{
this.dataPtr = dataPtr;
return this;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(city_id).append('|').append(region).append('|').append(dataPtr);
return sb.toString();
}
public DataBlock setRegion(String region)
{
this.region = region;
return this;
}
@Override
public String toString()
{
StringBuilder sb = new StringBuilder();
sb.append(city_id).append('|').append(region);
return sb.toString();
}
} }

View File

@ -76,7 +76,7 @@ public class DbSearcher
int city_id = (int)Util.getIntLong(data, 0); int city_id = (int)Util.getIntLong(data, 0);
String region = new String(data, 4, data.length - 4, "UTF-8"); String region = new String(data, 4, data.length - 4, "UTF-8");
return new DataBlock(city_id, region); return new DataBlock(city_id, region, dataPtr);
} }
/** /**
@ -204,7 +204,7 @@ public class DbSearcher
int city_id = (int)Util.getIntLong(data, 0); int city_id = (int)Util.getIntLong(data, 0);
String region = new String(data, 4, data.length - 4, "UTF-8"); String region = new String(data, 4, data.length - 4, "UTF-8");
return new DataBlock(city_id, region); return new DataBlock(city_id, region, dataPtr);
} }
/** /**
@ -274,7 +274,7 @@ public class DbSearcher
int city_id = (int)Util.getIntLong(data, 0); int city_id = (int)Util.getIntLong(data, 0);
String region = new String(data, 4, data.length - 4, "UTF-8"); String region = new String(data, 4, data.length - 4, "UTF-8");
return new DataBlock(city_id, region); return new DataBlock(city_id, region, dataPtr);
} }
/** /**