You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@zookeeper.apache.org by eo...@apache.org on 2019/07/29 15:15:40 UTC
[zookeeper] branch master updated: ZOOKEEPER-3468: Enable
BookKeeper checkstyle configuration on zookeeper-jute
This is an automated email from the ASF dual-hosted git repository.
eolivelli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/zookeeper.git
The following commit(s) were added to refs/heads/master by this push:
new 35f4aa2 ZOOKEEPER-3468: Enable BookKeeper checkstyle configuration on zookeeper-jute
35f4aa2 is described below
commit 35f4aa227463ca95941b9045f9c554aa1696782f
Author: tison <wa...@gmail.com>
AuthorDate: Mon Jul 29 17:15:26 2019 +0200
ZOOKEEPER-3468: Enable BookKeeper checkstyle configuration on zookeeper-jute
This pr is based on #1022
cc eolivelli maoling anmolnar
also locally test that add a 'author' tag would cause build failure.
Author: tison <wa...@gmail.com>
Reviewers: Norbert Kalmar <nk...@apache.org>, Enrico Olivelli <eo...@apache.org>
Closes #1023 from TisonKun/ZOOKEEPER-3468
---
checkstyle-strict.xml | 436 +++++++++++++++++++++
checkstyleSuppressions.xml | 3 +-
zookeeper-jute/pom.xml | 31 ++
.../java/org/apache/jute/BinaryInputArchive.java | 89 +++--
.../java/org/apache/jute/BinaryOutputArchive.java | 79 ++--
.../src/main/java/org/apache/jute/Index.java | 6 +-
.../main/java/org/apache/jute/InputArchive.java | 48 ++-
.../main/java/org/apache/jute/OutputArchive.java | 49 ++-
.../src/main/java/org/apache/jute/Record.java | 12 +-
.../main/java/org/apache/jute/RecordReader.java | 52 ++-
.../main/java/org/apache/jute/RecordWriter.java | 52 ++-
.../org/apache/jute/ToStringOutputArchive.java | 59 +--
.../src/main/java/org/apache/jute/Utils.java | 27 +-
.../java/org/apache/jute/compiler/CGenerator.java | 14 +-
.../org/apache/jute/compiler/CSharpGenerator.java | 17 +-
.../org/apache/jute/compiler/CppGenerator.java | 14 +-
.../java/org/apache/jute/compiler/JBoolean.java | 22 +-
.../java/org/apache/jute/compiler/JBuffer.java | 103 ++---
.../main/java/org/apache/jute/compiler/JByte.java | 10 +-
.../java/org/apache/jute/compiler/JCompType.java | 46 ++-
.../java/org/apache/jute/compiler/JDouble.java | 16 +-
.../main/java/org/apache/jute/compiler/JField.java | 45 +--
.../main/java/org/apache/jute/compiler/JFile.java | 50 +--
.../main/java/org/apache/jute/compiler/JFloat.java | 14 +-
.../main/java/org/apache/jute/compiler/JInt.java | 10 +-
.../main/java/org/apache/jute/compiler/JLong.java | 14 +-
.../main/java/org/apache/jute/compiler/JMap.java | 125 +++---
.../java/org/apache/jute/compiler/JRecord.java | 159 ++++----
.../java/org/apache/jute/compiler/JString.java | 20 +-
.../main/java/org/apache/jute/compiler/JType.java | 132 ++++---
.../java/org/apache/jute/compiler/JVector.java | 120 +++---
.../org/apache/jute/compiler/JavaGenerator.java | 20 +-
.../org/apache/jute/BinaryInputArchiveTest.java | 61 +--
.../org/apache/jute/TestCheckWriterReader.java | 14 +-
.../src/test/java/org/apache/jute/TestReader.java | 12 +-
.../src/test/java/org/apache/jute/TestWriter.java | 13 +-
.../org/apache/zookeeper/server/NIOServerCnxn.java | 2 -
37 files changed, 1291 insertions(+), 705 deletions(-)
diff --git a/checkstyle-strict.xml b/checkstyle-strict.xml
new file mode 100644
index 0000000..f4fa57e
--- /dev/null
+++ b/checkstyle-strict.xml
@@ -0,0 +1,436 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<!DOCTYPE module PUBLIC
+ "-//Puppy Crawl//DTD Check Configuration 1.3//EN"
+ "http://www.puppycrawl.com/dtds/configuration_1_3.dtd">
+
+<!-- This is a checkstyle configuration file. For descriptions of
+what the following rules do, please see the checkstyle configuration
+page at http://checkstyle.sourceforge.net/config.html -->
+
+<module name="Checker">
+
+ <module name="FileTabCharacter">
+ <!-- Checks that there are no tab characters in the file. -->
+ </module>
+
+ <module name="RegexpSingleline">
+ <!-- Checks that TODOs don't have stuff in parenthesis, e.g., username. -->
+ <property name="format" value="((//.*)|(\*.*))TODO\(" />
+ <property name="message" value="TODO comments must not include usernames." />
+ <property name="severity" value="error" />
+ </module>
+
+ <module name="RegexpSingleline">
+ <property name="format" value="\s+$"/>
+ <property name="message" value="Trailing whitespace"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="RegexpSingleline">
+ <property name="format" value="Throwables.propagate\("/>
+ <property name="message" value="Throwables.propagate is deprecated"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <!-- Prevent *Tests.java as tools may not pick them up -->
+ <module name="RegexpOnFilename">
+ <property name="fileNamePattern" value=".*Tests\.java$" />
+ </module>
+
+ <module name="SuppressionFilter">
+ <property name="file" value="${checkstyle.suppressions.file}" default="suppressions.xml" />
+ </module>
+
+ <!-- All Java AST specific tests live under TreeWalker module. -->
+ <module name="TreeWalker">
+
+ <!-- Allow use of comment to suppress javadocstyle -->
+ <module name="SuppressionCommentFilter">
+ <property name="offCommentFormat" value="CHECKSTYLE.OFF\: ([\w\|]+)"/>
+ <property name="onCommentFormat" value="CHECKSTYLE.ON\: ([\w\|]+)"/>
+ <property name="checkFormat" value="$1"/>
+ </module>
+
+ <module name="TodoComment">
+ <!-- Checks that disallowed strings are not used in comments. -->
+ <property name="format" value="(FIXME)|(XXX)|(@author)" />
+ </module>
+
+ <!--
+
+ IMPORT CHECKS
+
+ -->
+
+ <module name="RedundantImport">
+ <!-- Checks for redundant import statements. -->
+ <property name="severity" value="error"/>
+ <message key="import.redundancy"
+ value="Redundant import {0}."/>
+ </module>
+
+ <module name="ImportOrder">
+ <property name="severity" value="error"/>
+ <!-- This ensures that static imports go first. -->
+ <property name="option" value="top"/>
+ <property name="sortStaticImportsAlphabetically" value="true"/>
+ <property name="tokens" value="STATIC_IMPORT, IMPORT"/>
+ <message key="import.ordering"
+ value="Import {0} appears after other imports that it should precede"/>
+ </module>
+
+ <module name="AvoidStarImport">
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="IllegalImport">
+ <property name="illegalPkgs" value="autovalue.shaded, avro.shaded, bk-shade, com.google.api.client.repackaged, com.google.appengine.repackaged, io.netty.util.internal"/>
+ </module>
+
+ <module name="RedundantModifier">
+ <!-- Checks for redundant modifiers on various symbol definitions.
+ See: http://checkstyle.sourceforge.net/config_modifier.html#RedundantModifier
+ -->
+ <property name="tokens" value="METHOD_DEF, VARIABLE_DEF, ANNOTATION_FIELD_DEF, INTERFACE_DEF, CLASS_DEF, ENUM_DEF"/>
+ </module>
+
+ <!--
+ IllegalImport cannot blacklist classes, and c.g.api.client.util is used for some shaded
+ code and some useful code. So we need to fall back to Regexp.
+ -->
+ <module name="RegexpSinglelineJava">
+ <property name="format" value="com\.google\.api\.client\.util\.(ByteStreams|Charsets|Collections2|Joiner|Lists|Maps|Objects|Preconditions|Sets|Strings|Throwables)"/>
+ </module>
+
+ <!--
+ Require static importing from Preconditions.
+ -->
+ <module name="RegexpSinglelineJava">
+ <property name="format" value="^import com.google.common.base.Preconditions;$"/>
+ <property name="message" value="Static import functions from Guava Preconditions"/>
+ </module>
+
+ <module name="UnusedImports">
+ <property name="severity" value="error"/>
+ <property name="processJavadoc" value="true"/>
+ <message key="import.unused"
+ value="Unused import: {0}."/>
+ </module>
+
+ <!--
+
+ JAVADOC CHECKS
+
+ -->
+
+ <!-- Checks for Javadoc comments. -->
+ <!-- See http://checkstyle.sf.net/config_javadoc.html -->
+ <module name="JavadocMethod">
+ <property name="scope" value="protected"/>
+ <property name="severity" value="error"/>
+ <property name="allowMissingJavadoc" value="true"/>
+ <property name="allowMissingParamTags" value="true"/>
+ <property name="allowMissingReturnTag" value="true"/>
+ <property name="allowMissingThrowsTags" value="true"/>
+ <property name="allowThrowsTagsForSubclasses" value="true"/>
+ <property name="allowUndeclaredRTE" value="true"/>
+ </module>
+
+ <!-- Check that paragraph tags are used correctly in Javadoc. -->
+ <module name="JavadocParagraph"/>
+
+ <module name="JavadocType">
+ <property name="scope" value="protected"/>
+ <property name="severity" value="error"/>
+ <property name="allowMissingParamTags" value="true"/>
+ </module>
+
+ <module name="JavadocStyle">
+ <property name="severity" value="error"/>
+ <property name="checkHtml" value="true"/>
+ </module>
+
+ <!--
+
+ NAMING CHECKS
+
+ -->
+
+ <!-- Item 38 - Adhere to generally accepted naming conventions -->
+
+ <module name="PackageName">
+ <!-- Validates identifiers for package names against the
+ supplied expression. -->
+ <!-- Here the default checkstyle rule restricts package name parts to
+ seven characters, this is not in line with common practice at Google.
+ -->
+ <property name="format" value="^[a-z]+(\.[a-z][a-z0-9]{1,})*$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="TypeNameCheck">
+ <!-- Validates static, final fields against the
+ expression "^[A-Z][a-zA-Z0-9]*$". -->
+ <metadata name="altname" value="TypeName"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="ConstantNameCheck">
+ <!-- Validates non-private, static, final fields against the supplied
+ public/package final fields "^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$". -->
+ <metadata name="altname" value="ConstantName"/>
+ <property name="applyToPublic" value="true"/>
+ <property name="applyToProtected" value="true"/>
+ <property name="applyToPackage" value="true"/>
+ <property name="applyToPrivate" value="false"/>
+ <property name="format" value="^([A-Z][A-Za-z0-9_]*|FLAG_.*)$"/>
+ <message key="name.invalidPattern"
+ value="Variable ''{0}'' should be in ALL_CAPS (if it is a constant) or be private (otherwise)."/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="StaticVariableNameCheck">
+ <!-- Validates static, non-final fields against the supplied
+ expression "^[a-z][a-zA-Z0-9]*_?$". -->
+ <metadata name="altname" value="StaticVariableName"/>
+ <property name="applyToPublic" value="true"/>
+ <property name="applyToProtected" value="true"/>
+ <property name="applyToPackage" value="true"/>
+ <property name="applyToPrivate" value="true"/>
+ <property name="format" value="^[a-z][a-zA-Z0-9]*_?$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="MemberNameCheck">
+ <!-- Validates non-static members against the supplied expression. -->
+ <metadata name="altname" value="MemberName"/>
+ <property name="applyToPublic" value="true"/>
+ <property name="applyToProtected" value="true"/>
+ <property name="applyToPackage" value="true"/>
+ <property name="applyToPrivate" value="true"/>
+ <property name="format" value="^[a-z][a-zA-Z0-9]*$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="MethodNameCheck">
+ <!-- Validates identifiers for method names. -->
+ <metadata name="altname" value="MethodName"/>
+ <property name="format" value="(^[a-z][a-zA-Z0-9]*(_[a-zA-Z0-9]+)*$|Void)"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="ParameterName">
+ <!-- Validates identifiers for method parameters against the
+ expression "^[a-z][a-zA-Z0-9]*$". -->
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="LocalFinalVariableName">
+ <!-- Validates identifiers for local final variables against the
+ expression "^[a-z][a-zA-Z0-9]*$". -->
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="LocalVariableName">
+ <!-- Validates identifiers for local variables against the
+ expression "^[a-z][a-zA-Z0-9]*$". -->
+ <property name="severity" value="error"/>
+ </module>
+
+ <!-- Type parameters must be either one of the four blessed letters
+ T, K, V, W, X or else be capital-case terminated with a T,
+ such as MyGenericParameterT -->
+ <module name="ClassTypeParameterName">
+ <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*))$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="MethodTypeParameterName">
+ <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*T))$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="InterfaceTypeParameterName">
+ <property name="format" value="^(((T|K|V|W|X|R)[0-9]*)|([A-Z][a-z][a-zA-Z]*T))$"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <!--
+
+ LENGTH and CODING CHECKS
+
+ -->
+
+ <module name="LineLength">
+ <!-- Checks if a line is too long. -->
+ <property name="max" value="120"/>
+ <property name="severity" value="error"/>
+
+ <!--
+ The default ignore pattern exempts the following elements:
+ - import statements
+ - long URLs inside comments
+ -->
+
+ <property name="ignorePattern"
+ value="^(package .*;\s*)|(import .*;\s*)|( *\* .*https?://.*)$"/>
+ </module>
+
+ <module name="LeftCurly">
+ <!-- Checks for placement of the left curly brace ('{'). -->
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="RightCurly">
+ <!-- Checks right curlies on CATCH, ELSE, and TRY blocks are on
+ the same line. e.g., the following example is fine:
+ <pre>
+ if {
+ ...
+ } else
+ </pre>
+ -->
+ <!-- This next example is not fine:
+ <pre>
+ if {
+ ...
+ }
+ else
+ </pre>
+ -->
+ <property name="option" value="same"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <!-- Checks for braces around if and else blocks -->
+ <module name="NeedBraces">
+ <property name="severity" value="error"/>
+ <property name="tokens" value="LITERAL_IF, LITERAL_ELSE, LITERAL_FOR, LITERAL_WHILE, LITERAL_DO"/>
+ </module>
+
+ <module name="UpperEll">
+ <!-- Checks that long constants are defined with an upper ell.-->
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="FallThrough">
+ <!-- Warn about falling through to the next case statement. Similar to
+ javac -Xlint:fallthrough, but the check is suppressed if a single-line comment
+ on the last non-blank line preceding the fallen-into case contains 'fall through' (or
+ some other variants that we don't publicized to promote consistency).
+ -->
+ <property name="reliefPattern"
+ value="fall through|Fall through|fallthru|Fallthru|falls through|Falls through|fallthrough|Fallthrough|No break|NO break|no break|continue on"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <!-- Checks for over-complicated boolean expressions. -->
+ <module name="SimplifyBooleanExpression"/>
+
+ <!-- Detects empty statements (standalone ";" semicolon). -->
+ <module name="EmptyStatement"/>
+
+ <!--
+
+ MODIFIERS CHECKS
+
+ -->
+
+ <module name="ModifierOrder">
+ <!-- Warn if modifier order is inconsistent with JLS3 8.1.1, 8.3.1, and
+ 8.4.3. The prescribed order is:
+ public, protected, private, abstract, static, final, transient, volatile,
+ synchronized, native, strictfp
+ -->
+ <property name="severity" value="error"/>
+ </module>
+
+
+ <!--
+
+ WHITESPACE CHECKS
+
+ -->
+
+ <module name="WhitespaceAround">
+ <!-- Checks that various tokens are surrounded by whitespace.
+ This includes most binary operators and keywords followed
+ by regular or curly braces.
+ -->
+ <property name="tokens" value="ASSIGN, BAND, BAND_ASSIGN, BOR,
+ BOR_ASSIGN, BSR, BSR_ASSIGN, BXOR, BXOR_ASSIGN, COLON, DIV, DIV_ASSIGN,
+ EQUAL, GE, GT, LAND, LE, LITERAL_CATCH, LITERAL_DO, LITERAL_ELSE,
+ LITERAL_FINALLY, LITERAL_FOR, LITERAL_IF, LITERAL_RETURN,
+ LITERAL_SYNCHRONIZED, LITERAL_TRY, LITERAL_WHILE, LOR, LT, MINUS,
+ MINUS_ASSIGN, MOD, MOD_ASSIGN, NOT_EQUAL, PLUS, PLUS_ASSIGN, QUESTION,
+ SL, SL_ASSIGN, SR_ASSIGN, STAR, STAR_ASSIGN"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="WhitespaceAfter">
+ <!-- Checks that commas, semicolons and typecasts are followed by
+ whitespace.
+ -->
+ <property name="tokens" value="COMMA, SEMI, TYPECAST"/>
+ </module>
+
+ <module name="NoWhitespaceAfter">
+ <!-- Checks that there is no whitespace after various unary operators.
+ Linebreaks are allowed.
+ -->
+ <property name="tokens" value="BNOT, DEC, DOT, INC, LNOT, UNARY_MINUS,
+ UNARY_PLUS"/>
+ <property name="allowLineBreaks" value="true"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="NoWhitespaceBefore">
+ <!-- Checks that there is no whitespace before various unary operators.
+ Linebreaks are allowed.
+ -->
+ <property name="tokens" value="SEMI, DOT, POST_DEC, POST_INC"/>
+ <property name="allowLineBreaks" value="true"/>
+ <property name="severity" value="error"/>
+ </module>
+
+ <module name="OperatorWrap">
+ <!-- Checks that operators like + and ? appear at newlines rather than
+ at the end of the previous line.
+ -->
+ <property name="option" value="NL"/>
+ <property name="tokens" value="BAND, BOR, BSR, BXOR, DIV, EQUAL,
+ GE, GT, LAND, LE, LITERAL_INSTANCEOF, LOR, LT, MINUS, MOD,
+ NOT_EQUAL, PLUS, QUESTION, SL, SR, STAR "/>
+ </module>
+
+ <module name="OperatorWrap">
+ <!-- Checks that assignment operators are at the end of the line. -->
+ <property name="option" value="eol"/>
+ <property name="tokens" value="ASSIGN"/>
+ </module>
+
+ <module name="ParenPad">
+ <!-- Checks that there is no whitespace before close parens or after
+ open parens.
+ -->
+ <property name="severity" value="error"/>
+ </module>
+
+ </module>
+</module>
\ No newline at end of file
diff --git a/checkstyleSuppressions.xml b/checkstyleSuppressions.xml
index 53c96b5..9f9fbd0 100644
--- a/checkstyleSuppressions.xml
+++ b/checkstyleSuppressions.xml
@@ -18,8 +18,9 @@
<suppressions>
<!-- suppress all checks in the generated directories -->
+ <suppress checks=".*" files=".+[\\/]classes[\\/].+\.java" />
<suppress checks=".*" files=".+[\\/]generated[\\/].+\.java" />
<suppress checks=".*" files=".+[\\/]generated-sources[\\/].+\.java" />
<suppress checks=".*" files=".+[\\/]generated-test-sources[\\/].+\.java" />
-
+ <suppress checks="LineLength" files=".+[\\/]jute[\\/].+\.java"/>
</suppressions>
diff --git a/zookeeper-jute/pom.xml b/zookeeper-jute/pom.xml
index 0c4ce54..91b215f 100755
--- a/zookeeper-jute/pom.xml
+++ b/zookeeper-jute/pom.xml
@@ -153,6 +153,37 @@
<skip>true</skip>
</configuration>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-checkstyle-plugin</artifactId>
+ <version>3.0.0</version>
+ <dependencies>
+ <dependency>
+ <groupId>com.puppycrawl.tools</groupId>
+ <artifactId>checkstyle</artifactId>
+ <version>${checkstyle.version}</version>
+ </dependency>
+ </dependencies>
+ <configuration>
+ <configLocation>checkstyle-strict.xml</configLocation>
+ <suppressionsLocation>checkstyleSuppressions.xml</suppressionsLocation>
+ <encoding>UTF-8</encoding>
+ <consoleOutput>true</consoleOutput>
+ <failOnViolation>true</failOnViolation>
+ <includeResources>false</includeResources>
+ <includeTestSourceDirectory>true</includeTestSourceDirectory>
+ </configuration>
+ <executions>
+ <execution>
+ <id>checkstyle</id>
+ <phase>validate</phase>
+ <goals>
+ <goal>check</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
</plugins>
</build>
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java b/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
index 7722bff..c67a2c8 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/BinaryInputArchive.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,102 +22,121 @@ import java.io.DataInput;
import java.io.DataInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.StandardCharsets;
/**
*
*/
public class BinaryInputArchive implements InputArchive {
- static public final String UNREASONBLE_LENGTH= "Unreasonable length = ";
+
+ public static final String UNREASONBLE_LENGTH = "Unreasonable length = ";
+
+ // CHECKSTYLE.OFF: ConstantName - for backward compatibility
+ public static final int maxBuffer = Integer.getInteger("jute.maxbuffer", 0xfffff);
+ // CHECKSTYLE.ON:
+
private DataInput in;
-
- static public BinaryInputArchive getArchive(InputStream strm) {
+
+ public static BinaryInputArchive getArchive(InputStream strm) {
return new BinaryInputArchive(new DataInputStream(strm));
}
-
- static private class BinaryIndex implements Index {
+
+ private static class BinaryIndex implements Index {
private int nelems;
+
BinaryIndex(int nelems) {
this.nelems = nelems;
}
+
public boolean done() {
return (nelems <= 0);
}
+
public void incr() {
nelems--;
}
}
- /** Creates a new instance of BinaryInputArchive */
+
+ /**
+ * Creates a new instance of BinaryInputArchive.
+ */
public BinaryInputArchive(DataInput in) {
this.in = in;
}
-
+
public byte readByte(String tag) throws IOException {
return in.readByte();
}
-
+
public boolean readBool(String tag) throws IOException {
return in.readBoolean();
}
-
+
public int readInt(String tag) throws IOException {
return in.readInt();
}
-
+
public long readLong(String tag) throws IOException {
return in.readLong();
}
-
+
public float readFloat(String tag) throws IOException {
return in.readFloat();
}
-
+
public double readDouble(String tag) throws IOException {
return in.readDouble();
}
-
+
public String readString(String tag) throws IOException {
- int len = in.readInt();
- if (len == -1) return null;
+ int len = in.readInt();
+ if (len == -1) {
+ return null;
+ }
checkLength(len);
- byte b[] = new byte[len];
- in.readFully(b);
- return new String(b, "UTF8");
+ byte[] b = new byte[len];
+ in.readFully(b);
+ return new String(b, StandardCharsets.UTF_8);
}
-
- static public final int maxBuffer = Integer.getInteger("jute.maxbuffer", 0xfffff);
public byte[] readBuffer(String tag) throws IOException {
int len = readInt(tag);
- if (len == -1) return null;
+ if (len == -1) {
+ return null;
+ }
checkLength(len);
byte[] arr = new byte[len];
in.readFully(arr);
return arr;
}
-
+
public void readRecord(Record r, String tag) throws IOException {
r.deserialize(this, tag);
}
-
- public void startRecord(String tag) throws IOException {}
-
- public void endRecord(String tag) throws IOException {}
-
+
+ public void startRecord(String tag) throws IOException {
+ }
+
+ public void endRecord(String tag) throws IOException {
+ }
+
public Index startVector(String tag) throws IOException {
int len = readInt(tag);
if (len == -1) {
- return null;
+ return null;
}
- return new BinaryIndex(len);
+ return new BinaryIndex(len);
+ }
+
+ public void endVector(String tag) throws IOException {
}
-
- public void endVector(String tag) throws IOException {}
-
+
public Index startMap(String tag) throws IOException {
return new BinaryIndex(readInt(tag));
}
-
- public void endMap(String tag) throws IOException {}
+
+ public void endMap(String tag) throws IOException {
+ }
// Since this is a rough sanity check, add some padding to maxBuffer to
// make up for extra fields, etc. (otherwise e.g. clients may be able to
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/BinaryOutputArchive.java b/zookeeper-jute/src/main/java/org/apache/jute/BinaryOutputArchive.java
index a8f313c..4752d84 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/BinaryOutputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/BinaryOutputArchive.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,47 +33,50 @@ public class BinaryOutputArchive implements OutputArchive {
private ByteBuffer bb = ByteBuffer.allocate(1024);
private DataOutput out;
-
+
public static BinaryOutputArchive getArchive(OutputStream strm) {
return new BinaryOutputArchive(new DataOutputStream(strm));
}
-
- /** Creates a new instance of BinaryOutputArchive */
+
+ /**
+ * Creates a new instance of BinaryOutputArchive.
+ */
public BinaryOutputArchive(DataOutput out) {
this.out = out;
}
-
+
public void writeByte(byte b, String tag) throws IOException {
out.writeByte(b);
}
-
+
public void writeBool(boolean b, String tag) throws IOException {
out.writeBoolean(b);
}
-
+
public void writeInt(int i, String tag) throws IOException {
out.writeInt(i);
}
-
+
public void writeLong(long l, String tag) throws IOException {
out.writeLong(l);
}
-
+
public void writeFloat(float f, String tag) throws IOException {
out.writeFloat(f);
}
-
+
public void writeDouble(double d, String tag) throws IOException {
out.writeDouble(d);
}
-
+
/**
- * create our own char encoder to utf8. This is faster
+ * create our own char encoder to utf8. This is faster
* then string.getbytes(UTF8).
+ *
* @param s the string to encode into utf8
* @return utf8 byte sequence.
*/
- final private ByteBuffer stringToByteBuffer(CharSequence s) {
+ private ByteBuffer stringToByteBuffer(CharSequence s) {
bb.clear();
final int len = s.length();
for (int i = 0; i < len; i++) {
@@ -109,38 +112,42 @@ public class BinaryOutputArchive implements OutputArchive {
out.write(bb.array(), bb.position(), bb.limit());
}
- public void writeBuffer(byte barr[], String tag)
- throws IOException {
- if (barr == null) {
- out.writeInt(-1);
- return;
- }
- out.writeInt(barr.length);
+ public void writeBuffer(byte[] barr, String tag)
+ throws IOException {
+ if (barr == null) {
+ out.writeInt(-1);
+ return;
+ }
+ out.writeInt(barr.length);
out.write(barr);
}
-
+
public void writeRecord(Record r, String tag) throws IOException {
r.serialize(this, tag);
}
-
- public void startRecord(Record r, String tag) throws IOException {}
-
- public void endRecord(Record r, String tag) throws IOException {}
-
+
+ public void startRecord(Record r, String tag) throws IOException {
+ }
+
+ public void endRecord(Record r, String tag) throws IOException {
+ }
+
public void startVector(List<?> v, String tag) throws IOException {
- if (v == null) {
- writeInt(-1, tag);
- return;
- }
+ if (v == null) {
+ writeInt(-1, tag);
+ return;
+ }
writeInt(v.size(), tag);
}
-
- public void endVector(List<?> v, String tag) throws IOException {}
- public void startMap(TreeMap<?,?> v, String tag) throws IOException {
+ public void endVector(List<?> v, String tag) throws IOException {
+ }
+
+ public void startMap(TreeMap<?, ?> v, String tag) throws IOException {
writeInt(v.size(), tag);
}
-
- public void endMap(TreeMap<?,?> v, String tag) throws IOException {}
-
+
+ public void endMap(TreeMap<?, ?> v, String tag) throws IOException {
+ }
+
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/Index.java b/zookeeper-jute/src/main/java/org/apache/jute/Index.java
index 258c6b5..dfd39a3 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/Index.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/Index.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,6 +33,6 @@ package org.apache.jute;
*
*/
public interface Index {
- public boolean done();
- public void incr();
+ boolean done();
+ void incr();
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/InputArchive.java b/zookeeper-jute/src/main/java/org/apache/jute/InputArchive.java
index b19ab3d..1010abe 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/InputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/InputArchive.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -25,19 +25,35 @@ import java.io.IOException;
*
*/
public interface InputArchive {
- public byte readByte(String tag) throws IOException;
- public boolean readBool(String tag) throws IOException;
- public int readInt(String tag) throws IOException;
- public long readLong(String tag) throws IOException;
- public float readFloat(String tag) throws IOException;
- public double readDouble(String tag) throws IOException;
- public String readString(String tag) throws IOException;
- public byte[] readBuffer(String tag) throws IOException;
- public void readRecord(Record r, String tag) throws IOException;
- public void startRecord(String tag) throws IOException;
- public void endRecord(String tag) throws IOException;
- public Index startVector(String tag) throws IOException;
- public void endVector(String tag) throws IOException;
- public Index startMap(String tag) throws IOException;
- public void endMap(String tag) throws IOException;
+
+ byte readByte(String tag) throws IOException;
+
+ boolean readBool(String tag) throws IOException;
+
+ int readInt(String tag) throws IOException;
+
+ long readLong(String tag) throws IOException;
+
+ float readFloat(String tag) throws IOException;
+
+ double readDouble(String tag) throws IOException;
+
+ String readString(String tag) throws IOException;
+
+ byte[] readBuffer(String tag) throws IOException;
+
+ void readRecord(Record r, String tag) throws IOException;
+
+ void startRecord(String tag) throws IOException;
+
+ void endRecord(String tag) throws IOException;
+
+ Index startVector(String tag) throws IOException;
+
+ void endVector(String tag) throws IOException;
+
+ Index startMap(String tag) throws IOException;
+
+ void endMap(String tag) throws IOException;
+
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/OutputArchive.java b/zookeeper-jute/src/main/java/org/apache/jute/OutputArchive.java
index 5f78ea9..b076ca1 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/OutputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/OutputArchive.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -27,21 +27,36 @@ import java.util.TreeMap;
*
*/
public interface OutputArchive {
- public void writeByte(byte b, String tag) throws IOException;
- public void writeBool(boolean b, String tag) throws IOException;
- public void writeInt(int i, String tag) throws IOException;
- public void writeLong(long l, String tag) throws IOException;
- public void writeFloat(float f, String tag) throws IOException;
- public void writeDouble(double d, String tag) throws IOException;
- public void writeString(String s, String tag) throws IOException;
- public void writeBuffer(byte buf[], String tag)
- throws IOException;
- public void writeRecord(Record r, String tag) throws IOException;
- public void startRecord(Record r, String tag) throws IOException;
- public void endRecord(Record r, String tag) throws IOException;
- public void startVector(List<?> v, String tag) throws IOException;
- public void endVector(List<?> v, String tag) throws IOException;
- public void startMap(TreeMap<?,?> v, String tag) throws IOException;
- public void endMap(TreeMap<?,?> v, String tag) throws IOException;
+
+ void writeByte(byte b, String tag) throws IOException;
+
+ void writeBool(boolean b, String tag) throws IOException;
+
+ void writeInt(int i, String tag) throws IOException;
+
+ void writeLong(long l, String tag) throws IOException;
+
+ void writeFloat(float f, String tag) throws IOException;
+
+ void writeDouble(double d, String tag) throws IOException;
+
+ void writeString(String s, String tag) throws IOException;
+
+ void writeBuffer(byte[] buf, String tag)
+ throws IOException;
+
+ void writeRecord(Record r, String tag) throws IOException;
+
+ void startRecord(Record r, String tag) throws IOException;
+
+ void endRecord(Record r, String tag) throws IOException;
+
+ void startVector(List<?> v, String tag) throws IOException;
+
+ void endVector(List<?> v, String tag) throws IOException;
+
+ void startMap(TreeMap<?, ?> v, String tag) throws IOException;
+
+ void endMap(TreeMap<?, ?> v, String tag) throws IOException;
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/Record.java b/zookeeper-jute/src/main/java/org/apache/jute/Record.java
index d955280..cdec418 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/Record.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/Record.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -18,18 +18,14 @@
package org.apache.jute;
-import org.apache.yetus.audience.InterfaceAudience;
-
import java.io.IOException;
+import org.apache.yetus.audience.InterfaceAudience;
/**
* Interface that is implemented by generated classes.
- *
*/
@InterfaceAudience.Public
public interface Record {
- public void serialize(OutputArchive archive, String tag)
- throws IOException;
- public void deserialize(InputArchive archive, String tag)
- throws IOException;
+ void serialize(OutputArchive archive, String tag) throws IOException;
+ void deserialize(InputArchive archive, String tag) throws IOException;
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/RecordReader.java b/zookeeper-jute/src/main/java/org/apache/jute/RecordReader.java
index 75507bc..2c91d2e 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/RecordReader.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/RecordReader.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -27,61 +27,57 @@ import java.util.HashMap;
/**
* Front-end interface to deserializers. Also acts as a factory
* for deserializers.
- *
*/
public class RecordReader {
-
+
+ private static HashMap<String, Method> archiveFactory;
+
private InputArchive archive;
- static private HashMap<String, Method> archiveFactory;
-
static {
- archiveFactory = new HashMap<String, Method>();
+ archiveFactory = new HashMap<>();
try {
- archiveFactory.put("binary",
- BinaryInputArchive.class.getDeclaredMethod(
- "getArchive", new Class[]{ InputStream.class } ));
- } catch (SecurityException ex) {
- ex.printStackTrace();
- } catch (NoSuchMethodException ex) {
+ archiveFactory.put(
+ "binary",
+ BinaryInputArchive.class.getDeclaredMethod("getArchive", InputStream.class));
+ } catch (SecurityException | NoSuchMethodException ex) {
ex.printStackTrace();
}
}
-
- static private InputArchive createArchive(InputStream in, String format)
- throws IOException {
- Method factory = (Method) archiveFactory.get(format);
+
+ private static InputArchive createArchive(InputStream in, String format) {
+ Method factory = archiveFactory.get(format);
+
if (factory != null) {
- Object[] params = { in };
+ Object[] params = {in};
try {
return (InputArchive) factory.invoke(null, params);
- } catch (IllegalArgumentException ex) {
- ex.printStackTrace();
- } catch (InvocationTargetException ex) {
- ex.printStackTrace();
- } catch (IllegalAccessException ex) {
+ } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
+
return null;
}
+
/**
* Creates a new instance of RecordReader.
- * @param in Stream from which to deserialize a record
+ *
+ * @param in Stream from which to deserialize a record
* @param format Deserialization format ("binary", "xml", or "csv")
*/
- public RecordReader(InputStream in, String format)
- throws IOException {
+ public RecordReader(InputStream in, String format) {
archive = createArchive(in, format);
}
-
+
/**
- * Deserialize a record
+ * Deserialize a record.
+ *
* @param r Record to be deserialized
*/
public void read(Record r) throws IOException {
r.deserialize(archive, "");
}
-
+
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/RecordWriter.java b/zookeeper-jute/src/main/java/org/apache/jute/RecordWriter.java
index a5658b7..259a683 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/RecordWriter.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/RecordWriter.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -26,59 +26,53 @@ import java.util.HashMap;
/**
* Front-end for serializers. Also serves as a factory for serializers.
- *
*/
public class RecordWriter {
-
+
private OutputArchive archive;
-
+
static HashMap<String, Method> constructFactory() {
HashMap<String, Method> factory = new HashMap<String, Method>();
try {
- factory.put("binary",
- BinaryOutputArchive.class.getDeclaredMethod(
- "getArchive", new Class[]{ OutputStream.class }));
- } catch (SecurityException ex) {
- ex.printStackTrace();
- } catch (NoSuchMethodException ex) {
+ factory.put(
+ "binary",
+ BinaryOutputArchive.class.getDeclaredMethod("getArchive", OutputStream.class));
+ } catch (SecurityException | NoSuchMethodException ex) {
ex.printStackTrace();
}
+
return factory;
}
-
- static private HashMap<String, Method> archiveFactory = constructFactory();
-
- static private OutputArchive createArchive(OutputStream out,
- String format)
- throws IOException {
- Method factory = (Method) archiveFactory.get(format);
+
+ private static HashMap<String, Method> archiveFactory = constructFactory();
+
+ private static OutputArchive createArchive(OutputStream out, String format) {
+ Method factory = archiveFactory.get(format);
if (factory != null) {
- Object[] params = { out };
+ Object[] params = {out};
try {
return (OutputArchive) factory.invoke(null, params);
- } catch (IllegalArgumentException ex) {
- ex.printStackTrace();
- } catch (InvocationTargetException ex) {
- ex.printStackTrace();
- } catch (IllegalAccessException ex) {
+ } catch (IllegalArgumentException | InvocationTargetException | IllegalAccessException ex) {
ex.printStackTrace();
}
}
return null;
}
+
/**
- * Creates a new instance of RecordWriter
- * @param out Output stream where the records will be serialized
+ * Creates a new instance of RecordWriter.
+ *
+ * @param out Output stream where the records will be serialized
* @param format Serialization format ("binary", "xml", or "csv")
*/
- public RecordWriter(OutputStream out, String format)
- throws IOException {
+ public RecordWriter(OutputStream out, String format) {
archive = createArchive(out, format);
}
-
+
/**
- * Serialize a record
+ * Serialize a record.
+ *
* @param r record to be serialized
*/
public void write(Record r) throws IOException {
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java b/zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java
index 0fb0c6f..a144011 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/ToStringOutputArchive.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -35,74 +35,75 @@ public class ToStringOutputArchive implements OutputArchive {
private void throwExceptionOnError(String tag) throws IOException {
if (stream.checkError()) {
- throw new IOException("Error serializing "+tag);
+ throw new IOException("Error serializing " + tag);
}
}
-
+
private void printCommaUnlessFirst() {
if (!isFirst) {
stream.print(",");
}
isFirst = false;
}
-
- /** Creates a new instance of ToStringOutputArchive */
- public ToStringOutputArchive(OutputStream out)
- throws UnsupportedEncodingException {
+
+ /**
+ * Creates a new instance of ToStringOutputArchive.
+ */
+ public ToStringOutputArchive(OutputStream out) throws UnsupportedEncodingException {
stream = new PrintStream(out, true, "UTF-8");
}
-
+
public void writeByte(byte b, String tag) throws IOException {
- writeLong((long)b, tag);
+ writeLong((long) b, tag);
}
-
+
public void writeBool(boolean b, String tag) throws IOException {
printCommaUnlessFirst();
String val = b ? "T" : "F";
stream.print(val);
throwExceptionOnError(tag);
}
-
+
public void writeInt(int i, String tag) throws IOException {
- writeLong((long)i, tag);
+ writeLong((long) i, tag);
}
-
+
public void writeLong(long l, String tag) throws IOException {
printCommaUnlessFirst();
stream.print(l);
throwExceptionOnError(tag);
}
-
+
public void writeFloat(float f, String tag) throws IOException {
- writeDouble((double)f, tag);
+ writeDouble((double) f, tag);
}
-
+
public void writeDouble(double d, String tag) throws IOException {
printCommaUnlessFirst();
stream.print(d);
throwExceptionOnError(tag);
}
-
+
public void writeString(String s, String tag) throws IOException {
printCommaUnlessFirst();
stream.print(escapeString(s));
throwExceptionOnError(tag);
}
-
+
public void writeBuffer(byte[] buf, String tag)
- throws IOException {
+ throws IOException {
printCommaUnlessFirst();
stream.print(escapeBuffer(buf));
throwExceptionOnError(tag);
}
-
+
public void writeRecord(Record r, String tag) throws IOException {
if (r == null) {
return;
}
r.serialize(this, tag);
}
-
+
public void startRecord(Record r, String tag) throws IOException {
if (tag != null && !"".equals(tag)) {
printCommaUnlessFirst();
@@ -110,7 +111,7 @@ public class ToStringOutputArchive implements OutputArchive {
isFirst = true;
}
}
-
+
public void endRecord(Record r, String tag) throws IOException {
if (tag == null || "".equals(tag)) {
stream.print("\n");
@@ -120,25 +121,25 @@ public class ToStringOutputArchive implements OutputArchive {
isFirst = false;
}
}
-
+
public void startVector(List<?> v, String tag) throws IOException {
printCommaUnlessFirst();
stream.print("v{");
isFirst = true;
}
-
+
public void endVector(List<?> v, String tag) throws IOException {
stream.print("}");
isFirst = false;
}
-
- public void startMap(TreeMap<?,?> v, String tag) throws IOException {
+
+ public void startMap(TreeMap<?, ?> v, String tag) throws IOException {
printCommaUnlessFirst();
stream.print("m{");
isFirst = true;
}
-
- public void endMap(TreeMap<?,?> v, String tag) throws IOException {
+
+ public void endMap(TreeMap<?, ?> v, String tag) throws IOException {
stream.print("}");
isFirst = false;
}
@@ -153,7 +154,7 @@ public class ToStringOutputArchive implements OutputArchive {
int len = s.length();
for (int i = 0; i < len; i++) {
char c = s.charAt(i);
- switch(c) {
+ switch (c) {
case '\0':
sb.append("%00");
break;
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/Utils.java b/zookeeper-jute/src/main/java/org/apache/jute/Utils.java
index d4551e7..cf14f67 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/Utils.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/Utils.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,12 +22,14 @@ package org.apache.jute;
* Various utility functions for Hadoop record I/O runtime.
*/
public class Utils {
-
- /** Cannot create a new instance of Utils */
+
+ /**
+ * Cannot create a new instance of Utils.
+ */
private Utils() {
super();
}
-
+
/**
* equals function that actually compares two buffers.
*
@@ -35,12 +37,17 @@ public class Utils {
* @param twoarray Second buffer
* @return true if one and two contain exactly the same content, else false.
*/
- public static boolean bufEquals(byte onearray[], byte twoarray[] ) {
- if (onearray == twoarray) return true;
+ public static boolean bufEquals(byte[] onearray, byte[] twoarray) {
+ if (onearray == twoarray) {
+ return true;
+ }
+
boolean ret = (onearray.length == twoarray.length);
+
if (!ret) {
return ret;
}
+
for (int idx = 0; idx < onearray.length; idx++) {
if (onearray[idx] != twoarray[idx]) {
return false;
@@ -49,11 +56,11 @@ public class Utils {
return true;
}
- public static int compareBytes(byte b1[], int off1, int len1, byte b2[], int off2, int len2) {
+ public static int compareBytes(byte[] b1, int off1, int len1, byte[] b2, int off2, int len2) {
int i;
- for(i=0; i < len1 && i < len2; i++) {
- if (b1[off1+i] != b2[off2+i]) {
- return b1[off1+i] < b2[off2+i] ? -1 : 1;
+ for (i = 0; i < len1 && i < len2; i++) {
+ if (b1[off1 + i] != b2[off2 + i]) {
+ return b1[off1 + i] < b2[off2 + i] ? -1 : 1;
}
}
if (len1 != len2) {
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CGenerator.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CGenerator.java
index ef5dd54..5dddcfb 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CGenerator.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CGenerator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,16 +33,16 @@ class CGenerator {
private List<JRecord> mRecList;
private final File outputDirectory;
- /** Creates a new instance of CppGenerator
+ /**
+ * Creates a new instance of CppGenerator.
*
- * @param name possibly full pathname to the file
- * @param ilist included files (as JFile)
- * @param rlist List of records defined within this file
+ * @param name possibly full pathname to the file
+ * @param ilist included files (as JFile)
+ * @param rlist List of records defined within this file
* @param outputDirectory
*/
CGenerator(String name, List<JFile> ilist, List<JRecord> rlist,
- File outputDirectory)
- {
+ File outputDirectory) {
this.outputDirectory = outputDirectory;
mName = (new File(name)).getName();
mInclFiles = ilist;
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CSharpGenerator.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CSharpGenerator.java
index f59cdb2..f698ff3 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CSharpGenerator.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CSharpGenerator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,20 +22,23 @@ import java.io.File;
import java.io.IOException;
import java.util.List;
+/**
+ *
+ */
public class CSharpGenerator {
private List<JRecord> mRecList;
private final File outputDirectory;
- /** Creates a new instance of CSharpGenerator
+ /**
+ * Creates a new instance of CSharpGenerator.
*
- * @param name possibly full pathname to the file
- * @param ilist included files (as JFile)
- * @param rlist List of records defined within this file
+ * @param name possibly full pathname to the file
+ * @param ilist included files (as JFile)
+ * @param rlist List of records defined within this file
* @param outputDirectory
*/
CSharpGenerator(String name, List<JFile> ilist, List<JRecord> rlist,
- File outputDirectory)
- {
+ File outputDirectory) {
this.outputDirectory = outputDirectory;
mRecList = rlist;
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CppGenerator.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CppGenerator.java
index 3f5ccb3..8376654 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/CppGenerator.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/CppGenerator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -33,16 +33,16 @@ class CppGenerator {
private List<JRecord> mRecList;
private final File outputDirectory;
- /** Creates a new instance of CppGenerator
+ /**
+ * Creates a new instance of CppGenerator.
*
- * @param name possibly full pathname to the file
- * @param ilist included files (as JFile)
- * @param rlist List of records defined within this file
+ * @param name possibly full pathname to the file
+ * @param ilist included files (as JFile)
+ * @param rlist List of records defined within this file
* @param outputDirectory
*/
CppGenerator(String name, List<JFile> ilist, List<JRecord> rlist,
- File outputDirectory)
- {
+ File outputDirectory) {
this.outputDirectory = outputDirectory;
mName = (new File(name)).getName();
mInclFiles = ilist;
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBoolean.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBoolean.java
index b45b161..2d10ec4 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBoolean.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBoolean.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,29 +22,31 @@ package org.apache.jute.compiler;
*
*/
public class JBoolean extends JType {
-
- /** Creates a new instance of JBoolean */
+
+ /**
+ * Creates a new instance of JBoolean.
+ */
public JBoolean() {
super("int32_t", "bool", "bool", "boolean", "Bool", "Boolean", "bool", "toBoolean");
}
-
+
public String getSignature() {
return "z";
}
-
+
public String genJavaCompareTo(String fname) {
- return " ret = ("+fname+" == peer."+fname+")? 0 : ("+fname+"?1:-1);\n";
+ return " ret = (" + fname + " == peer." + fname + ")? 0 : (" + fname + "?1:-1);\n";
}
-
+
public String genJavaHashCode(String fname) {
- return " ret = ("+fname+")?0:1;\n";
+ return " ret = (" + fname + ")?0:1;\n";
}
String genCsharpHashCode(String fname) {
- return " ret = ("+capitalize(fname)+")?0:1;\n";
+ return " ret = (" + capitalize(fname) + ")?0:1;\n";
}
String genCsharpCompareTo(String name) {
- return " ret = ("+capitalize(name)+" == peer."+capitalize(name)+")? 0 : ("+capitalize(name)+"?1:-1);\n";
+ return " ret = (" + capitalize(name) + " == peer." + capitalize(name) + ")? 0 : (" + capitalize(name) + "?1:-1);\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBuffer.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBuffer.java
index b2be5bd..92274ed 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBuffer.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JBuffer.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,85 +22,88 @@ package org.apache.jute.compiler;
*
*/
public class JBuffer extends JCompType {
-
- /** Creates a new instance of JBuffer */
+
+ /**
+ * Creates a new instance of JBuffer.
+ */
public JBuffer() {
super("struct buffer", " ::std::string", "byte[]", "byte[]", "Buffer", "byte[]", "byte[]");
}
-
+
public String genCppGetSet(String fname, int fIdx) {
- String cgetFunc = " virtual const "+getCppType()+"& get"+fname+"() const {\n";
- cgetFunc += " return m"+fname+";\n";
+ String cgetFunc = " virtual const " + getCppType() + "& get" + fname + "() const {\n";
+ cgetFunc += " return m" + fname + ";\n";
cgetFunc += " }\n";
- String getFunc = " virtual "+getCppType()+"& get"+fname+"() {\n";
- getFunc += " bs_.set("+fIdx+");return m"+fname+";\n";
+ String getFunc = " virtual " + getCppType() + "& get" + fname + "() {\n";
+ getFunc += " bs_.set(" + fIdx + ");return m" + fname + ";\n";
getFunc += " }\n";
return cgetFunc + getFunc;
}
-
+
public String getSignature() {
return "B";
}
-
+
public String genJavaReadWrapper(String fname, String tag, boolean decl) {
String ret = "";
if (decl) {
- ret = " byte[] "+fname+";\n";
+ ret = " byte[] " + fname + ";\n";
}
- return ret + " "+fname+"=a_.readBuffer(\""+tag+"\");\n";
+ return ret + " " + fname + "=a_.readBuffer(\"" + tag + "\");\n";
}
-
+
public String genJavaWriteWrapper(String fname, String tag) {
- return " a_.writeBuffer("+fname+",\""+tag+"\");\n";
+ return " a_.writeBuffer(" + fname + ",\"" + tag + "\");\n";
}
-
+
public String genJavaCompareTo(String fname, String other) {
- StringBuilder sb = new StringBuilder();
- sb.append(" {\n");
- sb.append(" byte[] my = "+fname+";\n");
- sb.append(" byte[] ur = "+other+";\n");
- sb.append(" ret = org.apache.jute.Utils.compareBytes(my,0,my.length,ur,0,ur.length);\n");
- sb.append(" }\n");
- return sb.toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append(" {\n");
+ sb.append(" byte[] my = " + fname + ";\n");
+ sb.append(" byte[] ur = " + other + ";\n");
+ sb.append(" ret = org.apache.jute.Utils.compareBytes(my,0,my.length,ur,0,ur.length);\n");
+ sb.append(" }\n");
+ return sb.toString();
}
-
+
public String genJavaCompareTo(String fname) {
- return genJavaCompareTo(fname, "peer."+fname);
+ return genJavaCompareTo(fname, "peer." + fname);
}
+
public String genJavaCompareToWrapper(String fname, String other) {
- return " "+genJavaCompareTo(fname, other);
+ return " " + genJavaCompareTo(fname, other);
}
-
+
public String genJavaEquals(String fname, String peer) {
- return " ret = org.apache.jute.Utils.bufEquals("+fname+","+peer+");\n";
+ return " ret = org.apache.jute.Utils.bufEquals(" + fname + "," + peer + ");\n";
}
-
+
public String genJavaHashCode(String fname) {
- return " ret = java.util.Arrays.toString("+fname+").hashCode();\n";
+ return " ret = java.util.Arrays.toString(" + fname + ").hashCode();\n";
}
-
+
public String genJavaSlurpBytes(String b, String s, String l) {
- StringBuilder sb = new StringBuilder();
- sb.append(" {\n");
- sb.append(" int i = org.apache.jute.Utils.readVInt("+b+", "+s+");\n");
- sb.append(" int z = WritableUtils.getVIntSize(i);\n");
- sb.append(" "+s+" += z+i; "+l+" -= (z+i);\n");
- sb.append(" }\n");
- return sb.toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append(" {\n");
+ sb.append(" int i = org.apache.jute.Utils.readVInt(" + b + ", " + s + ");\n");
+ sb.append(" int z = WritableUtils.getVIntSize(i);\n");
+ sb.append(" " + s + " += z+i; " + l + " -= (z+i);\n");
+ sb.append(" }\n");
+ return sb.toString();
}
-
+
public String genJavaCompareBytes() {
- StringBuilder sb = new StringBuilder();
- sb.append(" {\n");
- sb.append(" int i1 = org.apache.jute.Utils.readVInt(b1, s1);\n");
- sb.append(" int i2 = org.apache.jute.Utils.readVInt(b2, s2);\n");
- sb.append(" int z1 = WritableUtils.getVIntSize(i1);\n");
- sb.append(" int z2 = WritableUtils.getVIntSize(i2);\n");
- sb.append(" s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
- sb.append(" int r1 = org.apache.jute.Utils.compareBytes(b1,s1,l1,b2,s2,l2);\n");
- sb.append(" if (r1 != 0) { return (r1<0)?-1:0; }\n");
- sb.append(" s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n");
- sb.append(" }\n");
- return sb.toString();
+ StringBuilder sb = new StringBuilder();
+ sb.append(" {\n");
+ sb.append(" int i1 = org.apache.jute.Utils.readVInt(b1, s1);\n");
+ sb.append(" int i2 = org.apache.jute.Utils.readVInt(b2, s2);\n");
+ sb.append(" int z1 = WritableUtils.getVIntSize(i1);\n");
+ sb.append(" int z2 = WritableUtils.getVIntSize(i2);\n");
+ sb.append(" s1+=z1; s2+=z2; l1-=z1; l2-=z2;\n");
+ sb.append(" int r1 = org.apache.jute.Utils.compareBytes(b1,s1,l1,b2,s2,l2);\n");
+ sb.append(" if (r1 != 0) { return (r1<0)?-1:0; }\n");
+ sb.append(" s1+=i1; s2+=i2; l1-=i1; l1-=i2;\n");
+ sb.append(" }\n");
+ return sb.toString();
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JByte.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JByte.java
index 4b1cea4..cc8a737 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JByte.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JByte.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,12 +22,14 @@ package org.apache.jute.compiler;
*
*/
public class JByte extends JType {
-
- /** Creates a new instance of JByte */
+
+ /**
+ * Creates a new instance of JByte.
+ */
public JByte() {
super("char", "int8_t", "byte", "byte", "Byte", "Byte", "byte", "toByte");
}
-
+
public String getSignature() {
return "b";
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JCompType.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JCompType.java
index d98658f..ebe95a2 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JCompType.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JCompType.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -23,44 +23,54 @@ package org.apache.jute.compiler;
* buffer, vector, map, and record.
*/
abstract class JCompType extends JType {
-
- /** Creates a new instance of JCompType */
- JCompType(String cType, String cppType, String csharpType, String javaType, String suffix, String wrapper, String csharpWrapper) {
+
+ /**
+ * Creates a new instance of JCompType.
+ */
+ JCompType(
+ String cType,
+ String cppType,
+ String csharpType,
+ String javaType,
+ String suffix,
+ String wrapper,
+ String csharpWrapper
+ ) {
super(cType, cppType, csharpType, javaType, suffix, wrapper, csharpWrapper, null);
}
-
+
String genCppGetSet(String fname, int fIdx) {
- String cgetFunc = " virtual const "+getCppType()+"& get"+fname+"() const {\n";
- cgetFunc += " return m"+fname+";\n";
+ String cgetFunc = " virtual const " + getCppType() + "& get" + fname + "() const {\n";
+ cgetFunc += " return m" + fname + ";\n";
cgetFunc += " }\n";
- String getFunc = " virtual "+getCppType()+"& get"+fname+"() {\n";
- getFunc += " bs_.set("+fIdx+");return m"+fname+";\n";
+ String getFunc = " virtual " + getCppType() + "& get" + fname + "() {\n";
+ getFunc += " bs_.set(" + fIdx + ");return m" + fname + ";\n";
getFunc += " }\n";
return cgetFunc + getFunc;
}
-
+
String genJavaCompareTo(String fname) {
- return " ret = "+fname+".compareTo(peer."+fname+");\n";
+ return " ret = " + fname + ".compareTo(peer." + fname + ");\n";
}
-
+
String genJavaEquals(String fname, String peer) {
- return " ret = "+fname+".equals("+peer+");\n";
+ return " ret = " + fname + ".equals(" + peer + ");\n";
}
-
+
String genJavaHashCode(String fname) {
- return " ret = "+fname+".hashCode();\n";
+ return " ret = " + fname + ".hashCode();\n";
}
String genCsharpHashCode(String fname) {
- return " ret = "+capitalize(fname)+".GetHashCode();\n";
+ return " ret = " + capitalize(fname) + ".GetHashCode();\n";
}
String genCsharpEquals(String name, String peer) {
String[] peerSplit = peer.split("\\.");
- return " ret = "+capitalize(name)+".Equals("+peerSplit[0] + "." + capitalize(peerSplit[1]) + ");\n";
+ return " ret = " + capitalize(name) + ".Equals(" + peerSplit[0] + "." + capitalize(peerSplit[1]) + ");\n";
}
String genCsharpCompareTo(String name) {
- return " ret = "+capitalize(name)+".CompareTo(peer."+capitalize(name)+");\n";
+ return " ret = " + capitalize(name) + ".CompareTo(peer." + capitalize(name) + ");\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JDouble.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JDouble.java
index 21f9cc8..4e22ff3 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JDouble.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JDouble.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,19 +22,21 @@ package org.apache.jute.compiler;
*
*/
public class JDouble extends JType {
-
- /** Creates a new instance of JDouble */
+
+ /**
+ * Creates a new instance of JDouble.
+ */
public JDouble() {
super("double", "double", "double", "double", "Double", "Double", "double", "toDouble");
}
-
+
public String getSignature() {
return "d";
}
-
+
public String genJavaHashCode(String fname) {
- String tmp = "Double.doubleToLongBits("+fname+")";
- return " ret = (int)("+tmp+"^("+tmp+">>>32));\n";
+ String tmp = "Double.doubleToLongBits(" + fname + ")";
+ return " ret = (int)(" + tmp + "^(" + tmp + ">>>32));\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JField.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JField.java
index 50f9fc9..395c0b6 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JField.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JField.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -24,25 +24,26 @@ package org.apache.jute.compiler;
public class JField {
private JType mType;
private String mName;
+
/**
- * Creates a new instance of JField
+ * Creates a new instance of JField.
*/
public JField(JType type, String name) {
mType = type;
mName = name;
}
-
+
public String getSignature() {
return mType.getSignature();
}
-
+
public String genCppDecl() {
return mType.genCppDecl(mName);
}
-
- public String genCDecl() {
- return mType.genCDecl(mName);
- }
+
+ public String genCDecl() {
+ return mType.genCDecl(mName);
+ }
public String genCsharpDecl() {
return mType.genCsharpDecl(mName);
@@ -51,15 +52,15 @@ public class JField {
public String genCsharpConstructorParam(String fname) {
return mType.genCsharpConstructorParam(fname);
}
-
+
public String genJavaDecl() {
return mType.genJavaDecl(mName);
}
-
+
public String genJavaConstructorParam(String fname) {
return mType.genJavaConstructorParam(fname);
}
-
+
public String getName() {
return mName;
}
@@ -67,15 +68,15 @@ public class JField {
public String getCsharpName() {
return "Id".equals(mName) ? "ZKId" : mName;
}
-
+
public String getTag() {
return mName;
}
-
+
public JType getType() {
return mType;
}
-
+
public String genCppGetSet(int fIdx) {
return mType.genCppGetSet(mName, fIdx);
}
@@ -101,34 +102,34 @@ public class JField {
}
public String genCsharpEquals() {
- return mType.genCsharpEquals(getCsharpName(), "peer."+getCsharpName());
+ return mType.genCsharpEquals(getCsharpName(), "peer." + getCsharpName());
}
public String genCsharpHashCode() {
return mType.genCsharpHashCode(getCsharpName());
}
-
+
public String genJavaGetSet(int fIdx) {
return mType.genJavaGetSet(mName, fIdx);
}
-
+
public String genJavaWriteMethodName() {
return mType.genJavaWriteMethod(getName(), getTag());
}
-
+
public String genJavaReadMethodName() {
return mType.genJavaReadMethod(getName(), getTag());
}
-
+
public String genJavaCompareTo() {
return mType.genJavaCompareTo(getName());
}
-
+
public String genJavaEquals() {
- return mType.genJavaEquals(getName(), "peer."+getName());
+ return mType.genJavaEquals(getName(), "peer." + getName());
}
-
+
public String genJavaHashCode() {
return mType.genJavaHashCode(getName());
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFile.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFile.java
index ae59490..1d5ed41 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFile.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFile.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -27,41 +27,43 @@ import java.util.List;
* Container for the Hadoop Record DDL.
* The main components of the file are filename, list of included files,
* and records defined in that file.
- *
*/
public class JFile {
-
+
private String mName;
private List<JFile> mInclFiles;
private List<JRecord> mRecords;
-
- /** Creates a new instance of JFile
+
+ /**
+ * Creates a new instance of JFile.
*
- * @param name possibly full pathname to the file
+ * @param name possibly full pathname to the file
* @param inclFiles included files (as JFile)
- * @param recList List of records defined within this file
+ * @param recList List of records defined within this file
*/
public JFile(String name, ArrayList<JFile> inclFiles,
- ArrayList<JRecord> recList)
- {
+ ArrayList<JRecord> recList) {
mName = name;
mInclFiles = inclFiles;
mRecords = recList;
}
-
- /** Strip the other pathname components and return the basename */
+
+ /**
+ * Strip the other pathname components and return the basename.
+ */
String getName() {
int idx = mName.lastIndexOf('/');
- return (idx > 0) ? mName.substring(idx) : mName;
+ return (idx > 0) ? mName.substring(idx) : mName;
}
-
- /** Generate record code in given language. Language should be all
- * lowercase.
- * @param outputDirectory
+
+ /**
+ * Generate record code in given language. Language should be all
+ * lowercase.
+ *
+ * @param outputDirectory
*/
public void genCode(String language, File outputDirectory)
- throws IOException
- {
+ throws IOException {
if ("c++".equals(language)) {
CppGenerator gen = new CppGenerator(mName, mInclFiles, mRecords,
outputDirectory);
@@ -71,13 +73,13 @@ public class JFile {
outputDirectory);
gen.genCode();
} else if ("c".equals(language)) {
- CGenerator gen = new CGenerator(mName, mInclFiles, mRecords,
- outputDirectory);
- gen.genCode();
+ CGenerator gen = new CGenerator(mName, mInclFiles, mRecords,
+ outputDirectory);
+ gen.genCode();
} else if ("csharp".equals(language)) {
- CSharpGenerator gen = new CSharpGenerator(mName, mInclFiles, mRecords,
- outputDirectory);
- gen.genCode();
+ CSharpGenerator gen = new CSharpGenerator(mName, mInclFiles, mRecords,
+ outputDirectory);
+ gen.genCode();
} else {
throw new IOException("Cannnot recognize language:" + language);
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFloat.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFloat.java
index a4be6ec..c4452f1 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFloat.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JFloat.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,18 +22,20 @@ package org.apache.jute.compiler;
*
*/
public class JFloat extends JType {
-
- /** Creates a new instance of JFloat */
+
+ /**
+ * Creates a new instance of JFloat.
+ */
public JFloat() {
super("float", "float", "float", "float", "Float", "Float", "float", "toFloat");
}
-
+
public String getSignature() {
return "f";
}
-
+
public String genJavaHashCode(String fname) {
- return " ret = Float.floatToIntBits("+fname+");\n";
+ return " ret = Float.floatToIntBits(" + fname + ");\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JInt.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JInt.java
index 23b902e..5632911 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JInt.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JInt.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,12 +22,14 @@ package org.apache.jute.compiler;
*
*/
public class JInt extends JType {
-
- /** Creates a new instance of JInt */
+
+ /**
+ * Creates a new instance of JInt.
+ */
public JInt() {
super("int32_t", "int32_t", "int", "int", "Int", "Integer", "int", "toInt");
}
-
+
public String getSignature() {
return "i";
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JLong.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JLong.java
index 342fd9a..4563789 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JLong.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JLong.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,17 +22,19 @@ package org.apache.jute.compiler;
*
*/
public class JLong extends JType {
-
- /** Creates a new instance of JLong */
+
+ /**
+ * Creates a new instance of JLong.
+ */
public JLong() {
super("int64_t", "int64_t", "long", "long", "Long", "Long", "long", "toLong");
}
-
+
public String getSignature() {
return "l";
}
-
+
public String genJavaHashCode(String fname) {
- return " ret = (int) ("+fname+"^("+fname+">>>32));\n";
+ return " ret = (int) (" + fname + "^(" + fname + ">>>32));\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JMap.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JMap.java
index cc503be..71c9642 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JMap.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JMap.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,79 +22,89 @@ package org.apache.jute.compiler;
*
*/
public class JMap extends JCompType {
-
- static private int level = 0;
-
- static private String getLevel() { return Integer.toString(level); }
-
- static private void incrLevel() { level++; }
-
- static private void decrLevel() { level--; }
-
- static private String getId(String id) { return id+getLevel(); }
-
+
+ private static int level = 0;
+
+ private static String getLevel() {
+ return Integer.toString(level);
+ }
+
+ private static void incrLevel() {
+ level++;
+ }
+
+ private static void decrLevel() {
+ level--;
+ }
+
+ private static String getId(String id) {
+ return id + getLevel();
+ }
+
private JType mKey;
private JType mValue;
-
- /** Creates a new instance of JMap */
+
+ /**
+ * Creates a new instance of JMap.
+ */
public JMap(JType t1, JType t2) {
- super("#error", " ::std::map<"+t1.getCppType()+","+t2.getCppType()+">",
+ super("#error", " ::std::map<" + t1.getCppType() + "," + t2.getCppType() + ">",
"System.Collections.Generic.SortedDictionary<string, string>", "java.util.TreeMap", "Map", "System.Collections.Generic.SortedDictionary<string, string>", "java.util.TreeMap");
mKey = t1;
mValue = t2;
}
-
+
public String getSignature() {
- return "{" + mKey.getSignature() + mValue.getSignature() +"}";
+ return "{" + mKey.getSignature() + mValue.getSignature() + "}";
}
-
+
public String genJavaCompareTo(String fname) {
return " throw new UnsupportedOperationException(\"comparing "
- + fname + " is unimplemented\");\n";
+ + fname + " is unimplemented\");\n";
}
-
+
public String genJavaReadWrapper(String fname, String tag, boolean decl) {
StringBuilder ret = new StringBuilder("");
if (decl) {
- ret.append(" java.util.TreeMap "+fname+";\n");
+ ret.append(" java.util.TreeMap " + fname + ";\n");
}
ret.append(" {\n");
incrLevel();
- ret.append(" org.apache.jute.Index "+getId("midx")+" = a_.startMap(\""+tag+"\");\n");
- ret.append(" "+fname+"=new java.util.TreeMap();\n");
- ret.append(" for (; !"+getId("midx")+".done(); "+getId("midx")+".incr()) {\n");
- ret.append(mKey.genJavaReadWrapper(getId("k"),getId("k"),true));
- ret.append(mValue.genJavaReadWrapper(getId("v"),getId("v"),true));
- ret.append(" "+fname+".put("+getId("k")+","+getId("v")+");\n");
+ ret.append(" org.apache.jute.Index " + getId("midx") + " = a_.startMap(\"" + tag + "\");\n");
+ ret.append(" " + fname + "=new java.util.TreeMap();\n");
+ ret.append(" for (; !" + getId("midx") + ".done(); " + getId("midx") + ".incr()) {\n");
+ ret.append(mKey.genJavaReadWrapper(getId("k"), getId("k"), true));
+ ret.append(mValue.genJavaReadWrapper(getId("v"), getId("v"), true));
+ ret.append(" " + fname + ".put(" + getId("k") + "," + getId("v") + ");\n");
ret.append(" }\n");
- ret.append(" a_.endMap(\""+tag+"\");\n");
+ ret.append(" a_.endMap(\"" + tag + "\");\n");
decrLevel();
ret.append(" }\n");
return ret.toString();
}
-
+
public String genJavaReadMethod(String fname, String tag) {
return genJavaReadWrapper(fname, tag, false);
}
-
+
public String genJavaWriteWrapper(String fname, String tag) {
StringBuilder ret = new StringBuilder(" {\n");
incrLevel();
- ret.append(" a_.startMap("+fname+",\""+tag+"\");\n");
- ret.append(" java.util.Set "+getId("es")+" = "+fname+".entrySet();\n");
- ret.append(" for(java.util.Iterator "+getId("midx")+" = "+getId("es")+".iterator(); "+getId("midx")+".hasNext(); ) {\n");
- ret.append(" java.util.Map.Entry "+getId("me")+" = (java.util.Map.Entry) "+getId("midx")+".next();\n");
- ret.append(" "+mKey.getJavaWrapperType()+" "+getId("k")+" = ("+mKey.getJavaWrapperType()+") "+getId("me")+".getKey();\n");
- ret.append(" "+mValue.getJavaWrapperType()+" "+getId("v")+" = ("+mValue.getJavaWrapperType()+") "+getId("me")+".getValue();\n");
- ret.append(mKey.genJavaWriteWrapper(getId("k"),getId("k")));
- ret.append(mValue.genJavaWriteWrapper(getId("v"),getId("v")));
+ ret.append(" a_.startMap(" + fname + ",\"" + tag + "\");\n");
+ ret.append(" java.util.Set " + getId("es") + " = " + fname + ".entrySet();\n");
+ ret.append(" for(java.util.Iterator " + getId("midx") + " = " + getId("es") + ".iterator(); " + getId("midx") + ".hasNext(); ) {\n");
+ ret.append(" java.util.Map.Entry " + getId("me") + " = (java.util.Map.Entry) " + getId("midx") + ".next();\n");
+ ret.append(" " + mKey.getJavaWrapperType() + " " + getId("k") + " = (" + mKey.getJavaWrapperType() + ") " + getId("me") + ".getKey();\n");
+ ret.append(" " + mValue.getJavaWrapperType() + " " + getId("v") + " = (" + mValue.getJavaWrapperType() + ") " + getId("me") + ".getValue();\n");
+ ret.append(mKey.genJavaWriteWrapper(getId("k"), getId("k")));
+ ret.append(mValue.genJavaWriteWrapper(getId("v"), getId("v")));
ret.append(" }\n");
- ret.append(" a_.endMap("+fname+",\""+tag+"\");\n");
+ ret.append(" a_.endMap(" + fname + ",\"" + tag + "\");\n");
ret.append(" }\n");
decrLevel();
return ret.toString();
}
-
+
public String genJavaWriteMethod(String fname, String tag) {
return genJavaWriteWrapper(fname, tag);
}
@@ -102,16 +112,16 @@ public class JMap extends JCompType {
public String genCsharpWriteWrapper(String fname, int tag) {
StringBuilder ret = new StringBuilder(" {\n");
incrLevel();
- ret.append(" a_.StartMap("+fname+",\""+tag+"\");\n");
- ret.append(" java.util.Set "+getId("es")+" = "+fname+".entrySet();\n");
- ret.append(" for(java.util.Iterator "+getId("midx")+" = "+getId("es")+".iterator(); "+getId("midx")+".hasNext(); ) {\n");
- ret.append(" java.util.Map.Entry "+getId("me")+" = (java.util.Map.Entry) "+getId("midx")+".next();\n");
- ret.append(" "+mKey.getCsharpWrapperType()+" "+getId("k")+" = ("+mKey.getCsharpWrapperType()+") "+getId("me")+".getKey();\n");
- ret.append(" "+mValue.getCsharpWrapperType()+" "+getId("v")+" = ("+mValue.getCsharpWrapperType()+") "+getId("me")+".getValue();\n");
- ret.append(mKey.genCsharpWriteWrapper(getId("k"),getId("k")));
- ret.append(mValue.genCsharpWriteWrapper(getId("v"),getId("v")));
+ ret.append(" a_.StartMap(" + fname + ",\"" + tag + "\");\n");
+ ret.append(" java.util.Set " + getId("es") + " = " + fname + ".entrySet();\n");
+ ret.append(" for(java.util.Iterator " + getId("midx") + " = " + getId("es") + ".iterator(); " + getId("midx") + ".hasNext(); ) {\n");
+ ret.append(" java.util.Map.Entry " + getId("me") + " = (java.util.Map.Entry) " + getId("midx") + ".next();\n");
+ ret.append(" " + mKey.getCsharpWrapperType() + " " + getId("k") + " = (" + mKey.getCsharpWrapperType() + ") " + getId("me") + ".getKey();\n");
+ ret.append(" " + mValue.getCsharpWrapperType() + " " + getId("v") + " = (" + mValue.getCsharpWrapperType() + ") " + getId("me") + ".getValue();\n");
+ ret.append(mKey.genCsharpWriteWrapper(getId("k"), getId("k")));
+ ret.append(mValue.genCsharpWriteWrapper(getId("v"), getId("v")));
ret.append(" }\n");
- ret.append(" a_.EndMap("+fname+",\""+tag+"\");\n");
+ ret.append(" a_.EndMap(" + fname + ",\"" + tag + "\");\n");
ret.append(" }\n");
decrLevel();
return ret.toString();
@@ -124,25 +134,24 @@ public class JMap extends JCompType {
public String genCsharpReadWrapper(String fname, int tag, boolean decl) {
StringBuilder ret = new StringBuilder("");
if (decl) {
- ret.append(" System.Collections.SortedDictionary<string,string> "+capitalize(fname)+";\n");
+ ret.append(" System.Collections.SortedDictionary<string,string> " + capitalize(fname) + ";\n");
}
ret.append(" {\n");
incrLevel();
- ret.append(" Org.Apache.Jute.IIndex "+getId("midx")+" = a_.StartMap(\""+tag+"\");\n");
- ret.append(" "+fname+"= new System.Collections.SortedDictionary<string,string>();\n");
- ret.append(" for (; !"+getId("midx")+".done(); "+getId("midx")+".incr()) {\n");
- ret.append(mKey.genCsharpReadWrapper(getId("k"),getId("k"),true));
- ret.append(mValue.genCsharpReadWrapper(getId("v"),getId("v"),true));
- ret.append(" "+fname+".Add("+getId("k")+","+getId("v")+");\n");
+ ret.append(" Org.Apache.Jute.IIndex " + getId("midx") + " = a_.StartMap(\"" + tag + "\");\n");
+ ret.append(" " + fname + "= new System.Collections.SortedDictionary<string,string>();\n");
+ ret.append(" for (; !" + getId("midx") + ".done(); " + getId("midx") + ".incr()) {\n");
+ ret.append(mKey.genCsharpReadWrapper(getId("k"), getId("k"), true));
+ ret.append(mValue.genCsharpReadWrapper(getId("v"), getId("v"), true));
+ ret.append(" " + fname + ".Add(" + getId("k") + "," + getId("v") + ");\n");
ret.append(" }\n");
- ret.append(" a_.EndMap(\""+tag+"\");\n");
+ ret.append(" a_.EndMap(\"" + tag + "\");\n");
decrLevel();
ret.append(" }\n");
return ret.toString();
}
-
String genCsharpReadMethod(String fname, int tag) {
return genCsharpReadWrapper(fname, tag, false);
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JRecord.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JRecord.java
index 83ca5b8..f53399a 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JRecord.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JRecord.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -38,14 +38,14 @@ public class JRecord extends JCompType {
private List<JField> mFields;
/**
- * Creates a new instance of JRecord
+ * Creates a new instance of JRecord.
*/
public JRecord(String name, ArrayList<JField> flist) {
- super("struct " + name.substring(name.lastIndexOf('.')+1),
- name.replaceAll("\\.","::"), getCsharpFQName(name), name, "Record", name, getCsharpFQName("IRecord"));
+ super("struct " + name.substring(name.lastIndexOf('.') + 1),
+ name.replaceAll("\\.", "::"), getCsharpFQName(name), name, "Record", name, getCsharpFQName("IRecord"));
mFQName = name;
int idx = name.lastIndexOf('.');
- mName = name.substring(idx+1);
+ mName = name.substring(idx + 1);
mModule = name.substring(0, idx);
mFields = flist;
}
@@ -80,7 +80,9 @@ public class JRecord extends JCompType {
for (int i = 0; i < parts.length; i++) {
String capitalized = parts[i].substring(0, 1).toUpperCase() + parts[i].substring(1).toLowerCase();
namespace.append(capitalized);
- if (i != parts.length - 1) namespace.append(".");
+ if (i != parts.length - 1) {
+ namespace.append(".");
+ }
}
return namespace.toString();
}
@@ -92,7 +94,7 @@ public class JRecord extends JCompType {
public String getSignature() {
StringBuilder sb = new StringBuilder();
sb.append("L").append(mName).append("(");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); ) {
String s = i.next().getSignature();
sb.append(s);
}
@@ -101,7 +103,7 @@ public class JRecord extends JCompType {
}
public String genCppDecl(String fname) {
- return " "+ getCppNameSpace() + "::" + mName+" m"+fname+";\n";
+ return " " + getCppNameSpace() + "::" + mName + " m" + fname + ";\n";
}
public String genJavaReadMethod(String fname, String tag) {
@@ -111,15 +113,15 @@ public class JRecord extends JCompType {
public String genJavaReadWrapper(String fname, String tag, boolean decl) {
StringBuilder ret = new StringBuilder("");
if (decl) {
- ret.append(" "+getJavaFQName()+" "+fname+";\n");
+ ret.append(" " + getJavaFQName() + " " + fname + ";\n");
}
- ret.append(" "+fname+"= new "+getJavaFQName()+"();\n");
- ret.append(" a_.readRecord("+fname+",\""+tag+"\");\n");
+ ret.append(" " + fname + "= new " + getJavaFQName() + "();\n");
+ ret.append(" a_.readRecord(" + fname + ",\"" + tag + "\");\n");
return ret.toString();
}
public String genJavaWriteWrapper(String fname, String tag) {
- return " a_.writeRecord("+fname+",\""+tag+"\");\n";
+ return " a_.writeRecord(" + fname + ",\"" + tag + "\");\n";
}
String genCsharpReadMethod(String fname, String tag) {
@@ -130,32 +132,33 @@ public class JRecord extends JCompType {
public String genCsharpReadWrapper(String fname, String tag, boolean decl) {
StringBuilder ret = new StringBuilder("");
if (decl) {
- ret.append(" "+getCsharpFQName(mFQName)+" "+fname+";\n");
+ ret.append(" " + getCsharpFQName(mFQName) + " " + fname + ";\n");
}
- ret.append(" "+fname+"= new "+getCsharpFQName(mFQName)+"();\n");
- ret.append(" a_.ReadRecord("+fname+",\""+tag+"\");\n");
+ ret.append(" " + fname + "= new " + getCsharpFQName(mFQName) + "();\n");
+ ret.append(" a_.ReadRecord(" + fname + ",\"" + tag + "\");\n");
return ret.toString();
}
public String genCsharpWriteWrapper(String fname, String tag) {
- return " a_.WriteRecord("+fname+",\""+tag+"\");\n";
+ return " a_.WriteRecord(" + fname + ",\"" + tag + "\");\n";
}
static Map<String, String> vectorStructs = new HashMap<String, String>();
+
public void genCCode(FileWriter h, FileWriter c) throws IOException {
for (JField f : mFields) {
if (f.getType() instanceof JVector) {
JVector jv = (JVector) f.getType();
JType jvType = jv.getElementType();
- String struct_name = JVector.extractVectorName(jvType);
- if (vectorStructs.get(struct_name) == null) {
- vectorStructs.put(struct_name, struct_name);
- h.write("struct " + struct_name + " {\n int32_t count;\n" + jv.getElementType().genCDecl("*data") + "\n};\n");
- h.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v);\n");
- h.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v);\n");
- h.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int32_t len);\n");
- h.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v);\n");
- c.write("int allocate_" + struct_name + "(struct " + struct_name + " *v, int32_t len) {\n");
+ String structName = JVector.extractVectorName(jvType);
+ if (vectorStructs.get(structName) == null) {
+ vectorStructs.put(structName, structName);
+ h.write("struct " + structName + " {\n int32_t count;\n" + jv.getElementType().genCDecl("*data") + "\n};\n");
+ h.write("int serialize_" + structName + "(struct oarchive *out, const char *tag, struct " + structName + " *v);\n");
+ h.write("int deserialize_" + structName + "(struct iarchive *in, const char *tag, struct " + structName + " *v);\n");
+ h.write("int allocate_" + structName + "(struct " + structName + " *v, int32_t len);\n");
+ h.write("int deallocate_" + structName + "(struct " + structName + " *v);\n");
+ c.write("int allocate_" + structName + "(struct " + structName + " *v, int32_t len) {\n");
c.write(" if (!len) {\n");
c.write(" v->count = 0;\n");
c.write(" v->data = 0;\n");
@@ -165,7 +168,7 @@ public class JRecord extends JCompType {
c.write(" }\n");
c.write(" return 0;\n");
c.write("}\n");
- c.write("int deallocate_" + struct_name + "(struct " + struct_name + " *v) {\n");
+ c.write("int deallocate_" + structName + "(struct " + structName + " *v) {\n");
c.write(" if (v->data) {\n");
c.write(" int32_t i;\n");
c.write(" for(i=0;i<v->count; i++) {\n");
@@ -176,7 +179,7 @@ public class JRecord extends JCompType {
c.write(" }\n");
c.write(" return 0;\n");
c.write("}\n");
- c.write("int serialize_" + struct_name + "(struct oarchive *out, const char *tag, struct " + struct_name + " *v)\n");
+ c.write("int serialize_" + structName + "(struct oarchive *out, const char *tag, struct " + structName + " *v)\n");
c.write("{\n");
c.write(" int32_t count = v->count;\n");
c.write(" int rc = 0;\n");
@@ -188,7 +191,7 @@ public class JRecord extends JCompType {
c.write(" rc = rc ? rc : out->end_vector(out, tag);\n");
c.write(" return rc;\n");
c.write("}\n");
- c.write("int deserialize_" + struct_name + "(struct iarchive *in, const char *tag, struct " + struct_name + " *v)\n");
+ c.write("int deserialize_" + structName + "(struct iarchive *in, const char *tag, struct " + structName + " *v)\n");
c.write("{\n");
c.write(" int rc = 0;\n");
c.write(" int32_t i;\n");
@@ -204,16 +207,16 @@ public class JRecord extends JCompType {
}
}
}
- String rec_name = getName();
- h.write("struct " + rec_name + " {\n");
+ String recName = getName();
+ h.write("struct " + recName + " {\n");
for (JField f : mFields) {
h.write(f.genCDecl());
}
h.write("};\n");
- h.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v);\n");
- h.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v);\n");
- h.write("void deallocate_" + rec_name + "(struct " + rec_name + "*);\n");
- c.write("int serialize_" + rec_name + "(struct oarchive *out, const char *tag, struct " + rec_name + " *v)");
+ h.write("int serialize_" + recName + "(struct oarchive *out, const char *tag, struct " + recName + " *v);\n");
+ h.write("int deserialize_" + recName + "(struct iarchive *in, const char *tag, struct " + recName + "*v);\n");
+ h.write("void deallocate_" + recName + "(struct " + recName + "*);\n");
+ c.write("int serialize_" + recName + "(struct oarchive *out, const char *tag, struct " + recName + " *v)");
c.write("{\n");
c.write(" int rc;\n");
c.write(" rc = out->start_record(out, tag);\n");
@@ -223,7 +226,7 @@ public class JRecord extends JCompType {
c.write(" rc = rc ? rc : out->end_record(out, tag);\n");
c.write(" return rc;\n");
c.write("}\n");
- c.write("int deserialize_" + rec_name + "(struct iarchive *in, const char *tag, struct " + rec_name + "*v)");
+ c.write("int deserialize_" + recName + "(struct iarchive *in, const char *tag, struct " + recName + "*v)");
c.write("{\n");
c.write(" int rc;\n");
c.write(" rc = in->start_record(in, tag);\n");
@@ -233,7 +236,7 @@ public class JRecord extends JCompType {
c.write(" rc = rc ? rc : in->end_record(in, tag);\n");
c.write(" return rc;\n");
c.write("}\n");
- c.write("void deallocate_" + rec_name + "(struct " + rec_name + "*v)");
+ c.write("void deallocate_" + recName + "(struct " + recName + "*v)");
c.write("{\n");
for (JField f : mFields) {
if (f.getType() instanceof JRecord) {
@@ -252,7 +255,7 @@ public class JRecord extends JCompType {
if (type instanceof JRecord) {
c.write(" rc = rc ? rc : serialize_" + extractStructName(type) + "(out, \"" + tag + "\", &v->" + name + ");\n");
} else if (type instanceof JVector) {
- c.write(" rc = rc ? rc : serialize_" + JVector.extractVectorName(((JVector)type).getElementType()) + "(out, \"" + tag + "\", &v->" + name + ");\n");
+ c.write(" rc = rc ? rc : serialize_" + JVector.extractVectorName(((JVector) type).getElementType()) + "(out, \"" + tag + "\", &v->" + name + ");\n");
} else {
c.write(" rc = rc ? rc : out->serialize_" + extractMethodSuffix(type) + "(out, \"" + tag + "\", &v->" + name + ");\n");
}
@@ -262,7 +265,7 @@ public class JRecord extends JCompType {
if (type instanceof JRecord) {
c.write(" rc = rc ? rc : deserialize_" + extractStructName(type) + "(in, \"" + tag + "\", &v->" + name + ");\n");
} else if (type instanceof JVector) {
- c.write(" rc = rc ? rc : deserialize_" + JVector.extractVectorName(((JVector)type).getElementType()) + "(in, \"" + tag + "\", &v->" + name + ");\n");
+ c.write(" rc = rc ? rc : deserialize_" + JVector.extractVectorName(((JVector) type).getElementType()) + "(in, \"" + tag + "\", &v->" + name + ");\n");
} else {
c.write(" rc = rc ? rc : in->deserialize_" + extractMethodSuffix(type) + "(in, \"" + tag + "\", &v->" + name + ");\n");
}
@@ -275,46 +278,50 @@ public class JRecord extends JCompType {
return t.getMethodSuffix();
}
- static private String extractStructName(JType t) {
+ private static String extractStructName(JType t) {
String type = t.getCType();
- if (!type.startsWith("struct ")) return type;
+
+ if (!type.startsWith("struct ")) {
+ return type;
+ }
+
return type.substring("struct ".length());
}
public void genCppCode(FileWriter hh, FileWriter cc)
- throws IOException {
+ throws IOException {
String[] ns = getCppNameSpace().split("::");
for (int i = 0; i < ns.length; i++) {
- hh.write("namespace "+ns[i]+" {\n");
+ hh.write("namespace " + ns[i] + " {\n");
}
- hh.write("class "+getName()+" : public ::hadoop::Record {\n");
+ hh.write("class " + getName() + " : public ::hadoop::Record {\n");
hh.write("private:\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); ) {
JField jf = i.next();
hh.write(jf.genCppDecl());
}
- hh.write(" mutable std::bitset<"+mFields.size()+"> bs_;\n");
+ hh.write(" mutable std::bitset<" + mFields.size() + "> bs_;\n");
hh.write("public:\n");
hh.write(" virtual void serialize(::hadoop::OArchive& a_, const char* tag) const;\n");
hh.write(" virtual void deserialize(::hadoop::IArchive& a_, const char* tag);\n");
hh.write(" virtual const ::std::string& type() const;\n");
hh.write(" virtual const ::std::string& signature() const;\n");
hh.write(" virtual bool validate() const;\n");
- hh.write(" virtual bool operator<(const "+getName()+"& peer_) const;\n");
- hh.write(" virtual bool operator==(const "+getName()+"& peer_) const;\n");
- hh.write(" virtual ~"+getName()+"() {};\n");
+ hh.write(" virtual bool operator<(const " + getName() + "& peer_) const;\n");
+ hh.write(" virtual bool operator==(const " + getName() + "& peer_) const;\n");
+ hh.write(" virtual ~" + getName() + "() {};\n");
int fIdx = 0;
for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
JField jf = i.next();
hh.write(jf.genCppGetSet(fIdx));
}
- hh.write("}; // end record "+getName()+"\n");
- for (int i=ns.length-1; i>=0; i--) {
- hh.write("} // end namespace "+ns[i]+"\n");
+ hh.write("}; // end record " + getName() + "\n");
+ for (int i = ns.length - 1; i >= 0; i--) {
+ hh.write("} // end namespace " + ns[i] + "\n");
}
- cc.write("void "+getCppFQName()+"::serialize(::hadoop::OArchive& a_, const char* tag) const {\n");
+ cc.write("void " + getCppFQName() + "::serialize(::hadoop::OArchive& a_, const char* tag) const {\n");
cc.write(" if (!validate()) throw new ::hadoop::IOException(\"All fields not set.\");\n");
cc.write(" a_.startRecord(*this,tag);\n");
fIdx = 0;
@@ -322,72 +329,72 @@ public class JRecord extends JCompType {
JField jf = i.next();
String name = jf.getName();
if (jf.getType() instanceof JBuffer) {
- cc.write(" a_.serialize(m"+name+",m"+name+".length(),\""+jf.getTag()+"\");\n");
+ cc.write(" a_.serialize(m" + name + ",m" + name + ".length(),\"" + jf.getTag() + "\");\n");
} else {
- cc.write(" a_.serialize(m"+name+",\""+jf.getTag()+"\");\n");
+ cc.write(" a_.serialize(m" + name + ",\"" + jf.getTag() + "\");\n");
}
- cc.write(" bs_.reset("+fIdx+");\n");
+ cc.write(" bs_.reset(" + fIdx + ");\n");
}
cc.write(" a_.endRecord(*this,tag);\n");
cc.write(" return;\n");
cc.write("}\n");
- cc.write("void "+getCppFQName()+"::deserialize(::hadoop::IArchive& a_, const char* tag) {\n");
+ cc.write("void " + getCppFQName() + "::deserialize(::hadoop::IArchive& a_, const char* tag) {\n");
cc.write(" a_.startRecord(*this,tag);\n");
fIdx = 0;
for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
JField jf = i.next();
String name = jf.getName();
if (jf.getType() instanceof JBuffer) {
- cc.write(" { size_t len=0; a_.deserialize(m"+name+",len,\""+jf.getTag()+"\");}\n");
+ cc.write(" { size_t len=0; a_.deserialize(m" + name + ",len,\"" + jf.getTag() + "\");}\n");
} else {
- cc.write(" a_.deserialize(m"+name+",\""+jf.getTag()+"\");\n");
+ cc.write(" a_.deserialize(m" + name + ",\"" + jf.getTag() + "\");\n");
}
- cc.write(" bs_.set("+fIdx+");\n");
+ cc.write(" bs_.set(" + fIdx + ");\n");
}
cc.write(" a_.endRecord(*this,tag);\n");
cc.write(" return;\n");
cc.write("}\n");
- cc.write("bool "+getCppFQName()+"::validate() const {\n");
+ cc.write("bool " + getCppFQName() + "::validate() const {\n");
cc.write(" if (bs_.size() != bs_.count()) return false;\n");
for (Iterator<JField> i = mFields.iterator(); i.hasNext(); fIdx++) {
JField jf = (JField) i.next();
JType type = jf.getType();
if (type instanceof JRecord) {
- cc.write(" if (!m"+jf.getName()+".validate()) return false;\n");
+ cc.write(" if (!m" + jf.getName() + ".validate()) return false;\n");
}
}
cc.write(" return true;\n");
cc.write("}\n");
- cc.write("bool "+getCppFQName()+"::operator< (const "+getCppFQName()+"& peer_) const {\n");
+ cc.write("bool " + getCppFQName() + "::operator< (const " + getCppFQName() + "& peer_) const {\n");
cc.write(" return (1\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); ) {
JField jf = i.next();
String name = jf.getName();
- cc.write(" && (m"+name+" < peer_.m"+name+")\n");
+ cc.write(" && (m" + name + " < peer_.m" + name + ")\n");
}
cc.write(" );\n");
cc.write("}\n");
- cc.write("bool "+getCppFQName()+"::operator== (const "+getCppFQName()+"& peer_) const {\n");
+ cc.write("bool " + getCppFQName() + "::operator== (const " + getCppFQName() + "& peer_) const {\n");
cc.write(" return (1\n");
- for (Iterator<JField> i = mFields.iterator(); i.hasNext();) {
+ for (Iterator<JField> i = mFields.iterator(); i.hasNext(); ) {
JField jf = i.next();
String name = jf.getName();
- cc.write(" && (m"+name+" == peer_.m"+name+")\n");
+ cc.write(" && (m" + name + " == peer_.m" + name + ")\n");
}
cc.write(" );\n");
cc.write("}\n");
- cc.write("const ::std::string&"+getCppFQName()+"::type() const {\n");
- cc.write(" static const ::std::string type_(\""+mName+"\");\n");
+ cc.write("const ::std::string&" + getCppFQName() + "::type() const {\n");
+ cc.write(" static const ::std::string type_(\"" + mName + "\");\n");
cc.write(" return type_;\n");
cc.write("}\n");
- cc.write("const ::std::string&"+getCppFQName()+"::signature() const {\n");
- cc.write(" static const ::std::string sig_(\""+getSignature()+"\");\n");
+ cc.write("const ::std::string&" + getCppFQName() + "::signature() const {\n");
+ cc.write(" static const ::std::string sig_(\"" + getSignature() + "\");\n");
cc.write(" return sig_;\n");
cc.write("}\n");
@@ -405,7 +412,7 @@ public class JRecord extends JCompType {
} else if (!pkgdir.isDirectory()) {
throw new IOException(pkgpath + " is not a directory.");
}
- try (FileWriter jj = new FileWriter(new File(pkgdir, getName()+".java"))) {
+ try (FileWriter jj = new FileWriter(new File(pkgdir, getName() + ".java"))) {
jj.write("// File generated by hadoop record compiler. Do not edit.\n");
jj.write("/**\n");
jj.write("* Licensed to the Apache Software Foundation (ASF) under one\n");
@@ -742,8 +749,6 @@ public class JRecord extends JCompType {
cs.write("}\n");
cs.write("}\n");
-
- cs.close();
}
}
@@ -755,8 +760,10 @@ public class JRecord extends JCompType {
pack = capitalize(pack);
pack = "Id".equals(pack) ? "ZKId" : pack;
fQName.append(capitalize(pack));
- if (i != packages.length - 1) fQName.append(".");
+ if (i != packages.length - 1) {
+ fQName.append(".");
+ }
}
return fQName.toString();
- }
+ }
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JString.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JString.java
index 7f246c3..60546cb 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JString.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JString.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,25 +22,27 @@ package org.apache.jute.compiler;
*
*/
public class JString extends JCompType {
-
- /** Creates a new instance of JString */
+
+ /**
+ * Creates a new instance of JString.
+ */
public JString() {
super("char *", " ::std::string", "string", "String", "String", "String", "string");
}
-
+
public String getSignature() {
return "s";
}
-
+
public String genJavaReadWrapper(String fname, String tag, boolean decl) {
String ret = "";
if (decl) {
- ret = " String "+fname+";\n";
+ ret = " String " + fname + ";\n";
}
- return ret + " "+fname+"=a_.readString(\""+tag+"\");\n";
+ return ret + " " + fname + "=a_.readString(\"" + tag + "\");\n";
}
-
+
public String genJavaWriteWrapper(String fname, String tag) {
- return " a_.writeString("+fname+",\""+tag+"\");\n";
+ return " a_.writeString(" + fname + ",\"" + tag + "\");\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JType.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JType.java
index ee1b9c0..d50ac01 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JType.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JType.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -20,11 +20,10 @@ package org.apache.jute.compiler;
/**
* Abstract Base class for all types supported by Hadoop Record I/O.
- *
*/
-abstract public class JType {
-
- private String mCName;
+public abstract class JType {
+
+ private String mCName;
private String mCppName;
private String mCsharpName;
private String mJavaName;
@@ -34,10 +33,10 @@ abstract public class JType {
private String mUnwrapMethod;
/**
- * Creates a new instance of JType
+ * Creates a new instance of JType.
*/
JType(String cname, String cppname, String csharpName, String javaname, String suffix, String wrapper, String csharpWrapper, String unwrap) {
- mCName = cname;
+ mCName = cname;
mCppName = cppname;
mCsharpName = "Id".equals(csharpName) ? "ZKId" : csharpName;
mJavaName = javaname;
@@ -46,64 +45,66 @@ abstract public class JType {
mSharpWrapper = csharpWrapper;
mUnwrapMethod = unwrap;
}
-
+
abstract String getSignature();
-
+
String genCppDecl(String fname) {
- return " "+mCppName+" m"+fname+";\n";
+ return " " + mCppName + " m" + fname + ";\n";
+ }
+
+ String genCDecl(String name) {
+ return " " + mCName + " " + name + ";\n";
}
-
- String genCDecl(String name) {
- return " " + mCName + " "+name+";\n";
- }
public String genCsharpDecl(String name) {
- return " private "+mCsharpName+" " +name+";\n";
+ return " private " + mCsharpName + " " + name + ";\n";
}
- String genJavaDecl (String fname) {
- return " private "+mJavaName+" " +fname+";\n";
+ String genJavaDecl(String fname) {
+ return " private " + mJavaName + " " + fname + ";\n";
}
-
- String genJavaConstructorParam (String fname) {
- return " "+mJavaName+" "+fname;
+
+ String genJavaConstructorParam(String fname) {
+ return " " + mJavaName + " " + fname;
}
-
+
String genCppGetSet(String fname, int fIdx) {
- String getFunc = " virtual "+mCppName+" get"+fname+"() const {\n";
- getFunc += " return m"+fname+";\n";
+ String getFunc = " virtual " + mCppName + " get" + fname + "() const {\n";
+ getFunc += " return m" + fname + ";\n";
getFunc += " }\n";
- String setFunc = " virtual void set"+fname+"("+mCppName+" m_) {\n";
- setFunc += " m"+fname+"=m_; bs_.set("+fIdx+");\n";
+ String setFunc = " virtual void set" + fname + "(" + mCppName + " m_) {\n";
+ setFunc += " m" + fname + "=m_; bs_.set(" + fIdx + ");\n";
setFunc += " }\n";
- return getFunc+setFunc;
+ return getFunc + setFunc;
}
String genCsharpGetSet(String fname, int fIdx) {
String getFunc = " public " + getCsharpType() + " " + capitalize(fname) + " { get; set; } ";
return getFunc;
}
-
+
static String capitalize(String s) {
- return s.substring(0,1).toUpperCase()+s.substring(1);
+ return s.substring(0, 1).toUpperCase() + s.substring(1);
}
+
String genJavaGetSet(String fname, int fIdx) {
- String getFunc = " public "+mJavaName+" get"+capitalize(fname)+"() {\n";
- getFunc += " return "+fname+";\n";
+ String getFunc = " public " + mJavaName + " get" + capitalize(fname) + "() {\n";
+ getFunc += " return " + fname + ";\n";
getFunc += " }\n";
- String setFunc = " public void set"+capitalize(fname)+"("+mJavaName+" m_) {\n";
- setFunc += " " + fname+"=m_;\n";
+ String setFunc = " public void set" + capitalize(fname) + "(" + mJavaName + " m_) {\n";
+ setFunc += " " + fname + "=m_;\n";
setFunc += " }\n";
- return getFunc+setFunc;
+ return getFunc + setFunc;
}
-
+
String getCType() {
- return mCName;
+ return mCName;
}
+
String getCppType() {
return mCppName;
}
-
+
String getCsharpType() {
return mCsharpName;
}
@@ -111,7 +112,7 @@ abstract public class JType {
String getJavaType() {
return mJavaName;
}
-
+
String getJavaWrapperType() {
return mWrapper;
}
@@ -119,86 +120,87 @@ abstract public class JType {
String getCsharpWrapperType() {
return mSharpWrapper;
}
-
+
String getMethodSuffix() {
return mMethodSuffix;
}
-
+
String genJavaWriteMethod(String fname, String tag) {
- return " a_.write"+mMethodSuffix+"("+fname+",\""+tag+"\");\n";
+ return " a_.write" + mMethodSuffix + "(" + fname + ",\"" + tag + "\");\n";
}
-
+
String genJavaReadMethod(String fname, String tag) {
- return " "+fname+"=a_.read"+mMethodSuffix+"(\""+tag+"\");\n";
+ return " " + fname + "=a_.read" + mMethodSuffix + "(\"" + tag + "\");\n";
}
-
+
String genJavaReadWrapper(String fname, String tag, boolean decl) {
String ret = "";
if (decl) {
- ret = " "+mWrapper+" "+fname+";\n";
+ ret = " " + mWrapper + " " + fname + ";\n";
}
- return ret + " "+fname+"=new "+mWrapper+"(a_.read"+mMethodSuffix+"(\""+tag+"\"));\n";
+ return ret + " " + fname + "=new " + mWrapper + "(a_.read" + mMethodSuffix + "(\"" + tag + "\"));\n";
}
-
+
String genJavaWriteWrapper(String fname, String tag) {
- return " a_.write"+mMethodSuffix+"("+fname+"."+mUnwrapMethod+"(),\""+tag+"\");\n";
+ return " a_.write" + mMethodSuffix + "(" + fname + "." + mUnwrapMethod + "(),\"" + tag + "\");\n";
}
-
+
String genJavaCompareTo(String fname) {
- return " ret = ("+fname+" == peer."+fname+")? 0 :(("+fname+"<peer."+fname+")?-1:1);\n";
+ return " ret = (" + fname + " == peer." + fname + ")? 0 :((" + fname + "<peer." + fname + ")?-1:1);\n";
}
-
+
String genJavaEquals(String fname, String peer) {
- return " ret = ("+fname+"=="+peer+");\n";
+ return " ret = (" + fname + "==" + peer + ");\n";
}
-
+
String genJavaHashCode(String fname) {
- return " ret = (int)"+fname+";\n";
+ return " ret = (int)" + fname + ";\n";
}
String genJavaConstructorSet(String fname, String name) {
- return " this."+fname+"="+name+";\n";
+ return " this." + fname + "=" + name + ";\n";
}
String genCsharpWriteMethod(String fname, String tag) {
- return " a_.Write"+mMethodSuffix+"("+capitalize(fname)+",\""+tag+"\");\n";
+ return " a_.Write" + mMethodSuffix + "(" + capitalize(fname) + ",\"" + tag + "\");\n";
}
String genCsharpReadMethod(String fname, String tag) {
- return " "+capitalize(fname)+"=a_.Read"+mMethodSuffix+"(\""+tag+"\");\n";
+ return " " + capitalize(fname) + "=a_.Read" + mMethodSuffix + "(\"" + tag + "\");\n";
}
String genCsharpReadWrapper(String fname, String tag, boolean decl) {
String ret = "";
if (decl) {
- ret = " "+mWrapper+" "+fname+";\n";
+ ret = " " + mWrapper + " " + fname + ";\n";
}
- return ret + " "+fname+"=a_.Read"+mMethodSuffix+"(\""+tag+"\");\n";
+ return ret + " " + fname + "=a_.Read" + mMethodSuffix + "(\"" + tag + "\");\n";
}
String genCsharpWriteWrapper(String fname, String tag) {
- if (mUnwrapMethod == null) return " a_.Write"+mMethodSuffix+"("+fname+","+tag+");\n";
- return " a_.Write"+mMethodSuffix+"("+fname+"."+mUnwrapMethod+"(),\""+tag+"\");\n";
+ return (mUnwrapMethod == null)
+ ? " a_.Write" + mMethodSuffix + "(" + fname + "," + tag + ");\n"
+ : " a_.Write" + mMethodSuffix + "(" + fname + "." + mUnwrapMethod + "(),\"" + tag + "\");\n";
}
String genCsharpCompareTo(String name) {
- return " ret = ("+capitalize(name)+" == peer."+capitalize(name)+")? 0 :(("+capitalize(name)+"<peer."+capitalize(name)+")?-1:1);\n";
+ return " ret = (" + capitalize(name) + " == peer." + capitalize(name) + ")? 0 :((" + capitalize(name) + "<peer." + capitalize(name) + ")?-1:1);\n";
}
String genCsharpEquals(String name, String peer) {
String[] peerSplit = peer.split("\\.");
- return " ret = ("+capitalize(name)+"=="+peerSplit[0] + "." + capitalize(peerSplit[1]) + ");\n";
+ return " ret = (" + capitalize(name) + "==" + peerSplit[0] + "." + capitalize(peerSplit[1]) + ");\n";
}
String genCsharpHashCode(String fname) {
- return " ret = (int)"+capitalize(fname)+";\n";
+ return " ret = (int)" + capitalize(fname) + ";\n";
}
String genCsharpConstructorSet(String mName, String fname) {
- return capitalize(fname)+"="+mName+";\n";
+ return capitalize(fname) + "=" + mName + ";\n";
}
public String genCsharpConstructorParam(String fname) {
- return " "+mCsharpName+" " +fname+"\n";
+ return " " + mCsharpName + " " + fname + "\n";
}
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JVector.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JVector.java
index 331970b..887d57e 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JVector.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JVector.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -22,97 +22,107 @@ package org.apache.jute.compiler;
*
*/
public class JVector extends JCompType {
-
- static private int level = 0;
-
- static private String getId(String id) { return id+getLevel(); }
-
- static private String getLevel() { return Integer.toString(level); }
-
- static private void incrLevel() { level++; }
-
- static private void decrLevel() { level--; }
-
+
+ private static int level = 0;
+
+ private static String getId(String id) {
+ return id + getLevel();
+ }
+
+ private static String getLevel() {
+ return Integer.toString(level);
+ }
+
+ private static void incrLevel() {
+ level++;
+ }
+
+ private static void decrLevel() {
+ level--;
+ }
+
private JType mElement;
-
- /** Creates a new instance of JVector */
+
+ /**
+ * Creates a new instance of JVector.
+ */
public JVector(JType t) {
- super("struct " + extractVectorName(t), " ::std::vector<"+t.getCppType()+">", "System.Collections.Generic.List<" + t.getCsharpType() + ">", "java.util.List<" + t.getJavaType() + ">", "Vector",
+ super("struct " + extractVectorName(t), " ::std::vector<" + t.getCppType() + ">", "System.Collections.Generic.List<" + t.getCsharpType() + ">", "java.util.List<" + t.getJavaType() + ">", "Vector",
"System.Collections.Generic.List<" + t.getCsharpType() + ">", "java.util.ArrayList<" + t.getJavaType() + ">");
mElement = t;
}
-
+
public String getSignature() {
return "[" + mElement.getSignature() + "]";
}
-
+
public String genJavaCompareTo(String fname) {
return " throw new UnsupportedOperationException(\"comparing "
- + fname + " is unimplemented\");\n";
+ + fname + " is unimplemented\");\n";
}
-
+
public String genJavaReadWrapper(String fname, String tag, boolean decl) {
StringBuilder ret = new StringBuilder("");
if (decl) {
- ret.append(" java.util.List "+fname+";\n");
+ ret.append(" java.util.List " + fname + ";\n");
}
ret.append(" {\n");
incrLevel();
- ret.append(" Index "+getId("vidx")+" = a_.startVector(\""+tag+"\");\n");
- ret.append(" if ("+getId("vidx")+"!= null) {");
- ret.append(" "+fname+"=new java.util.ArrayList<"+ mElement.getJavaType() + ">();\n");
- ret.append(" for (; !"+getId("vidx")+".done(); "+getId("vidx")+".incr()) {\n");
+ ret.append(" Index " + getId("vidx") + " = a_.startVector(\"" + tag + "\");\n");
+ ret.append(" if (" + getId("vidx") + "!= null) {");
+ ret.append(" " + fname + "=new java.util.ArrayList<" + mElement.getJavaType() + ">();\n");
+ ret.append(" for (; !" + getId("vidx") + ".done(); " + getId("vidx") + ".incr()) {\n");
ret.append(mElement.genJavaReadWrapper(getId("e"), getId("e"), true));
- ret.append(" "+fname+".add("+getId("e")+");\n");
+ ret.append(" " + fname + ".add(" + getId("e") + ");\n");
ret.append(" }\n");
ret.append(" }\n");
- ret.append(" a_.endVector(\""+tag+"\");\n");
+ ret.append(" a_.endVector(\"" + tag + "\");\n");
decrLevel();
ret.append(" }\n");
return ret.toString();
}
-
+
public String genJavaReadMethod(String fname, String tag) {
return genJavaReadWrapper(fname, tag, false);
}
-
+
public String genJavaWriteWrapper(String fname, String tag) {
StringBuilder ret = new StringBuilder(" {\n");
incrLevel();
- ret.append(" a_.startVector("+fname+",\""+tag+"\");\n");
- ret.append(" if ("+fname+"!= null) {");
- ret.append(" int "+getId("len")+" = "+fname+".size();\n");
- ret.append(" for(int "+getId("vidx")+" = 0; "+getId("vidx")+"<"+getId("len")+"; "+getId("vidx")+"++) {\n");
- ret.append(" "+mElement.getJavaWrapperType()+" "+getId("e")+" = ("+mElement.getJavaWrapperType()+") "+fname+".get("+getId("vidx")+");\n");
+ ret.append(" a_.startVector(" + fname + ",\"" + tag + "\");\n");
+ ret.append(" if (" + fname + "!= null) {");
+ ret.append(" int " + getId("len") + " = " + fname + ".size();\n");
+ ret.append(" for(int " + getId("vidx") + " = 0; " + getId("vidx") + "<" + getId("len") + "; " + getId("vidx") + "++) {\n");
+ ret.append(" " + mElement.getJavaWrapperType() + " " + getId("e") + " = (" + mElement.getJavaWrapperType() + ") " + fname + ".get(" + getId("vidx") + ");\n");
ret.append(mElement.genJavaWriteWrapper(getId("e"), getId("e")));
ret.append(" }\n");
ret.append(" }\n");
- ret.append(" a_.endVector("+fname+",\""+tag+"\");\n");
+ ret.append(" a_.endVector(" + fname + ",\"" + tag + "\");\n");
ret.append(" }\n");
decrLevel();
return ret.toString();
}
-
+
public String genJavaWriteMethod(String fname, String tag) {
return genJavaWriteWrapper(fname, tag);
}
-
+
public JType getElementType() {
- return mElement;
+ return mElement;
}
public String genCsharpWriteWrapper(String fname, String tag) {
StringBuilder ret = new StringBuilder(" {\n");
incrLevel();
- ret.append(" a_.StartVector("+capitalize(fname)+",\""+tag+"\");\n");
- ret.append(" if ("+capitalize(fname)+"!= null) {");
- ret.append(" int "+getId("len")+" = "+capitalize(fname)+".Count;\n");
- ret.append(" for(int "+getId("vidx")+" = 0; "+getId("vidx")+"<"+getId("len")+"; "+getId("vidx")+"++) {\n");
- ret.append(" "+mElement.getCsharpWrapperType()+" "+getId("e")+" = ("+mElement.getCsharpWrapperType()+") "+capitalize(fname)+"["+getId("vidx")+"];\n");
+ ret.append(" a_.StartVector(" + capitalize(fname) + ",\"" + tag + "\");\n");
+ ret.append(" if (" + capitalize(fname) + "!= null) {");
+ ret.append(" int " + getId("len") + " = " + capitalize(fname) + ".Count;\n");
+ ret.append(" for(int " + getId("vidx") + " = 0; " + getId("vidx") + "<" + getId("len") + "; " + getId("vidx") + "++) {\n");
+ ret.append(" " + mElement.getCsharpWrapperType() + " " + getId("e") + " = (" + mElement.getCsharpWrapperType() + ") " + capitalize(fname) + "[" + getId("vidx") + "];\n");
ret.append(mElement.genCsharpWriteWrapper(getId("e"), getId("e")));
ret.append(" }\n");
ret.append(" }\n");
- ret.append(" a_.EndVector("+capitalize(fname)+",\""+tag+"\");\n");
+ ret.append(" a_.EndVector(" + capitalize(fname) + ",\"" + tag + "\");\n");
ret.append(" }\n");
decrLevel();
return ret.toString();
@@ -123,31 +133,31 @@ public class JVector extends JCompType {
}
public String genCsharpReadWrapper(String fname, String tag, boolean decl) {
- StringBuilder ret = new StringBuilder("");
+ StringBuilder ret = new StringBuilder();
if (decl) {
- ret.append(" System.Collections.Generic.List<" + mElement.getCsharpType()+ "> "+capitalize(fname)+";\n");
+ ret.append(" System.Collections.Generic.List<" + mElement.getCsharpType() + "> " + capitalize(fname) + ";\n");
}
ret.append(" {\n");
incrLevel();
- ret.append(" IIndex "+getId("vidx")+" = a_.StartVector(\""+tag+"\");\n");
- ret.append(" if ("+getId("vidx")+"!= null) {");
- ret.append(" "+capitalize(fname)+"=new System.Collections.Generic.List<"+ mElement.getCsharpType() + ">();\n");
- ret.append(" for (; !"+getId("vidx")+".Done(); "+getId("vidx")+".Incr()) {\n");
+ ret.append(" IIndex " + getId("vidx") + " = a_.StartVector(\"" + tag + "\");\n");
+ ret.append(" if (" + getId("vidx") + "!= null) {");
+ ret.append(" " + capitalize(fname) + "=new System.Collections.Generic.List<" + mElement.getCsharpType() + ">();\n");
+ ret.append(" for (; !" + getId("vidx") + ".Done(); " + getId("vidx") + ".Incr()) {\n");
ret.append(mElement.genCsharpReadWrapper(getId("e"), getId("e"), true));
- ret.append(" "+capitalize(fname)+".Add("+getId("e")+");\n");
+ ret.append(" " + capitalize(fname) + ".Add(" + getId("e") + ");\n");
ret.append(" }\n");
ret.append(" }\n");
- ret.append(" a_.EndVector(\""+tag+"\");\n");
+ ret.append(" a_.EndVector(\"" + tag + "\");\n");
decrLevel();
ret.append(" }\n");
return ret.toString();
}
-
+
String genCsharpReadMethod(String fname, String tag) {
return genCsharpReadWrapper(fname, tag, false);
}
- static public String extractVectorName(JType jvType) {
- return JRecord.extractMethodSuffix(jvType)+"_vector";
- }
+ static String extractVectorName(JType jvType) {
+ return JRecord.extractMethodSuffix(jvType) + "_vector";
+ }
}
diff --git a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JavaGenerator.java b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JavaGenerator.java
index 250ff56..75e316d 100644
--- a/zookeeper-jute/src/main/java/org/apache/jute/compiler/JavaGenerator.java
+++ b/zookeeper-jute/src/main/java/org/apache/jute/compiler/JavaGenerator.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -29,21 +29,21 @@ import java.util.List;
class JavaGenerator {
private List<JRecord> mRecList;
private final File outputDirectory;
-
- /** Creates a new instance of JavaGenerator
+
+ /**
+ * Creates a new instance of JavaGenerator.
*
- * @param name possibly full pathname to the file
- * @param incl included files (as JFile)
- * @param records List of records defined within this file
- * @param outputDirectory
+ * @param name possibly full pathname to the file
+ * @param incl included files (as JFile)
+ * @param records List of records defined within this file
+ * @param outputDirectory
*/
JavaGenerator(String name, List<JFile> incl,
- List<JRecord> records, File outputDirectory)
- {
+ List<JRecord> records, File outputDirectory) {
mRecList = records;
this.outputDirectory = outputDirectory;
}
-
+
/**
* Generate Java code for records. This method is only a front-end to
* JRecord, since one file is generated for each record.
diff --git a/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java b/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
index 9226466..dcb39e4 100644
--- a/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
+++ b/zookeeper-jute/src/test/java/org/apache/jute/BinaryInputArchiveTest.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,29 +6,32 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.jute;
+import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
+import org.junit.Test;
// TODO: introduce JuteTestCase as in ZKTestCase
+
+/**
+ *
+ */
public class BinaryInputArchiveTest {
@Test
@@ -60,11 +63,11 @@ public class BinaryInputArchiveTest {
final int expected = 4;
final String tag = "tag1";
checkWriterAndReader(
- (oa) -> oa.writeInt(expected, tag),
- (ia) -> {
- int actual = ia.readInt(tag);
- assertEquals(expected, actual);
- }
+ (oa) -> oa.writeInt(expected, tag),
+ (ia) -> {
+ int actual = ia.readInt(tag);
+ assertEquals(expected, actual);
+ }
);
}
@@ -73,11 +76,11 @@ public class BinaryInputArchiveTest {
final boolean expected = false;
final String tag = "tag1";
checkWriterAndReader(
- (oa) -> oa.writeBool(expected, tag),
- (ia) -> {
+ (oa) -> oa.writeBool(expected, tag),
+ (ia) -> {
boolean actual = ia.readBool(tag);
assertEquals(expected, actual);
- }
+ }
);
}
@@ -86,11 +89,11 @@ public class BinaryInputArchiveTest {
final String expected = "hello";
final String tag = "tag1";
checkWriterAndReader(
- (oa) -> oa.writeString(expected, tag),
- (ia) -> {
- String actual = ia.readString(tag);
- assertEquals(expected, actual);
- }
+ (oa) -> oa.writeString(expected, tag),
+ (ia) -> {
+ String actual = ia.readString(tag);
+ assertEquals(expected, actual);
+ }
);
}
@@ -100,11 +103,11 @@ public class BinaryInputArchiveTest {
final String tag = "tag1";
final float delta = 1e-10f;
checkWriterAndReader(
- (oa) -> oa.writeFloat(expected, tag),
- (ia) -> {
+ (oa) -> oa.writeFloat(expected, tag),
+ (ia) -> {
float actual = ia.readFloat(tag);
assertEquals(expected, actual, delta);
- }
+ }
);
}
@@ -114,11 +117,11 @@ public class BinaryInputArchiveTest {
final String tag = "tag1";
final float delta = 1e-20f;
checkWriterAndReader(
- (oa) -> oa.writeDouble(expected, tag),
- (ia) -> {
+ (oa) -> oa.writeDouble(expected, tag),
+ (ia) -> {
double actual = ia.readDouble(tag);
assertEquals(expected, actual, delta);
- }
+ }
);
}
@@ -129,7 +132,7 @@ public class BinaryInputArchiveTest {
checkWriterAndReader(
(oa) -> oa.writeBuffer(expected, tag),
(ia) -> {
- byte [] actual = ia.readBuffer(tag);
+ byte[] actual = ia.readBuffer(tag);
assertArrayEquals(expected, actual);
}
);
diff --git a/zookeeper-jute/src/test/java/org/apache/jute/TestCheckWriterReader.java b/zookeeper-jute/src/test/java/org/apache/jute/TestCheckWriterReader.java
index 115f58b..81067ce 100644
--- a/zookeeper-jute/src/test/java/org/apache/jute/TestCheckWriterReader.java
+++ b/zookeeper-jute/src/test/java/org/apache/jute/TestCheckWriterReader.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,35 +6,33 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.jute;
+import static org.junit.Assert.fail;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
-import static org.junit.Assert.fail;
-
/**
* TestOutputArchive creates an output archive from a given outputstream.
*/
interface TestOutputArchive {
-
OutputArchive getArchive(OutputStream os) throws IOException;
}
interface TestInputArchive {
-
InputArchive getArchive(InputStream is) throws IOException;
}
diff --git a/zookeeper-jute/src/test/java/org/apache/jute/TestReader.java b/zookeeper-jute/src/test/java/org/apache/jute/TestReader.java
index a528b59..f74a729 100644
--- a/zookeeper-jute/src/test/java/org/apache/jute/TestReader.java
+++ b/zookeeper-jute/src/test/java/org/apache/jute/TestReader.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,19 +6,23 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.jute;
import java.io.IOException;
+/**
+ *
+ */
public interface TestReader {
void read(InputArchive ia) throws IOException;
}
diff --git a/zookeeper-jute/src/test/java/org/apache/jute/TestWriter.java b/zookeeper-jute/src/test/java/org/apache/jute/TestWriter.java
index ffaa9bc..7cd5fde 100644
--- a/zookeeper-jute/src/test/java/org/apache/jute/TestWriter.java
+++ b/zookeeper-jute/src/test/java/org/apache/jute/TestWriter.java
@@ -1,4 +1,4 @@
-/**
+/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
@@ -6,20 +6,23 @@
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
- * <p/>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p/>
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
+
package org.apache.jute;
import java.io.IOException;
-
+/**
+ *
+ */
public interface TestWriter {
/**
diff --git a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NIOServerCnxn.java b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NIOServerCnxn.java
index 48aadfc..d94d407 100644
--- a/zookeeper-server/src/main/java/org/apache/zookeeper/server/NIOServerCnxn.java
+++ b/zookeeper-server/src/main/java/org/apache/zookeeper/server/NIOServerCnxn.java
@@ -32,7 +32,6 @@ import java.security.cert.Certificate;
import java.util.Queue;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicInteger;
import org.apache.jute.BinaryInputArchive;
import org.apache.jute.Record;
@@ -40,7 +39,6 @@ import org.apache.zookeeper.WatchedEvent;
import org.apache.zookeeper.data.Id;
import org.apache.zookeeper.data.Stat;
import org.apache.zookeeper.proto.ReplyHeader;
-import org.apache.zookeeper.proto.RequestHeader;
import org.apache.zookeeper.proto.WatcherEvent;
import org.apache.zookeeper.server.NIOServerCnxnFactory.SelectorThread;
import org.apache.zookeeper.server.command.CommandExecutor;