diff options
Diffstat (limited to 'lib/java/src/main/java/org/apache/thrift/partial')
8 files changed, 168 insertions, 328 deletions
diff --git a/lib/java/src/main/java/org/apache/thrift/partial/EnumCache.java b/lib/java/src/main/java/org/apache/thrift/partial/EnumCache.java index 22423f10c..a56d20286 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/EnumCache.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/EnumCache.java @@ -19,22 +19,19 @@ package org.apache.thrift.partial; -import org.apache.thrift.partial.Validate; - -import org.apache.thrift.TEnum; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.util.HashMap; import java.util.Map; +import org.apache.thrift.TEnum; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; /** * Provides a memoized way to lookup an enum by its value. * - * This class is used internally by {@code TDeserializer}. - * It is not intended to be used separately on its own. + * <p>This class is used internally by {@code TDeserializer}. It is not intended to be used + * separately on its own. */ public class EnumCache { private static Logger LOG = LoggerFactory.getLogger(EnumCache.class); @@ -46,8 +43,7 @@ public class EnumCache { } /** - * Gets an instance of the enum type {@code enumClass} - * corresponding to the given {@code value}. + * Gets an instance of the enum type {@code enumClass} corresponding to the given {@code value}. * * @param enumClass class of the enum to be returned. * @param value value returned by {@code getValue()}. diff --git a/lib/java/src/main/java/org/apache/thrift/partial/PartialThriftComparer.java b/lib/java/src/main/java/org/apache/thrift/partial/PartialThriftComparer.java index f636c80d9..e635dc643 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/PartialThriftComparer.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/PartialThriftComparer.java @@ -19,26 +19,23 @@ package org.apache.thrift.partial; -import org.apache.thrift.TBase; -import org.apache.thrift.protocol.TType; - -import java.lang.StringBuilder; import java.nio.ByteBuffer; import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; import java.util.Set; +import org.apache.thrift.TBase; +import org.apache.thrift.protocol.TType; /** - * Enables comparison of two TBase instances such that the comparison - * is limited to the subset of fields defined by the supplied metadata. + * Enables comparison of two TBase instances such that the comparison is limited to the subset of + * fields defined by the supplied metadata. * - * This comparer is useful when comparing two instances where: - * -- one is generated by full deserialization. - * -- the other is generated by partial deserialization. + * <p>This comparer is useful when comparing two instances where: -- one is generated by full + * deserialization. -- the other is generated by partial deserialization. * - * The typical use case is to establish correctness of partial deserialization. + * <p>The typical use case is to establish correctness of partial deserialization. */ public class PartialThriftComparer<T extends TBase> { @@ -61,12 +58,12 @@ public class PartialThriftComparer<T extends TBase> { } /** - * Compares thrift objects {@code t1} and {@code t2} and - * returns true if they are equal false otherwise. The comparison is limited - * to the scope defined by {@code metadata}. - * <p> - * If the objects are not equal then it optionally records their differences - * if {@code sb} is supplied. + * Compares thrift objects {@code t1} and {@code t2} and returns true if they are equal false + * otherwise. The comparison is limited to the scope defined by {@code metadata}. + * + * <p>If the objects are not equal then it optionally records their differences if {@code sb} is + * supplied. + * * <p> * * @param t1 the first object. @@ -79,10 +76,7 @@ public class PartialThriftComparer<T extends TBase> { } private boolean areEqual( - ThriftMetadata.ThriftObject data, - Object o1, - Object o2, - StringBuilder sb) { + ThriftMetadata.ThriftObject data, Object o1, Object o2, StringBuilder sb) { byte fieldType = data.data.valueMetaData.type; switch (fieldType) { @@ -116,10 +110,7 @@ public class PartialThriftComparer<T extends TBase> { } private boolean areEqual( - ThriftMetadata.ThriftStruct data, - Object o1, - Object o2, - StringBuilder sb) { + ThriftMetadata.ThriftStruct data, Object o1, Object o2, StringBuilder sb) { ComparisonResult result = checkNullEquality(data, o1, o2, sb); if (result != ComparisonResult.UNKNOWN) { return result == ComparisonResult.EQUAL; @@ -151,10 +142,7 @@ public class PartialThriftComparer<T extends TBase> { } private boolean areEqual( - ThriftMetadata.ThriftPrimitive data, - Object o1, - Object o2, - StringBuilder sb) { + ThriftMetadata.ThriftPrimitive data, Object o1, Object o2, StringBuilder sb) { ComparisonResult result = checkNullEquality(data, o1, o2, sb); if (result != ComparisonResult.UNKNOWN) { @@ -173,11 +161,7 @@ public class PartialThriftComparer<T extends TBase> { return false; } - private boolean areEqual( - ThriftMetadata.ThriftEnum data, - Object o1, - Object o2, - StringBuilder sb) { + private boolean areEqual(ThriftMetadata.ThriftEnum data, Object o1, Object o2, StringBuilder sb) { ComparisonResult result = checkNullEquality(data, o1, o2, sb); if (result != ComparisonResult.UNKNOWN) { @@ -192,11 +176,7 @@ public class PartialThriftComparer<T extends TBase> { return false; } - private boolean areEqual( - ThriftMetadata.ThriftList data, - Object o1, - Object o2, - StringBuilder sb) { + private boolean areEqual(ThriftMetadata.ThriftList data, Object o1, Object o2, StringBuilder sb) { List<Object> l1 = (List<Object>) o1; List<Object> l2 = (List<Object>) o2; @@ -221,11 +201,7 @@ public class PartialThriftComparer<T extends TBase> { return true; } - private boolean areEqual( - ThriftMetadata.ThriftSet data, - Object o1, - Object o2, - StringBuilder sb) { + private boolean areEqual(ThriftMetadata.ThriftSet data, Object o1, Object o2, StringBuilder sb) { Set<Object> s1 = (Set<Object>) o1; Set<Object> s2 = (Set<Object>) o2; @@ -249,11 +225,7 @@ public class PartialThriftComparer<T extends TBase> { return true; } - private boolean areEqual( - ThriftMetadata.ThriftMap data, - Object o1, - Object o2, - StringBuilder sb) { + private boolean areEqual(ThriftMetadata.ThriftMap data, Object o1, Object o2, StringBuilder sb) { Map<Object, Object> m1 = (Map<Object, Object>) o1; Map<Object, Object> m2 = (Map<Object, Object>) o2; @@ -303,10 +275,7 @@ public class PartialThriftComparer<T extends TBase> { } private void appendResult( - ThriftMetadata.ThriftObject data, - StringBuilder sb, - String format, - Object... args) { + ThriftMetadata.ThriftObject data, StringBuilder sb, String format, Object... args) { if (sb != null) { String msg = String.format(format, args); sb.append(data.fieldId.getFieldName()); @@ -330,16 +299,12 @@ public class PartialThriftComparer<T extends TBase> { appendResult(data, sb, "%s (%s) != %s (%s)", o1name, o1s, o2name, o2s); } else { appendResult( - data, sb, "%s != %s\n%s =\n%s\n%s =\n%s\n", - o1name, o2name, o1name, o1s, o2name, o2s); + data, sb, "%s != %s\n%s =\n%s\n%s =\n%s\n", o1name, o2name, o1name, o1s, o2name, o2s); } } private ComparisonResult checkNullEquality( - ThriftMetadata.ThriftObject data, - Object o1, - Object o2, - StringBuilder sb) { + ThriftMetadata.ThriftObject data, Object o1, Object o2, StringBuilder sb) { if ((o1 == null) && (o2 == null)) { return ComparisonResult.EQUAL; } @@ -364,8 +329,7 @@ public class PartialThriftComparer<T extends TBase> { if (c1.size() != c2.size()) { appendResult( - data, sb, "%s1.size(%d) != %s2.size(%d)", - typeName, c1.size(), typeName, c2.size()); + data, sb, "%s1.size(%d) != %s2.size(%d)", typeName, c1.size(), typeName, c2.size()); return false; } diff --git a/lib/java/src/main/java/org/apache/thrift/partial/TFieldData.java b/lib/java/src/main/java/org/apache/thrift/partial/TFieldData.java index d77302e48..5119259f9 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/TFieldData.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/TFieldData.java @@ -22,8 +22,8 @@ package org.apache.thrift.partial; /** * Holds the type and id members of a {@link org.apache.thrift.protocol.TField} into a single int. * - * This encoding scheme obviates the need to instantiate TField - * during the partial deserialization process. + * <p>This encoding scheme obviates the need to instantiate TField during the partial + * deserialization process. */ public class TFieldData { public static int encode(byte type) { diff --git a/lib/java/src/main/java/org/apache/thrift/partial/ThriftField.java b/lib/java/src/main/java/org/apache/thrift/partial/ThriftField.java index 1b5a08c80..a0fbda6a6 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/ThriftField.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/ThriftField.java @@ -19,8 +19,6 @@ package org.apache.thrift.partial; -import org.apache.thrift.partial.Validate; - import java.util.ArrayList; import java.util.Collection; import java.util.Collections; @@ -28,21 +26,19 @@ import java.util.List; /** * Holds name of a thrift field and of its sub-fields recursively. - * <p> - * This class is meant to be used in conjunction with {@code TDeserializer}. + * + * <p>This class is meant to be used in conjunction with {@code TDeserializer}. */ public class ThriftField { - /** - * Name of this field as it appears in a thrift file. Case sensitive. - */ + /** Name of this field as it appears in a thrift file. Case sensitive. */ public final String name; /** * List of sub-fields of this field. * - * This list should have only those sub-fields that need to be deserialized - * by the {@code TDeserializer}. + * <p>This list should have only those sub-fields that need to be deserialized by the {@code + * TDeserializer}. */ public final List<ThriftField> fields; @@ -60,9 +56,7 @@ public class ThriftField { this.fields = Collections.unmodifiableList(fields); } - /** - * Constructs a {@link ThriftField} that does not have any sub-fields. - */ + /** Constructs a {@link ThriftField} that does not have any sub-fields. */ ThriftField(String name) { this(name, Collections.emptyList()); } @@ -146,15 +140,12 @@ public class ThriftField { /** * Generates and returns n-ary tree of fields and their sub-fields. - * <p> - * @param fieldNames collection of fully qualified field names. * - * for example, - * In case of PinJoin thrift struct, the following are valid field names - * -- signature - * -- pins.user.userId - * -- textSignal.termSignal.termDataMap + * <p> * + * @param fieldNames collection of fully qualified field names. + * <p>for example, In case of PinJoin thrift struct, the following are valid field names -- + * signature -- pins.user.userId -- textSignal.termSignal.termDataMap * @return n-ary tree of fields and their sub-fields. */ public static List<ThriftField> fromNames(Collection<String> fieldNames) { diff --git a/lib/java/src/main/java/org/apache/thrift/partial/ThriftFieldValueProcessor.java b/lib/java/src/main/java/org/apache/thrift/partial/ThriftFieldValueProcessor.java index 33982d1d2..edb106c15 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/ThriftFieldValueProcessor.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/ThriftFieldValueProcessor.java @@ -19,18 +19,17 @@ package org.apache.thrift.partial; +import java.nio.ByteBuffer; import org.apache.thrift.TEnum; import org.apache.thrift.TFieldIdEnum; -import java.nio.ByteBuffer; - /** - * Provides an abstraction to process deserialized field values and place them - * into the collection that holds them. This abstraction allows different types - * of collections to be output from partial deserialization. + * Provides an abstraction to process deserialized field values and place them into the collection + * that holds them. This abstraction allows different types of collections to be output from partial + * deserialization. * - * In case of the usual Thrift deserialization, the collection that holds field - * values is simply an instance of TBase. + * <p>In case of the usual Thrift deserialization, the collection that holds field values is simply + * an instance of TBase. */ public interface ThriftFieldValueProcessor<V> { @@ -39,15 +38,15 @@ public interface ThriftFieldValueProcessor<V> { V prepareStruct(Object instance); - void setBool(V valueCollection, TFieldIdEnum fieldId, boolean value); + void setBool(V valueCollection, TFieldIdEnum fieldId, boolean value); - void setByte(V valueCollection, TFieldIdEnum fieldId, byte value); + void setByte(V valueCollection, TFieldIdEnum fieldId, byte value); - void setInt16(V valueCollection, TFieldIdEnum fieldId, short value); + void setInt16(V valueCollection, TFieldIdEnum fieldId, short value); - void setInt32(V valueCollection, TFieldIdEnum fieldId, int value); + void setInt32(V valueCollection, TFieldIdEnum fieldId, int value); - void setInt64(V valueCollection, TFieldIdEnum fieldId, long value); + void setInt64(V valueCollection, TFieldIdEnum fieldId, long value); void setDouble(V valueCollection, TFieldIdEnum fieldId, double value); diff --git a/lib/java/src/main/java/org/apache/thrift/partial/ThriftMetadata.java b/lib/java/src/main/java/org/apache/thrift/partial/ThriftMetadata.java index 46a37f2d9..69f76cff6 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/ThriftMetadata.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/ThriftMetadata.java @@ -19,6 +19,14 @@ package org.apache.thrift.partial; +import java.io.Serializable; +import java.lang.reflect.Constructor; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.List; +import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.apache.thrift.TBase; import org.apache.thrift.TFieldIdEnum; @@ -31,20 +39,10 @@ import org.apache.thrift.meta_data.SetMetaData; import org.apache.thrift.meta_data.StructMetaData; import org.apache.thrift.protocol.TType; -import java.io.Serializable; -import java.lang.reflect.Constructor; -import java.util.ArrayList; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - /** - * Container for Thrift metadata classes such as {@link ThriftPrimitive}, - * {@link ThriftList}, etc. - * <p> - * This class is mainly used by {@code TDeserializer}. + * Container for Thrift metadata classes such as {@link ThriftPrimitive}, {@link ThriftList}, etc. + * + * <p>This class is mainly used by {@code TDeserializer}. */ public class ThriftMetadata { @@ -84,9 +82,8 @@ public class ThriftMetadata { /** * Base class of field types that can be partially deserialized. * - * Holds metadata necessary for partial deserialization. - * The metadata is internally computed and used; therefore it is not visible to - * the users of {@code TDeserializer}. + * <p>Holds metadata necessary for partial deserialization. The metadata is internally computed + * and used; therefore it is not visible to the users of {@code TDeserializer}. */ public abstract static class ThriftObject implements Serializable { public final ThriftObject parent; @@ -111,23 +108,17 @@ public class ThriftMetadata { */ protected abstract void toPrettyString(StringBuilder sb, int level); - /** - * Gets a space string whose length is proportional to the given indent level. - */ + /** Gets a space string whose length is proportional to the given indent level. */ protected String getIndent(int level) { return StringUtils.repeat(" ", level * 4); } - /** - * Helper method to append a formatted string to the given {@code StringBuilder}. - */ + /** Helper method to append a formatted string to the given {@code StringBuilder}. */ protected void append(StringBuilder sb, String format, Object... args) { sb.append(String.format(format, args)); } - /** - * Gets the name of this field. - */ + /** Gets the name of this field. */ protected String getName() { return this.fieldId.getFieldName(); } @@ -145,10 +136,7 @@ public class ThriftMetadata { private static class Factory { static ThriftObject createNew( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data, - List<ThriftField> fields) { + ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data, List<ThriftField> fields) { byte fieldType = data.valueMetaData.type; switch (fieldType) { @@ -183,9 +171,7 @@ public class ThriftMetadata { } } - /** - * Metadata about primitive types. - */ + /** Metadata about primitive types. */ public static class ThriftPrimitive extends ThriftObject { ThriftPrimitive(ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data) { super(parent, fieldId, data); @@ -248,15 +234,10 @@ public class ThriftMetadata { } } - /** - * Metadata of container like objects: list, set, map - */ + /** Metadata of container like objects: list, set, map */ public abstract static class ThriftContainer extends ThriftObject { - public ThriftContainer( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data) { + public ThriftContainer(ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data) { super(parent, fieldId, data); } @@ -267,20 +248,18 @@ public class ThriftMetadata { public final ThriftObject elementData; ThriftList( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data, - List<ThriftField> fields) { + ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data, List<ThriftField> fields) { super(parent, fieldId, data); - this.elementData = ThriftObject.Factory.createNew( - this, - FieldTypeEnum.LIST_ELEMENT, - new FieldMetaData( - getSubElementName(fieldId), - TFieldRequirementType.REQUIRED, - ((ListMetaData) data.valueMetaData).elemMetaData), - fields); + this.elementData = + ThriftObject.Factory.createNew( + this, + FieldTypeEnum.LIST_ELEMENT, + new FieldMetaData( + getSubElementName(fieldId), + TFieldRequirementType.REQUIRED, + ((ListMetaData) data.valueMetaData).elemMetaData), + fields); } @Override @@ -300,20 +279,18 @@ public class ThriftMetadata { public final ThriftObject elementData; ThriftSet( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data, - List<ThriftField> fields) { + ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data, List<ThriftField> fields) { super(parent, fieldId, data); - this.elementData = ThriftObject.Factory.createNew( - this, - FieldTypeEnum.SET_ELEMENT, - new FieldMetaData( - getSubElementName(fieldId), - TFieldRequirementType.REQUIRED, - ((SetMetaData) data.valueMetaData).elemMetaData), - fields); + this.elementData = + ThriftObject.Factory.createNew( + this, + FieldTypeEnum.SET_ELEMENT, + new FieldMetaData( + getSubElementName(fieldId), + TFieldRequirementType.REQUIRED, + ((SetMetaData) data.valueMetaData).elemMetaData), + fields); } @Override @@ -334,29 +311,28 @@ public class ThriftMetadata { public final ThriftObject valueData; ThriftMap( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data, - List<ThriftField> fields) { + ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data, List<ThriftField> fields) { super(parent, fieldId, data); - this.keyData = ThriftObject.Factory.createNew( - this, - FieldTypeEnum.MAP_KEY, - new FieldMetaData( - getSubElementName(fieldId, "key"), - TFieldRequirementType.REQUIRED, - ((MapMetaData) data.valueMetaData).keyMetaData), - Collections.emptyList()); - - this.valueData = ThriftObject.Factory.createNew( - this, - FieldTypeEnum.MAP_VALUE, - new FieldMetaData( - getSubElementName(fieldId, "value"), - TFieldRequirementType.REQUIRED, - ((MapMetaData) data.valueMetaData).valueMetaData), - fields); + this.keyData = + ThriftObject.Factory.createNew( + this, + FieldTypeEnum.MAP_KEY, + new FieldMetaData( + getSubElementName(fieldId, "key"), + TFieldRequirementType.REQUIRED, + ((MapMetaData) data.valueMetaData).keyMetaData), + Collections.emptyList()); + + this.valueData = + ThriftObject.Factory.createNew( + this, + FieldTypeEnum.MAP_VALUE, + new FieldMetaData( + getSubElementName(fieldId, "value"), + TFieldRequirementType.REQUIRED, + ((MapMetaData) data.valueMetaData).valueMetaData), + fields); } @Override @@ -378,14 +354,11 @@ public class ThriftMetadata { } /** - * Base class for metadata of ThriftStruct and ThriftUnion. - * Holds functionality that is common to both. + * Base class for metadata of ThriftStruct and ThriftUnion. Holds functionality that is common to + * both. */ public abstract static class ThriftStructBase<U extends TBase> extends ThriftObject { - public ThriftStructBase( - ThriftObject parent, - TFieldIdEnum fieldId, - FieldMetaData data) { + public ThriftStructBase(ThriftObject parent, TFieldIdEnum fieldId, FieldMetaData data) { super(parent, fieldId, data); } @@ -419,10 +392,7 @@ public class ThriftMetadata { } } - /** - * Metadata of a Thrift union. - * Currently not adequately supported. - */ + /** Metadata of a Thrift union. Currently not adequately supported. */ public static class ThriftUnion<U extends TBase> extends ThriftStructBase { public ThriftUnion( ThriftObject parent, @@ -442,9 +412,7 @@ public class ThriftMetadata { } } - /** - * Metadata of a Thrift struct. - */ + /** Metadata of a Thrift struct. */ public static class ThriftStruct<U extends TBase> extends ThriftStructBase { public final Map<Integer, ThriftObject> fields; @@ -474,14 +442,12 @@ public class ThriftMetadata { } public static <T extends TBase> ThriftStruct fromFieldNames( - Class<T> clasz, - Collection<String> fieldNames) { + Class<T> clasz, Collection<String> fieldNames) { return fromFields(clasz, ThriftField.fromNames(fieldNames)); } public static <T extends TBase> ThriftStruct fromFields( - Class<T> clasz, - Iterable<ThriftField> fields) { + Class<T> clasz, Iterable<ThriftField> fields) { Validate.checkNotNull(clasz, "clasz"); Validate.checkNotNull(fields, "fields"); @@ -521,9 +487,7 @@ public class ThriftMetadata { } private static <U extends TBase> Map<Integer, ThriftObject> getFields( - ThriftStruct parent, - Class<U> clasz, - Iterable<ThriftField> fieldsData) { + ThriftStruct parent, Class<U> clasz, Iterable<ThriftField> fieldsData) { Map<? extends TFieldIdEnum, FieldMetaData> fieldsMetaData = FieldMetaData.getStructMetaDataMap(clasz); @@ -535,7 +499,8 @@ public class ThriftMetadata { TFieldIdEnum fieldId = entry.getKey(); FieldMetaData fieldMetaData = entry.getValue(); ThriftObject field = - ThriftObject.Factory.createNew(parent, fieldId, fieldMetaData, Collections.emptyList()); + ThriftObject.Factory.createNew( + parent, fieldId, fieldMetaData, Collections.emptyList()); fields.put((int) fieldId.getThriftFieldId(), field); } } else { @@ -553,8 +518,7 @@ public class ThriftMetadata { } private static FieldMetaData findFieldMetaData( - Map<? extends TFieldIdEnum, FieldMetaData> fieldsMetaData, - String fieldName) { + Map<? extends TFieldIdEnum, FieldMetaData> fieldsMetaData, String fieldName) { for (FieldMetaData fieldData : fieldsMetaData.values()) { if (fieldData.fieldName.equals(fieldName)) { @@ -566,8 +530,7 @@ public class ThriftMetadata { } private static TFieldIdEnum findFieldId( - Map<? extends TFieldIdEnum, FieldMetaData> fieldsMetaData, - String fieldName) { + Map<? extends TFieldIdEnum, FieldMetaData> fieldsMetaData, String fieldName) { for (TFieldIdEnum fieldId : fieldsMetaData.keySet()) { if (fieldId.getFieldName().equals(fieldName)) { diff --git a/lib/java/src/main/java/org/apache/thrift/partial/ThriftStructProcessor.java b/lib/java/src/main/java/org/apache/thrift/partial/ThriftStructProcessor.java index 95789144d..249e6a256 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/ThriftStructProcessor.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/ThriftStructProcessor.java @@ -19,20 +19,19 @@ package org.apache.thrift.partial; -import org.apache.thrift.TBase; -import org.apache.thrift.TEnum; -import org.apache.thrift.TFieldIdEnum; - import java.nio.ByteBuffer; import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.HashMap; import java.util.HashSet; +import org.apache.thrift.TBase; +import org.apache.thrift.TEnum; +import org.apache.thrift.TFieldIdEnum; /** * Provides a way to create and initialize an instance of TBase during partial deserialization. * - * This class is supposed to be used as a helper class for {@code PartialThriftDeserializer}. + * <p>This class is supposed to be used as a helper class for {@code PartialThriftDeserializer}. */ public class ThriftStructProcessor implements ThriftFieldValueProcessor<TBase> { @@ -109,27 +108,27 @@ public class ThriftStructProcessor implements ThriftFieldValueProcessor<TBase> { } @Override - public void setBool(TBase valueCollection, TFieldIdEnum fieldId, boolean value) { + public void setBool(TBase valueCollection, TFieldIdEnum fieldId, boolean value) { valueCollection.setFieldValue(fieldId, value); } @Override - public void setByte(TBase valueCollection, TFieldIdEnum fieldId, byte value) { + public void setByte(TBase valueCollection, TFieldIdEnum fieldId, byte value) { valueCollection.setFieldValue(fieldId, value); } @Override - public void setInt16(TBase valueCollection, TFieldIdEnum fieldId, short value) { + public void setInt16(TBase valueCollection, TFieldIdEnum fieldId, short value) { valueCollection.setFieldValue(fieldId, value); } @Override - public void setInt32(TBase valueCollection, TFieldIdEnum fieldId, int value) { + public void setInt32(TBase valueCollection, TFieldIdEnum fieldId, int value) { valueCollection.setFieldValue(fieldId, value); } @Override - public void setInt64(TBase valueCollection, TFieldIdEnum fieldId, long value) { + public void setInt64(TBase valueCollection, TFieldIdEnum fieldId, long value) { valueCollection.setFieldValue(fieldId, value); } diff --git a/lib/java/src/main/java/org/apache/thrift/partial/Validate.java b/lib/java/src/main/java/org/apache/thrift/partial/Validate.java index ef0466a5e..f4bbd9a5a 100644 --- a/lib/java/src/main/java/org/apache/thrift/partial/Validate.java +++ b/lib/java/src/main/java/org/apache/thrift/partial/Validate.java @@ -26,30 +26,24 @@ import java.util.Collection; /** * A superset of Validate class in Apache commons lang3. * - * It provides consistent message strings for frequently encountered checks. - * That simplifies callers because they have to supply only the name of the argument - * that failed a check instead of having to supply the entire message. + * <p>It provides consistent message strings for frequently encountered checks. That simplifies + * callers because they have to supply only the name of the argument that failed a check instead of + * having to supply the entire message. */ public final class Validate { private Validate() {} - /** - * Validates that the given reference argument is not null. - */ + /** Validates that the given reference argument is not null. */ public static void checkNotNull(Object obj, String argName) { checkArgument(obj != null, "'%s' must not be null.", argName); } - /** - * Validates that the given integer argument is not zero or negative. - */ + /** Validates that the given integer argument is not zero or negative. */ public static void checkPositiveInteger(long value, String argName) { checkArgument(value > 0, "'%s' must be a positive integer.", argName); } - /** - * Validates that the given integer argument is not negative. - */ + /** Validates that the given integer argument is not negative. */ public static void checkNotNegative(long value, String argName) { checkArgument(value >= 0, "'%s' must not be negative.", argName); } @@ -61,83 +55,60 @@ public final class Validate { checkArgument(isPresent, "'%s' is required.", argName); } - /** - * Validates that the expression (that checks a field is valid) is true. - */ + /** Validates that the expression (that checks a field is valid) is true. */ public static void checkValid(boolean isValid, String argName) { checkArgument(isValid, "'%s' is invalid.", argName); } - /** - * Validates that the expression (that checks a field is valid) is true. - */ + /** Validates that the expression (that checks a field is valid) is true. */ public static void checkValid(boolean isValid, String argName, String validValues) { checkArgument(isValid, "'%s' is invalid. Valid values are: %s.", argName, validValues); } - /** - * Validates that the given string is not null and has non-zero length. - */ + /** Validates that the given string is not null and has non-zero length. */ public static void checkNotNullAndNotEmpty(String arg, String argName) { Validate.checkNotNull(arg, argName); - Validate.checkArgument( - arg.length() > 0, - "'%s' must not be empty.", - argName); + Validate.checkArgument(arg.length() > 0, "'%s' must not be empty.", argName); } - /** - * Validates that the given array is not null and has at least one element. - */ + /** Validates that the given array is not null and has at least one element. */ public static <T> void checkNotNullAndNotEmpty(T[] array, String argName) { Validate.checkNotNull(array, argName); checkNotEmpty(array.length, argName); } - /** - * Validates that the given array is not null and has at least one element. - */ + /** Validates that the given array is not null and has at least one element. */ public static void checkNotNullAndNotEmpty(byte[] array, String argName) { Validate.checkNotNull(array, argName); checkNotEmpty(array.length, argName); } - /** - * Validates that the given array is not null and has at least one element. - */ + /** Validates that the given array is not null and has at least one element. */ public static void checkNotNullAndNotEmpty(short[] array, String argName) { Validate.checkNotNull(array, argName); checkNotEmpty(array.length, argName); } - /** - * Validates that the given array is not null and has at least one element. - */ + /** Validates that the given array is not null and has at least one element. */ public static void checkNotNullAndNotEmpty(int[] array, String argName) { Validate.checkNotNull(array, argName); checkNotEmpty(array.length, argName); } - /** - * Validates that the given array is not null and has at least one element. - */ + /** Validates that the given array is not null and has at least one element. */ public static void checkNotNullAndNotEmpty(long[] array, String argName) { Validate.checkNotNull(array, argName); checkNotEmpty(array.length, argName); } - /** - * Validates that the given buffer is not null and has non-zero capacity. - */ + /** Validates that the given buffer is not null and has non-zero capacity. */ public static <T> void checkNotNullAndNotEmpty(Iterable<T> iter, String argName) { Validate.checkNotNull(iter, argName); int minNumElements = iter.iterator().hasNext() ? 1 : 0; checkNotEmpty(minNumElements, argName); } - /** - * Validates that the given set is not null and has an exact number of items. - */ + /** Validates that the given set is not null and has an exact number of items. */ public static <T> void checkNotNullAndNumberOfElements( Collection<T> collection, int numElements, String argName) { Validate.checkNotNull(collection, argName); @@ -146,18 +117,12 @@ public final class Validate { "Number of elements in '%s' must be exactly %s, %s given.", argName, numElements, - collection.size() - ); + collection.size()); } - /** - * Validates that the given two values are equal. - */ + /** Validates that the given two values are equal. */ public static void checkValuesEqual( - long value1, - String value1Name, - long value2, - String value2Name) { + long value1, String value1Name, long value2, String value2Name) { checkArgument( value1 == value2, "'%s' (%s) must equal '%s' (%s).", @@ -167,14 +132,9 @@ public final class Validate { value2); } - /** - * Validates that the first value is an integer multiple of the second value. - */ + /** Validates that the first value is an integer multiple of the second value. */ public static void checkIntegerMultiple( - long value1, - String value1Name, - long value2, - String value2Name) { + long value1, String value1Name, long value2, String value2Name) { checkArgument( (value1 % value2) == 0, "'%s' (%s) must be an integer multiple of '%s' (%s).", @@ -184,14 +144,8 @@ public final class Validate { value2); } - /** - * Validates that the first value is greater than the second value. - */ - public static void checkGreater( - long value1, - String value1Name, - long value2, - String value2Name) { + /** Validates that the first value is greater than the second value. */ + public static void checkGreater(long value1, String value1Name, long value2, String value2Name) { checkArgument( value1 > value2, "'%s' (%s) must be greater than '%s' (%s).", @@ -201,14 +155,9 @@ public final class Validate { value2); } - /** - * Validates that the first value is greater than or equal to the second value. - */ + /** Validates that the first value is greater than or equal to the second value. */ public static void checkGreaterOrEqual( - long value1, - String value1Name, - long value2, - String value2Name) { + long value1, String value1Name, long value2, String value2Name) { checkArgument( value1 >= value2, "'%s' (%s) must be greater than or equal to '%s' (%s).", @@ -218,14 +167,9 @@ public final class Validate { value2); } - /** - * Validates that the first value is less than or equal to the second value. - */ + /** Validates that the first value is less than or equal to the second value. */ public static void checkLessOrEqual( - long value1, - String value1Name, - long value2, - String value2Name) { + long value1, String value1Name, long value2, String value2Name) { checkArgument( value1 <= value2, "'%s' (%s) must be less than or equal to '%s' (%s).", @@ -235,14 +179,9 @@ public final class Validate { value2); } - /** - * Validates that the given value is within the given range of values. - */ + /** Validates that the given value is within the given range of values. */ public static void checkWithinRange( - long value, - String valueName, - long minValueInclusive, - long maxValueInclusive) { + long value, String valueName, long minValueInclusive, long maxValueInclusive) { checkArgument( (value >= minValueInclusive) && (value <= maxValueInclusive), "'%s' (%s) must be within the range [%s, %s].", @@ -252,14 +191,9 @@ public final class Validate { maxValueInclusive); } - /** - * Validates that the given value is within the given range of values. - */ + /** Validates that the given value is within the given range of values. */ public static void checkWithinRange( - double value, - String valueName, - double minValueInclusive, - double maxValueInclusive) { + double value, String valueName, double minValueInclusive, double maxValueInclusive) { checkArgument( (value >= minValueInclusive) && (value <= maxValueInclusive), "'%s' (%s) must be within the range [%s, %s].", @@ -277,10 +211,7 @@ public final class Validate { public static void checkPathExistsAsDir(Path path, String argName) { checkPathExists(path, argName); checkArgument( - Files.isDirectory(path), - "Path %s (%s) must point to a directory.", - argName, - path); + Files.isDirectory(path), "Path %s (%s) must point to a directory.", argName, path); } public static void checkPathExistsAsFile(Path path, String argName) { @@ -297,9 +228,6 @@ public final class Validate { } private static void checkNotEmpty(int arraySize, String argName) { - Validate.checkArgument( - arraySize > 0, - "'%s' must have at least one element.", - argName); + Validate.checkArgument(arraySize > 0, "'%s' must have at least one element.", argName); } } |