Skip to content

Commit

Permalink
fixed java coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
Klaas Bosteels authored and Klaas Bosteels committed Dec 2, 2008
1 parent 08c02d6 commit 11a9ee7
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 233 deletions.
132 changes: 66 additions & 66 deletions src/java/org/apache/hadoop/dumbo/AsCodeInputFormat.java
Expand Up @@ -35,73 +35,73 @@
*/
public class AsCodeInputFormat implements InputFormat<Text,Text>, JobConfigurable {

private InputFormat realInputFormat = null;
private boolean named = false;

public AsCodeInputFormat(InputFormat realInputFormat, boolean named) {
this.realInputFormat = realInputFormat;
this.named = named;
}

public AsCodeInputFormat(InputFormat realInputFormat) {
this(realInputFormat, false);
}

public AsCodeInputFormat(boolean named) {
this(null, named);
}

public AsCodeInputFormat() {
this(null, false);
}

public void configure(JobConf job) {
if (realInputFormat == null) {
Class<? extends InputFormat> realInputFormatClass
= job.getClass("dumbo.as.code.input.format.class", TextInputFormat.class, InputFormat.class);
try {
realInputFormat = realInputFormatClass.newInstance();
for (Class interface_ : realInputFormatClass.getInterfaces()) {
if (interface_.equals(JobConfigurable.class)) {
JobConfigurable jc = (JobConfigurable) realInputFormat;
jc.configure(job);
break;
}
}
} catch (InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
if (!named) {
named = job.getBoolean("dumbo.as.named.code", false);
}
}

@SuppressWarnings("unchecked")
private RecordReader<Text,Text> createRecordReader(InputSplit split, JobConf job,
Reporter reporter, String filename) throws IOException {
return new AsCodeRecordReader(realInputFormat.getRecordReader(split, job, reporter), filename);
}

public RecordReader<Text,Text> getRecordReader(InputSplit split, JobConf job,
Reporter reporter) throws IOException {
String filename = null;
if (named && split instanceof FileSplit) {
filename = ((FileSplit) split).getPath().getName();
}
return createRecordReader(split, job, reporter, filename);
}
private InputFormat realInputFormat = null;
private boolean named = false;

public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
return realInputFormat.getSplits(job, numSplits);
}
public AsCodeInputFormat(InputFormat realInputFormat, boolean named) {
this.realInputFormat = realInputFormat;
this.named = named;
}

public void validateInput(JobConf job) throws IOException {
realInputFormat.validateInput(job);
}
public AsCodeInputFormat(InputFormat realInputFormat) {
this(realInputFormat, false);
}

public AsCodeInputFormat(boolean named) {
this(null, named);
}

public AsCodeInputFormat() {
this(null, false);
}

public void configure(JobConf job) {
if (realInputFormat == null) {
Class<? extends InputFormat> realInputFormatClass
= job.getClass("dumbo.as.code.input.format.class", TextInputFormat.class, InputFormat.class);
try {
realInputFormat = realInputFormatClass.newInstance();
for (Class interface_ : realInputFormatClass.getInterfaces()) {
if (interface_.equals(JobConfigurable.class)) {
JobConfigurable jc = (JobConfigurable) realInputFormat;
jc.configure(job);
break;
}
}
} catch (InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
}
if (!named) {
named = job.getBoolean("dumbo.as.named.code", false);
}
}

@SuppressWarnings("unchecked")
private RecordReader<Text,Text> createRecordReader(InputSplit split, JobConf job,
Reporter reporter, String filename) throws IOException {
return new AsCodeRecordReader(realInputFormat.getRecordReader(split, job, reporter), filename);
}

public RecordReader<Text,Text> getRecordReader(InputSplit split, JobConf job,
Reporter reporter) throws IOException {
String filename = null;
if (named && split instanceof FileSplit) {
filename = ((FileSplit) split).getPath().getName();
}
return createRecordReader(split, job, reporter, filename);
}

public InputSplit[] getSplits(JobConf job, int numSplits) throws IOException {
return realInputFormat.getSplits(job, numSplits);
}

public void validateInput(JobConf job) throws IOException {
realInputFormat.validateInput(job);
}

}
72 changes: 36 additions & 36 deletions src/java/org/apache/hadoop/dumbo/AsCodeRecordReader.java
Expand Up @@ -29,46 +29,46 @@
*/
public class AsCodeRecordReader implements RecordReader<Text, Text> {

private RecordReader<Writable, Writable> realRecordReader;
private Writable realKey, realValue;
private String filenameCode = null;

public AsCodeRecordReader(RecordReader<Writable, Writable> realRecordReader, String filename) {
this.realRecordReader = realRecordReader;
realKey = realRecordReader.createKey();
realValue = realRecordReader.createValue();
if (filename != null) filenameCode = CodeUtils.stringToCode(filename);
}

public void close() throws IOException {
realRecordReader.close();
}
private RecordReader<Writable, Writable> realRecordReader;
private Writable realKey, realValue;
private String filenameCode = null;

public Text createKey() {
return new Text();
}
public AsCodeRecordReader(RecordReader<Writable, Writable> realRecordReader, String filename) {
this.realRecordReader = realRecordReader;
realKey = realRecordReader.createKey();
realValue = realRecordReader.createValue();
if (filename != null) filenameCode = CodeUtils.stringToCode(filename);
}

public Text createValue() {
return new Text();
}
public void close() throws IOException {
realRecordReader.close();
}

public long getPos() throws IOException {
return realRecordReader.getPos();
}
public Text createKey() {
return new Text();
}

public float getProgress() throws IOException {
return realRecordReader.getProgress();
}
public Text createValue() {
return new Text();
}

public boolean next(Text key, Text value) throws IOException {
if (!realRecordReader.next(realKey, realValue)) return false;
if (filenameCode != null) {
key.set(CodeUtils.codesToTuple(filenameCode, CodeUtils.writableToCode(realKey)));
} else {
key.set(CodeUtils.writableToCode(realKey));
}
value.set(CodeUtils.writableToCode(realValue));
return true;
}
public long getPos() throws IOException {
return realRecordReader.getPos();
}

public float getProgress() throws IOException {
return realRecordReader.getProgress();
}

public boolean next(Text key, Text value) throws IOException {
if (!realRecordReader.next(realKey, realValue)) return false;
if (filenameCode != null) {
key.set(CodeUtils.codesToTuple(filenameCode, CodeUtils.writableToCode(realKey)));
} else {
key.set(CodeUtils.writableToCode(realKey));
}
value.set(CodeUtils.writableToCode(realValue));
return true;
}

}
24 changes: 12 additions & 12 deletions src/java/org/apache/hadoop/dumbo/CatPath.java
Expand Up @@ -45,7 +45,7 @@ public class CatPath extends Configured implements Tool {
public int run(String[] args) throws Exception {
Configuration conf = getConf();
JobConf job = new JobConf(conf);

FileSystem fs = FileSystem.get(conf);
Path inputPath = new Path(args[1]);
List<FileStatus> inputFiles = new ArrayList<FileStatus>();
Expand All @@ -59,8 +59,8 @@ public int run(String[] args) throws Exception {
}

for (FileStatus fileStatus : inputFiles) {
FileSplit split = new FileSplit(fileStatus.getPath(), 0,
fileStatus.getLen()*fileStatus.getBlockSize(), (String[])null);
FileSplit split = new FileSplit(fileStatus.getPath(), 0,
fileStatus.getLen()*fileStatus.getBlockSize(), (String[])null);
InputFormat<Text,Text> inputformat;
if (args[0].toLowerCase().equals("sequencefileasnamedcode")) {
inputformat = new SequenceFileAsCodeInputFormat(true);
Expand All @@ -71,14 +71,14 @@ public int run(String[] args) throws Exception {
} else if (args[0].toLowerCase().equals("textascode")) {
inputformat = new TextAsCodeInputFormat(false);
} else {
AsCodeInputFormat asCodeInputformat;
if (args[0].toLowerCase().equals("asnamedcode")) {
asCodeInputformat = new AsCodeInputFormat(true);
} else {
asCodeInputformat = new AsCodeInputFormat(false);
}
asCodeInputformat.configure(job);
inputformat = asCodeInputformat;
AsCodeInputFormat asCodeInputformat;
if (args[0].toLowerCase().equals("asnamedcode")) {
asCodeInputformat = new AsCodeInputFormat(true);
} else {
asCodeInputformat = new AsCodeInputFormat(false);
}
asCodeInputformat.configure(job);
inputformat = asCodeInputformat;
}
RecordReader<Text,Text> reader = inputformat.getRecordReader(split, job, Reporter.NULL);
Text key = new Text(), value = new Text();
Expand All @@ -87,7 +87,7 @@ public int run(String[] args) throws Exception {
}
reader.close();
}

return 0;
}

Expand Down
4 changes: 3 additions & 1 deletion src/java/org/apache/hadoop/dumbo/CodeUtils.java
Expand Up @@ -233,7 +233,9 @@ public static String writableToCode(Writable w) {
return stringToCode(((Text)w).toString());
} else if (w instanceof Record) {
return recordToCode((Record)w);
} else return stringToCode(w.toString());
} else {
return stringToCode(w.toString());
}
}

public static CodeWritable codeToWritable(String code) {
Expand Down
78 changes: 39 additions & 39 deletions src/java/org/apache/hadoop/dumbo/CodeWritableMapper.java
Expand Up @@ -9,43 +9,43 @@

public class CodeWritableMapper implements Mapper {

private Mapper realMapper = null;
public void configure(JobConf job) {
try {
realMapper = job.getClass("dumbo.code.writable.map.class", null, Mapper.class).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
if (realMapper == null) throw new RuntimeException("map class property not set");
realMapper.configure(job);
}
@SuppressWarnings("unchecked")
public void map(Object key, Object value, OutputCollector output, Reporter reporter) throws IOException {
realMapper.map(key, value, new CodeWritableOutputCollector(output), reporter);
}
private static class CodeWritableOutputCollector implements OutputCollector {

private OutputCollector realOutputCollector;
public CodeWritableOutputCollector(OutputCollector realOutputCollector) {
this.realOutputCollector = realOutputCollector;
}
@SuppressWarnings("unchecked")
public void collect(Object key, Object value) throws IOException {
realOutputCollector.collect(new CodeWritable(key.toString()), new CodeWritable(value.toString()));
}
}

public void close() throws IOException {
realMapper.close();
}
private Mapper realMapper = null;

public void configure(JobConf job) {
try {
realMapper = job.getClass("dumbo.code.writable.map.class", null, Mapper.class).newInstance();
} catch (InstantiationException e) {
e.printStackTrace();
throw new RuntimeException(e);
} catch (IllegalAccessException e) {
e.printStackTrace();
throw new RuntimeException(e);
}
if (realMapper == null) throw new RuntimeException("map class property not set");
realMapper.configure(job);
}

@SuppressWarnings("unchecked")
public void map(Object key, Object value, OutputCollector output, Reporter reporter) throws IOException {
realMapper.map(key, value, new CodeWritableOutputCollector(output), reporter);
}

private static class CodeWritableOutputCollector implements OutputCollector {

private OutputCollector realOutputCollector;

public CodeWritableOutputCollector(OutputCollector realOutputCollector) {
this.realOutputCollector = realOutputCollector;
}

@SuppressWarnings("unchecked")
public void collect(Object key, Object value) throws IOException {
realOutputCollector.collect(new CodeWritable(key.toString()), new CodeWritable(value.toString()));
}

}

public void close() throws IOException {
realMapper.close();
}
}

0 comments on commit 11a9ee7

Please sign in to comment.