mirror of
https://github.com/microsoft/HybridRow.git
synced 2026-01-25 04:13:19 +00:00
Feature/java/port from dotnet (#1)
* Add pom.xml placeholder and Hybrid Row whitepaper * Checkpoint for safe keeping * Progressed on port from dotnet to java * Progressed on port from C# to Java * Brought in Utf8AnyString.java * Progressed on port from C# to Java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Updated documents releated to release of Microsoft Code under MIT License * Updated JRE copyright notices * Progressed on port from dotnet to java * Renamed jre as java because Java is used to can refer to two things: the platform and the language. In this case we are referring to the Java Platform, not the Java Runtime Environment. * Progressed on port * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on dotnet port to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Progressed on port from dotnet to java * Code cleanup, especially in Utf8String class which is much improved. * Progressed on port from dotnet to java. * Simplified Utf8String some more * Code cleanup * Excluding most tests with the expectation that we'll bring them in as we continue to expand our test matrix. * Added and debugged some tests * Added and debugged some tests * Added and debugged some tests * Added, revised, and debugged some tests and test issues * Added, revised, and debugged some tests and test issues * Added, revised, and debugged some tests and test issues * Optimized imports * Removed dead code * Updated java docs * Added, revised, and debugged some tests and test issues * Added, revised, and debugged some tests and test issues * Added, revised, and debugged some tests and test issues * Added, revised, and debugged some tests and test issues. Updated javadocs and pom.xml. We now add SystemSchema.json to azure-cosmos-serialization.jar. Javadocs don't currently build. * Javadoc update * Test update * Progressed on deserializing schemas. * Progressed on deserializing schemas. * Progressed on deserializing schemas. * testLoadSchmea passes * code cleanup in prep for next step: loading a namespace that includes a schema with a udt: the one that the Spark connector team needs. * code cleanup in prep for next step: loading a namespace that includes a schema with a udt: the one that the Spark connector team needs. * RootSegment.json now loads * Progressed on RowReader * Progressed on RowReader * RowReaderTest against RootSegment.json/RootSegment.hybridrow succeeds * RowReaderTest against RootSegment.json/RootSegment.hybridrow succeeds * Move RowScanner and DataItem out of test into main * Move RowScanner and DataItem out of test into main * Move RowScanner and DataItem out of test into main * RowIterable now works. RowIterable and RowScanner now include indexes of array elements. * RowIterable and RowScanner now support additional data types * RowScanner now implements Iterable<DataItem> and RowIterable has been removed. * POM now packages SystemSchema.json and SystemSchema class now loads the packaged SystemSchema.json * Updated pom.xml with required licensing info and attempted to produce javadocs. * Progressed on adding support for unsupported Utf8String features * Refinements to Utf8String and Utf8StringTest * Utf8StringTest improvements * Refinements to Utf8String and Utf8StringTest * Added caching of UTF-16 string caching to Utf8String to reduce the time and space cost of Utf8String.toUtf16(). Also: addressed a number of javadoc issues. * Addressed a number of javadoc issues and the javadocs now build. * Utf8String refinements with inefficient support instead of no support for Utf8String.charAt(int) * Bumped netty.version and updated javadocs for Utf8String * Code cleanup (javadoc improvements + tidying) * Utf8String optimizations * Tweaks * Tweaks
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -23,6 +23,7 @@ bld/
|
|||||||
[Bb]in/
|
[Bb]in/
|
||||||
[Oo]bj/
|
[Oo]bj/
|
||||||
[Ll]og/
|
[Ll]og/
|
||||||
|
target/
|
||||||
|
|
||||||
# Visual Studio 2015/2017 cache/options directory
|
# Visual Studio 2015/2017 cache/options directory
|
||||||
.vs/
|
.vs/
|
||||||
@@ -328,3 +329,4 @@ ASALocalRun/
|
|||||||
|
|
||||||
# MFractors (Xamarin productivity tool) working folder
|
# MFractors (Xamarin productivity tool) working folder
|
||||||
.mfractor/
|
.mfractor/
|
||||||
|
*.iml
|
||||||
|
|||||||
14
CONTRIBUTING.md
Normal file
14
CONTRIBUTING.md
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
This project welcomes contributions and suggestions. Most contributions require you to
|
||||||
|
agree to a Contributor License Agreement (CLA) declaring that you have the right to,
|
||||||
|
and actually do, grant us the rights to use your contribution. For details, visit
|
||||||
|
https://cla.microsoft.com.
|
||||||
|
|
||||||
|
When you submit a pull request, a CLA-bot will automatically determine whether you need
|
||||||
|
to provide a CLA and decorate the PR appropriately (e.g., label, comment). Simply follow the
|
||||||
|
instructions provided by the bot. You will only need to do this once across all repositories using our CLA.
|
||||||
|
|
||||||
|
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
||||||
|
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
|
||||||
|
or contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
||||||
21
LICENSE
21
LICENSE
@@ -1,21 +0,0 @@
|
|||||||
MIT License
|
|
||||||
|
|
||||||
Copyright (c) Microsoft Corporation. All rights reserved.
|
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
|
||||||
in the Software without restriction, including without limitation the rights
|
|
||||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
||||||
copies of the Software, and to permit persons to whom the Software is
|
|
||||||
furnished to do so, subject to the following conditions:
|
|
||||||
|
|
||||||
The above copyright notice and this permission notice shall be included in all
|
|
||||||
copies or substantial portions of the Software.
|
|
||||||
|
|
||||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
||||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
||||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
||||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
||||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
||||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
||||||
SOFTWARE
|
|
||||||
21
LICENSE.TXT
Normal file
21
LICENSE.TXT
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
Copyright (c) Microsoft Corporation.
|
||||||
|
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
15
README.md
15
README.md
@@ -1,14 +1,3 @@
|
|||||||
|
# PLACEHOLDER
|
||||||
|
|
||||||
# Contributing
|
TODO: DANOBLE: Write README.md
|
||||||
|
|
||||||
This project welcomes contributions and suggestions. Most contributions require you to agree to a
|
|
||||||
Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us
|
|
||||||
the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.
|
|
||||||
|
|
||||||
When you submit a pull request, a CLA bot will automatically determine whether you need to provide
|
|
||||||
a CLA and decorate the PR appropriately (e.g., status check, comment). Simply follow the instructions
|
|
||||||
provided by the bot. You will only need to do this once across all repos using our CLA.
|
|
||||||
|
|
||||||
This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).
|
|
||||||
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
|
|
||||||
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.
|
|
||||||
|
|||||||
480
dotnet/src/Core/UtfAnyString.cs
Normal file
480
dotnet/src/Core/UtfAnyString.cs
Normal file
@@ -0,0 +1,480 @@
|
|||||||
|
// ------------------------------------------------------------
|
||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// ------------------------------------------------------------
|
||||||
|
|
||||||
|
#pragma warning disable CA2225 // Operator overloads have named alternates
|
||||||
|
|
||||||
|
// ReSharper disable once UseNameofExpression
|
||||||
|
namespace Microsoft.Azure.Cosmos.Core.Utf8
|
||||||
|
{
|
||||||
|
using System;
|
||||||
|
using System.Diagnostics;
|
||||||
|
using System.Runtime.CompilerServices;
|
||||||
|
|
||||||
|
/// <summary>A string whose memory representation may be either UTF8 or UTF16.</summary>
|
||||||
|
/// <remarks>
|
||||||
|
/// This type supports polymorphic use of <see cref="string" /> and <see cref="Utf8String" />
|
||||||
|
/// when equality, hashing, and comparison are needed against either encoding. An API leveraging
|
||||||
|
/// <see cref="UtfAnyString" /> can avoid separate method overloads while still accepting either
|
||||||
|
/// encoding without imposing additional allocations.
|
||||||
|
/// </remarks>
|
||||||
|
[DebuggerDisplay("{ToString()}")]
|
||||||
|
public readonly struct UtfAnyString :
|
||||||
|
IEquatable<UtfAnyString>, IComparable<UtfAnyString>,
|
||||||
|
IEquatable<Utf8String>, IComparable<Utf8String>,
|
||||||
|
IEquatable<string>, IComparable<string>
|
||||||
|
{
|
||||||
|
public static UtfAnyString Empty => string.Empty;
|
||||||
|
|
||||||
|
private readonly object buffer;
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public UtfAnyString(string utf16String)
|
||||||
|
{
|
||||||
|
this.buffer = utf16String;
|
||||||
|
}
|
||||||
|
|
||||||
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
|
public UtfAnyString(Utf8String utf8String)
|
||||||
|
{
|
||||||
|
this.buffer = utf8String;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsUtf8 => this.buffer is Utf8String;
|
||||||
|
|
||||||
|
public bool IsUtf16 => this.buffer is string;
|
||||||
|
|
||||||
|
/// <summary>True if the length is empty.</summary>
|
||||||
|
public bool IsNull => object.ReferenceEquals(null, this.buffer);
|
||||||
|
|
||||||
|
/// <summary>True if the length is empty.</summary>
|
||||||
|
public bool IsEmpty
|
||||||
|
{
|
||||||
|
get
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return s.Length == 0;
|
||||||
|
default:
|
||||||
|
return ((Utf8String)this.buffer).IsEmpty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator UtfAnyString(string utf16String)
|
||||||
|
{
|
||||||
|
return new UtfAnyString(utf16String);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static implicit operator string(UtfAnyString str)
|
||||||
|
{
|
||||||
|
return str.buffer?.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public override string ToString()
|
||||||
|
{
|
||||||
|
// ReSharper disable once AssignNullToNotNullAttribute
|
||||||
|
return this.buffer?.ToString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Utf8String ToUtf8String()
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return Utf8String.TranscodeUtf16(s);
|
||||||
|
default:
|
||||||
|
return (Utf8String)this.buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ReferenceEquals(UtfAnyString other)
|
||||||
|
{
|
||||||
|
return this.buffer == other.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(UtfAnyString other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, other.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return other.Equals(s);
|
||||||
|
default:
|
||||||
|
return other.Equals((Utf8String)this.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Utf8Span other)
|
||||||
|
{
|
||||||
|
return other.Equals(this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override bool Equals(object obj)
|
||||||
|
{
|
||||||
|
switch (obj)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return this.Equals(s);
|
||||||
|
case Utf8String s:
|
||||||
|
return this.Equals(s);
|
||||||
|
case UtfAnyString s:
|
||||||
|
return this.Equals(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(Utf8String other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, other))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.Equals(this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool Equals(string other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, other);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return string.Equals(s, other, StringComparison.Ordinal);
|
||||||
|
default:
|
||||||
|
return ((Utf8String)this.buffer).Equals(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return !right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return !right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return !left.Equals(right);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator ==(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator !=(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return !right.Equals(left);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override int GetHashCode()
|
||||||
|
{
|
||||||
|
uint hash1 = 5381;
|
||||||
|
uint hash2 = hash1;
|
||||||
|
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return unchecked((int)(hash1 + (hash2 * 1566083941)));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
Utf16LittleEndianCodePointEnumerator thisEnumerator = new Utf16LittleEndianCodePointEnumerator(s);
|
||||||
|
for (int i = 0; thisEnumerator.MoveNext(); i++)
|
||||||
|
{
|
||||||
|
uint c = thisEnumerator.Current;
|
||||||
|
if (i % 2 == 0)
|
||||||
|
{
|
||||||
|
hash1 = ((hash1 << 5) + hash1) ^ c;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
hash2 = ((hash2 << 5) + hash2) ^ c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return (int)(hash1 + (hash2 * 1566083941));
|
||||||
|
}
|
||||||
|
|
||||||
|
default:
|
||||||
|
return this.buffer.GetHashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(UtfAnyString left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(UtfAnyString left, string right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(string left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(UtfAnyString left, Utf8String right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(Utf8String left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(UtfAnyString left, Utf8Span right)
|
||||||
|
{
|
||||||
|
return left.CompareTo(right) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) >= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator <=(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) <= 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool operator >=(Utf8Span left, UtfAnyString right)
|
||||||
|
{
|
||||||
|
return right.CompareTo(left) < 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(UtfAnyString other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, other.buffer))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, this.buffer) ? 0 : 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (other.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return this.CompareTo(s);
|
||||||
|
default:
|
||||||
|
return this.CompareTo((Utf8String)other.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Utf8String other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, other) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return -other.Span.CompareTo(s);
|
||||||
|
default:
|
||||||
|
return -other.Span.CompareTo((Utf8String)this.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(Utf8Span other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return -other.CompareTo(s);
|
||||||
|
default:
|
||||||
|
return -other.CompareTo((Utf8String)this.buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public int CompareTo(string other)
|
||||||
|
{
|
||||||
|
if (object.ReferenceEquals(null, this.buffer))
|
||||||
|
{
|
||||||
|
return object.ReferenceEquals(null, other) ? 0 : -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (this.buffer)
|
||||||
|
{
|
||||||
|
case string s:
|
||||||
|
return string.Compare(s, other, StringComparison.Ordinal);
|
||||||
|
default:
|
||||||
|
return ((Utf8String)this.buffer).CompareTo(other);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
public interface ISpanResizer<T> {
|
||||||
|
/**
|
||||||
|
* Resizes an existing a buffer.
|
||||||
|
* <typeparam name="T">The type of the elements of the memory.</typeparam>
|
||||||
|
*
|
||||||
|
* @param minimumLength The minimum required length (in elements) of the memory.
|
||||||
|
* @param buffer Optional existing memory to be copied to the new buffer. Ownership of <paramref
|
||||||
|
* name="buffer" /> is
|
||||||
|
* transferred as part of this call and it should not be used by the caller after this call
|
||||||
|
* completes.
|
||||||
|
* @return A new memory whose size is <em>at least as big</em> as <paramref name="minimumLength" />
|
||||||
|
* and containing the content of <paramref name="buffer" />.
|
||||||
|
*/
|
||||||
|
|
||||||
|
Span<T> Resize(int minimumLength);
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: Span<T> Resize(int minimumLength, Span<T> buffer = default);
|
||||||
|
Span<T> Resize(int minimumLength, Span<T> buffer);
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
|
||||||
|
public final class MemorySpanResizer<T> implements ISpanResizer<T> {
|
||||||
|
private Memory<T> memory;
|
||||||
|
|
||||||
|
|
||||||
|
public MemorySpanResizer() {
|
||||||
|
this(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public MemorySpanResizer(int initialCapacity = 0)
|
||||||
|
public MemorySpanResizer(int initialCapacity) {
|
||||||
|
checkArgument(initialCapacity >= 0);
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type parameters:
|
||||||
|
//ORIGINAL LINE: this.memory = initialCapacity == 0 ? default : new Memory<T>(new T[initialCapacity]);
|
||||||
|
this.memory = initialCapacity == 0 ? null : new Memory<T>((T[])new Object[initialCapacity]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Memory<T> getMemory() {
|
||||||
|
return this.memory;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <inheritdoc />
|
||||||
|
*/
|
||||||
|
|
||||||
|
public Span<T> Resize(int minimumLength) {
|
||||||
|
return Resize(minimumLength, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public Span<T> Resize(int minimumLength, Span<T> buffer = default)
|
||||||
|
public Span<T> Resize(int minimumLength, Span<T> buffer) {
|
||||||
|
if (this.memory.Length < minimumLength) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow direct instantiation of arrays of generic type
|
||||||
|
// parameters:
|
||||||
|
//ORIGINAL LINE: this.memory = new Memory<T>(new T[Math.Max(minimumLength, buffer.Length)]);
|
||||||
|
this.memory = new Memory<T>((T[])new Object[Math.max(minimumLength, buffer.Length)]);
|
||||||
|
}
|
||||||
|
|
||||||
|
Span<T> next = this.memory.Span;
|
||||||
|
if (!buffer.IsEmpty && next.Slice(0, buffer.Length) != buffer) {
|
||||||
|
buffer.CopyTo(next);
|
||||||
|
}
|
||||||
|
|
||||||
|
return next;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,48 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.layouts;
|
||||||
|
|
||||||
|
public class SamplingStringComparer implements IEqualityComparer<String> {
|
||||||
|
|
||||||
|
public static final SamplingStringComparer Default = new SamplingStringComparer();
|
||||||
|
|
||||||
|
public final boolean equals(String x, String y) {
|
||||||
|
checkArgument(x != null);
|
||||||
|
checkArgument(y != null);
|
||||||
|
|
||||||
|
return x.equals(y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int hashCode(String obj) {
|
||||||
|
checkArgument(obj != null);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint hash1 = 5381;
|
||||||
|
int hash1 = 5381;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint hash2 = hash1;
|
||||||
|
int hash2 = hash1;
|
||||||
|
final int numSamples = 4;
|
||||||
|
final int modulus = 13;
|
||||||
|
|
||||||
|
ReadOnlySpan<Character> utf16 = obj.AsSpan();
|
||||||
|
int max = Math.min(utf16.Length, numSamples);
|
||||||
|
for (int i = 0; i < max; i++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint c = utf16[(i * modulus) % utf16.Length];
|
||||||
|
int c = utf16[(i * modulus) % utf16.Length];
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
hash1 = ((hash1 << 5) + hash1) ^ c;
|
||||||
|
} else {
|
||||||
|
hash2 = ((hash2 << 5) + hash2) ^ c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash1 + (hash2 * 1566083941);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.layouts;
|
||||||
|
|
||||||
|
public class SamplingUtf8StringComparer implements IEqualityComparer<Utf8String> {
|
||||||
|
public static final SamplingUtf8StringComparer Default = new SamplingUtf8StringComparer();
|
||||||
|
|
||||||
|
public final boolean equals(Utf8String x, Utf8String y) {
|
||||||
|
checkArgument(x != null);
|
||||||
|
checkArgument(y != null);
|
||||||
|
|
||||||
|
return x.Span.equals(y.Span);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final int hashCode(Utf8String obj) {
|
||||||
|
checkArgument(obj != null);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint hash1 = 5381;
|
||||||
|
int hash1 = 5381;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint hash2 = hash1;
|
||||||
|
int hash2 = hash1;
|
||||||
|
final int numSamples = 4;
|
||||||
|
final int modulus = 13;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ReadOnlySpan<byte> utf8 = obj.Span.Span;
|
||||||
|
ReadOnlySpan<Byte> utf8 = obj.Span.Span;
|
||||||
|
int max = Math.min(utf8.Length, numSamples);
|
||||||
|
for (int i = 0; i < max; i++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint c = utf8[(i * modulus) % utf8.Length];
|
||||||
|
int c = utf8[(i * modulus) % utf8.Length];
|
||||||
|
if (i % 2 == 0) {
|
||||||
|
hash1 = ((hash1 << 5) + hash1) ^ c;
|
||||||
|
} else {
|
||||||
|
hash2 = ((hash2 << 5) + hash2) ^ c;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash1 + (hash2 * 1566083941);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
public final class Record {
|
||||||
|
|
||||||
|
public static Record empty() {
|
||||||
|
return new Record(0, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int crc32;
|
||||||
|
private int length;
|
||||||
|
|
||||||
|
public Record(int length, int crc32) {
|
||||||
|
this.length = length;
|
||||||
|
this.crc32 = crc32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int crc32() {
|
||||||
|
return this.crc32;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Record crc32(int value) {
|
||||||
|
this.crc32 = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int length() {
|
||||||
|
return this.length;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Record length(int value) {
|
||||||
|
this.length = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
|
||||||
|
|
||||||
|
public final class RecordIOFormatter {
|
||||||
|
|
||||||
|
public static final Layout RECORD_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.RECORD_SCHEMA_ID);
|
||||||
|
public static final Layout SEGMENT_LAYOUT = SystemSchema.layoutResolver.resolve(SystemSchema.SEGMENT_SCHEMA_ID);
|
||||||
|
|
||||||
|
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row) {
|
||||||
|
return FormatRecord(body, row, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public static Result FormatRecord(ReadOnlyMemory<byte> body, out RowBuffer row,
|
||||||
|
// ISpanResizer<byte> resizer = default)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public static Result FormatRecord(ReadOnlyMemory<Byte> body, Out<RowBuffer> row,
|
||||||
|
ISpanResizer<Byte> resizer) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||||
|
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||||
|
int estimatedSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.getSize() + body.Length;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, body.Span);
|
||||||
|
int crc32 = Crc32.Update(0, body.Span);
|
||||||
|
Record record = new Record(body.Length, crc32);
|
||||||
|
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.RECORD_LAYOUT, record.clone(),
|
||||||
|
RecordSerializer.Write, row.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result FormatSegment(Segment segment, Out<RowBuffer> row) {
|
||||||
|
return FormatSegment(segment, row, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public static Result FormatSegment(Segment segment, out RowBuffer row, ISpanResizer<byte>
|
||||||
|
// resizer = default)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public static Result FormatSegment(Segment segment, Out<RowBuffer> row, ISpanResizer<Byte> resizer) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: resizer = resizer != null ? resizer : DefaultSpanResizer<byte>.Default;
|
||||||
|
resizer = resizer != null ? resizer : DefaultSpanResizer < Byte >.Default;
|
||||||
|
int estimatedSize =
|
||||||
|
HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.getSize() + segment.comment() == null ? null :
|
||||||
|
segment.comment().length() != null ? segment.comment().length() : 0 + segment.sdl() == null ? null :
|
||||||
|
segment.sdl().length() != null ? segment.sdl().length() : 0 + 20;
|
||||||
|
|
||||||
|
return RecordIOFormatter.FormatObject(resizer, estimatedSize, RecordIOFormatter.SEGMENT_LAYOUT,
|
||||||
|
segment.clone(), SegmentSerializer.Write, row.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result FormatObject<T>(ISpanResizer<byte> resizer, int initialCapacity, Layout
|
||||||
|
// layout, T obj, RowWriter.WriterFunc<T> writer, out RowBuffer row)
|
||||||
|
private static <T> Result FormatObject(ISpanResizer<Byte> resizer, int initialCapacity, Layout layout, T obj,
|
||||||
|
RowWriter.WriterFunc<T> writer, Out<RowBuffer> row) {
|
||||||
|
row.setAndGet(new RowBuffer(initialCapacity, resizer));
|
||||||
|
row.get().initLayout(HybridRowVersion.V1, layout, SystemSchema.layoutResolver);
|
||||||
|
Result r = RowWriter.WriteBuffer(row.clone(), obj, writer);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
row.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,354 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowHeader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import it.unimi.dsi.fastutil.bytes.Byte2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.bytes.Byte2ObjectOpenHashMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
public final class RecordIOParser {
|
||||||
|
|
||||||
|
private Record record;
|
||||||
|
private Segment segment;
|
||||||
|
private State state = State.values()[0];
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Processes one buffers worth of data possibly advancing the parser state
|
||||||
|
*
|
||||||
|
* @param buffer1 The buffer to consume
|
||||||
|
* @param type Indicates the type of Hybrid Row produced in {@code record}
|
||||||
|
* @param record If non-empty, then the body of the next record in the sequence
|
||||||
|
* @param need The smallest number of bytes needed to advanced the parser state further
|
||||||
|
* <p>
|
||||||
|
* It is recommended that this method not be called again until at least this number of bytes are
|
||||||
|
* available.
|
||||||
|
* @param consumed The number of bytes consumed from the input buffer
|
||||||
|
* <p>
|
||||||
|
* This number may be less than the total buffer size if the parser moved to a new state.
|
||||||
|
* @return {@link Result#SUCCESS} if no error has occurred;, otherwise the {@link Result} of the last error
|
||||||
|
* encountered during parsing.
|
||||||
|
* <p>
|
||||||
|
* >
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public Result process(
|
||||||
|
@Nonnull final ByteBuf buffer,
|
||||||
|
@Nonnull final Out<ProductionType> type,
|
||||||
|
@Nonnull final Out<ByteBuf> record,
|
||||||
|
@Nonnull final Out<Integer> need,
|
||||||
|
@Nonnull final Out<Integer> consumed) {
|
||||||
|
|
||||||
|
Result result = Result.FAILURE;
|
||||||
|
type.set(ProductionType.NONE);
|
||||||
|
record.set(null);
|
||||||
|
|
||||||
|
final int start = buffer.readerIndex();
|
||||||
|
|
||||||
|
switch (this.state) {
|
||||||
|
|
||||||
|
case STATE:
|
||||||
|
this.state = State.NEED_SEGMENT_LENGTH;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
// goto case State.NeedSegmentLength;
|
||||||
|
|
||||||
|
case NEED_SEGMENT_LENGTH: {
|
||||||
|
|
||||||
|
final int minimalSegmentRowSize = HybridRowHeader.BYTES + RecordIOFormatter.SEGMENT_LAYOUT.size();
|
||||||
|
|
||||||
|
if (buffer.readableBytes() < minimalSegmentRowSize) {
|
||||||
|
consumed.set(buffer.readerIndex() - start);
|
||||||
|
need.set(minimalSegmentRowSize);
|
||||||
|
return Result.INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
ByteBuf span = buffer.slice(buffer.readerIndex(), minimalSegmentRowSize);
|
||||||
|
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
Out<Segment> tempOut_segment =
|
||||||
|
new Out<Segment>();
|
||||||
|
result = SegmentSerializer.read(tempReference_reader, tempOut_segment);
|
||||||
|
this.segment = tempOut_segment.get();
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = State.NEED_SEGMENT;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
goto case State.NEED_SEGMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
case NEED_SEGMENT: {
|
||||||
|
if (buffer.Length < this.segment.length()) {
|
||||||
|
need.set(this.segment.length());
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
return Result.INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, this.segment.Length);
|
||||||
|
Span<Byte> span = buffer.Span.Slice(0, this.segment.length());
|
||||||
|
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
Reference<RowReader> tempReference_reader2 =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
Out<Segment> tempOut_segment2
|
||||||
|
= new Out<Segment>();
|
||||||
|
result = SegmentSerializer.read(tempReference_reader2, tempOut_segment2);
|
||||||
|
this.segment = tempOut_segment2.get();
|
||||||
|
reader = tempReference_reader2.get();
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
record.set(buffer.Slice(0, span.Length));
|
||||||
|
buffer = buffer.Slice(span.Length);
|
||||||
|
need.set(0);
|
||||||
|
this.state = State.NEED_HEADER;
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
type.set(ProductionType.SEGMENT);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
case NEED_HEADER: {
|
||||||
|
if (buffer.Length < HybridRowHeader.BYTES) {
|
||||||
|
need.set(HybridRowHeader.BYTES);
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
return Result.INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
HybridRowHeader header;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
MemoryMarshal.TryRead(buffer.Span, out header);
|
||||||
|
if (header.Version != HybridRowVersion.V1) {
|
||||||
|
result = Result.INVALID_ROW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SchemaId.opEquals(header.SchemaId,
|
||||||
|
SystemSchema.SEGMENT_SCHEMA_ID)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
goto case State.NEED_SEGMENT
|
||||||
|
}
|
||||||
|
|
||||||
|
if (SchemaId.opEquals(header.SchemaId,
|
||||||
|
SystemSchema.RECORD_SCHEMA_ID)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
goto case State.NEED_RECORD
|
||||||
|
}
|
||||||
|
|
||||||
|
result = Result.INVALID_ROW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case NEED_RECORD: {
|
||||||
|
int minimalRecordRowSize = HybridRowHeader.BYTES + RecordIOFormatter.RECORD_LAYOUT.size();
|
||||||
|
if (buffer.Length < minimalRecordRowSize) {
|
||||||
|
need.set(minimalRecordRowSize);
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
return Result.INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Span<byte> span = b.Span.Slice(0, minimalRecordRowSize);
|
||||||
|
Span<Byte> span = buffer.Span.Slice(0, minimalRecordRowSize);
|
||||||
|
RowBuffer row = new RowBuffer(span, HybridRowVersion.V1, SystemSchema.layoutResolver);
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Reference<RowReader> tempReference_reader3 = new Reference<RowReader>(reader);
|
||||||
|
Out<Record> tempOut_record = new Out<Record>();
|
||||||
|
result = RecordSerializer.read(tempReference_reader3, tempOut_record);
|
||||||
|
this.record = tempOut_record.get();
|
||||||
|
reader = tempReference_reader3.get();
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = buffer.Slice(span.Length);
|
||||||
|
this.state = State.NEED_ROW;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
goto case State.NEED_ROW
|
||||||
|
}
|
||||||
|
|
||||||
|
case NEED_ROW: {
|
||||||
|
if (buffer.Length < this.record.length()) {
|
||||||
|
need.set(this.record.length());
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
return Result.INSUFFICIENT_BUFFER;
|
||||||
|
}
|
||||||
|
|
||||||
|
record.set(buffer.Slice(0, this.record.length()));
|
||||||
|
|
||||||
|
// Validate that the record has not been corrupted.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint crc32 = Crc32.Update(0, record.Span);
|
||||||
|
int crc32 = Crc32.Update(0, record.get().Span);
|
||||||
|
if (crc32 != this.record.crc32()) {
|
||||||
|
result = Result.INVALID_ROW;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer = buffer.Slice(this.record.length());
|
||||||
|
need.set(0);
|
||||||
|
this.state = State.NEED_HEADER;
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
type.set(ProductionType.RECORD);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.state = State.ERROR;
|
||||||
|
need.set(0);
|
||||||
|
consumed.set(buffer.Length - buffer.Length);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* True if a valid segment has been parsed.
|
||||||
|
*/
|
||||||
|
public boolean haveSegment() {
|
||||||
|
return this.state.value() >= State.NEED_HEADER.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If a valid segment has been parsed then current active segment, otherwise undefined.
|
||||||
|
*/
|
||||||
|
public Segment segment() {
|
||||||
|
checkState(this.haveSegment());
|
||||||
|
return this.segment;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the type of Hybrid Rows produced by the parser.
|
||||||
|
*/
|
||||||
|
public enum ProductionType {
|
||||||
|
/**
|
||||||
|
* No hybrid row was produced. The parser needs more data.
|
||||||
|
*/
|
||||||
|
NONE(0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A new segment row was produced.
|
||||||
|
*/
|
||||||
|
SEGMENT(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A record in the current segment was produced.
|
||||||
|
*/
|
||||||
|
RECORD(2);
|
||||||
|
|
||||||
|
public static final int BYTES = Integer.BYTES;
|
||||||
|
|
||||||
|
private static Int2ObjectMap<ProductionType> mappings;
|
||||||
|
private int value;
|
||||||
|
|
||||||
|
ProductionType(int value) {
|
||||||
|
this.value = value;
|
||||||
|
mappings().put(value, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static ProductionType from(int value) {
|
||||||
|
return mappings().get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Int2ObjectMap<ProductionType> mappings() {
|
||||||
|
if (mappings == null) {
|
||||||
|
synchronized (ProductionType.class) {
|
||||||
|
if (mappings == null) {
|
||||||
|
mappings = new Int2ObjectOpenHashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The states for the internal state machine.
|
||||||
|
* Note: numerical ordering of these states matters.
|
||||||
|
*/
|
||||||
|
private enum State {
|
||||||
|
STATE(
|
||||||
|
(byte) 0, "Start: no buffers have yet been provided to the parser"),
|
||||||
|
ERROR(
|
||||||
|
(byte) 1, "Unrecoverable parse error encountered"),
|
||||||
|
NEED_SEGMENT_LENGTH(
|
||||||
|
(byte) 2, "Parsing segment header length"),
|
||||||
|
NEED_SEGMENT(
|
||||||
|
(byte) 3, "Parsing segment header"),
|
||||||
|
NEED_HEADER(
|
||||||
|
(byte) 4, "Parsing HybridRow header"),
|
||||||
|
NEED_RECORD(
|
||||||
|
(byte) 5, "Parsing record header"),
|
||||||
|
NEED_ROW(
|
||||||
|
(byte) 6, "Parsing row body");
|
||||||
|
|
||||||
|
public static final int BYTES = Byte.SIZE;
|
||||||
|
|
||||||
|
private static Byte2ObjectMap<State> mappings;
|
||||||
|
private final String description;
|
||||||
|
private final byte value;
|
||||||
|
|
||||||
|
State(byte value, String description) {
|
||||||
|
this.description = description;
|
||||||
|
this.value = value;
|
||||||
|
mappings().put(value, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String description() {
|
||||||
|
return this.description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static State from(byte value) {
|
||||||
|
return mappings().get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Byte2ObjectMap<State> mappings() {
|
||||||
|
if (mappings == null) {
|
||||||
|
synchronized (State.class) {
|
||||||
|
if (mappings == null) {
|
||||||
|
mappings = new Byte2ObjectOpenHashMap<>();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return mappings;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,368 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
|
||||||
|
public final class RecordIOStream {
|
||||||
|
/**
|
||||||
|
* A function that produces RecordIO record bodies.
|
||||||
|
* <p>
|
||||||
|
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||||
|
* HybridRow, but any binary data is allowed.
|
||||||
|
*
|
||||||
|
* @param index The 0-based index of the record within the segment to be produced.
|
||||||
|
* @return A tuple with: Success if the body was produced without error, the error code otherwise.
|
||||||
|
* And, the byte sequence of the record body's row buffer.
|
||||||
|
*/
|
||||||
|
public delegate ValueTask
|
||||||
|
|
||||||
|
ProduceFuncAsync(long index);<(Result,ReadOnlyMemory<Byte>)>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads an entire RecordIO stream.
|
||||||
|
*
|
||||||
|
* @param stm The stream to read from.
|
||||||
|
* @param visitRecord A (required) delegate that is called once for each record.
|
||||||
|
* <p>
|
||||||
|
* <paramref name="visitRecord" /> is passed a {@link Memory{T}} of the byte sequence
|
||||||
|
* of the
|
||||||
|
* record body's row buffer.
|
||||||
|
* </p>
|
||||||
|
* <p>If <paramref name="visitRecord" /> returns an error then the sequence is aborted.</p>
|
||||||
|
* @param visitSegment An (optional) delegate that is called once for each segment header.
|
||||||
|
* <p>
|
||||||
|
* If <paramref name="visitSegment" /> is not provided then segment headers are parsed but
|
||||||
|
* skipped
|
||||||
|
* over.
|
||||||
|
* </p>
|
||||||
|
* <p>
|
||||||
|
* <paramref name="visitSegment" /> is passed a {@link Memory{T}} of the byte sequence of
|
||||||
|
* the segment header's row buffer.
|
||||||
|
* </p>
|
||||||
|
* <p>If <paramref name="visitSegment" /> returns an error then the sequence is aborted.</p>
|
||||||
|
* @param resizer Optional memory resizer.
|
||||||
|
* @return Success if the stream is parsed without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord,
|
||||||
|
Func<Memory<Byte>, Result> visitSegment) {
|
||||||
|
return ReadRecordIOAsync(stm, visitRecord, visitSegment, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Task<Result> ReadRecordIOAsync(Stream stm, Func<Memory<Byte>, Result> visitRecord) {
|
||||||
|
return ReadRecordIOAsync(stm, visitRecord, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: public static async Task<Result> ReadRecordIOAsync(this Stream stm, Func<Memory<byte>, Result>
|
||||||
|
// visitRecord, Func<Memory<byte>, Result> visitSegment = default, MemorySpanResizer<byte> resizer = default)
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public static Task<Result> ReadRecordIOAsync(InputStream stm,
|
||||||
|
tangible.Func1Param<Memory<Byte>, Result> visitRecord,
|
||||||
|
tangible.Func1Param<Memory<Byte>, Result> visitSegment,
|
||||||
|
MemorySpanResizer<Byte> resizer) {
|
||||||
|
checkArgument(stm != null);
|
||||||
|
checkArgument(visitRecord != null);
|
||||||
|
|
||||||
|
// Create a reusable, resizable buffer if the caller didn't provide one.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||||
|
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||||
|
|
||||||
|
RecordIOParser parser = null;
|
||||||
|
int need = 0;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Memory<byte> active = resizer.Memory;
|
||||||
|
Memory<Byte> active = resizer.getMemory();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Memory<byte> avail = default;
|
||||||
|
Memory<Byte> avail = null;
|
||||||
|
while (true) {
|
||||||
|
checkState(avail.Length < active.Length);
|
||||||
|
checkState(active.Length > 0);
|
||||||
|
checkState(active.Length >= need);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
int read = await stm.ReadAsync(active.Slice(avail.Length));
|
||||||
|
if (read == 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
avail = active.Slice(0, avail.Length + read);
|
||||||
|
|
||||||
|
// If there isn't enough data to move the parser forward then just read again.
|
||||||
|
if (avail.Length < need) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process the available data until no more forward progress is possible.
|
||||||
|
while (avail.Length > 0) {
|
||||||
|
// Loop around processing available data until we don't have anymore
|
||||||
|
RecordIOParser.ProductionType prodType;
|
||||||
|
Out<RecordIOParser.ProductionType> tempOut_prodType = new Out<RecordIOParser.ProductionType>();
|
||||||
|
Memory<Byte> record;
|
||||||
|
Out<Memory<Byte>> tempOut_record = new Out<Memory<Byte>>();
|
||||||
|
Out<Integer> tempOut_need = new Out<Integer>();
|
||||||
|
int consumed;
|
||||||
|
Out<Integer> tempOut_consumed = new Out<Integer>();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Result r = parser.Process(avail, out RecordIOParser.ProductionType prodType, out
|
||||||
|
// Memory<byte> record, out need, out int consumed);
|
||||||
|
Result r = parser.process(avail, tempOut_prodType, tempOut_record, tempOut_need, tempOut_consumed);
|
||||||
|
consumed = tempOut_consumed.get();
|
||||||
|
need = tempOut_need.get();
|
||||||
|
record = tempOut_record.get();
|
||||||
|
prodType = tempOut_prodType.get();
|
||||||
|
|
||||||
|
if ((r != Result.SUCCESS) && (r != Result.INSUFFICIENT_BUFFER)) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
active = active.Slice(consumed);
|
||||||
|
avail = avail.Slice(consumed);
|
||||||
|
if (avail.IsEmpty) {
|
||||||
|
active = resizer.getMemory();
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there wasn't enough data to move the parser forward then get more data.
|
||||||
|
if (r == Result.INSUFFICIENT_BUFFER) {
|
||||||
|
if (need > active.Length) {
|
||||||
|
resizer.Resize(need, avail.Span);
|
||||||
|
active = resizer.getMemory();
|
||||||
|
avail = resizer.getMemory().Slice(0, avail.Length);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Validate the Segment
|
||||||
|
if (prodType == RecordIOParser.ProductionType.SEGMENT) {
|
||||||
|
checkState(!record.IsEmpty);
|
||||||
|
r = visitSegment == null ? null : visitSegment.invoke(record) != null ?
|
||||||
|
visitSegment.invoke(record) : Result.SUCCESS;
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Consume the record.
|
||||||
|
if (prodType == RecordIOParser.ProductionType.RECORD) {
|
||||||
|
checkState(!record.IsEmpty);
|
||||||
|
|
||||||
|
r = visitRecord.invoke(record);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Make sure we processed all of the available data.
|
||||||
|
checkState(avail.Length == 0);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a RecordIO segment into a stream.
|
||||||
|
*
|
||||||
|
* @param stm The stream to write to.
|
||||||
|
* @param segment The segment header to write.
|
||||||
|
* @param produce A function to produces the record bodies for the segment.
|
||||||
|
* <p>
|
||||||
|
* The <paramref name="produce" /> function is called until either an error is encountered or it
|
||||||
|
* produces an empty body. An empty body terminates the segment.
|
||||||
|
* </p>
|
||||||
|
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
|
||||||
|
* @param resizer Optional memory resizer for RecordIO metadata row buffers.
|
||||||
|
* <p>
|
||||||
|
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
|
||||||
|
* blocks of memory are used concurrently.
|
||||||
|
* </p>
|
||||||
|
* @return Success if the stream is written without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce) {
|
||||||
|
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public static Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment, ProduceFunc
|
||||||
|
// produce, MemorySpanResizer<byte> resizer = default)
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
|
||||||
|
// output:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFunc produce,
|
||||||
|
MemorySpanResizer<Byte> resizer) {
|
||||||
|
return RecordIOStream.WriteRecordIOAsync(stm,
|
||||||
|
segment.clone(), index ->
|
||||||
|
{
|
||||||
|
ReadOnlyMemory<Byte> buffer;
|
||||||
|
Out<ReadOnlyMemory<Byte>> tempOut_buffer = new Out<ReadOnlyMemory<Byte>>();
|
||||||
|
buffer = tempOut_buffer.get();
|
||||||
|
return new ValueTask<(Result, ReadOnlyMemory < Byte >) > ((r,buffer))
|
||||||
|
}, resizer);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Writes a RecordIO segment into a stream.
|
||||||
|
*
|
||||||
|
* @param stm The stream to write to.
|
||||||
|
* @param segment The segment header to write.
|
||||||
|
* @param produce A function to produces the record bodies for the segment.
|
||||||
|
* <p>
|
||||||
|
* The <paramref name="produce" /> function is called until either an error is encountered or it
|
||||||
|
* produces an empty body. An empty body terminates the segment.
|
||||||
|
* </p>
|
||||||
|
* <p>If <paramref name="produce" /> returns an error then the sequence is aborted.</p>
|
||||||
|
* @param resizer Optional memory resizer for RecordIO metadata row buffers.
|
||||||
|
* <p>
|
||||||
|
* <em>Note:</em> This should <em>NOT</em> be the same resizer used to process any rows as both
|
||||||
|
* blocks of memory are used concurrently.
|
||||||
|
* </p>
|
||||||
|
* @return Success if the stream is written without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
|
||||||
|
public static Task<Result> WriteRecordIOAsync(Stream stm, Segment segment, ProduceFuncAsync produce) {
|
||||||
|
return WriteRecordIOAsync(stm, segment, produce, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: public static async Task<Result> WriteRecordIOAsync(this Stream stm, Segment segment,
|
||||||
|
// ProduceFuncAsync produce, MemorySpanResizer<byte> resizer = default)
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public static Task<Result> WriteRecordIOAsync(OutputStream stm, Segment segment, ProduceFuncAsync produce,
|
||||||
|
MemorySpanResizer<Byte> resizer) {
|
||||||
|
// Create a reusable, resizable buffer if the caller didn't provide one.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: resizer = resizer != null ? resizer : new MemorySpanResizer<byte>();
|
||||||
|
resizer = resizer != null ? resizer : new MemorySpanResizer<Byte>();
|
||||||
|
|
||||||
|
// Write a RecordIO stream.
|
||||||
|
Memory<Byte> metadata;
|
||||||
|
Out<Memory<Byte>> tempOut_metadata = new Out<Memory<Byte>>();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Result r = RecordIOStream.FormatSegment(segment, resizer, out Memory<byte> metadata);
|
||||||
|
Result r = RecordIOStream.FormatSegment(segment.clone(), resizer, tempOut_metadata);
|
||||||
|
metadata = tempOut_metadata.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await stm.WriteAsync(metadata);
|
||||||
|
|
||||||
|
long index = 0;
|
||||||
|
while (true) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ReadOnlyMemory<byte> body;
|
||||||
|
ReadOnlyMemory<Byte> body;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to the C# deconstruction assignments:
|
||||||
|
(r, body) =await produce (index++);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (body.IsEmpty) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
Out<Memory<Byte>> tempOut_metadata2 = new Out<Memory<Byte>>();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: r = RecordIOStream.FormatRow(body, resizer, out metadata);
|
||||||
|
r = RecordIOStream.FormatRow(body, resizer, tempOut_metadata2);
|
||||||
|
metadata = tempOut_metadata2.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Metadata and Body memory blocks should not overlap since they are both in
|
||||||
|
// play at the same time. If they do this usually means that the same resizer
|
||||||
|
// was incorrectly used for both. Check the resizer parameter passed to
|
||||||
|
// WriteRecordIOAsync for metadata.
|
||||||
|
checkState(!metadata.Span.Overlaps(body.Span));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await stm.WriteAsync(metadata);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await stm.WriteAsync(body);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Compute and format a record header for the given record body.
|
||||||
|
*
|
||||||
|
* @param body The body whose record header should be formatted.
|
||||||
|
* @param resizer The resizer to use in allocating a buffer for the record header.
|
||||||
|
* @param block The byte sequence of the written row buffer.
|
||||||
|
* @return Success if the write completes without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result FormatRow(ReadOnlyMemory<byte> body, MemorySpanResizer<byte> resizer, out Memory<byte> block)
|
||||||
|
private static Result FormatRow(ReadOnlyMemory<Byte> body, MemorySpanResizer<Byte> resizer, Out<Memory<Byte>> block) {
|
||||||
|
RowBuffer row;
|
||||||
|
Out<RowBuffer> tempOut_row = new Out<RowBuffer>();
|
||||||
|
Result r = RecordIOFormatter.FormatRecord(body, tempOut_row, resizer);
|
||||||
|
row = tempOut_row.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
block.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Format a segment.
|
||||||
|
*
|
||||||
|
* @param segment The segment to format.
|
||||||
|
* @param resizer The resizer to use in allocating a buffer for the segment.
|
||||||
|
* @param block The byte sequence of the written row buffer.
|
||||||
|
* @return Success if the write completes without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result FormatSegment(Segment segment, MemorySpanResizer<byte> resizer, out
|
||||||
|
// Memory<byte> block)
|
||||||
|
private static Result FormatSegment(Segment segment, MemorySpanResizer<Byte> resizer,
|
||||||
|
Out<Memory<Byte>> block) {
|
||||||
|
RowBuffer row;
|
||||||
|
Out<RowBuffer> tempOut_row =
|
||||||
|
new Out<RowBuffer>();
|
||||||
|
Result r = RecordIOFormatter.FormatSegment(segment.clone(), tempOut_row, resizer);
|
||||||
|
row = tempOut_row.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
block.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
block.setAndGet(resizer.getMemory().Slice(0, row.Length));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A function that produces RecordIO record bodies.
|
||||||
|
* <p>
|
||||||
|
* Record bodies are returned as memory blocks. It is expected that each block is a
|
||||||
|
* HybridRow, but any binary data is allowed.
|
||||||
|
*
|
||||||
|
* @param index The 0-based index of the record within the segment to be produced.
|
||||||
|
* @param buffer The byte sequence of the record body's row buffer.
|
||||||
|
* @return Success if the body was produced without error, the error code otherwise.
|
||||||
|
*/
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface ProduceFunc {
|
||||||
|
Result invoke(long index, Out<ReadOnlyMemory<Byte>> buffer);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,68 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.UtfAnyString;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
public final class RecordSerializer {
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static Result read(RowReader reader, Out<Record> record) {
|
||||||
|
|
||||||
|
Out<Integer> value = new Out<>();
|
||||||
|
record.set(Record.empty());
|
||||||
|
|
||||||
|
while (reader.read()) {
|
||||||
|
|
||||||
|
String path = reader.path().toUtf16();
|
||||||
|
checkState(path != null);
|
||||||
|
Result result;
|
||||||
|
|
||||||
|
// TODO: use Path tokens here
|
||||||
|
|
||||||
|
switch (path) {
|
||||||
|
|
||||||
|
case "length":
|
||||||
|
|
||||||
|
result = reader.readInt32(value);
|
||||||
|
record.get().length(value.get());
|
||||||
|
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "crc32":
|
||||||
|
|
||||||
|
result = reader.readInt32(value);
|
||||||
|
record.get().crc32(value.get());
|
||||||
|
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static Result write(RowWriter writer, TypeArgument typeArg, Record record) {
|
||||||
|
Result result = writer.writeInt32(new UtfAnyString("length"), record.length());
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
return writer.writeUInt32(new UtfAnyString("crc32"), record.crc32());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,123 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.recordio;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Utf8String;
|
||||||
|
import com.azure.data.cosmos.core.UtfAnyString;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
|
||||||
|
public final class SegmentSerializer {
|
||||||
|
|
||||||
|
private static final UtfAnyString COMMENT = new UtfAnyString("comment");
|
||||||
|
private static final UtfAnyString LENGTH = new UtfAnyString("length");
|
||||||
|
private static final UtfAnyString SDL = new UtfAnyString("sdl");
|
||||||
|
|
||||||
|
public static Result read(ByteBuf buffer, LayoutResolver resolver, Out<Segment> segment) {
|
||||||
|
RowReader reader = new RowReader(new RowBuffer(buffer, HybridRowVersion.V1, resolver));
|
||||||
|
return SegmentSerializer.read(reader, segment);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result read(RowReader reader, Out<Segment> segment) {
|
||||||
|
|
||||||
|
segment.set(new Segment(null, null));
|
||||||
|
|
||||||
|
final Out<String> comment = new Out<>();
|
||||||
|
final Out<Integer> length = new Out<>();
|
||||||
|
final Out<String> sdl = new Out<>();
|
||||||
|
|
||||||
|
while (reader.read()) {
|
||||||
|
|
||||||
|
// TODO: Use Path tokens here.
|
||||||
|
|
||||||
|
switch (Objects.requireNonNull(reader.path().toUtf16())) {
|
||||||
|
|
||||||
|
case "length": {
|
||||||
|
|
||||||
|
Result result = reader.readInt32(length);
|
||||||
|
segment.get().length(length.get());
|
||||||
|
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (reader.length() < segment.get().length()) {
|
||||||
|
// RowBuffer isn't big enough to contain the rest of the header so just return the length
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "comment": {
|
||||||
|
|
||||||
|
Result result = reader.readString(comment);
|
||||||
|
segment.get().comment(comment.get());
|
||||||
|
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "sdl": {
|
||||||
|
|
||||||
|
Result result = reader.readString(sdl);
|
||||||
|
segment.get().sdl(sdl.get());
|
||||||
|
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result write(RowWriter writer, TypeArgument typeArg, Segment segment) {
|
||||||
|
|
||||||
|
Result result;
|
||||||
|
|
||||||
|
if (segment.comment() != null) {
|
||||||
|
result = writer.writeString(COMMENT, segment.comment());
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (segment.sdl() != null) {
|
||||||
|
result = writer.writeString(SDL, segment.sdl());
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Defer writing the length until all other fields of the segment header are written.
|
||||||
|
// The length is then computed based on the current size of the underlying RowBuffer.
|
||||||
|
// Because the length field is itself fixed, writing the length can never change the length.
|
||||||
|
|
||||||
|
int length = writer.length();
|
||||||
|
result = writer.writeInt32(LENGTH, length);
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
checkState(length == writer.length());
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,84 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import Newtonsoft.Json.Converters.*;
|
||||||
|
import Newtonsoft.Json.Linq.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Helper class for parsing the polymorphic {@link PropertyType} subclasses from JSON.
|
||||||
|
*/
|
||||||
|
public class PropertySchemaConverter extends JsonConverter {
|
||||||
|
@Override
|
||||||
|
public boolean getCanWrite() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean CanConvert(java.lang.Class objectType) {
|
||||||
|
return objectType.isAssignableFrom(PropertyType.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
|
||||||
|
JsonSerializer serializer) {
|
||||||
|
PropertyType p;
|
||||||
|
if (reader.TokenType != JsonToken.StartObject) {
|
||||||
|
throw new JsonSerializationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
JObject propSchema = JObject.Load(reader);
|
||||||
|
TypeKind propType;
|
||||||
|
|
||||||
|
JToken value;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
if (!propSchema.TryGetValue("type", out value)) {
|
||||||
|
throw new JsonSerializationException("Required \"type\" property missing.");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (JsonReader typeReader = value.CreateReader()) {
|
||||||
|
typeReader.Read(); // Move to the start token
|
||||||
|
propType = TypeKind.forValue((new StringEnumConverter(true)).ReadJson(typeReader, TypeKind.class, null,
|
||||||
|
serializer));
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (propType) {
|
||||||
|
case Array:
|
||||||
|
p = new ArrayPropertyType();
|
||||||
|
break;
|
||||||
|
case SET:
|
||||||
|
p = new SetPropertyType();
|
||||||
|
break;
|
||||||
|
case MAP:
|
||||||
|
p = new MapPropertyType();
|
||||||
|
break;
|
||||||
|
case Object:
|
||||||
|
p = new ObjectPropertyType();
|
||||||
|
break;
|
||||||
|
case Tuple:
|
||||||
|
p = new TuplePropertyType();
|
||||||
|
break;
|
||||||
|
case TAGGED:
|
||||||
|
p = new TaggedPropertyType();
|
||||||
|
break;
|
||||||
|
case Schema:
|
||||||
|
p = new UdtPropertyType();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
p = new PrimitivePropertyType();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
serializer.Populate(propSchema.CreateReader(), p);
|
||||||
|
return p;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
|
||||||
|
@Override
|
||||||
|
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,37 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
|
||||||
|
public class StrictBooleanConverter extends JsonConverter {
|
||||||
|
@Override
|
||||||
|
public boolean getCanWrite() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean CanConvert(java.lang.Class objectType) {
|
||||||
|
return objectType == Boolean.class;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
|
||||||
|
JsonSerializer serializer) {
|
||||||
|
switch (reader.TokenType) {
|
||||||
|
case JsonToken.Boolean:
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
default:
|
||||||
|
throw new JsonSerializationException(String.format("Token \"%1$s\" of type %2$s was not a JSON bool",
|
||||||
|
reader.Value, reader.TokenType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value,
|
||||||
|
// JsonSerializer serializer)
|
||||||
|
@Override
|
||||||
|
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.schemas;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
|
||||||
|
import java.math.BigInteger;
|
||||||
|
|
||||||
|
public class StrictIntegerConverter extends JsonConverter {
|
||||||
|
@Override
|
||||||
|
public boolean getCanWrite() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean CanConvert(java.lang.Class objectType) {
|
||||||
|
return StrictIntegerConverter.IsIntegerType(objectType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object ReadJson(JsonReader reader, java.lang.Class objectType, Object existingValue,
|
||||||
|
JsonSerializer serializer) {
|
||||||
|
switch (reader.TokenType) {
|
||||||
|
case JsonToken.Integer:
|
||||||
|
return serializer.Deserialize(reader, objectType);
|
||||||
|
default:
|
||||||
|
throw new JsonSerializationException(String.format("Token \"%1$s\" of type %2$s was not a JSON " +
|
||||||
|
"integer", reader.Value, reader.TokenType));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [ExcludeFromCodeCoverage] public override void WriteJson(JsonWriter writer, object value,
|
||||||
|
// JsonSerializer serializer)
|
||||||
|
@Override
|
||||||
|
public void WriteJson(JsonWriter writer, Object value, JsonSerializer serializer) {
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean IsIntegerType(java.lang.Class type) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: if (type == typeof(long) || type == typeof(ulong) || type == typeof(int) || type == typeof
|
||||||
|
// (uint) || type == typeof(short) || type == typeof(ushort) || type == typeof(byte) || type == typeof(sbyte)
|
||||||
|
// || type == typeof(BigInteger))
|
||||||
|
return type == Long.class || type == Long.class || type == Integer.class || type == Integer.class || type == Short.class || type == Short.class || type == Byte.class || type == Byte.class || type == BigInteger.class;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolverNamespace;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.SystemSchema;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public class BenchmarkSuiteBase {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
//ORIGINAL LINE: private protected const int InitialCapacity = 2 * 1024 * 1024;
|
||||||
|
protected static final int InitialCapacity = 2 * 1024 * 1024;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
//ORIGINAL LINE: private protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)
|
||||||
|
// SystemSchema.LayoutResolver;
|
||||||
|
protected LayoutResolverNamespace DefaultResolver = (LayoutResolverNamespace)SystemSchema.layoutResolver;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Methods returning tuples are not converted by C# to Java Converter:
|
||||||
|
// private protected async Task<(List<Dictionary<Utf8String, object>>, LayoutResolverNamespace)>
|
||||||
|
// LoadExpectedAsync(string expectedFile)
|
||||||
|
// {
|
||||||
|
// LayoutResolverNamespace resolver = this.DefaultResolver;
|
||||||
|
// List<Dictionary<Utf8String, object>> expected = new List<Dictionary<Utf8String, object>>();
|
||||||
|
// using (Stream stm = new FileStream(expectedFile, FileMode.Open))
|
||||||
|
// {
|
||||||
|
// // Read a RecordIO stream.
|
||||||
|
// MemorySpanResizer<byte> resizer = new MemorySpanResizer<byte>(BenchmarkSuiteBase.InitialCapacity);
|
||||||
|
// Result r = await stm.ReadRecordIOAsync(record =>
|
||||||
|
// {
|
||||||
|
// r = BenchmarkSuiteBase.LoadOneRow(record, resolver, out Dictionary<Utf8String, object>
|
||||||
|
// rowValue);
|
||||||
|
// ResultAssert.IsSuccess(r);
|
||||||
|
// expected.Add(rowValue);
|
||||||
|
// return Result.Success;
|
||||||
|
// }
|
||||||
|
// , segment =>
|
||||||
|
// {
|
||||||
|
// r = SegmentSerializer.Read(segment.Span, SystemSchema.LayoutResolver, out Segment s);
|
||||||
|
// ResultAssert.IsSuccess(r);
|
||||||
|
// Assert.IsNotNull(s.SDL);
|
||||||
|
// resolver = new LayoutResolverNamespace(Namespace.Parse(s.SDL), resolver);
|
||||||
|
// return Result.Success;
|
||||||
|
// }
|
||||||
|
// , resizer);
|
||||||
|
//
|
||||||
|
// ResultAssert.IsSuccess(r);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// return (expected, resolver);
|
||||||
|
// }
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
//ORIGINAL LINE: private protected static Result LoadOneRow(Memory<byte> buffer, LayoutResolver resolver, out
|
||||||
|
// Dictionary<Utf8String, object> rowValue)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
protected static Result LoadOneRow(Memory<Byte> buffer, LayoutResolver resolver,
|
||||||
|
Out<HashMap<Utf8String, Object>> rowValue) {
|
||||||
|
RowBuffer row = new RowBuffer(buffer.Span, HybridRowVersion.V1, resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
Result tempVar = DiagnosticConverter.ReaderToDynamic(tempReference_reader, rowValue);
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: private protected static async Task WriteAllRowsAsync(string file, string sdl, LayoutResolver
|
||||||
|
// resolver, Layout layout, List<Dictionary<Utf8String, object>> rows)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
protected static Task WriteAllRowsAsync(String file, String sdl, LayoutResolver resolver, Layout layout,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> rows) {
|
||||||
|
try (Stream stm = new FileStream(file, FileMode.Truncate)) {
|
||||||
|
// Create a reusable, resizable buffer.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MemorySpanResizer<byte> resizer = new MemorySpanResizer<byte>(BenchmarkSuiteBase
|
||||||
|
// .InitialCapacity);
|
||||||
|
MemorySpanResizer<Byte> resizer = new MemorySpanResizer<Byte>(BenchmarkSuiteBase.InitialCapacity);
|
||||||
|
|
||||||
|
// Write a RecordIO stream.
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'out' keyword - these are
|
||||||
|
// not converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Result r = await stm.WriteRecordIOAsync(new Segment("HybridRow.Tests.Perf Expected
|
||||||
|
// Results", sdl), (long index, out ReadOnlyMemory<byte> body) =>
|
||||||
|
Result r = await RecordIOStream.WriteRecordIOAsync(stm,
|
||||||
|
new Segment("HybridRow.Tests.Perf Expected Results", sdl), (long index, out ReadOnlyMemory<Byte>body) ->
|
||||||
|
{
|
||||||
|
body = null;
|
||||||
|
if (index >= rows.size()) {
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
StreamingRowGenerator writer = new StreamingRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout,
|
||||||
|
resolver, resizer);
|
||||||
|
|
||||||
|
Result r2 = writer.WriteBuffer(rows.get((int)index));
|
||||||
|
if (r2 != Result.SUCCESS) {
|
||||||
|
return r2;
|
||||||
|
}
|
||||||
|
|
||||||
|
body = resizer.getMemory().Slice(0, writer.getLength());
|
||||||
|
return Result.SUCCESS;
|
||||||
|
});
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
//ORIGINAL LINE: private protected static class ResultAssert
|
||||||
|
protected static class ResultAssert {
|
||||||
|
public static void IsSuccess(Result actual) {
|
||||||
|
assert actual == Result.SUCCESS || Result.SUCCESS == actual;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,130 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import org.bson.BsonWriter;
|
||||||
|
import org.bson.BsonBinaryWriter
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
public final class BsonJsonModelRowGenerator implements Closeable {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.MemoryStream is
|
||||||
|
// input or output:
|
||||||
|
private MemoryStream stream;
|
||||||
|
private BsonWriter writer;
|
||||||
|
|
||||||
|
public BsonJsonModelRowGenerator(int capacity) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.MemoryStream
|
||||||
|
// is input or output:
|
||||||
|
this.stream = new MemoryStream(capacity);
|
||||||
|
this.writer = new BsonBinaryWriter(this.stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return (int)this.stream.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
this.stream.SetLength(0);
|
||||||
|
this.stream.Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ToArray()
|
||||||
|
public byte[] ToArray() {
|
||||||
|
return this.stream.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBuffer(HashMap<Utf8String, Object> dict) {
|
||||||
|
this.writer.writeStartDocument();
|
||||||
|
for ((Utf8String propPath,Object propValue) : dict)
|
||||||
|
{
|
||||||
|
this.JsonModelSwitch(propPath, propValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.writer.Dispose();
|
||||||
|
this.stream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void JsonModelSwitch(Utf8String path, Object value) {
|
||||||
|
if (path != null) {
|
||||||
|
this.writer.writeName(path.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (value) {
|
||||||
|
case null:
|
||||||
|
this.writer.writeNull();
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case bool x:
|
||||||
|
case
|
||||||
|
boolean x:
|
||||||
|
this.writer.writeBoolean(x);
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case long x:
|
||||||
|
case
|
||||||
|
long x:
|
||||||
|
this.writer.writeInt64(x);
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case double x:
|
||||||
|
case
|
||||||
|
double x:
|
||||||
|
this.writer.writeDouble(x);
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case string x:
|
||||||
|
case String
|
||||||
|
x:
|
||||||
|
this.writer.writeString(x);
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case Utf8String x:
|
||||||
|
case Utf8String
|
||||||
|
x:
|
||||||
|
this.writer.writeString(x.toString());
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case byte[] x:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
case
|
||||||
|
byte[] x:
|
||||||
|
this.writer.writeBytes(x);
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case Dictionary<Utf8String, object> x:
|
||||||
|
case HashMap < Utf8String, Object > x:
|
||||||
|
this.writer.writeStartDocument();
|
||||||
|
for ((Utf8String propPath,Object propValue) :x)
|
||||||
|
{
|
||||||
|
this.JsonModelSwitch(propPath, propValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndDocument();
|
||||||
|
return;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case List<object> x:
|
||||||
|
case ArrayList < Object > x:
|
||||||
|
this.writer.writeStartArray();
|
||||||
|
for (Object item : x) {
|
||||||
|
this.JsonModelSwitch(null, item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndArray();
|
||||||
|
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", value.getClass().getSimpleName()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import MongoDB.Bson.*;
|
||||||
|
import MongoDB.Bson.IO.*;
|
||||||
|
|
||||||
|
public final class BsonReaderExtensions {
|
||||||
|
public static void VisitBsonDocument(BsonReader bsonReader) {
|
||||||
|
bsonReader.ReadStartDocument();
|
||||||
|
BsonType type;
|
||||||
|
while ((type = bsonReader.ReadBsonType()) != BsonType.EndOfDocument) {
|
||||||
|
String path = bsonReader.ReadName();
|
||||||
|
switch (type) {
|
||||||
|
case BsonType.Array:
|
||||||
|
BsonReaderExtensions.VisitBsonArray(bsonReader);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BsonType.Document:
|
||||||
|
BsonReaderExtensions.VisitBsonDocument(bsonReader);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
bsonReader.SkipValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bsonReader.ReadEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void VisitBsonArray(BsonReader bsonReader) {
|
||||||
|
bsonReader.ReadStartArray();
|
||||||
|
BsonType type;
|
||||||
|
while ((type = bsonReader.ReadBsonType()) != BsonType.EndOfDocument) {
|
||||||
|
switch (type) {
|
||||||
|
case BsonType.Array:
|
||||||
|
BsonReaderExtensions.VisitBsonArray(bsonReader);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case BsonType.Document:
|
||||||
|
BsonReaderExtensions.VisitBsonDocument(bsonReader);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
bsonReader.SkipValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bsonReader.ReadEndArray();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,314 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import MongoDB.Bson.*;
|
||||||
|
import MongoDB.Bson.IO.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Float128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
import org.bson.BsonBinaryWriter;
|
||||||
|
import org.bson.BsonWriter;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
public final class BsonRowGenerator implements Closeable {
|
||||||
|
private Layout layout;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.MemoryStream is
|
||||||
|
// input or output:
|
||||||
|
private MemoryStream stream;
|
||||||
|
private BsonWriter writer;
|
||||||
|
|
||||||
|
public BsonRowGenerator(int capacity, Layout layout, LayoutResolver resolver) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.MemoryStream
|
||||||
|
// is input or output:
|
||||||
|
this.stream = new MemoryStream(capacity);
|
||||||
|
this.writer = new BsonBinaryWriter(this.stream);
|
||||||
|
this.layout = layout;
|
||||||
|
this.resolver = resolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return (int)this.stream.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
this.stream.SetLength(0);
|
||||||
|
this.stream.Position = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ToArray()
|
||||||
|
public byte[] ToArray() {
|
||||||
|
return this.stream.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBuffer(HashMap<Utf8String, Object> dict) {
|
||||||
|
this.writer.writeStartDocument();
|
||||||
|
for (LayoutColumn c : this.layout.columns()) {
|
||||||
|
this.LayoutCodeSwitch(c.path(), c.typeArg().clone(), dict.get(c.path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.writer.Dispose();
|
||||||
|
this.stream.Dispose();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchArray(TypeArgument typeArg, Object value) {
|
||||||
|
|
||||||
|
checkArgument(typeArg.typeArgs().count() == 1);
|
||||||
|
this.writer.writeStartArray();
|
||||||
|
|
||||||
|
for (Object item : (ArrayList<Object>)value) {
|
||||||
|
this.LayoutCodeSwitch(null, typeArg.typeArgs().get(0).clone(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchMap(TypeArgument typeArg, Object value) {
|
||||||
|
checkArgument(typeArg.typeArgs().count() == 2);
|
||||||
|
|
||||||
|
this.writer.writeStartArray();
|
||||||
|
for (Object item : (ArrayList<Object>)value) {
|
||||||
|
this.DispatchTuple(typeArg.clone(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.writeEndArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchNullable(TypeArgument typeArg, Object value) {
|
||||||
|
checkArgument(typeArg.typeArgs().count() == 1);
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
this.LayoutCodeSwitch(null, typeArg.typeArgs().get(0).clone(), value);
|
||||||
|
} else {
|
||||||
|
this.writer.writeNull();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchObject(TypeArgument typeArg, Object value) {
|
||||||
|
this.writer.writeStartDocument();
|
||||||
|
// TODO: support properties in an object scope.
|
||||||
|
this.writer.writeEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchSet(TypeArgument typeArg, Object value) {
|
||||||
|
checkArgument(typeArg.typeArgs().count() == 1);
|
||||||
|
|
||||||
|
this.writer.WriteStartArray();
|
||||||
|
for (Object item : (ArrayList<Object>)value) {
|
||||||
|
this.LayoutCodeSwitch(null, typeArg.typeArgs().get(0).clone(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.WriteEndArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchTuple(TypeArgument typeArg, Object value) {
|
||||||
|
checkArgument(typeArg.typeArgs().count() >= 2);
|
||||||
|
ArrayList<Object> items = (ArrayList<Object>)value;
|
||||||
|
checkArgument(items.size() == typeArg.typeArgs().count());
|
||||||
|
|
||||||
|
this.writer.WriteStartArray();
|
||||||
|
for (int i = 0; i < items.size(); i++) {
|
||||||
|
Object item = items.get(i);
|
||||||
|
this.LayoutCodeSwitch(null, typeArg.typeArgs().get(i).clone(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.WriteEndArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DispatchUDT(TypeArgument typeArg, Object value) {
|
||||||
|
this.writer.WriteStartDocument();
|
||||||
|
|
||||||
|
HashMap<Utf8String, Object> dict = (HashMap<Utf8String, Object>)value;
|
||||||
|
Layout udt = this.resolver.resolve(typeArg.typeArgs().schemaId().clone());
|
||||||
|
for (LayoutColumn c : udt.columns()) {
|
||||||
|
this.LayoutCodeSwitch(c.path(), c.typeArg().clone(), dict.get(c.path()));
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.WriteEndDocument();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void LayoutCodeSwitch(UtfAnyString path, TypeArgument typeArg, Object value) {
|
||||||
|
if (!path.IsNull) {
|
||||||
|
this.writer.WriteName(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (typeArg.type().LayoutCode) {
|
||||||
|
case Null:
|
||||||
|
this.writer.WriteNull();
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Boolean:
|
||||||
|
this.writer.WriteBoolean(value == null ? false : (Boolean)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Int8:
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (byte)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Int16:
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (Short)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Int32:
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (Integer)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Int64:
|
||||||
|
this.writer.WriteInt64(value == null ? 0 : (Long)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case UInt8:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteInt32(value == null ? default(byte) : (byte)value);
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (Byte)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case UInt16:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteInt32(value == null ? default(ushort) : (ushort)value);
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (short)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case UInt32:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteInt32(value == null ? default(int) : unchecked((int)(uint)value));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
this.writer.WriteInt32(value == null ? 0 : (int)(int)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case UInt64:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteInt64(value == null ? default(long) : unchecked((long)(ulong)value));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
this.writer.WriteInt64(value == null ? 0 : (long)(long)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case VarInt:
|
||||||
|
this.writer.WriteInt64(value == null ? 0 : (Long)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case VarUInt:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteInt64(value == null ? default(long) : unchecked((long)(ulong)value));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
this.writer.WriteInt64(value == null ? 0 : (long)(long)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Float32:
|
||||||
|
this.writer.WriteDouble(value == null ? 0 : (Float)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Float64:
|
||||||
|
this.writer.WriteDouble(value == null ? 0 : (Double)value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Float128:
|
||||||
|
Decimal128 d128 = null;
|
||||||
|
if (value != null) {
|
||||||
|
Float128 f128 = (Float128)value;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: d128 = unchecked(Decimal128.FromIEEEBits((ulong)f128.High, (ulong)f128.Low));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
d128 = Decimal128.FromIEEEBits((long) f128.high(), (long) f128.low());
|
||||||
|
}
|
||||||
|
|
||||||
|
this.writer.WriteDecimal128(d128);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Decimal:
|
||||||
|
this.writer.WriteDecimal128(value == null ? null : new Decimal128((BigDecimal)value));
|
||||||
|
return;
|
||||||
|
|
||||||
|
case DateTime:
|
||||||
|
this.writer.WriteDateTime(value == null ? 0 : ((LocalDateTime)value).getTime());
|
||||||
|
return;
|
||||||
|
|
||||||
|
case UnixDateTime:
|
||||||
|
this.writer.WriteDateTime(value == null ? 0 : ((UnixDateTime)value).getMilliseconds());
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Guid:
|
||||||
|
this.writer.WriteString(value == null ? "" : ((UUID)value).toString());
|
||||||
|
return;
|
||||||
|
|
||||||
|
case MongoDbObjectId:
|
||||||
|
this.writer.WriteObjectId(value == null ? null : new ObjectId(((MongoDbObjectId)value).ToByteArray()));
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Utf8:
|
||||||
|
this.writer.WriteString(value == null ? "" : ((Utf8String)value).toString());
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Binary:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.writer.WriteBytes(value == null ? default(byte[]) : (byte[])value);
|
||||||
|
this.writer.WriteBytes(value == null ? null : (byte[])value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case ObjectScope:
|
||||||
|
case ImmutableObjectScope:
|
||||||
|
this.DispatchObject(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case TypedArrayScope:
|
||||||
|
case ImmutableTypedArrayScope:
|
||||||
|
this.DispatchArray(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case TypedSetScope:
|
||||||
|
case ImmutableTypedSetScope:
|
||||||
|
this.DispatchSet(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case TypedMapScope:
|
||||||
|
case ImmutableTypedMapScope:
|
||||||
|
this.DispatchMap(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case TupleScope:
|
||||||
|
case ImmutableTupleScope:
|
||||||
|
case TypedTupleScope:
|
||||||
|
case ImmutableTypedTupleScope:
|
||||||
|
case TaggedScope:
|
||||||
|
case ImmutableTaggedScope:
|
||||||
|
case Tagged2Scope:
|
||||||
|
case ImmutableTagged2Scope:
|
||||||
|
this.DispatchTuple(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case NullableScope:
|
||||||
|
case ImmutableNullableScope:
|
||||||
|
this.DispatchNullable(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
case Schema:
|
||||||
|
case ImmutableSchema:
|
||||||
|
this.DispatchUDT(typeArg.clone(), value);
|
||||||
|
return;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", typeArg.clone()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,311 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests involving generated (early bound) code compiled from schema based on a partial implementation
|
||||||
|
* of Cassandra Hotel Schema described here: https: //www.oreilly.com/ideas/cassandra-data-modeling .
|
||||||
|
* <p>
|
||||||
|
* The tests here differ from {@link SchematizedMicroBenchmarkSuite} in that they rely on
|
||||||
|
* the schema being known at compile time instead of runtime. This allows code to be generated that
|
||||||
|
* directly addresses the schema structure instead of dynamically discovering schema structure at
|
||||||
|
* runtime.
|
||||||
|
* </p>
|
||||||
|
*/
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public sealed class CodeGenMicroBenchmarkSuite : MicroBenchmarkSuiteBase
|
||||||
|
public final class CodeGenMicroBenchmarkSuite extends MicroBenchmarkSuiteBase {
|
||||||
|
private static final int GuestCount = 1000;
|
||||||
|
private static final int HotelCount = 10000;
|
||||||
|
private static final int RoomsCount = 10000;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenGuestsReadBenchmarkAsync()
|
||||||
|
public Task CodeGenGuestsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenReadBenchmark(resolver, "Guests", "Guests",
|
||||||
|
CodeGenMicroBenchmarkSuite.GuestCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenGuestsWriteBenchmarkAsync()
|
||||||
|
public Task CodeGenGuestsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenWriteBenchmark(resolver, "Guests", "Guests",
|
||||||
|
CodeGenMicroBenchmarkSuite.GuestCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenHotelReadBenchmarkAsync()
|
||||||
|
public Task CodeGenHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenReadBenchmark(resolver, "Hotels", "Hotels",
|
||||||
|
CodeGenMicroBenchmarkSuite.HotelCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenHotelWriteBenchmarkAsync()
|
||||||
|
public Task CodeGenHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenWriteBenchmark(resolver, "Hotels", "Hotels",
|
||||||
|
CodeGenMicroBenchmarkSuite.HotelCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenRoomsReadBenchmarkAsync()
|
||||||
|
public Task CodeGenRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenReadBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
CodeGenMicroBenchmarkSuite.RoomsCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task CodeGenRoomsWriteBenchmarkAsync()
|
||||||
|
public Task CodeGenRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.CodeGenWriteBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
CodeGenMicroBenchmarkSuite.RoomsCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufGuestsReadBenchmarkAsync()
|
||||||
|
public Task ProtobufGuestsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufReadBenchmark("Guests", "Guests", CodeGenMicroBenchmarkSuite.GuestCount,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufGuestsWriteBenchmarkAsync()
|
||||||
|
public Task ProtobufGuestsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufWriteBenchmark("Guests", "Guests", CodeGenMicroBenchmarkSuite.GuestCount,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufHotelReadBenchmarkAsync()
|
||||||
|
public Task ProtobufHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufReadBenchmark("Hotels", "Hotels", CodeGenMicroBenchmarkSuite.HotelCount,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufHotelWriteBenchmarkAsync()
|
||||||
|
public Task ProtobufHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufWriteBenchmark("Hotels", "Hotels", CodeGenMicroBenchmarkSuite.HotelCount,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufRoomsReadBenchmarkAsync()
|
||||||
|
public Task ProtobufRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufReadBenchmark("Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
CodeGenMicroBenchmarkSuite.RoomsCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task ProtobufRoomsWriteBenchmarkAsync()
|
||||||
|
public Task ProtobufRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
CodeGenMicroBenchmarkSuite.ProtobufWriteBenchmark("Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
CodeGenMicroBenchmarkSuite.RoomsCount, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CodeGenReadBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName,
|
||||||
|
int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.CodeGenWriter = new CodeGenRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
context.CodeGenWriter.Reset();
|
||||||
|
|
||||||
|
Result r = context.CodeGenWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(context.CodeGenWriter.ToArray());
|
||||||
|
expectedSerialized.add(context.CodeGenWriter.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Read", dataSetName, "HybridRowGen", innerLoopIterations, ref context, (ref BenchmarkContext ctx, byte[] tableValue) =>
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Read", dataSetName, "HybridRowGen", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
Result r = ctx.CodeGenWriter.ReadBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void CodeGenWriteBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName
|
||||||
|
, int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.CodeGenWriter = new CodeGenRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Write", dataSetName, "HybridRowGen", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
ctx.CodeGenWriter.Reset();
|
||||||
|
|
||||||
|
Result r = ctx.CodeGenWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) -> ctx.CodeGenWriter.Length, expected);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProtobufReadBenchmark(String schemaName, String dataSetName, int innerLoopIterations,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.ProtobufWriter = new ProtobufRowGenerator(schemaName, BenchmarkSuiteBase.InitialCapacity);
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
context.ProtobufWriter.WriteBuffer(tableValue);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(context.ProtobufWriter.ToArray());
|
||||||
|
expectedSerialized.add(context.ProtobufWriter.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Read", dataSetName, "Protobuf",
|
||||||
|
// innerLoopIterations, ref context, (ref BenchmarkContext ctx, byte[] tableValue) => ctx.ProtobufWriter
|
||||||
|
// .ReadBuffer(tableValue), (ref BenchmarkContext ctx, byte[] tableValue) => tableValue.Length,
|
||||||
|
// expectedSerialized);
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Read", dataSetName, "Protobuf", innerLoopIterations,
|
||||||
|
tempReference_context,
|
||||||
|
(ref BenchmarkContext ctx, byte[] tableValue) -> ctx.ProtobufWriter.ReadBuffer(tableValue),
|
||||||
|
(ref BenchmarkContext ctx, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void ProtobufWriteBenchmark(String schemaName, String dataSetName, int innerLoopIterations,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.ProtobufWriter = new ProtobufRowGenerator(schemaName, BenchmarkSuiteBase.InitialCapacity);
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("CodeGen", "Write", dataSetName, "Protobuf", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
ctx.ProtobufWriter.WriteBuffer(tableValue);
|
||||||
|
}, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) -> ctx.ProtobufWriter.Length, expected);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,108 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(TestData.SchemaFile, TestData.Target)] public sealed class
|
||||||
|
// GenerateBenchmarkSuite : BenchmarkSuiteBase
|
||||||
|
public final class GenerateBenchmarkSuite extends BenchmarkSuiteBase {
|
||||||
|
private String sdl;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateGuestsBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateGuestsBenchmarkAsync()
|
||||||
|
public Task GenerateGuestsBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await this.GenerateBenchmarkAsync("Guests", 50, TestData.GuestsExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateHotelBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateHotelBenchmarkAsync()
|
||||||
|
public Task GenerateHotelBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await this.GenerateBenchmarkAsync("Hotels", 100, TestData.HotelExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateRoomsBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task GenerateRoomsBenchmarkAsync()
|
||||||
|
public Task GenerateRoomsBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await this.GenerateBenchmarkAsync("Available_Rooms_By_Hotel_Date", 100, TestData.RoomsExpected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
this.sdl = Files.readString(TestData.SchemaFile);
|
||||||
|
Namespace schema = Namespace.Parse(this.sdl);
|
||||||
|
this.DefaultResolver = new LayoutResolverNamespace(schema, SystemSchema.LayoutResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: private async Task GenerateBenchmarkAsync(string schemaName, int outerLoopIterations, string
|
||||||
|
// expectedFile)
|
||||||
|
private Task GenerateBenchmarkAsync(String schemaName, int outerLoopIterations, String expectedFile) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> rows = GenerateBenchmarkSuite.GenerateBenchmarkInputs(resolver,
|
||||||
|
schemaName, outerLoopIterations);
|
||||||
|
|
||||||
|
Schema tableSchema = resolver.Namespace.Schemas.Find(x = schemaName.equals( > x.Name))
|
||||||
|
TypeArgument typeArg = new TypeArgument(LayoutType.UDT,
|
||||||
|
new TypeArgumentList(tableSchema.getSchemaId().clone()));
|
||||||
|
|
||||||
|
boolean allMatch = rows.size() == expected.Count;
|
||||||
|
for (int i = 0; allMatch && i < rows.size(); i++) {
|
||||||
|
allMatch |= HybridRowValueGenerator.DynamicTypeArgumentEquals(resolver, expected[i], rows.get(i),
|
||||||
|
typeArg.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!allMatch) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await BenchmarkSuiteBase.
|
||||||
|
WriteAllRowsAsync(expectedFile, this.sdl, resolver, resolver.Resolve(tableSchema.getSchemaId().clone()), rows);
|
||||||
|
System.out.printf("Updated expected file at: %1$s" + "\r\n", (new File(expectedFile)).getAbsolutePath());
|
||||||
|
Assert.IsTrue(allMatch, "Expected output does not match expected file.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ArrayList<HashMap<Utf8String, Object>> GenerateBenchmarkInputs(LayoutResolverNamespace resolver,
|
||||||
|
String schemaName,
|
||||||
|
int outerLoopIterations) {
|
||||||
|
HybridRowGeneratorConfig generatorConfig = new HybridRowGeneratorConfig();
|
||||||
|
final int seed = 42;
|
||||||
|
RandomGenerator rand = new RandomGenerator(new Random(seed));
|
||||||
|
HybridRowValueGenerator valueGenerator = new HybridRowValueGenerator(rand, generatorConfig);
|
||||||
|
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> rows = new ArrayList<HashMap<Utf8String, Object>>(outerLoopIterations);
|
||||||
|
for (int iteration = 0; iteration != outerLoopIterations; iteration += outerLoopIterations < 0 ? 0 : 1) {
|
||||||
|
TypeArgument typeArg = new TypeArgument(LayoutType.UDT, new TypeArgumentList(layout.getSchemaId().clone()));
|
||||||
|
HashMap<Utf8String, Object> rowValue =
|
||||||
|
(HashMap<Utf8String, Object>)valueGenerator.GenerateLayoutType(resolver, typeArg.clone());
|
||||||
|
rows.add(rowValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,193 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.ISpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: public ref struct JsonModelRowGenerator
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# ref struct:
|
||||||
|
public final class JsonModelRowGenerator {
|
||||||
|
private RowBuffer row = new RowBuffer();
|
||||||
|
|
||||||
|
|
||||||
|
public JsonModelRowGenerator(int capacity, Layout layout, LayoutResolver resolver) {
|
||||||
|
this(capacity, layout, resolver, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonModelRowGenerator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public JsonModelRowGenerator(int capacity, Layout layout, LayoutResolver resolver,
|
||||||
|
// ISpanResizer<byte> resizer = default)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
public JsonModelRowGenerator(int capacity, Layout layout, LayoutResolver resolver, ISpanResizer<Byte> resizer) {
|
||||||
|
this.row = new RowBuffer(capacity, resizer);
|
||||||
|
this.row.initLayout(HybridRowVersion.V1, layout, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return this.row.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowReader GetReader() {
|
||||||
|
Reference<RowBuffer> tempReference_row = new Reference<RowBuffer>(this.row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
|
||||||
|
return new RowReader(ref this.row)
|
||||||
|
this.row = tempReference_row.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
|
||||||
|
// output:
|
||||||
|
public boolean ReadFrom(InputStream stream, int length) {
|
||||||
|
return this.row.readFrom(stream, length, HybridRowVersion.V1, this.row.resolver());
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
Layout layout = this.row.resolver().resolve(this.row.header().schemaId().clone());
|
||||||
|
this.row.initLayout(HybridRowVersion.V1, layout, this.row.resolver());
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ToArray()
|
||||||
|
public byte[] ToArray() {
|
||||||
|
return this.row.toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result WriteBuffer(HashMap<Utf8String, Object> value) {
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(this.row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
Result tempVar = RowWriter.writeBuffer(tempReference_row, value, (RowWriter RowWriter writer, TypeArgument typeArg,
|
||||||
|
HashMap<Utf8String, Object> dict) ->
|
||||||
|
{
|
||||||
|
for ((Utf8String propPath,Object propValue) :dict)
|
||||||
|
{
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer =
|
||||||
|
new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer);
|
||||||
|
Result result = JsonModelRowGenerator.JsonModelSwitch(tempReference_writer, propPath, propValue);
|
||||||
|
writer = tempReference_writer.get();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
});
|
||||||
|
this.row = tempReference_row.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is input or
|
||||||
|
// output:
|
||||||
|
public void WriteTo(OutputStream stream) {
|
||||||
|
this.row.writeTo(stream);
|
||||||
|
}
|
||||||
|
|
||||||
|
public JsonModelRowGenerator clone() {
|
||||||
|
JsonModelRowGenerator varCopy = new JsonModelRowGenerator();
|
||||||
|
varCopy.row = this.row.clone();
|
||||||
|
return varCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result JsonModelSwitch(Reference<RowWriter> writer, Utf8String path, Object value) {
|
||||||
|
switch (value) {
|
||||||
|
case null:
|
||||||
|
return writer.get().writeNull(path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case bool x:
|
||||||
|
case
|
||||||
|
boolean x:
|
||||||
|
return writer.get().writeBoolean(path, x);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case long x:
|
||||||
|
case
|
||||||
|
long x:
|
||||||
|
return writer.get().writeInt64(path, x);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case double x:
|
||||||
|
case
|
||||||
|
double x:
|
||||||
|
return writer.get().writeFloat64(path, x);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case string x:
|
||||||
|
case String
|
||||||
|
x:
|
||||||
|
return writer.get().WriteString(path, x);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case Utf8String x:
|
||||||
|
case Utf8String
|
||||||
|
x:
|
||||||
|
return writer.get().WriteString(path, x.Span);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case byte[] x:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
case
|
||||||
|
byte[] x:
|
||||||
|
return writer.get().WriteBinary(path, x);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case ReadOnlyMemory<byte> x:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
case ReadOnlyMemory < Byte > x:
|
||||||
|
return writer.get().WriteBinary(path, x.Span);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case Dictionary<Utf8String, object> x:
|
||||||
|
case HashMap < Utf8String, Object > x:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these
|
||||||
|
// are not converted by C# to Java Converter:
|
||||||
|
return writer.get().writeScope(path, new TypeArgument(LayoutType.Object), x,
|
||||||
|
(RowWriter RowWriter writer2, TypeArgument typeArg, HashMap<Utf8String, Object> dict) ->
|
||||||
|
{
|
||||||
|
for ((Utf8String propPath,Object propValue) :dict)
|
||||||
|
{
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer2 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer2);
|
||||||
|
Result result = JsonModelRowGenerator.JsonModelSwitch(tempReference_writer2, propPath, propValue);
|
||||||
|
writer2 = tempReference_writer2.get();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
});
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# pattern variables in 'case' statements:
|
||||||
|
//ORIGINAL LINE: case List<object> x:
|
||||||
|
case ArrayList < Object > x:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
return writer.get().writeScope(path, new TypeArgument(LayoutType.Array), x, (RowWriter RowWriter writer2, TypeArgument typeArg, ArrayList<Object> list) ->
|
||||||
|
{
|
||||||
|
for (Object elm : list) {
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer2 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer2);
|
||||||
|
Result result = JsonModelRowGenerator.JsonModelSwitch(tempReference_writer2, null, elm);
|
||||||
|
writer2 = tempReference_writer2.get();
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
});
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", value.getClass().getSimpleName()));
|
||||||
|
return Result.FAILURE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,62 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
public class Measurements implements Closeable {
|
||||||
|
private static final long RunId = LocalDateTime.UtcNow.getTime();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.FileStream is
|
||||||
|
// input or output:
|
||||||
|
private FileStream file;
|
||||||
|
private TextWriter writer;
|
||||||
|
|
||||||
|
public Measurements(String path) {
|
||||||
|
File info = new File(path);
|
||||||
|
if (info.exists()) {
|
||||||
|
this.file = new FileOutputStream(path, true);
|
||||||
|
this.writer = new OutputStreamWriter(this.file, java.nio.charset.StandardCharsets.US_ASCII);
|
||||||
|
} else {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.FileStream
|
||||||
|
// is input or output:
|
||||||
|
this.file = new FileStream(path, FileMode.CreateNew);
|
||||||
|
this.writer = new OutputStreamWriter(this.file, java.nio.charset.StandardCharsets.US_ASCII);
|
||||||
|
this.writer.WriteLine("RunId,Model,Operation,Schema,API,Iterations,Size (bytes),Total (ms),Duration (ms)," +
|
||||||
|
"Allocated (bytes),ThreadId,Gen0,Gen1,Gen2,Total Allocated (bytes)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void WriteMeasurement(String model, String operation, String schema, String api,
|
||||||
|
int outerLoopIterations, int innerLoopIterations, long totalSize,
|
||||||
|
double totalDurationMs, int threadId, int gen0, int gen1, int gen2,
|
||||||
|
long totalAllocatedBytes) {
|
||||||
|
System.out.printf("RunId: %1$s, \nModel: %2$s \nOperation: %3$s \nSchema: %4$s \nAPI: %5$s" + "\r\n",
|
||||||
|
Measurements.RunId, model, operation, schema, api);
|
||||||
|
|
||||||
|
System.out.printf("\n\nIterations: %1$s \nSize (bytes): %1.0f \nTotal (ms): %2.4f \nDuration (ms): %3.4f " +
|
||||||
|
"\nAllocated (bytes): %4.4f" + "\r\n", outerLoopIterations, totalSize / outerLoopIterations,
|
||||||
|
totalDurationMs, totalDurationMs / (outerLoopIterations * innerLoopIterations),
|
||||||
|
totalAllocatedBytes / (outerLoopIterations * innerLoopIterations));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The '4:n0' format specifier is not converted to Java:
|
||||||
|
System.out.printf("\n\nThread: %1$s \nCollections: %2$s, %3$s, %4$s \nTotal Allocated: {4:n0} (bytes)" + "\r" +
|
||||||
|
"\n", threadId, gen0, gen1, gen2, totalAllocatedBytes);
|
||||||
|
|
||||||
|
|
||||||
|
this.writer.WriteLine("{0},{1},{2},{3},{4},{5},{6:F0},{7:F8},{8:F8},{9:F8},{10},{11},{12},{13},{14:0}",
|
||||||
|
Measurements.RunId, model, operation, schema, api, outerLoopIterations, totalSize / outerLoopIterations,
|
||||||
|
totalDurationMs, totalDurationMs / (outerLoopIterations * innerLoopIterations), totalAllocatedBytes / (outerLoopIterations * innerLoopIterations), threadId, gen0, gen1, gen2, totalAllocatedBytes);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final void close() throws IOException {
|
||||||
|
this.writer.Flush();
|
||||||
|
this.writer.Dispose();
|
||||||
|
this.file.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,127 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import JetBrains.Profiler.Api.*;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods", Justification
|
||||||
|
// = "Perf Benchmark")] public class MicroBenchmarkSuiteBase : BenchmarkSuiteBase
|
||||||
|
public class MicroBenchmarkSuiteBase extends BenchmarkSuiteBase {
|
||||||
|
private static final String MetricsResultFile = "HybridRowPerf.csv";
|
||||||
|
private static final int WarmCount = 5;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods",
|
||||||
|
// Justification = "Perf Benchmark")] private protected static void Benchmark<TValue>(string model, string
|
||||||
|
// operation, string schema, string api, int innerLoopIterations, ref BenchmarkContext context,
|
||||||
|
// BenchmarkBody<TValue> loopBody, BenchmarkMeasure<TValue> measure, List<TValue> expected)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods",
|
||||||
|
// Justification = "Perf Benchmark")] private protected static void Benchmark<TValue>(string model, string
|
||||||
|
// operation, string schema, string api, int innerLoopIterations, ref BenchmarkContext context,
|
||||||
|
// BenchmarkBody<TValue> loopBody, BenchmarkMeasure<TValue> measure, List<TValue> expected)
|
||||||
|
protected static <TValue> void Benchmark(String model, String operation, String schema, String api,
|
||||||
|
int innerLoopIterations, Reference<BenchmarkContext> context,
|
||||||
|
BenchmarkBody<TValue> loopBody, BenchmarkMeasure<TValue> measure,
|
||||||
|
ArrayList<TValue> expected) {
|
||||||
|
Stopwatch sw = new Stopwatch();
|
||||||
|
double durationMs = 0;
|
||||||
|
long rowSize = 0;
|
||||||
|
|
||||||
|
// Warm
|
||||||
|
int warm = Math.min(MicroBenchmarkSuiteBase.WarmCount, expected.size());
|
||||||
|
for (int i = 0; i < warm; i++) {
|
||||||
|
for (int innerLoop = 0; innerLoop < innerLoopIterations; innerLoop++) {
|
||||||
|
loopBody.invoke(context, expected.get(i));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
System.gc();
|
||||||
|
System.runFinalization();
|
||||||
|
Thread.sleep(1000);
|
||||||
|
int gen0 = GC.CollectionCount(0);
|
||||||
|
int gen1 = GC.CollectionCount(1);
|
||||||
|
int gen2 = GC.CollectionCount(2);
|
||||||
|
long allocated = GC.GetAllocatedBytesForCurrentThread();
|
||||||
|
int threadId = Thread.currentThread().ManagedThreadId;
|
||||||
|
ThreadPriority currentPriority = Thread.currentThread().Priority;
|
||||||
|
Thread.currentThread().Priority = ThreadPriority.Highest;
|
||||||
|
MemoryProfiler.CollectAllocations(true);
|
||||||
|
MemoryProfiler.GetSnapshot();
|
||||||
|
try {
|
||||||
|
for (TValue tableValue : expected) {
|
||||||
|
sw.Restart();
|
||||||
|
MicroBenchmarkSuiteBase.BenchmarkInnerLoop(innerLoopIterations, tableValue, context, loopBody);
|
||||||
|
sw.Stop();
|
||||||
|
durationMs += sw.Elapsed.TotalMilliseconds;
|
||||||
|
rowSize += measure.invoke(context, tableValue);
|
||||||
|
}
|
||||||
|
} finally {
|
||||||
|
Thread.currentThread().Priority = currentPriority;
|
||||||
|
gen0 = GC.CollectionCount(0) - gen0;
|
||||||
|
gen1 = GC.CollectionCount(1) - gen1;
|
||||||
|
gen2 = GC.CollectionCount(2) - gen2;
|
||||||
|
allocated = GC.GetAllocatedBytesForCurrentThread() - allocated;
|
||||||
|
MemoryProfiler.GetSnapshot();
|
||||||
|
MemoryProfiler.CollectAllocations(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
try (Measurements m = new Measurements(MicroBenchmarkSuiteBase.MetricsResultFile)) {
|
||||||
|
m.WriteMeasurement(model, operation, schema, api, expected.size(), innerLoopIterations, rowSize,
|
||||||
|
durationMs, threadId, gen0, gen1, gen2, allocated);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.NoInlining)] private static void BenchmarkInnerLoop<TValue>(int
|
||||||
|
// innerLoopIterations, TValue tableValue, ref BenchmarkContext context, BenchmarkBody<TValue> loopBody)
|
||||||
|
private static <TValue> void BenchmarkInnerLoop(int innerLoopIterations, TValue tableValue,
|
||||||
|
Reference<BenchmarkContext> context,
|
||||||
|
BenchmarkBody<TValue> loopBody) {
|
||||||
|
for (int innerLoop = 0; innerLoop < innerLoopIterations; innerLoop++) {
|
||||||
|
loopBody.invoke(context, tableValue);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface BenchmarkBody<TValue> {
|
||||||
|
void invoke(Reference<BenchmarkContext> context, TValue value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface BenchmarkMeasure<TValue> {
|
||||||
|
long invoke(Reference<BenchmarkContext> context, TValue value);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may
|
||||||
|
// differ from the original:
|
||||||
|
//ORIGINAL LINE: private protected ref struct BenchmarkContext
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# ref struct:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to C# 'private protected' access:
|
||||||
|
protected final static class BenchmarkContext {
|
||||||
|
public CodeGenRowGenerator CodeGenWriter = new CodeGenRowGenerator();
|
||||||
|
public JsonModelRowGenerator JsonModelWriter = new JsonModelRowGenerator();
|
||||||
|
public WriteRowGenerator PatchWriter = new WriteRowGenerator();
|
||||||
|
public ProtobufRowGenerator ProtobufWriter = new ProtobufRowGenerator();
|
||||||
|
public StreamingRowGenerator StreamingWriter = new StreamingRowGenerator();
|
||||||
|
|
||||||
|
public BenchmarkContext clone() {
|
||||||
|
BenchmarkContext varCopy = new BenchmarkContext();
|
||||||
|
|
||||||
|
varCopy.CodeGenWriter = this.CodeGenWriter.clone();
|
||||||
|
varCopy.ProtobufWriter = this.ProtobufWriter.clone();
|
||||||
|
varCopy.PatchWriter = this.PatchWriter.clone();
|
||||||
|
varCopy.StreamingWriter = this.StreamingWriter.clone();
|
||||||
|
varCopy.JsonModelWriter = this.JsonModelWriter.clone();
|
||||||
|
|
||||||
|
return varCopy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,338 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import Google.Protobuf.*;
|
||||||
|
import Google.Protobuf.Collections.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Address;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Available_Rooms_By_Hotel_Date;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Guests;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Hotels;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.PostalCode;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable DontUseNamespaceAliases // Namespace Aliases should be avoided
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning restore DontUseNamespaceAliases // Namespace Aliases should be avoided
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal ref struct ProtobufRowGenerator
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# ref struct:
|
||||||
|
public final class ProtobufRowGenerator {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private ReadOnlySpan<byte> active;
|
||||||
|
private ReadOnlySpan<Byte> active;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private readonly byte[] buffer;
|
||||||
|
private byte[] buffer;
|
||||||
|
private String schemaName;
|
||||||
|
|
||||||
|
public ProtobufRowGenerator() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtobufRowGenerator(String schemaName, int capacity) {
|
||||||
|
this.schemaName = schemaName;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.buffer = new byte[capacity];
|
||||||
|
this.buffer = new byte[capacity];
|
||||||
|
this.active = this.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getLength() {
|
||||||
|
return this.active.Length;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public void ReadBuffer(byte[] buffer)
|
||||||
|
public void ReadBuffer(byte[] buffer) {
|
||||||
|
switch (this.schemaName) {
|
||||||
|
case "Hotels":
|
||||||
|
ProtobufRowGenerator.ReadBufferHotel(buffer);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Guests":
|
||||||
|
ProtobufRowGenerator.ReadBufferGuest(buffer);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Available_Rooms_By_Hotel_Date":
|
||||||
|
ProtobufRowGenerator.ReadBufferRoom(buffer);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown schema will be ignored: %s", this.schemaName));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ToArray()
|
||||||
|
public byte[] ToArray() {
|
||||||
|
return this.active.ToArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void WriteBuffer(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
switch (this.schemaName) {
|
||||||
|
case "Hotels":
|
||||||
|
this.WriteBufferHotel(tableValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Guests":
|
||||||
|
this.WriteBufferGuest(tableValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "Available_Rooms_By_Hotel_Date":
|
||||||
|
this.WriteBufferRoom(tableValue);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown schema will be ignored: %s", this.schemaName));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProtobufRowGenerator clone() {
|
||||||
|
ProtobufRowGenerator varCopy = new ProtobufRowGenerator();
|
||||||
|
|
||||||
|
varCopy.schemaName = this.schemaName;
|
||||||
|
varCopy.buffer = this.buffer;
|
||||||
|
varCopy.active = this.active;
|
||||||
|
|
||||||
|
return varCopy;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Address MakeAddress(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
Address address = new Address();
|
||||||
|
for ((Utf8String key,Object value) :tableValue)
|
||||||
|
{
|
||||||
|
switch (key.toString()) {
|
||||||
|
case "street":
|
||||||
|
address.setStreet(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "city":
|
||||||
|
address.setCity(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "state":
|
||||||
|
address.setState(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "postal_code":
|
||||||
|
address.setPostalCode(value == null ? null : ProtobufRowGenerator.MakePostalCode((HashMap<Utf8String, Object>)value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return address;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PostalCode MakePostalCode(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
PostalCode postalCode = new PostalCode();
|
||||||
|
for ((Utf8String key,Object value) :tableValue)
|
||||||
|
{
|
||||||
|
switch (key.toString()) {
|
||||||
|
case "zip":
|
||||||
|
postalCode.setZip((Integer)value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "plus4":
|
||||||
|
postalCode.setPlus4((Short)value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
throw new IllegalStateException();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return postalCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PopulateStringAddressMap(MapField<String,
|
||||||
|
Address> field,
|
||||||
|
ArrayList<Object> list) {
|
||||||
|
for (Object item : list) {
|
||||||
|
ArrayList<Object> tuple = (ArrayList<Object>)item;
|
||||||
|
String key = ((Utf8String)tuple.get(0)).toString();
|
||||||
|
Address value =
|
||||||
|
ProtobufRowGenerator.MakeAddress((HashMap<Utf8String, Object>)tuple.get(1));
|
||||||
|
field.Add(key, value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void PopulateStringList(RepeatedField<String> field, ArrayList<Object> list) {
|
||||||
|
for (Object item : list) {
|
||||||
|
field.Add(((Utf8String)item).toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static void ReadBufferGuest(byte[] buffer)
|
||||||
|
private static void ReadBufferGuest(byte[] buffer) {
|
||||||
|
Guests item =
|
||||||
|
new Guests();
|
||||||
|
item.MergeFrom(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static void ReadBufferHotel(byte[] buffer)
|
||||||
|
private static void ReadBufferHotel(byte[] buffer) {
|
||||||
|
Hotels item =
|
||||||
|
new Hotels();
|
||||||
|
item.MergeFrom(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static void ReadBufferRoom(byte[] buffer)
|
||||||
|
private static void ReadBufferRoom(byte[] buffer) {
|
||||||
|
Available_Rooms_By_Hotel_Date item = new azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Available_Rooms_By_Hotel_Date();
|
||||||
|
item.MergeFrom(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteBufferGuest(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Guests room =
|
||||||
|
new azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Guests();
|
||||||
|
try (CodedOutputStream stm = new CodedOutputStream(this.buffer)) {
|
||||||
|
for ((Utf8String key,Object value) :tableValue)
|
||||||
|
{
|
||||||
|
switch (key.toString()) {
|
||||||
|
case "guest_id":
|
||||||
|
room.setGuestId(value == null ? null : ((UUID)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "first_name":
|
||||||
|
room.setFirstName(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "last_name":
|
||||||
|
room.setLastName(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "title":
|
||||||
|
room.setTitle(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "emails":
|
||||||
|
if (value != null) {
|
||||||
|
ProtobufRowGenerator.PopulateStringList(room.getEmails(), (ArrayList<Object>)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "phone_numbers":
|
||||||
|
if (value != null) {
|
||||||
|
ProtobufRowGenerator.PopulateStringList(room.getPhoneNumbers(), (ArrayList<Object>)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "addresses":
|
||||||
|
if (value != null) {
|
||||||
|
ProtobufRowGenerator.PopulateStringAddressMap(room.getAddresses(),
|
||||||
|
(ArrayList<Object>)value);
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "confirm_number":
|
||||||
|
room.setConfirmNumber(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert.Fail("should never happen");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
room.WriteTo(stm);
|
||||||
|
stm.Flush();
|
||||||
|
this.active = this.buffer.AsSpan(0, (int)stm.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteBufferHotel(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Hotels room =
|
||||||
|
new azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Hotels();
|
||||||
|
try (CodedOutputStream stm = new CodedOutputStream(this.buffer)) {
|
||||||
|
for ((Utf8String key,Object value) :tableValue)
|
||||||
|
{
|
||||||
|
switch (key.toString()) {
|
||||||
|
case "hotel_id":
|
||||||
|
room.setHotelId(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "name":
|
||||||
|
room.setName(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "phone":
|
||||||
|
room.setPhone(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "address":
|
||||||
|
room.setAddress(value == null ? null : ProtobufRowGenerator.MakeAddress((HashMap<Utf8String,
|
||||||
|
Object>)value));
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert.Fail("should never happen");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
room.WriteTo(stm);
|
||||||
|
stm.Flush();
|
||||||
|
this.active = this.buffer.AsSpan(0, (int)stm.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteBufferRoom(HashMap<Utf8String, Object> tableValue) {
|
||||||
|
azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Available_Rooms_By_Hotel_Date room = new azure.data.cosmos.serialization.hybridrow.perf.CassandraHotel.Protobuf.Available_Rooms_By_Hotel_Date();
|
||||||
|
try (CodedOutputStream stm = new CodedOutputStream(this.buffer)) {
|
||||||
|
for ((Utf8String key,Object value) :tableValue)
|
||||||
|
{
|
||||||
|
switch (key.toString()) {
|
||||||
|
case "hotel_id":
|
||||||
|
room.setHotelId(value == null ? null : ((Utf8String)value).toString());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "date":
|
||||||
|
room.setDate(value == null ? null : ((LocalDateTime)value).getTime());
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "room_number":
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: room.RoomNumber = (Nullable<byte>)value;
|
||||||
|
room.setRoomNumber((Byte)value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
case "is_available":
|
||||||
|
room.setIsAvailable((Boolean)value);
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
Assert.Fail("should never happen");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
room.WriteTo(stm);
|
||||||
|
stm.Flush();
|
||||||
|
this.active = this.buffer.AsSpan(0, (int)stm.Position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||||
|
|
||||||
|
import java.io.Closeable;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods",
|
||||||
|
// Justification = "Perf Benchmark")][DeploymentItem("TestData\\*.hr", "TestData")] public sealed class ReaderBenchmark
|
||||||
|
public final class ReaderBenchmark {
|
||||||
|
private static final String CombinedScriptsData = "TestData\\CombinedScriptsData.hr";
|
||||||
|
private static final int InitialCapacity = 2 * 1024 * 1024;
|
||||||
|
private static final int MeasureCount = 10;
|
||||||
|
private static final int WarmCount = 5;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][Ignore] public async Task AllAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][Ignore] public async Task AllAsync()
|
||||||
|
public Task AllAsync() {
|
||||||
|
final String dir = "E:\\TestData\\HybridRow";
|
||||||
|
for (File childFile : (new File(dir)).EnumerateFiles("*.hr")) {
|
||||||
|
try (BenchmarkContext context = new BenchmarkContext(childFile.getPath(), false, false)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await ReaderBenchmark.
|
||||||
|
BenchmarkAsync(context, (object arg) -> ReaderBenchmark.RowReaderBenchmarkAsync(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(ReaderBenchmark.CombinedScriptsData, "TestData")]
|
||||||
|
// public async Task RowReaderAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(ReaderBenchmark.CombinedScriptsData, "TestData")]
|
||||||
|
// public async Task RowReaderAsync()
|
||||||
|
public Task RowReaderAsync() {
|
||||||
|
try (BenchmarkContext context = new BenchmarkContext(ReaderBenchmark.CombinedScriptsData, true, true)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await ReaderBenchmark.BenchmarkAsync(context, (object arg) -> ReaderBenchmark.RowReaderBenchmarkAsync(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][Ignore] public async Task SpecificFileAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][Ignore] public async Task SpecificFileAsync()
|
||||||
|
public Task SpecificFileAsync() {
|
||||||
|
final String filename = "E:\\TestData\\HybridRow\\Lastfm.hr";
|
||||||
|
try (BenchmarkContext context = new BenchmarkContext(filename, true, true)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await ReaderBenchmark.BenchmarkAsync(context, (object arg) -> ReaderBenchmark.RowReaderBenchmarkAsync(arg));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods",
|
||||||
|
// Justification = "Perf Benchmark")] private static async Task BenchmarkAsync(BenchmarkContext context,
|
||||||
|
// Func<object, Task> body)
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Reliability", "CA2001:Avoid calling problematic methods",
|
||||||
|
// Justification = "Perf Benchmark")] private static async Task BenchmarkAsync(BenchmarkContext context,
|
||||||
|
// Func<object, Task> body)
|
||||||
|
private static Task BenchmarkAsync(BenchmarkContext context, tangible.Func1Param<Object, Task> body) {
|
||||||
|
try (SingleThreadedTaskScheduler scheduler = new SingleThreadedTaskScheduler()) {
|
||||||
|
// Warm
|
||||||
|
System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
|
||||||
|
for (int i = 0; i < ReaderBenchmark.WarmCount; i++) {
|
||||||
|
context.Reset();
|
||||||
|
sw.Restart();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await Task.
|
||||||
|
Factory.StartNew(body, context, CancellationToken.None, TaskCreationOptions.None, scheduler).Unwrap();
|
||||||
|
sw.Stop();
|
||||||
|
if (context.getShowWarmSummary()) {
|
||||||
|
context.Summarize(sw.Elapsed);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Execute
|
||||||
|
double[] timing = new double[ReaderBenchmark.MeasureCount];
|
||||||
|
for (int i = 0; i < ReaderBenchmark.MeasureCount; i++) {
|
||||||
|
System.gc();
|
||||||
|
System.runFinalization();
|
||||||
|
context.Reset();
|
||||||
|
sw.Restart();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
await Task.
|
||||||
|
Factory.StartNew(body, context, CancellationToken.None, TaskCreationOptions.None, scheduler).Unwrap();
|
||||||
|
sw.Stop();
|
||||||
|
if (context.getShowSummary()) {
|
||||||
|
context.Summarize(sw.Elapsed);
|
||||||
|
}
|
||||||
|
|
||||||
|
timing[i] = sw.Elapsed.TotalMilliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
Arrays.sort(timing);
|
||||||
|
System.out.println(String.format("File: %1$s, Mean: %1.4f",
|
||||||
|
Path.GetFileNameWithoutExtension(context.getInputFile()), timing[ReaderBenchmark.MeasureCount / 2]));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: private static async Task RowReaderBenchmarkAsync(object ctx)
|
||||||
|
private static Task RowReaderBenchmarkAsync(Object ctx) {
|
||||||
|
BenchmarkContext context = (BenchmarkContext)ctx;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MemorySpanResizer<byte> resizer = new MemorySpanResizer<byte>(ReaderBenchmark.InitialCapacity);
|
||||||
|
MemorySpanResizer<Byte> resizer = new MemorySpanResizer<Byte>(ReaderBenchmark.InitialCapacity);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
Result r = await
|
||||||
|
RecordIOStream.ReadRecordIOAsync(context.getInput(),
|
||||||
|
record ->
|
||||||
|
{
|
||||||
|
context.IncrementRecordCount();
|
||||||
|
r = ReaderBenchmark.VisitOneRow(record, context.getResolver());
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}, segment ->
|
||||||
|
{
|
||||||
|
Segment _;
|
||||||
|
Out<Segment> tempOut__ =
|
||||||
|
new Out<Segment>();
|
||||||
|
r = SegmentSerializer.Read(segment.Span, context.getResolver(), tempOut__);
|
||||||
|
_ = tempOut__.get();
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
|
||||||
|
// TODO: do something with embedded schema.
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}, resizer);
|
||||||
|
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result VisitOneRow(Memory<byte> buffer, LayoutResolver resolver)
|
||||||
|
private static Result VisitOneRow(Memory<Byte> buffer, LayoutResolver resolver) {
|
||||||
|
RowBuffer row = new RowBuffer(buffer.Span, HybridRowVersion.V1, resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
return RowReaderExtensions.VisitReader(reader.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static class BenchmarkContext implements Closeable {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is
|
||||||
|
// input or output:
|
||||||
|
private Stream input;
|
||||||
|
private String inputFile;
|
||||||
|
private long recordCount;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private boolean showSummary;
|
||||||
|
private boolean showWarmSummary;
|
||||||
|
|
||||||
|
|
||||||
|
public BenchmarkContext(String inputFile, boolean showSummary) {
|
||||||
|
this(inputFile, showSummary, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public BenchmarkContext(String inputFile) {
|
||||||
|
this(inputFile, true, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public BenchmarkContext(string inputFile, bool showSummary = true, bool showWarmSummary =
|
||||||
|
// false)
|
||||||
|
public BenchmarkContext(String inputFile, boolean showSummary, boolean showWarmSummary) {
|
||||||
|
this.inputFile = inputFile;
|
||||||
|
this.showSummary = showSummary;
|
||||||
|
this.showWarmSummary = showWarmSummary;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.FileStream
|
||||||
|
// is input or output:
|
||||||
|
this.input = new FileStream(inputFile, FileMode.Open);
|
||||||
|
this.resolver = SystemSchema.LayoutResolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: C# to Java Converter cannot determine whether this System.IO.Stream is
|
||||||
|
// input or output:
|
||||||
|
public Stream getInput() {
|
||||||
|
return this.input;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInputFile() {
|
||||||
|
return this.inputFile;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LayoutResolver getResolver() {
|
||||||
|
return this.resolver;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getShowSummary() {
|
||||||
|
return this.showSummary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getShowWarmSummary() {
|
||||||
|
return this.showWarmSummary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void IncrementRecordCount() {
|
||||||
|
this.recordCount++;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Reset() {
|
||||||
|
this.recordCount = 0;
|
||||||
|
this.input.Seek(0, SeekOrigin.Begin);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Summarize(TimeSpan duration) {
|
||||||
|
System.out.print(String.format("Total Time: %0.4f, ", duration.TotalMilliseconds));
|
||||||
|
System.out.println(String.format("Record Count: %1$s", this.recordCount));
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
this.input.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static class SingleThreadedTaskScheduler extends TaskScheduler implements Closeable {
|
||||||
|
private CancellationTokenSource cancel;
|
||||||
|
private EventWaitHandle ready;
|
||||||
|
private ConcurrentQueue<Task> tasks;
|
||||||
|
private Thread worker;
|
||||||
|
|
||||||
|
// Creates a new instance with the specified degree of parallelism.
|
||||||
|
public SingleThreadedTaskScheduler() {
|
||||||
|
this.tasks = new ConcurrentQueue<Task>();
|
||||||
|
this.ready = new ManualResetEvent(false);
|
||||||
|
this.worker = new Thread() {
|
||||||
|
void run() {
|
||||||
|
this.DoWork();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
this.cancel = new CancellationTokenSource();
|
||||||
|
this.worker.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gets the maximum concurrency level supported by this scheduler.
|
||||||
|
@Override
|
||||||
|
public int getMaximumConcurrencyLevel() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void close() throws IOException {
|
||||||
|
if (!this.cancel.IsCancellationRequested) {
|
||||||
|
this.cancel.Cancel();
|
||||||
|
this.worker.join();
|
||||||
|
this.ready == null ? null : this.ready.Dispose();
|
||||||
|
this.cancel == null ? null : this.cancel.Dispose();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected java.lang.Iterable<Task> GetScheduledTasks() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Queues a task to the scheduler.
|
||||||
|
@Override
|
||||||
|
protected void QueueTask(Task task) {
|
||||||
|
synchronized (this.tasks) {
|
||||||
|
this.tasks.Enqueue(task);
|
||||||
|
if (Thread.currentThread() != this.worker) {
|
||||||
|
this.ready.Set();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean TryDequeue(Task task) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Attempts to execute the specified task on the current thread.
|
||||||
|
@Override
|
||||||
|
protected boolean TryExecuteTaskInline(Task task, boolean taskWasPreviouslyQueued) {
|
||||||
|
// If this thread isn't already processing a task, we don't support inlining
|
||||||
|
if (Thread.currentThread() != this.worker) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If the task was previously queued, then skip it.
|
||||||
|
if (taskWasPreviouslyQueued) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.TryExecuteTask(task);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void DoWork() {
|
||||||
|
while (!this.cancel.IsCancellationRequested) {
|
||||||
|
Task item;
|
||||||
|
Out<Task> tempOut_item = new Out<Task>();
|
||||||
|
if (this.tasks.TryDequeue(tempOut_item)) {
|
||||||
|
item = tempOut_item.get();
|
||||||
|
this.TryExecuteTask(item);
|
||||||
|
} else {
|
||||||
|
item = tempOut_item.get();
|
||||||
|
this.ready.WaitOne(TimeSpan.FromSeconds(1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,88 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
|
||||||
|
import static com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode.IMMUTABLE_TAGGED2_SCOPE;
|
||||||
|
|
||||||
|
public final class RowReaderExtensions {
|
||||||
|
public static Result VisitReader(Reference<RowReader> reader) {
|
||||||
|
while (reader.get().Read()) {
|
||||||
|
Utf8Span path = reader.get().getPathSpan();
|
||||||
|
switch (reader.get().getType().LayoutCode) {
|
||||||
|
case Null:
|
||||||
|
case Boolean:
|
||||||
|
case Int8:
|
||||||
|
case Int16:
|
||||||
|
case Int32:
|
||||||
|
case Int64:
|
||||||
|
case UInt8:
|
||||||
|
case UInt16:
|
||||||
|
case UInt32:
|
||||||
|
case UInt64:
|
||||||
|
case VarInt:
|
||||||
|
case VarUInt:
|
||||||
|
case Float32:
|
||||||
|
case Float64:
|
||||||
|
case Float128:
|
||||||
|
case Decimal:
|
||||||
|
case DateTime:
|
||||||
|
case UnixDateTime:
|
||||||
|
case Guid:
|
||||||
|
case MongoDbObjectId:
|
||||||
|
case Utf8:
|
||||||
|
case Binary:
|
||||||
|
break;
|
||||||
|
|
||||||
|
case NullableScope:
|
||||||
|
case ImmutableNullableScope: {
|
||||||
|
if (!reader.get().getHasValue()) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no 'goto' in Java:
|
||||||
|
goto case LayoutCode.TypedTupleScope
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectScope:
|
||||||
|
case ImmutableObjectScope:
|
||||||
|
case Schema:
|
||||||
|
case ImmutableSchema:
|
||||||
|
case ArrayScope:
|
||||||
|
case ImmutableArrayScope:
|
||||||
|
case TypedArrayScope:
|
||||||
|
case ImmutableTypedArrayScope:
|
||||||
|
case TypedSetScope:
|
||||||
|
case ImmutableTypedSetScope:
|
||||||
|
case TypedMapScope:
|
||||||
|
case ImmutableTypedMapScope:
|
||||||
|
case TupleScope:
|
||||||
|
case ImmutableTupleScope:
|
||||||
|
case TypedTupleScope:
|
||||||
|
case ImmutableTypedTupleScope:
|
||||||
|
case TaggedScope:
|
||||||
|
case ImmutableTaggedScope:
|
||||||
|
case Tagged2Scope:
|
||||||
|
case IMMUTABLE_TAGGED2_SCOPE: {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
Result r = reader.get().ReadScope(null, (ref RowReader child, Object _) -> child.VisitReader());
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
default: {
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", reader.get().getType().LayoutCode));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,639 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import MongoDB.Bson.IO.*;
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(TestData.SchemaFile, TestData.Target)] public sealed class
|
||||||
|
// SchematizedMicroBenchmarkSuite : MicroBenchmarkSuiteBase
|
||||||
|
public final class SchematizedMicroBenchmarkSuite extends MicroBenchmarkSuiteBase {
|
||||||
|
private static final JsonSerializerSettings JsonSettings = new JsonSerializerSettings
|
||||||
|
private String sdl;
|
||||||
|
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonGuestsReadBenchmarkAsync()
|
||||||
|
public Task BsonGuestsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonReadBenchmark(resolver, "Guests", "Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonGuestsWriteBenchmarkAsync()
|
||||||
|
public Task BsonGuestsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonWriteBenchmark(resolver, "Guests", "Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task BsonHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task BsonHotelReadBenchmarkAsync()
|
||||||
|
public Task BsonHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonReadBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task BsonHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task BsonHotelWriteBenchmarkAsync()
|
||||||
|
public Task BsonHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonWriteBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonRoomsReadBenchmarkAsync()
|
||||||
|
public Task BsonRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonReadBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms", 10000,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task BsonRoomsWriteBenchmarkAsync()
|
||||||
|
public Task BsonRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.BsonWriteBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms", 10000,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonGuestsReadBenchmarkAsync()
|
||||||
|
public Task JsonGuestsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonReadBenchmark("Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonGuestsWriteBenchmarkAsync()
|
||||||
|
public Task JsonGuestsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonWriteBenchmark("Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task JsonHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task JsonHotelReadBenchmarkAsync()
|
||||||
|
public Task JsonHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonReadBenchmark("Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task JsonHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task JsonHotelWriteBenchmarkAsync()
|
||||||
|
public Task JsonHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonWriteBenchmark("Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonRoomsReadBenchmarkAsync()
|
||||||
|
public Task JsonRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonReadBenchmark("Rooms", 10000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task JsonRoomsWriteBenchmarkAsync()
|
||||||
|
public Task JsonRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace _) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.JsonWriteBenchmark("Rooms", 10000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutGuestsReadBenchmarkAsync()
|
||||||
|
public Task LayoutGuestsReadBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 1000;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutReadBenchmark(resolver, "Guests", "Guests", innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutGuestsWriteBenchmarkAsync()
|
||||||
|
public Task LayoutGuestsWriteBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 1000;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutWriteBenchmark(resolver, "Guests", "Guests", innerLoopIterations,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutHotelReadBenchmarkAsync()
|
||||||
|
public Task LayoutHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutReadBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutHotelWriteBenchmarkAsync()
|
||||||
|
public Task LayoutHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutWriteBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutRoomsReadBenchmarkAsync()
|
||||||
|
public Task LayoutRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutReadBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms", 1000,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task LayoutRoomsWriteBenchmarkAsync()
|
||||||
|
public Task LayoutRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.LayoutWriteBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms", 1000,
|
||||||
|
expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
this.sdl = Files.readString(TestData.SchemaFile);
|
||||||
|
Namespace schema = Namespace.Parse(this.sdl);
|
||||||
|
this.DefaultResolver = new LayoutResolverNamespace(schema, SystemSchema.LayoutResolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingGuestsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingGuestsReadBenchmarkAsync()
|
||||||
|
public Task StreamingGuestsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingReadBenchmark(resolver, "Guests", "Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingGuestsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.GuestsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingGuestsWriteBenchmarkAsync()
|
||||||
|
public Task StreamingGuestsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.GuestsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingWriteBenchmark(resolver, "Guests", "Guests", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingHotelReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingHotelReadBenchmarkAsync()
|
||||||
|
public Task StreamingHotelReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingReadBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingHotelWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.HotelExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingHotelWriteBenchmarkAsync()
|
||||||
|
public Task StreamingHotelWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.HotelExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingWriteBenchmark(resolver, "Hotels", "Hotels", 1000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingRoomsReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingRoomsReadBenchmarkAsync()
|
||||||
|
public Task StreamingRoomsReadBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingReadBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
10000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingRoomsWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.RoomsExpected, TestData.Target)] public
|
||||||
|
// async Task StreamingRoomsWriteBenchmarkAsync()
|
||||||
|
public Task StreamingRoomsWriteBenchmarkAsync() {
|
||||||
|
String expectedFile = TestData.RoomsExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
SchematizedMicroBenchmarkSuite.StreamingWriteBenchmark(resolver, "Available_Rooms_By_Hotel_Date", "Rooms",
|
||||||
|
10000, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BsonReadBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName,
|
||||||
|
int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
try (BsonRowGenerator writer = new BsonRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver)) {
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
writer.Reset();
|
||||||
|
writer.WriteBuffer(tableValue);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(writer.ToArray());
|
||||||
|
expectedSerialized.add(writer.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "BSON",
|
||||||
|
// innerLoopIterations, ref ignoredContext, (ref BenchmarkContext _, byte[] tableValue) =>
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "BSON", innerLoopIterations,
|
||||||
|
tempReference_ignoredContext, (ref BenchmarkContext _, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
try (MemoryStream stm = new MemoryStream(tableValue)) {
|
||||||
|
try (BsonBinaryReader bsonReader = new BsonBinaryReader(stm)) {
|
||||||
|
bsonReader.VisitBsonDocument();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (ref BenchmarkContext _, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BsonWriteBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName,
|
||||||
|
int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
try (BsonRowGenerator writer = new BsonRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver)) {
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are
|
||||||
|
// not converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Write", dataSetName, "BSON", innerLoopIterations,
|
||||||
|
tempReference_ignoredContext, (ref BenchmarkContext _, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
writer.Reset();
|
||||||
|
writer.WriteBuffer(tableValue);
|
||||||
|
}, (ref BenchmarkContext _, HashMap<Utf8String, Object> tableValue) -> writer.getLength(), expected);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonReadBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Encoding utf8Encoding = new UTF8Encoding();
|
||||||
|
JsonSerializer jsonSerializer = JsonSerializer.Create(SchematizedMicroBenchmarkSuite.JsonSettings);
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(BenchmarkSuiteBase.InitialCapacity)) {
|
||||||
|
try (OutputStreamWriter textWriter = new OutputStreamWriter(jsonStream)) {
|
||||||
|
try (JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)) {
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
jsonSerializer.Serialize(jsonWriter, tableValue);
|
||||||
|
jsonWriter.Flush();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(jsonStream.ToArray());
|
||||||
|
expectedSerialized.add((Byte)jsonStream.ToArray());
|
||||||
|
jsonStream.SetLength(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "JSON",
|
||||||
|
// innerLoopIterations, ref ignoredContext, (ref BenchmarkContext _, byte[] tableValue) =>
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "JSON", innerLoopIterations,
|
||||||
|
tempReference_ignoredContext, (ref BenchmarkContext _, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(tableValue)) {
|
||||||
|
try (InputStreamReader textReader = new InputStreamReader(jsonStream)) {
|
||||||
|
try (JsonTextReader jsonReader = new JsonTextReader(textReader)) {
|
||||||
|
while (jsonReader.Read()) {
|
||||||
|
// Just visit the entire structure without materializing any of the values.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (ref BenchmarkContext _, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonWriteBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
Encoding utf8Encoding = new UTF8Encoding();
|
||||||
|
JsonSerializer jsonSerializer = JsonSerializer.Create(SchematizedMicroBenchmarkSuite.JsonSettings);
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(BenchmarkSuiteBase.InitialCapacity)) {
|
||||||
|
try (OutputStreamWriter textWriter = new OutputStreamWriter(jsonStream)) {
|
||||||
|
try (JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)) {
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword -
|
||||||
|
// these are not converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Write", dataSetName, "JSON",
|
||||||
|
innerLoopIterations, tempReference_ignoredContext, (ref BenchmarkContext _, HashMap<Utf8String,
|
||||||
|
Object> tableValue) ->
|
||||||
|
{
|
||||||
|
jsonStream.SetLength(0);
|
||||||
|
jsonSerializer.Serialize(jsonWriter, tableValue);
|
||||||
|
jsonWriter.Flush();
|
||||||
|
}, (ref BenchmarkContext _, HashMap<Utf8String, Object> value) -> jsonStream.Length, expected);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LayoutReadBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName,
|
||||||
|
int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.StreamingWriter = new StreamingRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
context.StreamingWriter.Reset();
|
||||||
|
|
||||||
|
Result r = context.StreamingWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(context.StreamingWriter.ToArray());
|
||||||
|
expectedSerialized.add((Byte)context.StreamingWriter.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "Layout",
|
||||||
|
// innerLoopIterations, ref context, (ref BenchmarkContext ctx, byte[] tableValue) =>
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "Layout", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
VisitRowGenerator visitor = new VisitRowGenerator(tableValue.AsSpan(), resolver);
|
||||||
|
Result r = visitor.DispatchLayout(layout);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void LayoutWriteBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName,
|
||||||
|
int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.PatchWriter = new WriteRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Write", dataSetName, "Layout", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> dict) ->
|
||||||
|
{
|
||||||
|
ctx.PatchWriter.Reset();
|
||||||
|
Result r = ctx.PatchWriter.DispatchLayout(layout, dict);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> _) -> ctx.PatchWriter.Length, expected);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void StreamingReadBenchmark(LayoutResolverNamespace resolver, String schemaName, String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x = schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.StreamingWriter = new StreamingRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
context.StreamingWriter.Reset();
|
||||||
|
|
||||||
|
Result r = context.StreamingWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(context.StreamingWriter.ToArray());
|
||||||
|
expectedSerialized.add((Byte)context.StreamingWriter.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "HybridRow", innerLoopIterations, ref context, (ref BenchmarkContext ctx, byte[] tableValue) =>
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Read", dataSetName, "HybridRow", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
RowBuffer row = new RowBuffer(tableValue.AsSpan(), HybridRowVersion.V1, resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row = new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
RowReaderExtensions.VisitReader(reader.clone());
|
||||||
|
}, (ref BenchmarkContext ctx, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void StreamingWriteBenchmark(LayoutResolverNamespace resolver, String schemaName,
|
||||||
|
String dataSetName, int innerLoopIterations,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.StreamingWriter = new StreamingRowGenerator(BenchmarkSuiteBase.InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
MicroBenchmarkSuiteBase.Benchmark("Schematized", "Write", dataSetName, "HybridRow", innerLoopIterations,
|
||||||
|
tempReference_context, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
ctx.StreamingWriter.Reset();
|
||||||
|
|
||||||
|
Result r = ctx.StreamingWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> _) -> ctx.StreamingWriter.Length, expected);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Names of assets in the TestData folder.
|
||||||
|
*/
|
||||||
|
public class TestData {
|
||||||
|
public static final String GuestsExpected = "TestData\\GuestsSchemaExpected.hr";
|
||||||
|
public static final String HotelExpected = "TestData\\HotelSchemaExpected.hr";
|
||||||
|
public static final String Messages1KExpected = "TestData\\Messages1KExpected.hr";
|
||||||
|
public static final String RoomsExpected = "TestData\\RoomsSchemaExpected.hr";
|
||||||
|
public static final String SchemaFile = "TestData\\CassandraHotelSchema.json";
|
||||||
|
/**
|
||||||
|
* The folder to which TestData assets should be copied during deployment.
|
||||||
|
*/
|
||||||
|
public static final String Target = "TestData";
|
||||||
|
}
|
||||||
@@ -0,0 +1,339 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf;
|
||||||
|
|
||||||
|
import MongoDB.Bson.IO.*;
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests involving fully (or mostly) unschematized test data.
|
||||||
|
*/
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public sealed class UnschematizedMicroBenchmarkSuite : MicroBenchmarkSuiteBase
|
||||||
|
public final class UnschematizedMicroBenchmarkSuite extends MicroBenchmarkSuiteBase {
|
||||||
|
private static final JsonSerializerSettings JsonSettings = new JsonSerializerSettings
|
||||||
|
|
||||||
|
{
|
||||||
|
NullValueHandling = NullValueHandling.Ignore, Formatting = Formatting.Indented
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task BsonMessages1KReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task BsonMessages1KReadBenchmarkAsync()
|
||||||
|
public Task BsonMessages1KReadBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.BsonReadBenchmark("Messages1K", innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task BsonMessages1KWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task BsonMessages1KWriteBenchmarkAsync()
|
||||||
|
public Task BsonMessages1KWriteBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.BsonWriteBenchmark("Messages1K", innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task JsonMessages1KReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task JsonMessages1KReadBenchmarkAsync()
|
||||||
|
public Task JsonMessages1KReadBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.JsonReadBenchmark("Messages1K", innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task JsonMessages1KWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task JsonMessages1KWriteBenchmarkAsync()
|
||||||
|
public Task JsonMessages1KWriteBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.JsonWriteBenchmark("Messages1K", innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task Messages1KReadBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task Messages1KReadBenchmarkAsync()
|
||||||
|
public Task Messages1KReadBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.JsonModelReadBenchmark(resolver, "TypedJsonHybridRowSchema", "Messages1K",
|
||||||
|
innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task Messages1KWriteBenchmarkAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem(TestData.Messages1KExpected, TestData.Target)]
|
||||||
|
// public async Task Messages1KWriteBenchmarkAsync()
|
||||||
|
public Task Messages1KWriteBenchmarkAsync() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
//#if DEBUG
|
||||||
|
final int innerLoopIterations = 1;
|
||||||
|
//#else
|
||||||
|
final int innerLoopIterations = 10;
|
||||||
|
//#endif
|
||||||
|
String expectedFile = TestData.Messages1KExpected;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
(List < Dictionary < Utf8String, object >> expected, LayoutResolverNamespace resolver) =await
|
||||||
|
this.LoadExpectedAsync(expectedFile);
|
||||||
|
UnschematizedMicroBenchmarkSuite.JsonModelWriteBenchmark(resolver, "TypedJsonHybridRowSchema", "Messages1K",
|
||||||
|
innerLoopIterations, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BsonReadBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
try (BsonJsonModelRowGenerator writer = new BsonJsonModelRowGenerator(InitialCapacity)) {
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
writer.Reset();
|
||||||
|
writer.WriteBuffer(tableValue);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(writer.ToArray());
|
||||||
|
expectedSerialized.add(writer.ToArray());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Unschematized", "Read", dataSetName, "BSON", innerLoopIterations, ref ignoredContext, (ref BenchmarkContext _, byte[] tableValue) =>
|
||||||
|
Benchmark("Unschematized", "Read", dataSetName, "BSON", innerLoopIterations, tempReference_ignoredContext, (ref BenchmarkContext _, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
try (MemoryStream stm = new MemoryStream(tableValue)) {
|
||||||
|
try (BsonBinaryReader bsonReader = new BsonBinaryReader(stm)) {
|
||||||
|
bsonReader.VisitBsonDocument();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (ref BenchmarkContext _, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void BsonWriteBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
try (BsonJsonModelRowGenerator writer = new BsonJsonModelRowGenerator(InitialCapacity)) {
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are
|
||||||
|
// not converted by C# to Java Converter:
|
||||||
|
Benchmark("Unschematized", "Write", dataSetName, "BSON", innerLoopIterations,
|
||||||
|
tempReference_ignoredContext, (ref BenchmarkContext _, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
writer.Reset();
|
||||||
|
writer.WriteBuffer(tableValue);
|
||||||
|
}, (ref BenchmarkContext _, HashMap<Utf8String, Object> tableValue) -> writer.getLength(), expected);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonModelReadBenchmark(LayoutResolverNamespace resolver, String schemaName,
|
||||||
|
String dataSetName, int innerLoopIterations,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.JsonModelWriter = new JsonModelRowGenerator(InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
context.JsonModelWriter.Reset();
|
||||||
|
|
||||||
|
Result r = context.JsonModelWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(context.JsonModelWriter.ToArray());
|
||||||
|
expectedSerialized.add(context.JsonModelWriter.ToArray());
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Unschematized", "Read", dataSetName, "HybridRowSparse",
|
||||||
|
// innerLoopIterations, ref context, (ref BenchmarkContext ctx, byte[] tableValue) =>
|
||||||
|
Benchmark("Unschematized", "Read", dataSetName, "HybridRowSparse",
|
||||||
|
innerLoopIterations, tempReference_context, (ref BenchmarkContext ctx, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
RowBuffer row = new RowBuffer(tableValue.AsSpan(), HybridRowVersion.V1, resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
RowReaderExtensions.VisitReader(reader.clone());
|
||||||
|
}, (ref BenchmarkContext ctx, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonModelWriteBenchmark(LayoutResolverNamespace resolver, String schemaName,
|
||||||
|
String dataSetName, int innerLoopIterations,
|
||||||
|
ArrayList<HashMap<Utf8String, Object>> expected) {
|
||||||
|
Layout layout = resolver.Resolve(tangible.ListHelper.find(resolver.getNamespace().getSchemas(), x =
|
||||||
|
schemaName.equals( > x.Name)).SchemaId)
|
||||||
|
BenchmarkContext context = new BenchmarkContext();
|
||||||
|
context.JsonModelWriter = new JsonModelRowGenerator(InitialCapacity, layout, resolver);
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_context = new Reference<BenchmarkContext>(context);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
Benchmark("Unschematized", "Write", dataSetName, "HybridRowSparse",
|
||||||
|
innerLoopIterations, tempReference_context, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) ->
|
||||||
|
{
|
||||||
|
ctx.JsonModelWriter.Reset();
|
||||||
|
|
||||||
|
Result r = ctx.JsonModelWriter.WriteBuffer(tableValue);
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
}, (ref BenchmarkContext ctx, HashMap<Utf8String, Object> tableValue) -> ctx.JsonModelWriter.Length, expected);
|
||||||
|
context = tempReference_context.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonReadBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
// Serialize input data to sequence of byte buffers.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: List<byte[]> expectedSerialized = new List<byte[]>(expected.Count);
|
||||||
|
ArrayList<byte[]> expectedSerialized = new ArrayList<byte[]>(expected.size());
|
||||||
|
Encoding utf8Encoding = new UTF8Encoding();
|
||||||
|
JsonSerializer jsonSerializer = JsonSerializer.Create(UnschematizedMicroBenchmarkSuite.JsonSettings);
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(InitialCapacity)) {
|
||||||
|
try (OutputStreamWriter textWriter = new OutputStreamWriter(jsonStream)) {
|
||||||
|
try (JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)) {
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
for (HashMap<Utf8String, Object> tableValue : expected) {
|
||||||
|
jsonSerializer.Serialize(jsonWriter, tableValue);
|
||||||
|
jsonWriter.Flush();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: expectedSerialized.Add(jsonStream.ToArray());
|
||||||
|
expectedSerialized.add((Byte)jsonStream.ToArray());
|
||||||
|
jsonStream.SetLength(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MicroBenchmarkSuiteBase.Benchmark("Unschematized", "Read", dataSetName, "JSON",
|
||||||
|
// innerLoopIterations, ref ignoredContext, (ref BenchmarkContext _, byte[] tableValue) =>
|
||||||
|
Benchmark("Unschematized", "Read", dataSetName, "JSON", innerLoopIterations,
|
||||||
|
tempReference_ignoredContext, (ref BenchmarkContext _, byte[] tableValue) ->
|
||||||
|
{
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(tableValue)) {
|
||||||
|
try (InputStreamReader textReader = new InputStreamReader(jsonStream)) {
|
||||||
|
try (JsonTextReader jsonReader = new JsonTextReader(textReader)) {
|
||||||
|
while (jsonReader.Read()) {
|
||||||
|
// Just visit the entire structure without materializing any of the values.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, (ref BenchmarkContext _, byte[] tableValue) -> tableValue.length, expectedSerialized);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void JsonWriteBenchmark(String dataSetName, int innerLoopIterations, ArrayList<HashMap<Utf8String,
|
||||||
|
Object>> expected) {
|
||||||
|
Encoding utf8Encoding = new UTF8Encoding();
|
||||||
|
JsonSerializer jsonSerializer = JsonSerializer.Create(UnschematizedMicroBenchmarkSuite.JsonSettings);
|
||||||
|
try (MemoryStream jsonStream = new MemoryStream(InitialCapacity)) {
|
||||||
|
try (OutputStreamWriter textWriter = new OutputStreamWriter(jsonStream)) {
|
||||||
|
try (JsonTextWriter jsonWriter = new JsonTextWriter(textWriter)) {
|
||||||
|
BenchmarkContext ignoredContext = null;
|
||||||
|
jsonSerializer.Converters.Add(new Utf8StringJsonConverter());
|
||||||
|
|
||||||
|
Reference<BenchmarkContext> tempReference_ignoredContext = new Reference<BenchmarkContext>(ignoredContext);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword -
|
||||||
|
// these are not converted by C# to Java Converter:
|
||||||
|
Benchmark("Unschematized", "Write", dataSetName, "JSON",
|
||||||
|
innerLoopIterations, tempReference_ignoredContext, (ref BenchmarkContext _, HashMap<Utf8String,
|
||||||
|
Object> tableValue) ->
|
||||||
|
{
|
||||||
|
jsonStream.SetLength(0);
|
||||||
|
jsonSerializer.Serialize(jsonWriter, tableValue);
|
||||||
|
jsonWriter.Flush();
|
||||||
|
}, (ref BenchmarkContext _, HashMap<Utf8String, Object> value) -> jsonStream.Length, expected);
|
||||||
|
ignoredContext = tempReference_ignoredContext.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import com.google.protobuf.Parser;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
public final class Address implements Message<Address> {
|
||||||
|
/**
|
||||||
|
* Field number for the "city" field.
|
||||||
|
*/
|
||||||
|
public static final int CityFieldNumber = 2;
|
||||||
|
/**
|
||||||
|
* Field number for the "postal_code" field.
|
||||||
|
*/
|
||||||
|
public static final int PostalCodeFieldNumber = 4;
|
||||||
|
/**
|
||||||
|
* Field number for the "state" field.
|
||||||
|
*/
|
||||||
|
public static final int StateFieldNumber = 3;
|
||||||
|
/**
|
||||||
|
* Field number for the "street" field.
|
||||||
|
*/
|
||||||
|
public static final int StreetFieldNumber = 1;
|
||||||
|
private static final Parser<?> _parser = new Address().getParserForType();
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_city_codec = Google.Protobuf.FieldCodec.<String>ForClassWrapper(18);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not support 'partial' methods:
|
||||||
|
// partial void OnConstruction();
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_state_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(26);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_street_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(10);
|
||||||
|
private Google.Protobuf.UnknownFieldSet _unknownFields;
|
||||||
|
private String city_;
|
||||||
|
private PostalCode postalCode_;
|
||||||
|
private String state_;
|
||||||
|
private String street_;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Address()
|
||||||
|
public Address() {
|
||||||
|
OnConstruction();
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Address(Address other)
|
||||||
|
public Address(Address other) {
|
||||||
|
this();
|
||||||
|
setStreet(other.getStreet());
|
||||||
|
setCity(other.getCity());
|
||||||
|
setState(other.getState());
|
||||||
|
setPostalCode(other.postalCode_ != null ? other.getPostalCode().Clone() : null);
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.Clone(other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string City
|
||||||
|
public String getCity() {
|
||||||
|
return city_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCity(String value) {
|
||||||
|
city_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] pbr::MessageDescriptor pb::IMessage.Descriptor
|
||||||
|
public Google.Protobuf.Reflection getDescriptor() {
|
||||||
|
return getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf.Reflection
|
||||||
|
// .MessageDescriptor Descriptor
|
||||||
|
public static Google.Protobuf.Reflection.MessageDescriptor getDescriptor() {
|
||||||
|
return CassandraHotelSchemaReflection.getDescriptor().MessageTypes[1];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf
|
||||||
|
// .MessageParser<Address> Parser
|
||||||
|
public static Google.Protobuf.MessageParser<Address> getParser() {
|
||||||
|
return _parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Microsoft.Azure.Cosmos.Serialization
|
||||||
|
// .HybridRow.Tests.Perf.CassandraHotel.Protobuf.PostalCode PostalCode
|
||||||
|
public PostalCode getPostalCode() {
|
||||||
|
return postalCode_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPostalCode(PostalCode value) {
|
||||||
|
postalCode_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string State
|
||||||
|
public String getState() {
|
||||||
|
return state_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setState(String value) {
|
||||||
|
state_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string Street
|
||||||
|
public String getStreet() {
|
||||||
|
return street_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStreet(String value) {
|
||||||
|
street_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize()
|
||||||
|
public int CalculateSize() {
|
||||||
|
int size = 0;
|
||||||
|
if (street_ != null) {
|
||||||
|
size += _single_street_codec.CalculateSizeWithTag(getStreet());
|
||||||
|
}
|
||||||
|
if (city_ != null) {
|
||||||
|
size += _single_city_codec.CalculateSizeWithTag(getCity());
|
||||||
|
}
|
||||||
|
if (state_ != null) {
|
||||||
|
size += _single_state_codec.CalculateSizeWithTag(getState());
|
||||||
|
}
|
||||||
|
if (postalCode_ != null) {
|
||||||
|
size += 1 + Google.Protobuf.CodedOutputStream.ComputeMessageSize(getPostalCode());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
size += _unknownFields.CalculateSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Address Clone()
|
||||||
|
public Address Clone() {
|
||||||
|
return new Address(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Address other)
|
||||||
|
public void MergeFrom(Address other) {
|
||||||
|
if (other == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other.street_ != null) {
|
||||||
|
if (street_ == null || !other.getStreet().equals("")) {
|
||||||
|
setStreet(other.getStreet());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.city_ != null) {
|
||||||
|
if (city_ == null || !other.getCity().equals("")) {
|
||||||
|
setCity(other.getCity());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.state_ != null) {
|
||||||
|
if (state_ == null || !other.getState().equals("")) {
|
||||||
|
setState(other.getState());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.postalCode_ != null) {
|
||||||
|
if (postalCode_ == null) {
|
||||||
|
postalCode_ = new PostalCode();
|
||||||
|
}
|
||||||
|
getPostalCode().MergeFrom(other.getPostalCode());
|
||||||
|
}
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Google.Protobuf
|
||||||
|
// .CodedInputStream input)
|
||||||
|
public void MergeFrom(Google.Protobuf.CodedInputStream input) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint tag;
|
||||||
|
int tag;
|
||||||
|
while ((tag = input.ReadTag()) != 0) {
|
||||||
|
switch (tag) {
|
||||||
|
default:
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
|
break;
|
||||||
|
case 10: {
|
||||||
|
String value = _single_street_codec.Read(input);
|
||||||
|
if (street_ == null || !value.equals("")) {
|
||||||
|
setStreet(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
String value = _single_city_codec.Read(input);
|
||||||
|
if (city_ == null || !value.equals("")) {
|
||||||
|
setCity(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 26: {
|
||||||
|
String value = _single_state_codec.Read(input);
|
||||||
|
if (state_ == null || !value.equals("")) {
|
||||||
|
setState(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 34: {
|
||||||
|
if (postalCode_ == null) {
|
||||||
|
postalCode_ = new PostalCode();
|
||||||
|
}
|
||||||
|
input.ReadMessage(postalCode_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(Google.Protobuf
|
||||||
|
// .CodedOutputStream output)
|
||||||
|
public void WriteTo(Google.Protobuf.CodedOutputStream output) {
|
||||||
|
if (street_ != null) {
|
||||||
|
_single_street_codec.WriteTagAndValue(output, getStreet());
|
||||||
|
}
|
||||||
|
if (city_ != null) {
|
||||||
|
_single_city_codec.WriteTagAndValue(output, getCity());
|
||||||
|
}
|
||||||
|
if (state_ != null) {
|
||||||
|
_single_state_codec.WriteTagAndValue(output, getState());
|
||||||
|
}
|
||||||
|
if (postalCode_ != null) {
|
||||||
|
output.WriteRawTag(34);
|
||||||
|
output.WriteMessage(getPostalCode());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
_unknownFields.WriteTo(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other)
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return Equals(other instanceof Address ? (Address)other : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public bool Equals(Address other)
|
||||||
|
public boolean equals(Address other) {
|
||||||
|
if (ReferenceEquals(other, null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ReferenceEquals(other, this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!getStreet().equals(other.getStreet())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getCity().equals(other.getCity())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getState().equals(other.getState())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getPostalCode().equals(other.getPostalCode())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode()
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 1;
|
||||||
|
if (street_ != null) {
|
||||||
|
hash ^= getStreet().hashCode();
|
||||||
|
}
|
||||||
|
if (city_ != null) {
|
||||||
|
hash ^= getCity().hashCode();
|
||||||
|
}
|
||||||
|
if (state_ != null) {
|
||||||
|
hash ^= getState().hashCode();
|
||||||
|
}
|
||||||
|
if (postalCode_ != null) {
|
||||||
|
hash ^= getPostalCode().hashCode();
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
hash ^= _unknownFields.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override string ToString()
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Google.Protobuf.JsonFormatter.ToDiagnosticString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,320 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
public final class Available_Rooms_By_Hotel_Date implements Google.Protobuf.IMessage<Available_Rooms_By_Hotel_Date> {
|
||||||
|
/**
|
||||||
|
* Field number for the "date" field.
|
||||||
|
*/
|
||||||
|
public static final int DateFieldNumber = 2;
|
||||||
|
/**
|
||||||
|
* Field number for the "hotel_id" field.
|
||||||
|
*/
|
||||||
|
public static final int HotelIdFieldNumber = 1;
|
||||||
|
/**
|
||||||
|
* Field number for the "is_available" field.
|
||||||
|
*/
|
||||||
|
public static final int IsAvailableFieldNumber = 4;
|
||||||
|
/**
|
||||||
|
* Field number for the "room_number" field.
|
||||||
|
*/
|
||||||
|
public static final int RoomNumberFieldNumber = 3;
|
||||||
|
private static final Google.Protobuf.MessageParser<Available_Rooms_By_Hotel_Date> _parser =
|
||||||
|
new Google.Protobuf.MessageParser<Available_Rooms_By_Hotel_Date>(() -> new Available_Rooms_By_Hotel_Date());
|
||||||
|
private static final Google.Protobuf.FieldCodec<Long> _single_date_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<Long>ForStructWrapper(18);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not support 'partial' methods:
|
||||||
|
// partial void OnConstruction();
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_hotelId_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(10);
|
||||||
|
private static final Google.Protobuf.FieldCodec<Boolean> _single_isAvailable_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<Boolean>ForStructWrapper(34);
|
||||||
|
private static final Google.Protobuf.FieldCodec<Integer> _single_roomNumber_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<Integer>ForStructWrapper(26);
|
||||||
|
private Google.Protobuf.UnknownFieldSet _unknownFields;
|
||||||
|
private Long date_;
|
||||||
|
private String hotelId_;
|
||||||
|
private Boolean isAvailable_;
|
||||||
|
private Integer roomNumber_;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Available_Rooms_By_Hotel_Date()
|
||||||
|
public Available_Rooms_By_Hotel_Date() {
|
||||||
|
OnConstruction();
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Available_Rooms_By_Hotel_Date
|
||||||
|
// (Available_Rooms_By_Hotel_Date other)
|
||||||
|
public Available_Rooms_By_Hotel_Date(Available_Rooms_By_Hotel_Date other) {
|
||||||
|
this();
|
||||||
|
setHotelId(other.getHotelId());
|
||||||
|
setDate(other.getDate());
|
||||||
|
setRoomNumber(other.getRoomNumber());
|
||||||
|
setIsAvailable(other.getIsAvailable());
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.Clone(other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* datetime
|
||||||
|
*/
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Nullable<long> Date
|
||||||
|
public Long getDate() {
|
||||||
|
return date_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDate(Long value) {
|
||||||
|
date_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] pbr::MessageDescriptor pb::IMessage.Descriptor
|
||||||
|
public Google.Protobuf.Reflection getDescriptor() {
|
||||||
|
return getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf.Reflection
|
||||||
|
// .MessageDescriptor Descriptor
|
||||||
|
public static Google.Protobuf.Reflection.MessageDescriptor getDescriptor() {
|
||||||
|
return CassandraHotelSchemaReflection.getDescriptor().MessageTypes[3];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string HotelId
|
||||||
|
public String getHotelId() {
|
||||||
|
return hotelId_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHotelId(String value) {
|
||||||
|
hotelId_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Nullable<bool> IsAvailable
|
||||||
|
public Boolean getIsAvailable() {
|
||||||
|
return isAvailable_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAvailable(Boolean value) {
|
||||||
|
isAvailable_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf
|
||||||
|
// .MessageParser<Available_Rooms_By_Hotel_Date> Parser
|
||||||
|
public static Google.Protobuf.MessageParser<Available_Rooms_By_Hotel_Date> getParser() {
|
||||||
|
return _parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Nullable<int> RoomNumber
|
||||||
|
public Integer getRoomNumber() {
|
||||||
|
return roomNumber_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoomNumber(Integer value) {
|
||||||
|
roomNumber_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize()
|
||||||
|
public int CalculateSize() {
|
||||||
|
int size = 0;
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
size += _single_hotelId_codec.CalculateSizeWithTag(getHotelId());
|
||||||
|
}
|
||||||
|
if (date_ != null) {
|
||||||
|
size += _single_date_codec.CalculateSizeWithTag(getDate());
|
||||||
|
}
|
||||||
|
if (roomNumber_ != null) {
|
||||||
|
size += _single_roomNumber_codec.CalculateSizeWithTag(getRoomNumber());
|
||||||
|
}
|
||||||
|
if (isAvailable_ != null) {
|
||||||
|
size += _single_isAvailable_codec.CalculateSizeWithTag(getIsAvailable());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
size += _unknownFields.CalculateSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Available_Rooms_By_Hotel_Date Clone()
|
||||||
|
public Available_Rooms_By_Hotel_Date Clone() {
|
||||||
|
return new Available_Rooms_By_Hotel_Date(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom
|
||||||
|
// (Available_Rooms_By_Hotel_Date other)
|
||||||
|
public void MergeFrom(Available_Rooms_By_Hotel_Date other) {
|
||||||
|
if (other == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other.hotelId_ != null) {
|
||||||
|
if (hotelId_ == null || !other.getHotelId().equals("")) {
|
||||||
|
setHotelId(other.getHotelId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.date_ != null) {
|
||||||
|
if (date_ == null || other.getDate() != 0L) {
|
||||||
|
setDate(other.getDate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.roomNumber_ != null) {
|
||||||
|
if (roomNumber_ == null || other.getRoomNumber() != 0) {
|
||||||
|
setRoomNumber(other.getRoomNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.isAvailable_ != null) {
|
||||||
|
if (isAvailable_ == null || other.getIsAvailable() != false) {
|
||||||
|
setIsAvailable(other.getIsAvailable());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Google.Protobuf
|
||||||
|
// .CodedInputStream input)
|
||||||
|
public void MergeFrom(Google.Protobuf.CodedInputStream input) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint tag;
|
||||||
|
int tag;
|
||||||
|
while ((tag = input.ReadTag()) != 0) {
|
||||||
|
switch (tag) {
|
||||||
|
default:
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
|
break;
|
||||||
|
case 10: {
|
||||||
|
String value = _single_hotelId_codec.Read(input);
|
||||||
|
if (hotelId_ == null || !value.equals("")) {
|
||||||
|
setHotelId(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
Long value = _single_date_codec.Read(input);
|
||||||
|
if (date_ == null || value != 0L) {
|
||||||
|
setDate(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 26: {
|
||||||
|
Integer value = _single_roomNumber_codec.Read(input);
|
||||||
|
if (roomNumber_ == null || value != 0) {
|
||||||
|
setRoomNumber(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 34: {
|
||||||
|
Boolean value = _single_isAvailable_codec.Read(input);
|
||||||
|
if (isAvailable_ == null || value != false) {
|
||||||
|
setIsAvailable(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(Google.Protobuf
|
||||||
|
// .CodedOutputStream output)
|
||||||
|
public void WriteTo(Google.Protobuf.CodedOutputStream output) {
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
_single_hotelId_codec.WriteTagAndValue(output, getHotelId());
|
||||||
|
}
|
||||||
|
if (date_ != null) {
|
||||||
|
_single_date_codec.WriteTagAndValue(output, getDate());
|
||||||
|
}
|
||||||
|
if (roomNumber_ != null) {
|
||||||
|
_single_roomNumber_codec.WriteTagAndValue(output, getRoomNumber());
|
||||||
|
}
|
||||||
|
if (isAvailable_ != null) {
|
||||||
|
_single_isAvailable_codec.WriteTagAndValue(output, getIsAvailable());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
_unknownFields.WriteTo(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other)
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return Equals(other instanceof Available_Rooms_By_Hotel_Date ? (Available_Rooms_By_Hotel_Date)other : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public bool Equals
|
||||||
|
// (Available_Rooms_By_Hotel_Date other)
|
||||||
|
public boolean equals(Available_Rooms_By_Hotel_Date other) {
|
||||||
|
if (ReferenceEquals(other, null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ReferenceEquals(other, this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!getHotelId().equals(other.getHotelId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getDate() != other.getDate()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getRoomNumber() != other.getRoomNumber()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getIsAvailable() != other.getIsAvailable()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode()
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 1;
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
hash ^= getHotelId().hashCode();
|
||||||
|
}
|
||||||
|
if (date_ != null) {
|
||||||
|
hash ^= getDate().hashCode();
|
||||||
|
}
|
||||||
|
if (roomNumber_ != null) {
|
||||||
|
hash ^= getRoomNumber().hashCode();
|
||||||
|
}
|
||||||
|
if (isAvailable_ != null) {
|
||||||
|
hash ^= getIsAvailable().hashCode();
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
hash ^= _unknownFields.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override string ToString()
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Google.Protobuf.JsonFormatter.ToDiagnosticString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,120 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Holder for reflection information generated from TestData/CassandraHotelSchema.proto
|
||||||
|
*/
|
||||||
|
public final class CassandraHotelSchemaReflection {
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#region Descriptor
|
||||||
|
|
||||||
|
private static Google.Protobuf.Reflection.FileDescriptor descriptor;
|
||||||
|
|
||||||
|
static {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: byte[] descriptorData = System.Convert.FromBase64String(string.Concat
|
||||||
|
// ("CiNUZXN0RGF0YS9DYXNzYW5kcmFIb3RlbFNjaGVtYS5wcm90bxJITWljcm9z",
|
||||||
|
// "b2Z0LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9uLkh5YnJpZFJvdy5UZXN0",
|
||||||
|
// "cy5QZXJmLkNhc3NhbmRyYUhvdGVsGh5nb29nbGUvcHJvdG9idWYvd3JhcHBl",
|
||||||
|
// "cnMucHJvdG8iYgoKUG9zdGFsQ29kZRIoCgN6aXAYASABKAsyGy5nb29nbGUu",
|
||||||
|
// "cHJvdG9idWYuSW50MzJWYWx1ZRIqCgVwbHVzNBgCIAEoCzIbLmdvb2dsZS5w",
|
||||||
|
// "cm90b2J1Zi5JbnQzMlZhbHVlIvsBCgdBZGRyZXNzEiwKBnN0cmVldBgBIAEo",
|
||||||
|
// "CzIcLmdvb2dsZS5wcm90b2J1Zi5TdHJpbmdWYWx1ZRIqCgRjaXR5GAIgASgL",
|
||||||
|
// "MhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEisKBXN0YXRlGAMgASgL",
|
||||||
|
// "MhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEmkKC3Bvc3RhbF9jb2Rl",
|
||||||
|
// "GAQgASgLMlQuTWljcm9zb2Z0LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9u",
|
||||||
|
// "Lkh5YnJpZFJvdy5UZXN0cy5QZXJmLkNhc3NhbmRyYUhvdGVsLlBvc3RhbENv",
|
||||||
|
// "ZGUi9QEKBkhvdGVscxIuCghob3RlbF9pZBgBIAEoCzIcLmdvb2dsZS5wcm90",
|
||||||
|
// "b2J1Zi5TdHJpbmdWYWx1ZRIqCgRuYW1lGAIgASgLMhwuZ29vZ2xlLnByb3Rv",
|
||||||
|
// "YnVmLlN0cmluZ1ZhbHVlEisKBXBob25lGAMgASgLMhwuZ29vZ2xlLnByb3Rv",
|
||||||
|
// "YnVmLlN0cmluZ1ZhbHVlEmIKB2FkZHJlc3MYBCABKAsyUS5NaWNyb3NvZnQu",
|
||||||
|
// "QXp1cmUuQ29zbW9zLlNlcmlhbGl6YXRpb24uSHlicmlkUm93LlRlc3RzLlBl",
|
||||||
|
// "cmYuQ2Fzc2FuZHJhSG90ZWwuQWRkcmVzcyLeAQodQXZhaWxhYmxlX1Jvb21z",
|
||||||
|
// "X0J5X0hvdGVsX0RhdGUSLgoIaG90ZWxfaWQYASABKAsyHC5nb29nbGUucHJv",
|
||||||
|
// "dG9idWYuU3RyaW5nVmFsdWUSKQoEZGF0ZRgCIAEoCzIbLmdvb2dsZS5wcm90",
|
||||||
|
// "b2J1Zi5JbnQ2NFZhbHVlEjAKC3Jvb21fbnVtYmVyGAMgASgLMhsuZ29vZ2xl",
|
||||||
|
// "LnByb3RvYnVmLkludDMyVmFsdWUSMAoMaXNfYXZhaWxhYmxlGAQgASgLMhou",
|
||||||
|
// "Z29vZ2xlLnByb3RvYnVmLkJvb2xWYWx1ZSKfBAoGR3Vlc3RzEi4KCGd1ZXN0",
|
||||||
|
// "X2lkGAEgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEjAKCmZp",
|
||||||
|
// "cnN0X25hbWUYAiABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUS",
|
||||||
|
// "LwoJbGFzdF9uYW1lGAMgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh",
|
||||||
|
// "bHVlEisKBXRpdGxlGAQgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh",
|
||||||
|
// "bHVlEg4KBmVtYWlscxgFIAMoCRIVCg1waG9uZV9udW1iZXJzGAYgAygJEnIK",
|
||||||
|
// "CWFkZHJlc3NlcxgHIAMoCzJfLk1pY3Jvc29mdC5BenVyZS5Db3Ntb3MuU2Vy",
|
||||||
|
// "aWFsaXphdGlvbi5IeWJyaWRSb3cuVGVzdHMuUGVyZi5DYXNzYW5kcmFIb3Rl",
|
||||||
|
// "bC5HdWVzdHMuQWRkcmVzc2VzRW50cnkSNAoOY29uZmlybV9udW1iZXIYCCAB",
|
||||||
|
// "KAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUagwEKDkFkZHJlc3Nl",
|
||||||
|
// "c0VudHJ5EgsKA2tleRgBIAEoCRJgCgV2YWx1ZRgCIAEoCzJRLk1pY3Jvc29m",
|
||||||
|
// "dC5BenVyZS5Db3Ntb3MuU2VyaWFsaXphdGlvbi5IeWJyaWRSb3cuVGVzdHMu",
|
||||||
|
// "UGVyZi5DYXNzYW5kcmFIb3RlbC5BZGRyZXNzOgI4AUJUqgJRTWljcm9zb2Z0",
|
||||||
|
// "LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9uLkh5YnJpZFJvdy5UZXN0cy5Q",
|
||||||
|
// "ZXJmLkNhc3NhbmRyYUhvdGVsLlByb3RvYnVmYgZwcm90bzM="));
|
||||||
|
byte[] descriptorData = System.Convert.FromBase64String(String.Concat(
|
||||||
|
"CiNUZXN0RGF0YS9DYXNzYW5kcmFIb3RlbFNjaGVtYS5wcm90bxJITWljcm9z",
|
||||||
|
"b2Z0LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9uLkh5YnJpZFJvdy5UZXN0",
|
||||||
|
"cy5QZXJmLkNhc3NhbmRyYUhvdGVsGh5nb29nbGUvcHJvdG9idWYvd3JhcHBl",
|
||||||
|
"cnMucHJvdG8iYgoKUG9zdGFsQ29kZRIoCgN6aXAYASABKAsyGy5nb29nbGUu",
|
||||||
|
"cHJvdG9idWYuSW50MzJWYWx1ZRIqCgVwbHVzNBgCIAEoCzIbLmdvb2dsZS5w",
|
||||||
|
"cm90b2J1Zi5JbnQzMlZhbHVlIvsBCgdBZGRyZXNzEiwKBnN0cmVldBgBIAEo",
|
||||||
|
"CzIcLmdvb2dsZS5wcm90b2J1Zi5TdHJpbmdWYWx1ZRIqCgRjaXR5GAIgASgL",
|
||||||
|
"MhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEisKBXN0YXRlGAMgASgL",
|
||||||
|
"MhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEmkKC3Bvc3RhbF9jb2Rl",
|
||||||
|
"GAQgASgLMlQuTWljcm9zb2Z0LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9u",
|
||||||
|
"Lkh5YnJpZFJvdy5UZXN0cy5QZXJmLkNhc3NhbmRyYUhvdGVsLlBvc3RhbENv",
|
||||||
|
"ZGUi9QEKBkhvdGVscxIuCghob3RlbF9pZBgBIAEoCzIcLmdvb2dsZS5wcm90",
|
||||||
|
"b2J1Zi5TdHJpbmdWYWx1ZRIqCgRuYW1lGAIgASgLMhwuZ29vZ2xlLnByb3Rv",
|
||||||
|
"YnVmLlN0cmluZ1ZhbHVlEisKBXBob25lGAMgASgLMhwuZ29vZ2xlLnByb3Rv",
|
||||||
|
"YnVmLlN0cmluZ1ZhbHVlEmIKB2FkZHJlc3MYBCABKAsyUS5NaWNyb3NvZnQu",
|
||||||
|
"QXp1cmUuQ29zbW9zLlNlcmlhbGl6YXRpb24uSHlicmlkUm93LlRlc3RzLlBl",
|
||||||
|
"cmYuQ2Fzc2FuZHJhSG90ZWwuQWRkcmVzcyLeAQodQXZhaWxhYmxlX1Jvb21z",
|
||||||
|
"X0J5X0hvdGVsX0RhdGUSLgoIaG90ZWxfaWQYASABKAsyHC5nb29nbGUucHJv",
|
||||||
|
"dG9idWYuU3RyaW5nVmFsdWUSKQoEZGF0ZRgCIAEoCzIbLmdvb2dsZS5wcm90",
|
||||||
|
"b2J1Zi5JbnQ2NFZhbHVlEjAKC3Jvb21fbnVtYmVyGAMgASgLMhsuZ29vZ2xl",
|
||||||
|
"LnByb3RvYnVmLkludDMyVmFsdWUSMAoMaXNfYXZhaWxhYmxlGAQgASgLMhou",
|
||||||
|
"Z29vZ2xlLnByb3RvYnVmLkJvb2xWYWx1ZSKfBAoGR3Vlc3RzEi4KCGd1ZXN0",
|
||||||
|
"X2lkGAEgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1ZhbHVlEjAKCmZp",
|
||||||
|
"cnN0X25hbWUYAiABKAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUS",
|
||||||
|
"LwoJbGFzdF9uYW1lGAMgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh",
|
||||||
|
"bHVlEisKBXRpdGxlGAQgASgLMhwuZ29vZ2xlLnByb3RvYnVmLlN0cmluZ1Zh",
|
||||||
|
"bHVlEg4KBmVtYWlscxgFIAMoCRIVCg1waG9uZV9udW1iZXJzGAYgAygJEnIK",
|
||||||
|
"CWFkZHJlc3NlcxgHIAMoCzJfLk1pY3Jvc29mdC5BenVyZS5Db3Ntb3MuU2Vy",
|
||||||
|
"aWFsaXphdGlvbi5IeWJyaWRSb3cuVGVzdHMuUGVyZi5DYXNzYW5kcmFIb3Rl",
|
||||||
|
"bC5HdWVzdHMuQWRkcmVzc2VzRW50cnkSNAoOY29uZmlybV9udW1iZXIYCCAB",
|
||||||
|
"KAsyHC5nb29nbGUucHJvdG9idWYuU3RyaW5nVmFsdWUagwEKDkFkZHJlc3Nl",
|
||||||
|
"c0VudHJ5EgsKA2tleRgBIAEoCRJgCgV2YWx1ZRgCIAEoCzJRLk1pY3Jvc29m",
|
||||||
|
"dC5BenVyZS5Db3Ntb3MuU2VyaWFsaXphdGlvbi5IeWJyaWRSb3cuVGVzdHMu",
|
||||||
|
"UGVyZi5DYXNzYW5kcmFIb3RlbC5BZGRyZXNzOgI4AUJUqgJRTWljcm9zb2Z0",
|
||||||
|
"LkF6dXJlLkNvc21vcy5TZXJpYWxpemF0aW9uLkh5YnJpZFJvdy5UZXN0cy5Q",
|
||||||
|
"ZXJmLkNhc3NhbmRyYUhvdGVsLlByb3RvYnVmYgZwcm90bzM="));
|
||||||
|
descriptor = Google.Protobuf.Reflection.FileDescriptor.FromGeneratedCode(descriptorData,
|
||||||
|
new Google.Protobuf.Reflection.FileDescriptor[] { Google.Protobuf.WellKnownTypes.WrappersReflection.Descriptor }, new Google.Protobuf.Reflection.GeneratedClrTypeInfo(null, new Google.Protobuf.Reflection.GeneratedClrTypeInfo[] { new Google.Protobuf.Reflection.GeneratedClrTypeInfo(PostalCode.class, PostalCode.getParser(), new String[] { "Zip", "Plus4" }, null, null, null), new Google.Protobuf.Reflection.GeneratedClrTypeInfo(Address.class, Address.getParser(), new String[] { "Street", "City", "State", "PostalCode" }, null, null, null), new Google.Protobuf.Reflection.GeneratedClrTypeInfo(Hotels.class, Hotels.getParser(), new String[] { "HotelId", "Name", "Phone", "Address" }, null, null, null), new Google.Protobuf.Reflection.GeneratedClrTypeInfo(Available_Rooms_By_Hotel_Date.class, Available_Rooms_By_Hotel_Date.getParser(), new String[] { "HotelId", "Date", "RoomNumber", "IsAvailable" }, null, null, null), new Google.Protobuf.Reflection.GeneratedClrTypeInfo(Guests.class, Guests.getParser(), new String[] { "GuestId", "FirstName", "LastName", "Title", "Emails", "PhoneNumbers", "Addresses", "ConfirmNumber" }, null, null, new Google.Protobuf.Reflection.GeneratedClrTypeInfo[] { null }) }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* File descriptor for TestData/CassandraHotelSchema.proto
|
||||||
|
*/
|
||||||
|
public static Google.Protobuf.Reflection.FileDescriptor getDescriptor() {
|
||||||
|
return descriptor;
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#endregion
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,445 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
public final class Guests implements Google.Protobuf.IMessage<Guests> {
|
||||||
|
/**
|
||||||
|
* Field number for the "addresses" field.
|
||||||
|
*/
|
||||||
|
public static final int AddressesFieldNumber = 7;
|
||||||
|
/**
|
||||||
|
* Field number for the "confirm_number" field.
|
||||||
|
*/
|
||||||
|
public static final int ConfirmNumberFieldNumber = 8;
|
||||||
|
/**
|
||||||
|
* Field number for the "emails" field.
|
||||||
|
*/
|
||||||
|
public static final int EmailsFieldNumber = 5;
|
||||||
|
/**
|
||||||
|
* Field number for the "first_name" field.
|
||||||
|
*/
|
||||||
|
public static final int FirstNameFieldNumber = 2;
|
||||||
|
/**
|
||||||
|
* Field number for the "guest_id" field.
|
||||||
|
*/
|
||||||
|
public static final int GuestIdFieldNumber = 1;
|
||||||
|
/**
|
||||||
|
* Field number for the "last_name" field.
|
||||||
|
*/
|
||||||
|
public static final int LastNameFieldNumber = 3;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not support 'partial' methods:
|
||||||
|
// partial void OnConstruction();
|
||||||
|
/**
|
||||||
|
* Field number for the "phone_numbers" field.
|
||||||
|
*/
|
||||||
|
public static final int PhoneNumbersFieldNumber = 6;
|
||||||
|
/**
|
||||||
|
* Field number for the "title" field.
|
||||||
|
*/
|
||||||
|
public static final int TitleFieldNumber = 4;
|
||||||
|
private static final Google.Protobuf.Collections.MapField<String, Address>.Codec _map_addresses_codec =
|
||||||
|
new Google.Protobuf.Collections.MapField<String, Address>.Codec(Google.Protobuf.FieldCodec.ForString(10),
|
||||||
|
Google.Protobuf.FieldCodec.ForMessage(18,
|
||||||
|
Address.getParser()), 58);
|
||||||
|
private static final Google.Protobuf.MessageParser<Guests> _parser =
|
||||||
|
new Google.Protobuf.MessageParser<Guests>(() -> new Guests());
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _repeated_emails_codec =
|
||||||
|
Google.Protobuf.FieldCodec.ForString(42);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _repeated_phoneNumbers_codec =
|
||||||
|
Google.Protobuf.FieldCodec.ForString(50);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_confirmNumber_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(66);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_firstName_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(18);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_guestId_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(10);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_lastName_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(26);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_title_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(34);
|
||||||
|
private final Google.Protobuf.Collections.MapField<String, Address> addresses_ =
|
||||||
|
new Google.Protobuf.Collections.MapField<String, Address>();
|
||||||
|
private final Google.Protobuf.Collections.RepeatedField<String> emails_ =
|
||||||
|
new Google.Protobuf.Collections.RepeatedField<String>();
|
||||||
|
private final Google.Protobuf.Collections.RepeatedField<String> phoneNumbers_ =
|
||||||
|
new Google.Protobuf.Collections.RepeatedField<String>();
|
||||||
|
private Google.Protobuf.UnknownFieldSet _unknownFields;
|
||||||
|
private String confirmNumber_;
|
||||||
|
private String firstName_;
|
||||||
|
private String guestId_;
|
||||||
|
private String lastName_;
|
||||||
|
private String title_;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Guests()
|
||||||
|
public Guests() {
|
||||||
|
OnConstruction();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Guests(Guests other)
|
||||||
|
public Guests(Guests other) {
|
||||||
|
this();
|
||||||
|
setGuestId(other.getGuestId());
|
||||||
|
setFirstName(other.getFirstName());
|
||||||
|
setLastName(other.getLastName());
|
||||||
|
setTitle(other.getTitle());
|
||||||
|
emails_ = other.emails_.Clone();
|
||||||
|
phoneNumbers_ = other.phoneNumbers_.Clone();
|
||||||
|
addresses_ = other.addresses_.Clone();
|
||||||
|
setConfirmNumber(other.getConfirmNumber());
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.Clone(other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Google.Protobuf.Collections
|
||||||
|
// .MapField<string, azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.Protobuf.Address>
|
||||||
|
// Addresses
|
||||||
|
public Google.Protobuf.Collections.MapField<String, Address> getAddresses() {
|
||||||
|
return addresses_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string ConfirmNumber
|
||||||
|
public String getConfirmNumber() {
|
||||||
|
return confirmNumber_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConfirmNumber(String value) {
|
||||||
|
confirmNumber_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf.Reflection
|
||||||
|
// .MessageDescriptor Descriptor
|
||||||
|
public static Google.Protobuf.Reflection.MessageDescriptor getDescriptor() {
|
||||||
|
return CassandraHotelSchemaReflection.getDescriptor().MessageTypes[4];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] pbr::MessageDescriptor pb::IMessage.Descriptor
|
||||||
|
public Google.Protobuf.Reflection getDescriptor() {
|
||||||
|
return getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Google.Protobuf.Collections
|
||||||
|
// .RepeatedField<string> Emails
|
||||||
|
public Google.Protobuf.Collections.RepeatedField<String> getEmails() {
|
||||||
|
return emails_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string FirstName
|
||||||
|
public String getFirstName() {
|
||||||
|
return firstName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFirstName(String value) {
|
||||||
|
firstName_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* guid
|
||||||
|
*/
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string GuestId
|
||||||
|
public String getGuestId() {
|
||||||
|
return guestId_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGuestId(String value) {
|
||||||
|
guestId_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string LastName
|
||||||
|
public String getLastName() {
|
||||||
|
return lastName_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastName(String value) {
|
||||||
|
lastName_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf
|
||||||
|
// .MessageParser<Guests> Parser
|
||||||
|
public static Google.Protobuf.MessageParser<Guests> getParser() {
|
||||||
|
return _parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Google.Protobuf.Collections
|
||||||
|
// .RepeatedField<string> PhoneNumbers
|
||||||
|
public Google.Protobuf.Collections.RepeatedField<String> getPhoneNumbers() {
|
||||||
|
return phoneNumbers_;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string Title
|
||||||
|
public String getTitle() {
|
||||||
|
return title_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String value) {
|
||||||
|
title_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize()
|
||||||
|
public int CalculateSize() {
|
||||||
|
int size = 0;
|
||||||
|
if (guestId_ != null) {
|
||||||
|
size += _single_guestId_codec.CalculateSizeWithTag(getGuestId());
|
||||||
|
}
|
||||||
|
if (firstName_ != null) {
|
||||||
|
size += _single_firstName_codec.CalculateSizeWithTag(getFirstName());
|
||||||
|
}
|
||||||
|
if (lastName_ != null) {
|
||||||
|
size += _single_lastName_codec.CalculateSizeWithTag(getLastName());
|
||||||
|
}
|
||||||
|
if (title_ != null) {
|
||||||
|
size += _single_title_codec.CalculateSizeWithTag(getTitle());
|
||||||
|
}
|
||||||
|
size += emails_.CalculateSize(_repeated_emails_codec);
|
||||||
|
size += phoneNumbers_.CalculateSize(_repeated_phoneNumbers_codec);
|
||||||
|
size += addresses_.CalculateSize(_map_addresses_codec);
|
||||||
|
if (confirmNumber_ != null) {
|
||||||
|
size += _single_confirmNumber_codec.CalculateSizeWithTag(getConfirmNumber());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
size += _unknownFields.CalculateSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Guests Clone()
|
||||||
|
public Guests Clone() {
|
||||||
|
return new Guests(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Guests other)
|
||||||
|
public void MergeFrom(Guests other) {
|
||||||
|
if (other == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other.guestId_ != null) {
|
||||||
|
if (guestId_ == null || !other.getGuestId().equals("")) {
|
||||||
|
setGuestId(other.getGuestId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.firstName_ != null) {
|
||||||
|
if (firstName_ == null || !other.getFirstName().equals("")) {
|
||||||
|
setFirstName(other.getFirstName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.lastName_ != null) {
|
||||||
|
if (lastName_ == null || !other.getLastName().equals("")) {
|
||||||
|
setLastName(other.getLastName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.title_ != null) {
|
||||||
|
if (title_ == null || !other.getTitle().equals("")) {
|
||||||
|
setTitle(other.getTitle());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
emails_.Add(other.emails_);
|
||||||
|
phoneNumbers_.Add(other.phoneNumbers_);
|
||||||
|
addresses_.Add(other.addresses_);
|
||||||
|
if (other.confirmNumber_ != null) {
|
||||||
|
if (confirmNumber_ == null || !other.getConfirmNumber().equals("")) {
|
||||||
|
setConfirmNumber(other.getConfirmNumber());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Google.Protobuf
|
||||||
|
// .CodedInputStream input)
|
||||||
|
public void MergeFrom(Google.Protobuf.CodedInputStream input) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint tag;
|
||||||
|
int tag;
|
||||||
|
while ((tag = input.ReadTag()) != 0) {
|
||||||
|
switch (tag) {
|
||||||
|
default:
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
|
break;
|
||||||
|
case 10: {
|
||||||
|
String value = _single_guestId_codec.Read(input);
|
||||||
|
if (guestId_ == null || !value.equals("")) {
|
||||||
|
setGuestId(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
String value = _single_firstName_codec.Read(input);
|
||||||
|
if (firstName_ == null || !value.equals("")) {
|
||||||
|
setFirstName(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 26: {
|
||||||
|
String value = _single_lastName_codec.Read(input);
|
||||||
|
if (lastName_ == null || !value.equals("")) {
|
||||||
|
setLastName(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 34: {
|
||||||
|
String value = _single_title_codec.Read(input);
|
||||||
|
if (title_ == null || !value.equals("")) {
|
||||||
|
setTitle(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 42: {
|
||||||
|
emails_.AddEntriesFrom(input, _repeated_emails_codec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 50: {
|
||||||
|
phoneNumbers_.AddEntriesFrom(input, _repeated_phoneNumbers_codec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 58: {
|
||||||
|
addresses_.AddEntriesFrom(input, _map_addresses_codec);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 66: {
|
||||||
|
String value = _single_confirmNumber_codec.Read(input);
|
||||||
|
if (confirmNumber_ == null || !value.equals("")) {
|
||||||
|
setConfirmNumber(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(Google.Protobuf
|
||||||
|
// .CodedOutputStream output)
|
||||||
|
public void WriteTo(Google.Protobuf.CodedOutputStream output) {
|
||||||
|
if (guestId_ != null) {
|
||||||
|
_single_guestId_codec.WriteTagAndValue(output, getGuestId());
|
||||||
|
}
|
||||||
|
if (firstName_ != null) {
|
||||||
|
_single_firstName_codec.WriteTagAndValue(output, getFirstName());
|
||||||
|
}
|
||||||
|
if (lastName_ != null) {
|
||||||
|
_single_lastName_codec.WriteTagAndValue(output, getLastName());
|
||||||
|
}
|
||||||
|
if (title_ != null) {
|
||||||
|
_single_title_codec.WriteTagAndValue(output, getTitle());
|
||||||
|
}
|
||||||
|
emails_.WriteTo(output, _repeated_emails_codec);
|
||||||
|
phoneNumbers_.WriteTo(output, _repeated_phoneNumbers_codec);
|
||||||
|
addresses_.WriteTo(output, _map_addresses_codec);
|
||||||
|
if (confirmNumber_ != null) {
|
||||||
|
_single_confirmNumber_codec.WriteTagAndValue(output, getConfirmNumber());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
_unknownFields.WriteTo(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other)
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return Equals(other instanceof Guests ? (Guests)other : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public bool Equals(Guests other)
|
||||||
|
public boolean equals(Guests other) {
|
||||||
|
if (ReferenceEquals(other, null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ReferenceEquals(other, this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!getGuestId().equals(other.getGuestId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getFirstName().equals(other.getFirstName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getLastName().equals(other.getLastName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getTitle().equals(other.getTitle())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!emails_.equals(other.emails_)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!phoneNumbers_.equals(other.phoneNumbers_)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getAddresses().equals(other.getAddresses())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getConfirmNumber().equals(other.getConfirmNumber())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode()
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 1;
|
||||||
|
if (guestId_ != null) {
|
||||||
|
hash ^= getGuestId().hashCode();
|
||||||
|
}
|
||||||
|
if (firstName_ != null) {
|
||||||
|
hash ^= getFirstName().hashCode();
|
||||||
|
}
|
||||||
|
if (lastName_ != null) {
|
||||||
|
hash ^= getLastName().hashCode();
|
||||||
|
}
|
||||||
|
if (title_ != null) {
|
||||||
|
hash ^= getTitle().hashCode();
|
||||||
|
}
|
||||||
|
hash ^= emails_.hashCode();
|
||||||
|
hash ^= phoneNumbers_.hashCode();
|
||||||
|
hash ^= getAddresses().hashCode();
|
||||||
|
if (confirmNumber_ != null) {
|
||||||
|
hash ^= getConfirmNumber().hashCode();
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
hash ^= _unknownFields.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override string ToString()
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Google.Protobuf.JsonFormatter.ToDiagnosticString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,316 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
public final class Hotels implements Google.Protobuf.IMessage<Hotels> {
|
||||||
|
/**
|
||||||
|
* Field number for the "address" field.
|
||||||
|
*/
|
||||||
|
public static final int AddressFieldNumber = 4;
|
||||||
|
/**
|
||||||
|
* Field number for the "hotel_id" field.
|
||||||
|
*/
|
||||||
|
public static final int HotelIdFieldNumber = 1;
|
||||||
|
/**
|
||||||
|
* Field number for the "name" field.
|
||||||
|
*/
|
||||||
|
public static final int NameFieldNumber = 2;
|
||||||
|
/**
|
||||||
|
* Field number for the "phone" field.
|
||||||
|
*/
|
||||||
|
public static final int PhoneFieldNumber = 3;
|
||||||
|
private static final Google.Protobuf.MessageParser<Hotels> _parser =
|
||||||
|
new Google.Protobuf.MessageParser<Hotels>(() -> new Hotels());
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_hotelId_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(10);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not support 'partial' methods:
|
||||||
|
// partial void OnConstruction();
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_name_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(18);
|
||||||
|
private static final Google.Protobuf.FieldCodec<String> _single_phone_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<String>ForClassWrapper(26);
|
||||||
|
private Google.Protobuf.UnknownFieldSet _unknownFields;
|
||||||
|
private Address address_;
|
||||||
|
private String hotelId_;
|
||||||
|
private String name_;
|
||||||
|
private String phone_;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Hotels()
|
||||||
|
public Hotels() {
|
||||||
|
OnConstruction();
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Hotels(Hotels other)
|
||||||
|
public Hotels(Hotels other) {
|
||||||
|
this();
|
||||||
|
setHotelId(other.getHotelId());
|
||||||
|
setName(other.getName());
|
||||||
|
setPhone(other.getPhone());
|
||||||
|
setAddress(other.address_ != null ? other.getAddress().Clone() : null);
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.Clone(other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Microsoft.Azure.Cosmos.Serialization
|
||||||
|
// .HybridRow.Tests.Perf.CassandraHotel.Protobuf.Address Address
|
||||||
|
public Address getAddress() {
|
||||||
|
return address_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAddress(Address value) {
|
||||||
|
address_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] pbr::MessageDescriptor pb::IMessage.Descriptor
|
||||||
|
public Google.Protobuf.Reflection getDescriptor() {
|
||||||
|
return getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf.Reflection
|
||||||
|
// .MessageDescriptor Descriptor
|
||||||
|
public static Google.Protobuf.Reflection.MessageDescriptor getDescriptor() {
|
||||||
|
return CassandraHotelSchemaReflection.getDescriptor().MessageTypes[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string HotelId
|
||||||
|
public String getHotelId() {
|
||||||
|
return hotelId_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHotelId(String value) {
|
||||||
|
hotelId_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string Name
|
||||||
|
public String getName() {
|
||||||
|
return name_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String value) {
|
||||||
|
name_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf
|
||||||
|
// .MessageParser<Hotels> Parser
|
||||||
|
public static Google.Protobuf.MessageParser<Hotels> getParser() {
|
||||||
|
return _parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public string Phone
|
||||||
|
public String getPhone() {
|
||||||
|
return phone_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPhone(String value) {
|
||||||
|
phone_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize()
|
||||||
|
public int CalculateSize() {
|
||||||
|
int size = 0;
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
size += _single_hotelId_codec.CalculateSizeWithTag(getHotelId());
|
||||||
|
}
|
||||||
|
if (name_ != null) {
|
||||||
|
size += _single_name_codec.CalculateSizeWithTag(getName());
|
||||||
|
}
|
||||||
|
if (phone_ != null) {
|
||||||
|
size += _single_phone_codec.CalculateSizeWithTag(getPhone());
|
||||||
|
}
|
||||||
|
if (address_ != null) {
|
||||||
|
size += 1 + Google.Protobuf.CodedOutputStream.ComputeMessageSize(getAddress());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
size += _unknownFields.CalculateSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Hotels Clone()
|
||||||
|
public Hotels Clone() {
|
||||||
|
return new Hotels(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Hotels other)
|
||||||
|
public void MergeFrom(Hotels other) {
|
||||||
|
if (other == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other.hotelId_ != null) {
|
||||||
|
if (hotelId_ == null || !other.getHotelId().equals("")) {
|
||||||
|
setHotelId(other.getHotelId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.name_ != null) {
|
||||||
|
if (name_ == null || !other.getName().equals("")) {
|
||||||
|
setName(other.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.phone_ != null) {
|
||||||
|
if (phone_ == null || !other.getPhone().equals("")) {
|
||||||
|
setPhone(other.getPhone());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.address_ != null) {
|
||||||
|
if (address_ == null) {
|
||||||
|
address_ = new Address();
|
||||||
|
}
|
||||||
|
getAddress().MergeFrom(other.getAddress());
|
||||||
|
}
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Google.Protobuf
|
||||||
|
// .CodedInputStream input)
|
||||||
|
public void MergeFrom(Google.Protobuf.CodedInputStream input) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint tag;
|
||||||
|
int tag;
|
||||||
|
while ((tag = input.ReadTag()) != 0) {
|
||||||
|
switch (tag) {
|
||||||
|
default:
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
|
break;
|
||||||
|
case 10: {
|
||||||
|
String value = _single_hotelId_codec.Read(input);
|
||||||
|
if (hotelId_ == null || !value.equals("")) {
|
||||||
|
setHotelId(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
String value = _single_name_codec.Read(input);
|
||||||
|
if (name_ == null || !value.equals("")) {
|
||||||
|
setName(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 26: {
|
||||||
|
String value = _single_phone_codec.Read(input);
|
||||||
|
if (phone_ == null || !value.equals("")) {
|
||||||
|
setPhone(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 34: {
|
||||||
|
if (address_ == null) {
|
||||||
|
address_ = new Address();
|
||||||
|
}
|
||||||
|
input.ReadMessage(address_);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(Google.Protobuf
|
||||||
|
// .CodedOutputStream output)
|
||||||
|
public void WriteTo(Google.Protobuf.CodedOutputStream output) {
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
_single_hotelId_codec.WriteTagAndValue(output, getHotelId());
|
||||||
|
}
|
||||||
|
if (name_ != null) {
|
||||||
|
_single_name_codec.WriteTagAndValue(output, getName());
|
||||||
|
}
|
||||||
|
if (phone_ != null) {
|
||||||
|
_single_phone_codec.WriteTagAndValue(output, getPhone());
|
||||||
|
}
|
||||||
|
if (address_ != null) {
|
||||||
|
output.WriteRawTag(34);
|
||||||
|
output.WriteMessage(getAddress());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
_unknownFields.WriteTo(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other)
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return Equals(other instanceof Hotels ? (Hotels)other : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public bool Equals(Hotels other)
|
||||||
|
public boolean equals(Hotels other) {
|
||||||
|
if (ReferenceEquals(other, null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ReferenceEquals(other, this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!getHotelId().equals(other.getHotelId())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getName().equals(other.getName())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getPhone().equals(other.getPhone())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!getAddress().equals(other.getAddress())) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode()
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 1;
|
||||||
|
if (hotelId_ != null) {
|
||||||
|
hash ^= getHotelId().hashCode();
|
||||||
|
}
|
||||||
|
if (name_ != null) {
|
||||||
|
hash ^= getName().hashCode();
|
||||||
|
}
|
||||||
|
if (phone_ != null) {
|
||||||
|
hash ^= getPhone().hashCode();
|
||||||
|
}
|
||||||
|
if (address_ != null) {
|
||||||
|
hash ^= getAddress().hashCode();
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
hash ^= _unknownFields.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override string ToString()
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Google.Protobuf.JsonFormatter.ToDiagnosticString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,232 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.perf.cassandrahotel.protobuf;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.perf.*;
|
||||||
|
import com.google.protobuf.Message;
|
||||||
|
import com.google.protobuf.Parser;
|
||||||
|
|
||||||
|
// <auto-generated>
|
||||||
|
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||||
|
// source: TestData/CassandraHotelSchema.proto
|
||||||
|
// </auto-generated>
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pb = Google.Protobuf;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbc = Google.Protobuf.Collections;
|
||||||
|
//C# TO JAVA CONVERTER NOTE: There is no Java equivalent to C# namespace aliases:
|
||||||
|
//using pbr = Google.Protobuf.Reflection;
|
||||||
|
|
||||||
|
public final class PostalCode implements Message<PostalCode> {
|
||||||
|
/**
|
||||||
|
* Field number for the "plus4" field.
|
||||||
|
*/
|
||||||
|
public static final int Plus4FieldNumber = 2;
|
||||||
|
/**
|
||||||
|
* Field number for the "zip" field.
|
||||||
|
*/
|
||||||
|
public static final int ZipFieldNumber = 1;
|
||||||
|
private static final Parser<PostalCode> _parser = new Parser<PostalCode>(() -> new PostalCode());
|
||||||
|
private static final Google.Protobuf.FieldCodec<Integer> _single_plus4_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<Integer>ForStructWrapper(18);
|
||||||
|
private static final Google.Protobuf.FieldCodec<Integer> _single_zip_codec =
|
||||||
|
Google.Protobuf.FieldCodec.<Integer>ForStructWrapper(10);
|
||||||
|
private Google.Protobuf.UnknownFieldSet _unknownFields;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not support 'partial' methods:
|
||||||
|
// partial void OnConstruction();
|
||||||
|
private Integer plus4_;
|
||||||
|
private Integer zip_;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public PostalCode()
|
||||||
|
public PostalCode() {
|
||||||
|
OnConstruction();
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public PostalCode(PostalCode other)
|
||||||
|
public PostalCode(PostalCode other) {
|
||||||
|
this();
|
||||||
|
setZip(other.getZip());
|
||||||
|
setPlus4(other.getPlus4());
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.Clone(other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf.Reflection
|
||||||
|
// .MessageDescriptor Descriptor
|
||||||
|
public static Google.Protobuf.Reflection.MessageDescriptor getDescriptor() {
|
||||||
|
return CassandraHotelSchemaReflection.getDescriptor().MessageTypes[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] pbr::MessageDescriptor pb::IMessage.Descriptor
|
||||||
|
public Google.Protobuf.Reflection getDescriptor() {
|
||||||
|
return getDescriptor();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public static Google.Protobuf
|
||||||
|
// .MessageParser<PostalCode> Parser
|
||||||
|
public static Google.Protobuf.MessageParser<PostalCode> getParser() {
|
||||||
|
return _parser;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Nullable<int> Plus4
|
||||||
|
public Integer getPlus4() {
|
||||||
|
return plus4_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlus4(Integer value) {
|
||||||
|
plus4_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public Nullable<int> Zip
|
||||||
|
public Integer getZip() {
|
||||||
|
return zip_;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setZip(Integer value) {
|
||||||
|
zip_ = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public int CalculateSize()
|
||||||
|
public int CalculateSize() {
|
||||||
|
int size = 0;
|
||||||
|
if (zip_ != null) {
|
||||||
|
size += _single_zip_codec.CalculateSizeWithTag(getZip());
|
||||||
|
}
|
||||||
|
if (plus4_ != null) {
|
||||||
|
size += _single_plus4_codec.CalculateSizeWithTag(getPlus4());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
size += _unknownFields.CalculateSize();
|
||||||
|
}
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public PostalCode Clone()
|
||||||
|
public PostalCode Clone() {
|
||||||
|
return new PostalCode(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(PostalCode other)
|
||||||
|
public void MergeFrom(PostalCode other) {
|
||||||
|
if (other == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (other.zip_ != null) {
|
||||||
|
if (zip_ == null || other.getZip() != 0) {
|
||||||
|
setZip(other.getZip());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (other.plus4_ != null) {
|
||||||
|
if (plus4_ == null || other.getPlus4() != 0) {
|
||||||
|
setPlus4(other.getPlus4());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void MergeFrom(Google.Protobuf
|
||||||
|
// .CodedInputStream input)
|
||||||
|
public void MergeFrom(Google.Protobuf.CodedInputStream input) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint tag;
|
||||||
|
int tag;
|
||||||
|
while ((tag = input.ReadTag()) != 0) {
|
||||||
|
switch (tag) {
|
||||||
|
default:
|
||||||
|
_unknownFields = Google.Protobuf.UnknownFieldSet.MergeFieldFrom(_unknownFields, input);
|
||||||
|
break;
|
||||||
|
case 10: {
|
||||||
|
Integer value = _single_zip_codec.Read(input);
|
||||||
|
if (zip_ == null || value != 0) {
|
||||||
|
setZip(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 18: {
|
||||||
|
Integer value = _single_plus4_codec.Read(input);
|
||||||
|
if (plus4_ == null || value != 0) {
|
||||||
|
setPlus4(value);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public void WriteTo(Google.Protobuf
|
||||||
|
// .CodedOutputStream output)
|
||||||
|
public void WriteTo(Google.Protobuf.CodedOutputStream output) {
|
||||||
|
if (zip_ != null) {
|
||||||
|
_single_zip_codec.WriteTagAndValue(output, getZip());
|
||||||
|
}
|
||||||
|
if (plus4_ != null) {
|
||||||
|
_single_plus4_codec.WriteTagAndValue(output, getPlus4());
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
_unknownFields.WriteTo(output);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override bool Equals(object other)
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
return Equals(other instanceof PostalCode ? (PostalCode)other : null);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public bool Equals(PostalCode other)
|
||||||
|
public boolean equals(PostalCode other) {
|
||||||
|
if (ReferenceEquals(other, null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ReferenceEquals(other, this)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (getZip() != other.getZip()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (getPlus4() != other.getPlus4()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return Equals(_unknownFields, other._unknownFields);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override int GetHashCode()
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int hash = 1;
|
||||||
|
if (zip_ != null) {
|
||||||
|
hash ^= getZip().hashCode();
|
||||||
|
}
|
||||||
|
if (plus4_ != null) {
|
||||||
|
hash ^= getPlus4().hashCode();
|
||||||
|
}
|
||||||
|
if (_unknownFields != null) {
|
||||||
|
hash ^= _unknownFields.hashCode();
|
||||||
|
}
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [System.Diagnostics.DebuggerNonUserCodeAttribute] public override string ToString()
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Google.Protobuf.JsonFormatter.ToDiagnosticString(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
public final class ArrayAssert {
|
||||||
|
public static <T> void AreEqual(T[] expected, T[] actual) {
|
||||||
|
if (expected == null) {
|
||||||
|
assert actual == null;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
assert actual != null;
|
||||||
|
assert expected.length == actual.length;
|
||||||
|
for (int i = 0; i < expected.length; i++) {
|
||||||
|
assert expected[i] == actual[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void AreEqual(T[] expected, T[] actual, String message) {
|
||||||
|
if (expected == null) {
|
||||||
|
Assert.IsNull(actual, message);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsNotNull(actual, message);
|
||||||
|
Assert.AreEqual(expected.length, actual.length, message);
|
||||||
|
for (int i = 0; i < expected.length; i++) {
|
||||||
|
Assert.AreEqual(expected[i], actual[i], message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void AreEqual(T[] expected, T[] actual, String message, Object... parameters) {
|
||||||
|
if (expected == null) {
|
||||||
|
Assert.IsNull(actual, message, parameters);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.IsNotNull(actual, message, parameters);
|
||||||
|
Assert.AreEqual(expected.length, actual.length, message, parameters);
|
||||||
|
for (int i = 0; i < expected.length; i++) {
|
||||||
|
Assert.AreEqual(expected[i], actual[i], message, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
public final class AssertThrowsException {
|
||||||
|
/**
|
||||||
|
* Safely converts an object to a string, handling null values and null characters. Null
|
||||||
|
* values are converted to "(null)". Null characters are converted to "\\0".
|
||||||
|
*
|
||||||
|
* @param input The object to convert to a string.
|
||||||
|
* @return The converted string.
|
||||||
|
*/
|
||||||
|
public static String ReplaceNulls(Object input) {
|
||||||
|
String input1 = input == null ? null : input.toString();
|
||||||
|
if (input1 == null) {
|
||||||
|
return "(null)";
|
||||||
|
}
|
||||||
|
return Assert.ReplaceNullChars(input1);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the code specified by delegate <paramref name="action" /> throws exact given
|
||||||
|
* exception of type <typeparamref name="T" /> (and not of derived type) and throws <code>
|
||||||
|
* AssertFailedException
|
||||||
|
* </code> if code does not throws exception or throws exception of type other than
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*
|
||||||
|
* @param action Delegate to code to be tested and which is expected to throw exception.
|
||||||
|
* @param message The message to include in the exception when <paramref name="action" /> does
|
||||||
|
* not throws exception of type <typeparamref name="T" />.
|
||||||
|
*
|
||||||
|
* <typeparam name="T">Type of exception expected to be thrown.</typeparam>
|
||||||
|
* @return The exception that was thrown.
|
||||||
|
* @throws T:Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException Thrown if
|
||||||
|
* <paramref name="action" /> does
|
||||||
|
* not throws exception of type
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*/
|
||||||
|
public static <T extends RuntimeException> T ThrowsException(tangible.Action0Param action, String message) {
|
||||||
|
return AssertThrowsException.ThrowsException(action, message, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the code specified by delegate <paramref name="action" /> throws exact given
|
||||||
|
* exception of type <typeparamref name="T" /> (and not of derived type) and throws <code>
|
||||||
|
* AssertFailedException
|
||||||
|
* </code> if code does not throws exception or throws exception of type other than
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*
|
||||||
|
* @param action Delegate to code to be tested and which is expected to throw exception.
|
||||||
|
* @param message The message to include in the exception when <paramref name="action" /> does
|
||||||
|
* not throws exception of type <typeparamref name="T" />.
|
||||||
|
* @param parameters An array of parameters to use when formatting <paramref name="message" />.
|
||||||
|
* <typeparam name="T">Type of exception expected to be thrown.</typeparam>
|
||||||
|
* @return The exception that was thrown.
|
||||||
|
* @throws T:Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException Thrown if
|
||||||
|
* <paramref name="action" /> does
|
||||||
|
* not throws exception of type
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*/
|
||||||
|
public static <T extends RuntimeException> T ThrowsException(tangible.Action0Param action, String message,
|
||||||
|
Object... parameters) {
|
||||||
|
if (action == null) {
|
||||||
|
throw new NullPointerException("action");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (message == null) {
|
||||||
|
throw new NullPointerException("message");
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
action.invoke();
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
if (T.class != ex.getClass()) {
|
||||||
|
Assert.Fail(String.format("Threw exception %3$s, but exception %2$s was expected. %1$s\nException " +
|
||||||
|
"Message: %4$s\nStack Trace: %5$s", AssertThrowsException.ReplaceNulls(message),
|
||||||
|
(Object)T.class.Name, ex.getClass().getSimpleName(), ex.getMessage(),
|
||||||
|
(Object)ex.StackTrace), parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
return (T)ex;
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert.Fail(String.format("No exception thrown. %2$s exception was expected. %1$s",
|
||||||
|
AssertThrowsException.ReplaceNulls(message), T.class.Name), parameters);
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether the code specified by delegate <paramref name="action" /> throws exact given
|
||||||
|
* exception of type <typeparamref name="T" /> (and not of derived type) and throws <code>
|
||||||
|
* AssertFailedException
|
||||||
|
* </code> if code does not throws exception or throws exception of type other than
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*
|
||||||
|
* @param action Delegate to code to be tested and which is expected to throw exception.
|
||||||
|
* <typeparam name="T">Type of exception expected to be thrown.</typeparam>
|
||||||
|
* @return The exception that was thrown.
|
||||||
|
* @throws T:Microsoft.VisualStudio.TestTools.UnitTesting.AssertFailedException Thrown if
|
||||||
|
* <paramref name="action" /> does
|
||||||
|
* not throws exception of type
|
||||||
|
* <typeparamref name="T" />.
|
||||||
|
*/
|
||||||
|
public static <T extends RuntimeException> T ThrowsException(tangible.Action0Param action) {
|
||||||
|
return AssertThrowsException.ThrowsException(action, "", null);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,614 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Float128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.NullValue;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Public Fields
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("Naming", "DontUseVarForVariableTypes", Justification = "The types here
|
||||||
|
// are anonymous.")][DeploymentItem(CrossVersioningUnitTests.SchemaFile, "TestData")][DeploymentItem
|
||||||
|
// (CrossVersioningUnitTests.ExpectedFile, "TestData")] public sealed class CrossVersioningUnitTests
|
||||||
|
public final class CrossVersioningUnitTests {
|
||||||
|
private static final String ExpectedFile = "TestData\\CrossVersioningExpected.json";
|
||||||
|
private static final LocalDateTime SampleDateTime = LocalDateTime.parse("2018-08-14 02:05:00.0000000");
|
||||||
|
private static final Float128 SampleFloat128 = new Float128(0, 42);
|
||||||
|
private static final UUID SampleGuid = UUID.fromString("{2A9C25B9-922E-4611-BB0A-244A9496503C}");
|
||||||
|
private static final MongoDbObjectId SampleMongoDbObjectId = new MongoDbObjectId(704643072, 0); // 42 in big-endian
|
||||||
|
private static final UnixDateTime SampleUnixDateTime = new UnixDateTime(42);
|
||||||
|
private static final String SchemaFile = "TestData\\CrossVersioningSchema.json";
|
||||||
|
private Expected expected;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Test code.")] public void CrossVersionDeleteSparse()
|
||||||
|
public void CrossVersionDeleteSparse() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Sparse")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<DeleteRowDispatcher>ReadFrom(this.resolver,
|
||||||
|
this.expected.getCrossVersionSparse());
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:CrossVersioningUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:CrossVersioningUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:CrossVersioningUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:CrossVersioningUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:CrossVersioningUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("array_t<int8>", value:new byte[] { -86, -86, -86 })
|
||||||
|
d.LayoutCodeSwitch("array_t<array_t<float32>>", value:new float[][]
|
||||||
|
{
|
||||||
|
new float[] { 1, 2, 3 },
|
||||||
|
new float[] { 1, 2, 3 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
|
||||||
|
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||||
|
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
|
||||||
|
Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
|
||||||
|
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
|
||||||
|
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||||
|
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
|
||||||
|
{
|
||||||
|
new byte[] { 1, 2, 3 },
|
||||||
|
new byte[] { 4, 5, 6 },
|
||||||
|
new byte[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<set_t<int32>>", value:new int[][]
|
||||||
|
{
|
||||||
|
new int[] { 1, 2, 3 },
|
||||||
|
new int[] { 4, 5, 6 },
|
||||||
|
new int[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<udt>", value:new Point[]
|
||||||
|
{
|
||||||
|
new Point(1, 2),
|
||||||
|
new Point(3, 4),
|
||||||
|
new Point(5, 6)
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("map_t<utf8,utf8>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create("Mark", "Luke"), Tuple.Create("Harrison", "Han") })
|
||||||
|
d.LayoutCodeSwitch("map_t<int8,array_t<int8>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((byte)1, new byte[] { 1, 2, 3 }), Tuple.Create((byte)2,
|
||||||
|
new byte[] { 4, 5, 6 }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<int16,map_t<int32,int32>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((short)1, new System.Tuple<T1, T2>[] { Tuple.Create(1, 2),
|
||||||
|
Tuple.Create(3, 4) }), Tuple.Create((short)2, new System.Tuple<T1, T2>[] { Tuple.Create(5, 6),
|
||||||
|
Tuple.Create(7, 8) }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<float64,udt>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create(1.0, new Point(1, 2)), Tuple.Create(2.0, new Point(3, 4)),
|
||||||
|
Tuple.Create(3.0, new Point(5, 6)) })
|
||||||
|
|
||||||
|
assert this.expected.getCrossVersionNullSparse() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionReadFixed()
|
||||||
|
public void CrossVersionReadFixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Fixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<ReadRowDispatcher>ReadFrom(this.resolver,
|
||||||
|
this.expected.getCrossVersionFixed());
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:CrossVersioningUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:CrossVersioningUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:CrossVersioningUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:CrossVersioningUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:CrossVersioningUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionReadNullFixed()
|
||||||
|
public void CrossVersionReadNullFixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Fixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<NullRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool");
|
||||||
|
d.LayoutCodeSwitch("int8");
|
||||||
|
d.LayoutCodeSwitch("int16");
|
||||||
|
d.LayoutCodeSwitch("int32");
|
||||||
|
d.LayoutCodeSwitch("int64");
|
||||||
|
d.LayoutCodeSwitch("uint8");
|
||||||
|
d.LayoutCodeSwitch("uint16");
|
||||||
|
d.LayoutCodeSwitch("uint32");
|
||||||
|
d.LayoutCodeSwitch("uint64");
|
||||||
|
d.LayoutCodeSwitch("float32");
|
||||||
|
d.LayoutCodeSwitch("float64");
|
||||||
|
d.LayoutCodeSwitch("float128");
|
||||||
|
d.LayoutCodeSwitch("decimal");
|
||||||
|
d.LayoutCodeSwitch("datetime");
|
||||||
|
d.LayoutCodeSwitch("unixdatetime");
|
||||||
|
d.LayoutCodeSwitch("guid");
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid");
|
||||||
|
d.LayoutCodeSwitch("utf8");
|
||||||
|
d.LayoutCodeSwitch("binary");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionReadNullSparse()
|
||||||
|
public void CrossVersionReadNullSparse() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Sparse")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<NullRowDispatcher>ReadFrom(this.resolver,
|
||||||
|
this.expected.getCrossVersionNullSparse());
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool");
|
||||||
|
d.LayoutCodeSwitch("int8");
|
||||||
|
d.LayoutCodeSwitch("int16");
|
||||||
|
d.LayoutCodeSwitch("int32");
|
||||||
|
d.LayoutCodeSwitch("int64");
|
||||||
|
d.LayoutCodeSwitch("uint8");
|
||||||
|
d.LayoutCodeSwitch("uint16");
|
||||||
|
d.LayoutCodeSwitch("uint32");
|
||||||
|
d.LayoutCodeSwitch("uint64");
|
||||||
|
d.LayoutCodeSwitch("float32");
|
||||||
|
d.LayoutCodeSwitch("float64");
|
||||||
|
d.LayoutCodeSwitch("float128");
|
||||||
|
d.LayoutCodeSwitch("decimal");
|
||||||
|
d.LayoutCodeSwitch("datetime");
|
||||||
|
d.LayoutCodeSwitch("unixdatetime");
|
||||||
|
d.LayoutCodeSwitch("guid");
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid");
|
||||||
|
d.LayoutCodeSwitch("utf8");
|
||||||
|
d.LayoutCodeSwitch("binary");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionReadNullVariable()
|
||||||
|
public void CrossVersionReadNullVariable() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Variable")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<NullRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("varint");
|
||||||
|
d.LayoutCodeSwitch("varuint");
|
||||||
|
d.LayoutCodeSwitch("utf8");
|
||||||
|
d.LayoutCodeSwitch("binary");
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Test code.")] public void CrossVersionReadSparse()
|
||||||
|
public void CrossVersionReadSparse() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Sparse")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<ReadRowDispatcher>ReadFrom(this.resolver,
|
||||||
|
this.expected.getCrossVersionSparse());
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:CrossVersioningUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:CrossVersioningUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:CrossVersioningUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:CrossVersioningUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:CrossVersioningUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("array_t<int8>", value:new byte[] { -86, -86, -86 })
|
||||||
|
d.LayoutCodeSwitch("array_t<array_t<float32>>", value:new float[][]
|
||||||
|
{
|
||||||
|
new float[] { 1, 2, 3 },
|
||||||
|
new float[] { 1, 2, 3 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
|
||||||
|
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||||
|
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
|
||||||
|
Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
|
||||||
|
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
|
||||||
|
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||||
|
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
|
||||||
|
{
|
||||||
|
new byte[] { 1, 2, 3 },
|
||||||
|
new byte[] { 4, 5, 6 },
|
||||||
|
new byte[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<set_t<int32>>", value:new int[][]
|
||||||
|
{
|
||||||
|
new int[] { 1, 2, 3 },
|
||||||
|
new int[] { 4, 5, 6 },
|
||||||
|
new int[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<udt>", value:new Point[]
|
||||||
|
{
|
||||||
|
new Point(1, 2),
|
||||||
|
new Point(3, 4),
|
||||||
|
new Point(5, 6)
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("map_t<utf8,utf8>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create("Mark", "Luke"), Tuple.Create("Harrison", "Han") })
|
||||||
|
d.LayoutCodeSwitch("map_t<int8,array_t<int8>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((byte)1, new byte[] { 1, 2, 3 }), Tuple.Create((byte)2,
|
||||||
|
new byte[] { 4, 5, 6 }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<int16,map_t<int32,int32>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((short)1, new System.Tuple<T1, T2>[] { Tuple.Create(1, 2),
|
||||||
|
Tuple.Create(3, 4) }), Tuple.Create((short)2, new System.Tuple<T1, T2>[] { Tuple.Create(5, 6),
|
||||||
|
Tuple.Create(7, 8) }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<float64,udt>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create(2.0, new Point(3, 4)), Tuple.Create(3.0, new Point(5, 6)),
|
||||||
|
Tuple.Create(1.0, new Point(1, 2)) })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionReadVariable()
|
||||||
|
public void CrossVersionReadVariable() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Variable")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<ReadRowDispatcher>ReadFrom(this.resolver,
|
||||||
|
this.expected.getCrossVersionVariable());
|
||||||
|
d.LayoutCodeSwitch("varint", value:-6148914691236517206L)
|
||||||
|
d.LayoutCodeSwitch("varuint", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionWriteFixed()
|
||||||
|
public void CrossVersionWriteFixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Fixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:CrossVersioningUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:CrossVersioningUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:CrossVersioningUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:CrossVersioningUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:CrossVersioningUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
|
||||||
|
assert this.expected.getCrossVersionFixed() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionWriteNullFixed()
|
||||||
|
public void CrossVersionWriteNullFixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Fixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
assert this.expected.getCrossVersionNullFixed() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionWriteNullSparse()
|
||||||
|
public void CrossVersionWriteNullSparse() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Sparse")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
assert this.expected.getCrossVersionNullSparse() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionWriteNullVariable()
|
||||||
|
public void CrossVersionWriteNullVariable() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Variable")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
assert this.expected.getCrossVersionNullVariable() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Test code.")] public void CrossVersionWriteSparse()
|
||||||
|
public void CrossVersionWriteSparse() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Sparse")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:CrossVersioningUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:CrossVersioningUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:CrossVersioningUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:CrossVersioningUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:CrossVersioningUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("array_t<int8>", value:new byte[] { -86, -86, -86 })
|
||||||
|
d.LayoutCodeSwitch("array_t<array_t<float32>>", value:new float[][]
|
||||||
|
{
|
||||||
|
new float[] { 1, 2, 3 },
|
||||||
|
new float[] { 1, 2, 3 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
|
||||||
|
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||||
|
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
|
||||||
|
Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
|
||||||
|
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
|
||||||
|
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||||
|
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
|
||||||
|
{
|
||||||
|
new byte[] { 1, 2, 3 },
|
||||||
|
new byte[] { 4, 5, 6 },
|
||||||
|
new byte[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<set_t<int32>>", value:new int[][]
|
||||||
|
{
|
||||||
|
new int[] { 1, 2, 3 },
|
||||||
|
new int[] { 4, 5, 6 },
|
||||||
|
new int[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<udt>", value:new Point[]
|
||||||
|
{
|
||||||
|
new Point(1, 2),
|
||||||
|
new Point(3, 4),
|
||||||
|
new Point(5, 6)
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("map_t<utf8,utf8>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create("Mark", "Luke"), Tuple.Create("Harrison", "Han") })
|
||||||
|
d.LayoutCodeSwitch("map_t<int8,array_t<int8>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((byte)1, new byte[] { 1, 2, 3 }), Tuple.Create((byte)2,
|
||||||
|
new byte[] { 4, 5, 6 }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<int16,map_t<int32,int32>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((short)1, new System.Tuple<T1, T2>[] { Tuple.Create(1, 2),
|
||||||
|
Tuple.Create(3, 4) }), Tuple.Create((short)2, new System.Tuple<T1, T2>[] { Tuple.Create(5, 6),
|
||||||
|
Tuple.Create(7, 8) }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<float64,udt>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create(1.0, new Point(1, 2)), Tuple.Create(2.0, new Point(3, 4)),
|
||||||
|
Tuple.Create(3.0, new Point(5, 6)) })
|
||||||
|
|
||||||
|
assert this.expected.getCrossVersionSparse() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CrossVersionWriteVariable()
|
||||||
|
public void CrossVersionWriteVariable() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Variable")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("varint", value:-6148914691236517206L)
|
||||||
|
d.LayoutCodeSwitch("varuint", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
|
||||||
|
assert this.expected.getCrossVersionVariable() == d.RowToHex();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespace()
|
||||||
|
public void ParseNamespace() {
|
||||||
|
String json = Files.readString(CrossVersioningUnitTests.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
json = Files.readString(CrossVersioningUnitTests.ExpectedFile);
|
||||||
|
this.expected = JsonConvert.<Expected>DeserializeObject(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.Performance", "CA1812:AvoidUninstantiatedInternalClasses", Justification = "Instantiated through Reflection.")] private sealed class Expected
|
||||||
|
private final static class Expected {
|
||||||
|
private String CrossVersionFixed;
|
||||||
|
private String CrossVersionNullFixed;
|
||||||
|
private String CrossVersionNullSparse;
|
||||||
|
private String CrossVersionNullVariable;
|
||||||
|
private String CrossVersionSparse;
|
||||||
|
private String CrossVersionVariable;
|
||||||
|
|
||||||
|
public String getCrossVersionFixed() {
|
||||||
|
return CrossVersionFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionFixed(String value) {
|
||||||
|
CrossVersionFixed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrossVersionNullFixed() {
|
||||||
|
return CrossVersionNullFixed;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionNullFixed(String value) {
|
||||||
|
CrossVersionNullFixed = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrossVersionNullSparse() {
|
||||||
|
return CrossVersionNullSparse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionNullSparse(String value) {
|
||||||
|
CrossVersionNullSparse = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrossVersionNullVariable() {
|
||||||
|
return CrossVersionNullVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionNullVariable(String value) {
|
||||||
|
CrossVersionNullVariable = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrossVersionSparse() {
|
||||||
|
return CrossVersionSparse;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionSparse(String value) {
|
||||||
|
CrossVersionSparse = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCrossVersionVariable() {
|
||||||
|
return CrossVersionVariable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCrossVersionVariable(String value) {
|
||||||
|
CrossVersionVariable = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private final static class Point implements IDispatchable {
|
||||||
|
public int X;
|
||||||
|
public int Y;
|
||||||
|
|
||||||
|
public Point(int x, int y) {
|
||||||
|
this.X = x;
|
||||||
|
this.Y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope) {
|
||||||
|
dispatcher.get().LayoutCodeSwitch(scope, "x", value:this.X)
|
||||||
|
dispatcher.get().LayoutCodeSwitch(scope, "y", value:this.Y)
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tempVar = obj instanceof Point;
|
||||||
|
Point point = tempVar ? (Point)obj : null;
|
||||||
|
return tempVar && this.equals(point);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
return ((new Integer(this.X)).hashCode() * 397) ^ (new Integer(this.Y)).hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Point other) {
|
||||||
|
return this.X == other.X && this.Y == other.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,892 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.unit.customerschema.Hotel;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeSet;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// ReSharper disable once StringLiteralTypo
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("Naming", "DontUseVarForVariableTypes", Justification = "The types here
|
||||||
|
// are anonymous.")][DeploymentItem("TestData\\CustomerSchema.json", "TestData")] public sealed class
|
||||||
|
// CustomerExampleUnitTests
|
||||||
|
public final class CustomerExampleUnitTests {
|
||||||
|
|
||||||
|
private final Hotel hotelExample = new Hotel() {
|
||||||
|
Id = "The-Westin-St-John-Resort-Villas-1187",
|
||||||
|
Name ="The Westin St. John Resort Villas",
|
||||||
|
Phone ="+1 340-693-8000",
|
||||||
|
Address = new Address {
|
||||||
|
Street = "300B Chocolate Hole", City = "Great Cruz Bay", State = "VI", PostalCode = new PostalCode {
|
||||||
|
Zip = 00830, Plus4 = 0001
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private LayoutResolver customerResolver;
|
||||||
|
private Namespace customerSchema;
|
||||||
|
private Layout guestLayout;
|
||||||
|
private Layout hotelLayout;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateGuest()
|
||||||
|
public void CreateGuest() {
|
||||||
|
RowBuffer row = new RowBuffer(1024 * 1024);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.guestLayout, this.customerResolver);
|
||||||
|
|
||||||
|
Guest g1 = new Guest();
|
||||||
|
g1.Id = UUID.fromString("64d9d6d3-fd6b-4556-8c6e-d960a7ece7b9");
|
||||||
|
g1.FirstName = "John";
|
||||||
|
g1.LastName = "Adams";
|
||||||
|
g1.Title = "President of the United States";
|
||||||
|
g1.PhoneNumbers = new ArrayList<String>(Arrays.asList("(202) 456-1111"));
|
||||||
|
g1.ConfirmNumber = "(202) 456-1111";
|
||||||
|
g1.Emails = new TreeSet<String> {
|
||||||
|
"president@whitehouse.gov"
|
||||||
|
}
|
||||||
|
Address tempVar = new Address();
|
||||||
|
tempVar.setStreet("1600 Pennsylvania Avenue NW");
|
||||||
|
tempVar.setCity("Washington, D.C.");
|
||||||
|
tempVar.setState("DC");
|
||||||
|
PostalCode tempVar2 = new PostalCode();
|
||||||
|
tempVar2.setZip(20500);
|
||||||
|
tempVar2.setPlus4(0001);
|
||||||
|
tempVar.setPostalCode(tempVar2);
|
||||||
|
g1.Addresses = new HashMap<String, Address>(Map.ofEntries(Map.entry("home", tempVar)));
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc1 = RowCursor.create(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc1 =
|
||||||
|
new Reference<RowCursor>(rc1);
|
||||||
|
this.WriteGuest(tempReference_row2, tempReference_rc1, g1);
|
||||||
|
rc1 = tempReference_rc1.get();
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc2 = RowCursor.create(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc2 =
|
||||||
|
new Reference<RowCursor>(rc2);
|
||||||
|
Guest g2 = this.ReadGuest(tempReference_row4, tempReference_rc2);
|
||||||
|
rc2 = tempReference_rc2.get();
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
assert g1 == g2;
|
||||||
|
|
||||||
|
// Append an item to an existing list.
|
||||||
|
Reference<RowBuffer> tempReference_row5 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc3 = RowCursor.create(tempReference_row5);
|
||||||
|
row = tempReference_row5.get();
|
||||||
|
Reference<RowBuffer> tempReference_row6 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc3 =
|
||||||
|
new Reference<RowCursor>(rc3);
|
||||||
|
int index = this.AppendGuestEmail(tempReference_row6, tempReference_rc3, "vice_president@whitehouse.gov");
|
||||||
|
rc3 = tempReference_rc3.get();
|
||||||
|
row = tempReference_row6.get();
|
||||||
|
assert 1 == index;
|
||||||
|
g1.Emails.add("vice_president@whitehouse.gov");
|
||||||
|
Reference<RowBuffer> tempReference_row7 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc4 = RowCursor.create(tempReference_row7);
|
||||||
|
row = tempReference_row7.get();
|
||||||
|
Reference<RowBuffer> tempReference_row8 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc4 =
|
||||||
|
new Reference<RowCursor>(rc4);
|
||||||
|
g2 = this.ReadGuest(tempReference_row8, tempReference_rc4);
|
||||||
|
rc4 = tempReference_rc4.get();
|
||||||
|
row = tempReference_row8.get();
|
||||||
|
assert g1 == g2;
|
||||||
|
|
||||||
|
// Prepend an item to an existing list.
|
||||||
|
Reference<RowBuffer> tempReference_row9 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc5 = RowCursor.create(tempReference_row9);
|
||||||
|
row = tempReference_row9.get();
|
||||||
|
Reference<RowBuffer> tempReference_row10 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc5 =
|
||||||
|
new Reference<RowCursor>(rc5);
|
||||||
|
index = this.PrependGuestEmail(tempReference_row10, tempReference_rc5, "ex_president@whitehouse.gov");
|
||||||
|
rc5 = tempReference_rc5.get();
|
||||||
|
row = tempReference_row10.get();
|
||||||
|
assert 0 == index;
|
||||||
|
g1.Emails = new TreeSet<String> {
|
||||||
|
"ex_president@whitehouse.gov", "president@whitehouse.gov", "vice_president@whitehouse.gov"
|
||||||
|
}
|
||||||
|
Reference<RowBuffer> tempReference_row11 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc6 = RowCursor.create(tempReference_row11);
|
||||||
|
row = tempReference_row11.get();
|
||||||
|
Reference<RowBuffer> tempReference_row12 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc6 =
|
||||||
|
new Reference<RowCursor>(rc6);
|
||||||
|
g2 = this.ReadGuest(tempReference_row12, tempReference_rc6);
|
||||||
|
rc6 = tempReference_rc6.get();
|
||||||
|
row = tempReference_row12.get();
|
||||||
|
assert g1 == g2;
|
||||||
|
|
||||||
|
// InsertAt an item to an existing list.
|
||||||
|
Reference<RowBuffer> tempReference_row13 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc7 = RowCursor.create(tempReference_row13);
|
||||||
|
row = tempReference_row13.get();
|
||||||
|
Reference<RowBuffer> tempReference_row14 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc7 =
|
||||||
|
new Reference<RowCursor>(rc7);
|
||||||
|
index = this.InsertAtGuestEmail(tempReference_row14, tempReference_rc7, 1, "future_president@whitehouse.gov");
|
||||||
|
rc7 = tempReference_rc7.get();
|
||||||
|
row = tempReference_row14.get();
|
||||||
|
assert 1 == index;
|
||||||
|
g1.Emails = new TreeSet<String> {
|
||||||
|
"ex_president@whitehouse.gov", "future_president@whitehouse.gov", "president@whitehouse.gov",
|
||||||
|
"vice_president@whitehouse.gov"
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row15 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor rc8 = RowCursor.create(tempReference_row15);
|
||||||
|
row = tempReference_row15.get();
|
||||||
|
Reference<RowBuffer> tempReference_row16 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_rc8 =
|
||||||
|
new Reference<RowCursor>(rc8);
|
||||||
|
g2 = this.ReadGuest(tempReference_row16, tempReference_rc8);
|
||||||
|
rc8 = tempReference_rc8.get();
|
||||||
|
row = tempReference_row16.get();
|
||||||
|
assert g1 == g2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateHotel()
|
||||||
|
public void CreateHotel() {
|
||||||
|
RowBuffer row = new RowBuffer(0);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver);
|
||||||
|
|
||||||
|
Hotel h1 = this.hotelExample;
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor root = RowCursor.create(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_root =
|
||||||
|
new Reference<RowCursor>(root);
|
||||||
|
this.WriteHotel(tempReference_row2, tempReference_root, h1);
|
||||||
|
root = tempReference_root.get();
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
root = RowCursor.create(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_root2 =
|
||||||
|
new Reference<RowCursor>(root);
|
||||||
|
Hotel h2 = this.ReadHotel(tempReference_row4, tempReference_root2);
|
||||||
|
root = tempReference_root2.get();
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
|
||||||
|
assert h1 == h2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void FrozenHotel()
|
||||||
|
public void FrozenHotel() {
|
||||||
|
RowBuffer row = new RowBuffer(0);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.hotelLayout, this.customerResolver);
|
||||||
|
|
||||||
|
Hotel h1 = this.hotelExample;
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor root = RowCursor.create(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_root =
|
||||||
|
new Reference<RowCursor>(root);
|
||||||
|
this.WriteHotel(tempReference_row2, tempReference_root, h1);
|
||||||
|
root = tempReference_root.get();
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
root = RowCursor.create(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Address tempVar = new Address();
|
||||||
|
tempVar.setStreet("300B Brownie Way");
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowCursor> tempReference_root2 =
|
||||||
|
new Reference<RowCursor>(root);
|
||||||
|
ResultAssert.InsufficientPermissions(this.PartialUpdateHotelAddress(tempReference_row4, tempReference_root2, tempVar));
|
||||||
|
root = tempReference_root2.get();
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString("TestData\\CustomerSchema.json");
|
||||||
|
this.customerSchema = Namespace.Parse(json);
|
||||||
|
this.customerResolver = new LayoutResolverNamespace(this.customerSchema);
|
||||||
|
this.hotelLayout = this.customerResolver.Resolve(tangible.ListHelper.find(this.customerSchema.getSchemas(),
|
||||||
|
x -> x.Name.equals("Hotels")).SchemaId);
|
||||||
|
this.guestLayout = this.customerResolver.Resolve(tangible.ListHelper.find(this.customerSchema.getSchemas(),
|
||||||
|
x -> x.Name.equals("Guests")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int AppendGuestEmail(Reference<RowBuffer> row, Reference<RowCursor> root, String email) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("emails", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor emailScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().ReadScope(row, root, out emailScope));
|
||||||
|
assert !emailScope.MoveTo(row, Integer.MAX_VALUE);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref emailScope, email));
|
||||||
|
return emailScope.Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int InsertAtGuestEmail(Reference<RowBuffer> row, Reference<RowCursor> root, int i,
|
||||||
|
String email) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("emails", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor emailScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().ReadScope(row, root, out emailScope));
|
||||||
|
assert emailScope.MoveTo(row, i);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref emailScope, email,
|
||||||
|
UpdateOptions.InsertAt));
|
||||||
|
return emailScope.Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Result PartialUpdateHotelAddress(Reference<RowBuffer> row, Reference<RowCursor> root,
|
||||||
|
Address a) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("address", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor addressScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
Result r = c.<LayoutUDT>TypeAs().ReadScope(row, root, out addressScope);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
Layout addressLayout = addressScope.Layout;
|
||||||
|
if (a.Street != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert addressLayout.TryFind("street", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
r = c.<LayoutUtf8>TypeAs().WriteVariable(row, ref addressScope, c, a.Street);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.City != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert addressLayout.TryFind("city", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
r = c.<LayoutUtf8>TypeAs().WriteVariable(row, ref addressScope, c, a.City);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.State != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert addressLayout.TryFind("state", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
r = c.<LayoutUtf8>TypeAs().WriteFixed(row, ref addressScope, c, a.State);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (a.PostalCode != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert addressLayout.TryFind("postal_code", out c);
|
||||||
|
addressScope.Find(row, c.Path);
|
||||||
|
RowCursor postalCodeScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
r = c.<LayoutUDT>TypeAs().WriteScope(row, ref addressScope, c.TypeArgs, out postalCodeScope);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_postalCodeScope =
|
||||||
|
new Reference<RowCursor>(postalCodeScope);
|
||||||
|
this.WritePostalCode(row, tempReference_postalCodeScope, c.TypeArgs, a.PostalCode);
|
||||||
|
postalCodeScope = tempReference_postalCodeScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private int PrependGuestEmail(Reference<RowBuffer> row, Reference<RowCursor> root, String email) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("emails", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor emailScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().ReadScope(row, root, out emailScope));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref emailScope, email,
|
||||||
|
UpdateOptions.InsertAt));
|
||||||
|
return emailScope.Index;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Address ReadAddress(Reference<RowBuffer> row, Reference<RowCursor> addressScope) {
|
||||||
|
Address a = new Address();
|
||||||
|
Layout addressLayout = addressScope.get().getLayout();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("street", out c);
|
||||||
|
Out<String> tempOut_Street = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, addressScope, c, tempOut_Street));
|
||||||
|
a.Street = tempOut_Street.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("city", out c);
|
||||||
|
Out<String> tempOut_City = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, addressScope, c, tempOut_City));
|
||||||
|
a.City = tempOut_City.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("state", out c);
|
||||||
|
Out<String> tempOut_State = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadFixed(row, addressScope, c, tempOut_State));
|
||||||
|
a.State = tempOut_State.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("postal_code", out c);
|
||||||
|
addressScope.get().Find(row, c.Path);
|
||||||
|
RowCursor postalCodeScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUDT>TypeAs().ReadScope(row, addressScope, out postalCodeScope));
|
||||||
|
Reference<RowCursor> tempReference_postalCodeScope =
|
||||||
|
new Reference<RowCursor>(postalCodeScope);
|
||||||
|
a.PostalCode = CustomerExampleUnitTests.ReadPostalCode(row, tempReference_postalCodeScope);
|
||||||
|
postalCodeScope = tempReference_postalCodeScope.get();
|
||||||
|
Reference<RowCursor> tempReference_postalCodeScope2 =
|
||||||
|
new Reference<RowCursor>(postalCodeScope);
|
||||||
|
RowCursors.skip(addressScope.get().clone(), row,
|
||||||
|
tempReference_postalCodeScope2);
|
||||||
|
postalCodeScope = tempReference_postalCodeScope2.get();
|
||||||
|
return a;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Guest ReadGuest(Reference<RowBuffer> row, Reference<RowCursor> root) {
|
||||||
|
Guest g = new Guest();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("guest_id", out c);
|
||||||
|
Out<UUID> tempOut_Id = new Out<UUID>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutGuid>TypeAs().ReadFixed(row, root, c, tempOut_Id));
|
||||||
|
g.Id = tempOut_Id.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("first_name", out c);
|
||||||
|
Out<String> tempOut_FirstName = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_FirstName));
|
||||||
|
g.FirstName = tempOut_FirstName.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("last_name", out c);
|
||||||
|
Out<String> tempOut_LastName = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_LastName));
|
||||||
|
g.LastName = tempOut_LastName.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("title", out c);
|
||||||
|
Out<String> tempOut_Title = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_Title));
|
||||||
|
g.Title = tempOut_Title.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("confirm_number", out c);
|
||||||
|
Out<String> tempOut_ConfirmNumber = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_ConfirmNumber));
|
||||||
|
g.ConfirmNumber = tempOut_ConfirmNumber.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("emails", out c);
|
||||||
|
RowCursor emailScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out emailScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref emailScope, out emailScope) == Result.SUCCESS) {
|
||||||
|
g.Emails = new TreeSet<String>();
|
||||||
|
while (emailScope.MoveNext(row)) {
|
||||||
|
String item;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().ReadSparse(row, ref emailScope,
|
||||||
|
out item));
|
||||||
|
g.Emails.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("phone_numbers", out c);
|
||||||
|
RowCursor phoneNumbersScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out phoneNumbersScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref phoneNumbersScope, out phoneNumbersScope) == Result.SUCCESS) {
|
||||||
|
g.PhoneNumbers = new ArrayList<String>();
|
||||||
|
while (phoneNumbersScope.MoveNext(row)) {
|
||||||
|
String item;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().ReadSparse(row, ref phoneNumbersScope,
|
||||||
|
out item));
|
||||||
|
g.PhoneNumbers.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("addresses", out c);
|
||||||
|
RowCursor addressesScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out addressesScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedMap>TypeAs().ReadScope(row, ref addressesScope, out addressesScope) == Result.SUCCESS) {
|
||||||
|
Reference<RowCursor> tempReference_addressesScope = new Reference<RowCursor>(addressesScope);
|
||||||
|
TypeArgument tupleType = LayoutType.TypedMap.FieldType(tempReference_addressesScope).clone();
|
||||||
|
addressesScope = tempReference_addressesScope.get();
|
||||||
|
TypeArgument t0 = tupleType.getTypeArgs().get(0).clone();
|
||||||
|
TypeArgument t1 = tupleType.getTypeArgs().get(1).clone();
|
||||||
|
g.Addresses = new HashMap<String, Address>();
|
||||||
|
RowCursor pairScope = null;
|
||||||
|
Reference<RowCursor> tempReference_pairScope = new Reference<RowCursor>(pairScope);
|
||||||
|
while (addressesScope.MoveNext(row, tempReference_pairScope)) {
|
||||||
|
pairScope = tempReference_pairScope.get();
|
||||||
|
Reference<RowCursor> tempReference_addressesScope2 = new Reference<RowCursor>(addressesScope);
|
||||||
|
Out<RowCursor> tempOut_pairScope = new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().ReadScope(row,
|
||||||
|
tempReference_addressesScope2, tempOut_pairScope));
|
||||||
|
pairScope = tempOut_pairScope.get();
|
||||||
|
addressesScope = tempReference_addressesScope2.get();
|
||||||
|
assert RowCursors.moveNext(pairScope.clone(), row);
|
||||||
|
Reference<RowCursor> tempReference_pairScope2 = new Reference<RowCursor>(pairScope);
|
||||||
|
String key;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(t0.<LayoutUtf8>TypeAs().ReadSparse(row, tempReference_pairScope2, out key));
|
||||||
|
pairScope = tempReference_pairScope2.get();
|
||||||
|
assert RowCursors.moveNext(pairScope.clone(), row);
|
||||||
|
Reference<RowCursor> tempReference_pairScope3 = new Reference<RowCursor>(pairScope);
|
||||||
|
RowCursor addressScope;
|
||||||
|
Out<RowCursor> tempOut_addressScope = new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t1.<LayoutUDT>TypeAs().ReadScope(row, tempReference_pairScope3, tempOut_addressScope));
|
||||||
|
addressScope = tempOut_addressScope.get();
|
||||||
|
pairScope = tempReference_pairScope3.get();
|
||||||
|
Reference<RowCursor> tempReference_addressScope = new Reference<RowCursor>(addressScope);
|
||||||
|
Address value = CustomerExampleUnitTests.ReadAddress(row, tempReference_addressScope);
|
||||||
|
addressScope = tempReference_addressScope.get();
|
||||||
|
g.Addresses.put(key, value);
|
||||||
|
Reference<RowCursor> tempReference_addressScope2 = new Reference<RowCursor>(addressScope);
|
||||||
|
assert !RowCursors.moveNext(pairScope.clone(), row, tempReference_addressScope2);
|
||||||
|
addressScope = tempReference_addressScope2.get();
|
||||||
|
}
|
||||||
|
pairScope = tempReference_pairScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return g;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Hotel ReadHotel(Reference<RowBuffer> row, Reference<RowCursor> root) {
|
||||||
|
Hotel h = new Hotel();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("hotel_id", out c);
|
||||||
|
Out<String> tempOut_Id = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_Id));
|
||||||
|
h.Id = tempOut_Id.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("name", out c);
|
||||||
|
Out<String> tempOut_Name = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_Name));
|
||||||
|
h.Name = tempOut_Name.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("phone", out c);
|
||||||
|
Out<String> tempOut_Phone = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_Phone));
|
||||||
|
h.Phone = tempOut_Phone.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("address", out c);
|
||||||
|
assert c.Type.Immutable;
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor addressScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUDT>TypeAs().ReadScope(row, root, out addressScope));
|
||||||
|
assert addressScope.Immutable;
|
||||||
|
Reference<RowCursor> tempReference_addressScope =
|
||||||
|
new Reference<RowCursor>(addressScope);
|
||||||
|
h.Address = CustomerExampleUnitTests.ReadAddress(row, tempReference_addressScope);
|
||||||
|
addressScope = tempReference_addressScope.get();
|
||||||
|
Reference<RowCursor> tempReference_addressScope2 =
|
||||||
|
new Reference<RowCursor>(addressScope);
|
||||||
|
RowCursors.skip(root.get().clone(), row,
|
||||||
|
tempReference_addressScope2);
|
||||||
|
addressScope = tempReference_addressScope2.get();
|
||||||
|
return h;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PostalCode ReadPostalCode(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> postalCodeScope) {
|
||||||
|
Layout postalCodeLayout = postalCodeScope.get().getLayout();
|
||||||
|
PostalCode pc = new PostalCode();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert postalCodeLayout.TryFind("zip", out c);
|
||||||
|
Out<Integer> tempOut_Zip = new Out<Integer>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutInt32>TypeAs().ReadFixed(row, postalCodeScope, c, tempOut_Zip));
|
||||||
|
pc.Zip = tempOut_Zip.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert postalCodeLayout.TryFind("plus4", out c);
|
||||||
|
postalCodeScope.get().Find(row, c.Path);
|
||||||
|
short plus4;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutInt16>TypeAs().ReadSparse(row, postalCodeScope, out plus4) == Result.SUCCESS) {
|
||||||
|
pc.Plus4 = plus4;
|
||||||
|
}
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteAddress(Reference<RowBuffer> row, Reference<RowCursor> addressScope,
|
||||||
|
TypeArgumentList typeArgs, Address a) {
|
||||||
|
Layout addressLayout = this.customerResolver.Resolve(typeArgs.getSchemaId().clone());
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("street", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, addressScope, c, a.Street));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("city", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, addressScope, c, a.City));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("state", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteFixed(row, addressScope, c, a.State));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert addressLayout.TryFind("postal_code", out c);
|
||||||
|
addressScope.get().Find(row, c.Path);
|
||||||
|
RowCursor postalCodeScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUDT>TypeAs().WriteScope(row, addressScope, c.TypeArgs, out postalCodeScope));
|
||||||
|
Reference<RowCursor> tempReference_postalCodeScope =
|
||||||
|
new Reference<RowCursor>(postalCodeScope);
|
||||||
|
this.WritePostalCode(row, tempReference_postalCodeScope, c.TypeArgs, a.PostalCode);
|
||||||
|
postalCodeScope = tempReference_postalCodeScope.get();
|
||||||
|
Reference<RowCursor> tempReference_postalCodeScope2 =
|
||||||
|
new Reference<RowCursor>(postalCodeScope);
|
||||||
|
RowCursors.skip(addressScope.get().clone(), row,
|
||||||
|
tempReference_postalCodeScope2);
|
||||||
|
postalCodeScope = tempReference_postalCodeScope2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteGuest(Reference<RowBuffer> row, Reference<RowCursor> root, Guest g) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("guest_id", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutGuid>TypeAs().WriteFixed(row, root, c, g.Id));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("first_name", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, g.FirstName));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("last_name", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, g.LastName));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("title", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, g.Title));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.guestLayout.TryFind("confirm_number", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, g.ConfirmNumber));
|
||||||
|
|
||||||
|
if (g.Emails != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.guestLayout.TryFind("emails", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor emailScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, root, c.TypeArgs, out emailScope));
|
||||||
|
for (String email : g.Emails) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref emailScope, email));
|
||||||
|
assert !emailScope.MoveNext(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_emailScope =
|
||||||
|
new Reference<RowCursor>(emailScope);
|
||||||
|
RowCursors.skip(root.get().clone(), row,
|
||||||
|
tempReference_emailScope);
|
||||||
|
emailScope = tempReference_emailScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.PhoneNumbers != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.guestLayout.TryFind("phone_numbers", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor phoneNumbersScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, root, c.TypeArgs,
|
||||||
|
out phoneNumbersScope));
|
||||||
|
for (String phone : g.PhoneNumbers) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref phoneNumbersScope
|
||||||
|
, phone));
|
||||||
|
assert !phoneNumbersScope.MoveNext(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_phoneNumbersScope =
|
||||||
|
new Reference<RowCursor>(phoneNumbersScope);
|
||||||
|
RowCursors.skip(root.get().clone(), row,
|
||||||
|
tempReference_phoneNumbersScope);
|
||||||
|
phoneNumbersScope = tempReference_phoneNumbersScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (g.Addresses != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.guestLayout.TryFind("addresses", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor addressesScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUniqueScope>TypeAs().WriteScope(row, root, c.TypeArgs, out addressesScope));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
TypeArgument tupleType = c.<LayoutUniqueScope>TypeAs().FieldType(ref addressesScope);
|
||||||
|
TypeArgument t0 = tupleType.getTypeArgs().get(0).clone();
|
||||||
|
TypeArgument t1 = tupleType.getTypeArgs().get(1).clone();
|
||||||
|
for (Map.Entry<String, Address> pair : g.Addresses.entrySet()) {
|
||||||
|
RowCursor tempCursor;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
root.get().Clone(out tempCursor).Find(row, Utf8String.Empty);
|
||||||
|
RowCursor tupleScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().WriteScope(row, ref tempCursor,
|
||||||
|
c.TypeArgs, out tupleScope));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(t0.<LayoutUtf8>TypeAs().WriteSparse(row, ref tupleScope, pair.getKey()));
|
||||||
|
assert tupleScope.MoveNext(row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
RowCursor addressScope;
|
||||||
|
Out<RowCursor> tempOut_addressScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t1.<LayoutUDT>TypeAs().WriteScope(row, tempReference_tupleScope,
|
||||||
|
t1.getTypeArgs().clone(), tempOut_addressScope));
|
||||||
|
addressScope = tempOut_addressScope.get();
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
Reference<RowCursor> tempReference_addressScope =
|
||||||
|
new Reference<RowCursor>(addressScope);
|
||||||
|
this.WriteAddress(row, tempReference_addressScope, t1.getTypeArgs().clone(), pair.getValue());
|
||||||
|
addressScope = tempReference_addressScope.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !tupleScope.MoveNext(row, ref addressScope);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUniqueScope>TypeAs().MoveField(row, ref addressesScope,
|
||||||
|
ref tempCursor));
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_addressesScope =
|
||||||
|
new Reference<RowCursor>(addressesScope);
|
||||||
|
RowCursors.skip(root.get().clone(), row,
|
||||||
|
tempReference_addressesScope);
|
||||||
|
addressesScope = tempReference_addressesScope.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteHotel(Reference<RowBuffer> row, Reference<RowCursor> root, Hotel h) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("hotel_id", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, h.Id));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("name", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, h.Name));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("phone", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, h.Phone));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.hotelLayout.TryFind("address", out c);
|
||||||
|
root.get().Find(row, c.Path);
|
||||||
|
RowCursor addressScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUDT>TypeAs().WriteScope(row, root, c.TypeArgs, out addressScope));
|
||||||
|
Reference<RowCursor> tempReference_addressScope =
|
||||||
|
new Reference<RowCursor>(addressScope);
|
||||||
|
this.WriteAddress(row, tempReference_addressScope, c.TypeArgs, h.Address);
|
||||||
|
addressScope = tempReference_addressScope.get();
|
||||||
|
Reference<RowCursor> tempReference_addressScope2 =
|
||||||
|
new Reference<RowCursor>(addressScope);
|
||||||
|
RowCursors.skip(root.get().clone(), row,
|
||||||
|
tempReference_addressScope2);
|
||||||
|
addressScope = tempReference_addressScope2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WritePostalCode(Reference<RowBuffer> row, Reference<RowCursor> postalCodeScope,
|
||||||
|
TypeArgumentList typeArgs, PostalCode pc) {
|
||||||
|
Layout postalCodeLayout = this.customerResolver.Resolve(typeArgs.getSchemaId().clone());
|
||||||
|
assert postalCodeLayout != null;
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert postalCodeLayout.TryFind("zip", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutInt32>TypeAs().WriteFixed(row, postalCodeScope, c, pc.Zip));
|
||||||
|
if (pc.Plus4.HasValue) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert postalCodeLayout.TryFind("plus4", out c);
|
||||||
|
postalCodeScope.get().Find(row, c.Path);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutInt16>TypeAs().WriteSparse(row, postalCodeScope, pc.Plus4.Value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,167 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutIndexedScope;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedSet;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal struct DeleteRowDispatcher : IDispatcher
|
||||||
|
public final class DeleteRowDispatcher implements IDispatcher {
|
||||||
|
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t) {
|
||||||
|
Dispatch(dispatcher, root, col, t, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void Dispatch<TLayout, TValue>(ref RowOperationDispatcher dispatcher, ref RowCursor root,
|
||||||
|
// LayoutColumn col, LayoutType t, TValue value = default) where TLayout : LayoutType<TValue>
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t, TValue value) {
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().deleteSparse(tempReference_Row, root));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchArray(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor arrayScope;
|
||||||
|
Out<RowCursor> tempOut_arrayScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedArray>typeAs().ReadScope(tempReference_Row, scope, tempOut_arrayScope));
|
||||||
|
arrayScope = tempOut_arrayScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
if (!arrayScope.Immutable) {
|
||||||
|
List items = (List)value;
|
||||||
|
for (Object item : items) {
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
assert arrayScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref arrayScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedArray>typeAs().DeleteScope(tempReference_Row3, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchMap(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 2);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor mapScope;
|
||||||
|
Out<RowCursor> tempOut_mapScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedMap>typeAs().ReadScope(tempReference_Row, scope, tempOut_mapScope));
|
||||||
|
mapScope = tempOut_mapScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
if (!mapScope.Immutable) {
|
||||||
|
List items = (List)value;
|
||||||
|
for (Object item : items) {
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
assert mapScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref mapScope, null, LayoutType.TypedTuple, typeArgs.clone(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedMap>typeAs().DeleteScope(tempReference_Row3, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchNullable(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutNullable>typeAs().DeleteScope(tempReference_Row, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchObject(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchSet(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor setScope;
|
||||||
|
Out<RowCursor> tempOut_setScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedSet>typeAs().ReadScope(tempReference_Row, scope, tempOut_setScope));
|
||||||
|
setScope = tempOut_setScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
if (!setScope.Immutable) {
|
||||||
|
List items = (List)value;
|
||||||
|
for (Object item : items) {
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
assert setScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref setScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedSet>typeAs().DeleteScope(tempReference_Row3, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchTuple(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() >= 2);
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutIndexedScope>typeAs().DeleteScope(tempReference_Row, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchUDT(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs, Object value) {
|
||||||
|
Reference<RowBuffer> tempReference_Row = new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutUDT>typeAs().DeleteScope(tempReference_Row, scope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
|
||||||
|
public interface IDispatchable {
|
||||||
|
void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope);
|
||||||
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
|
||||||
|
public interface IDispatcher {
|
||||||
|
|
||||||
|
<TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutColumn col,
|
||||||
|
LayoutType t);
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: void Dispatch<TLayout, TValue>(ref RowOperationDispatcher dispatcher, ref RowCursor scope,
|
||||||
|
// LayoutColumn col, LayoutType t, TValue value = default) where TLayout : LayoutType<TValue>;
|
||||||
|
<TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutColumn col,
|
||||||
|
LayoutType t, TValue value);
|
||||||
|
|
||||||
|
void DispatchArray(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType t, TypeArgumentList typeArgs, Object value);
|
||||||
|
|
||||||
|
void DispatchMap(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType t, TypeArgumentList typeArgs, Object value);
|
||||||
|
|
||||||
|
void DispatchNullable(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType t, TypeArgumentList typeArgs, Object value);
|
||||||
|
|
||||||
|
void DispatchObject(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope);
|
||||||
|
|
||||||
|
void DispatchSet(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType t, TypeArgumentList typeArgs, Object value);
|
||||||
|
|
||||||
|
void DispatchTuple(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType t, TypeArgumentList typeArgs, Object value);
|
||||||
|
|
||||||
|
void DispatchUDT(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope,
|
||||||
|
LayoutType type, TypeArgumentList typeArgs, Object value);
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,46 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class LayoutTypeUnitTests
|
||||||
|
public class LayoutTypeUnitTests {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void LayoutTypeTest()
|
||||||
|
public final void LayoutTypeTest() {
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Boolean);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Int8);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Int16);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Int32);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Int64);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.UInt8);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.UInt16);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.UInt32);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.UInt64);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.VarInt);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.VarUInt);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Float32);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Float64);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Decimal);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Null);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Boolean);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.DateTime);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Guid);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Utf8);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Binary);
|
||||||
|
LayoutTypeUnitTests.TestLayoutTypeApi(LayoutType.Object);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void TestLayoutTypeApi(LayoutType t) {
|
||||||
|
assert t.getName() != null;
|
||||||
|
assert !tangible.StringHelper.isNullOrWhiteSpace(t.getName());
|
||||||
|
Assert.AreNotSame(null, t.getIsFixed(), t.getName());
|
||||||
|
Assert.AreNotSame(null, t.getAllowVariable(), t.getName());
|
||||||
|
Assert.AreNotSame(null, t.getIsBool(), t.getName());
|
||||||
|
Assert.AreNotSame(null, t.getIsNull(), t.getName());
|
||||||
|
Assert.AreNotSame(null, t.getIsVarint(), t.getName());
|
||||||
|
Assert.IsTrue(t.Size >= 0, t.getName());
|
||||||
|
Assert.AreNotEqual(LayoutCode.Invalid, t.LayoutCode, t.getName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal struct NullRowDispatcher : IDispatcher
|
||||||
|
public final class NullRowDispatcher implements IDispatcher {
|
||||||
|
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t) {
|
||||||
|
Dispatch(dispatcher, root, col, t, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void Dispatch<TLayout, TValue>(ref RowOperationDispatcher dispatcher, ref RowCursor root,
|
||||||
|
// LayoutColumn col, LayoutType t, TValue expected = default) where TLayout : LayoutType<TValue>
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t, TValue expected) {
|
||||||
|
switch (col == null ? null : col.getStorage()) {
|
||||||
|
case Fixed:
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
TValue _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.NotFound(t.<TLayout>TypeAs().ReadFixed(tempReference_Row, root, col, out _));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
break;
|
||||||
|
case Variable:
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
TValue _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.NotFound(t.<TLayout>TypeAs().ReadVariable(tempReference_Row2, root, col, out _));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
TValue _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.NotFound(t.<TLayout>TypeAs().ReadSparse(tempReference_Row3, root, out _));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchArray(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchMap(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs, Object value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchNullable(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchObject(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchSet(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchTuple(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchUDT(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs, Object value) {
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,753 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// ReSharper disable StringLiteralTypo
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(NullableUnitTests.SchemaFile, "TestData")] public sealed class
|
||||||
|
// NullableUnitTests
|
||||||
|
public final class NullableUnitTests {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
private static final String SchemaFile = "TestData\\NullableSchema.json";
|
||||||
|
private Layout layout;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateNullables()
|
||||||
|
public void CreateNullables() {
|
||||||
|
RowBuffer row = new RowBuffer(NullableUnitTests.InitialRowSize);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.layout, this.resolver);
|
||||||
|
|
||||||
|
Nullables t1 = new Nullables();
|
||||||
|
t1.NullBool = new ArrayList<Boolean>(Arrays.asList(true, false, null));
|
||||||
|
t1.NullArray = new ArrayList<Float>(Arrays.asList(1.2F, null, 3.0F));
|
||||||
|
t1.NullSet = new ArrayList<String>(Arrays.asList(null, "abc", "def"));
|
||||||
|
t1.NullTuple = new ArrayList<(Integer, Long) > (Arrays.asList((1, 2), (null, 3),(4, null),(null, null)))
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: t1.NullMap = new Dictionary<System.GuidCodec, Nullable<byte>> { { System.GuidCodec.Parse
|
||||||
|
// ("{00000000-0000-0000-0000-000000000000}"), 1 }, { System.GuidCodec.Parse
|
||||||
|
// ("{4674962B-CE11-4916-81C5-0421EE36F168}"), 20 }, { System.GuidCodec.Parse
|
||||||
|
// ("{7499C40E-7077-45C1-AE5F-3E384966B3B9}"), null }};
|
||||||
|
t1.NullMap = new HashMap<UUID, Byte>(Map.ofEntries(Map.entry(UUID.fromString("{00000000-0000-0000-0000" +
|
||||||
|
"-000000000000}"), 1), Map.entry(UUID.fromString("{4674962B-CE11-4916-81C5-0421EE36F168}"), 20),
|
||||||
|
Map.entry(UUID.fromString("{7499C40E-7077-45C1-AE5F-3E384966B3B9}"), null)));
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
this.WriteNullables(tempReference_row, RowCursor.create(tempReference_row2, out _), t1);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
Nullables t2 = this.ReadNullables(tempReference_row3, RowCursor.create(tempReference_row4, out _));
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
assert t1 == t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString(NullableUnitTests.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
this.layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Nullables")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The C# 'struct' constraint has no equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result ReadNullable<TValue>(ref RowBuffer row, ref RowCursor scope, TypeArgument
|
||||||
|
// itemType, out Nullable<TValue> item, out RowCursor nullableScope) where TValue : struct
|
||||||
|
private static <TValue> Result ReadNullable(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
Out<TValue> item,
|
||||||
|
Out<RowCursor> nullableScope) {
|
||||||
|
TValue value;
|
||||||
|
Out<TValue> tempOut_value = new Out<TValue>();
|
||||||
|
Result r = NullableUnitTests.ReadNullableImpl(row, scope, itemType.clone(), tempOut_value,
|
||||||
|
nullableScope.clone());
|
||||||
|
value = tempOut_value.get();
|
||||||
|
if ((r != Result.SUCCESS) && (r != Result.NOT_FOUND)) {
|
||||||
|
item.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
item.setAndGet((r == Result.NOT_FOUND) ? null : value);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TValue> Result ReadNullable(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
Out<TValue> item,
|
||||||
|
Out<RowCursor> nullableScope) {
|
||||||
|
Result r = NullableUnitTests.ReadNullableImpl(row, scope, itemType.clone(), item, nullableScope.clone());
|
||||||
|
return (r == Result.NOT_FOUND) ? Result.SUCCESS : r;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TValue> Result ReadNullableImpl(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
Out<TValue> item,
|
||||||
|
Out<RowCursor> nullableScope) {
|
||||||
|
Result r = itemType.getType().<LayoutNullable>TypeAs().ReadScope(row, scope, nullableScope.clone());
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
item.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (RowCursors.moveNext(nullableScope.get().clone(), row)) {
|
||||||
|
ResultAssert.IsSuccess(LayoutNullable.HasValue(row, nullableScope.clone()));
|
||||||
|
return itemType.getTypeArgs().get(0).getType().<LayoutType<TValue>>TypeAs().ReadSparse(row,
|
||||||
|
nullableScope.clone(), item);
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultAssert.NotFound(LayoutNullable.HasValue(row, nullableScope.clone()));
|
||||||
|
item.setAndGet(null);
|
||||||
|
return Result.NOT_FOUND;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Nullables ReadNullables(Reference<RowBuffer> row, Reference<RowCursor> root) {
|
||||||
|
Nullables value = new Nullables();
|
||||||
|
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("nullbool", out c);
|
||||||
|
RowCursor scope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>typeAs().ReadScope(row, ref scope, out scope) == Result.SUCCESS) {
|
||||||
|
value.NullBool = new ArrayList<Boolean>();
|
||||||
|
RowCursor nullableScope = null;
|
||||||
|
Reference<RowCursor> tempReference_nullableScope =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
while (scope.MoveNext(row, tempReference_nullableScope)) {
|
||||||
|
nullableScope = tempReference_nullableScope.get();
|
||||||
|
Reference<RowCursor> tempReference_scope =
|
||||||
|
new Reference<RowCursor>(scope);
|
||||||
|
Nullable<Boolean> item;
|
||||||
|
Out<TValue> tempOut_item = new Out<TValue>();
|
||||||
|
Out<RowCursor> tempOut_nullableScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_scope, c.TypeArgs[0], tempOut_item
|
||||||
|
, tempOut_nullableScope));
|
||||||
|
nullableScope = tempOut_nullableScope.get();
|
||||||
|
item = tempOut_item.get();
|
||||||
|
scope = tempReference_scope.get();
|
||||||
|
value.NullBool.add(item);
|
||||||
|
}
|
||||||
|
nullableScope = tempReference_nullableScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("nullarray", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>typeAs().ReadScope(row, ref scope, out scope) == Result.SUCCESS) {
|
||||||
|
value.NullArray = new ArrayList<Float>();
|
||||||
|
RowCursor nullableScope = null;
|
||||||
|
Reference<RowCursor> tempReference_nullableScope2 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
while (scope.MoveNext(row, tempReference_nullableScope2)) {
|
||||||
|
nullableScope = tempReference_nullableScope2.get();
|
||||||
|
Reference<RowCursor> tempReference_scope2 =
|
||||||
|
new Reference<RowCursor>(scope);
|
||||||
|
Nullable<Float> item;
|
||||||
|
Out<TValue> tempOut_item2 = new Out<TValue>();
|
||||||
|
Out<RowCursor> tempOut_nullableScope2 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_scope2, c.TypeArgs[0],
|
||||||
|
tempOut_item2, tempOut_nullableScope2));
|
||||||
|
nullableScope = tempOut_nullableScope2.get();
|
||||||
|
item = tempOut_item2.get();
|
||||||
|
scope = tempReference_scope2.get();
|
||||||
|
value.NullArray.add(item);
|
||||||
|
}
|
||||||
|
nullableScope = tempReference_nullableScope2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("nullset", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedSet>typeAs().ReadScope(row, ref scope, out scope) == Result.SUCCESS) {
|
||||||
|
value.NullSet = new ArrayList<String>();
|
||||||
|
RowCursor nullableScope = null;
|
||||||
|
Reference<RowCursor> tempReference_nullableScope3 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
while (scope.MoveNext(row, tempReference_nullableScope3)) {
|
||||||
|
nullableScope = tempReference_nullableScope3.get();
|
||||||
|
Reference<RowCursor> tempReference_scope3 =
|
||||||
|
new Reference<RowCursor>(scope);
|
||||||
|
String item;
|
||||||
|
Out<TValue> tempOut_item3 = new Out<TValue>();
|
||||||
|
Out<RowCursor> tempOut_nullableScope3 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_scope3, c.TypeArgs[0],
|
||||||
|
tempOut_item3, tempOut_nullableScope3));
|
||||||
|
nullableScope = tempOut_nullableScope3.get();
|
||||||
|
item = tempOut_item3.get();
|
||||||
|
scope = tempReference_scope3.get();
|
||||||
|
value.NullSet.add(item);
|
||||||
|
}
|
||||||
|
nullableScope = tempReference_nullableScope3.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("nulltuple", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>typeAs().ReadScope(row, ref scope, out scope) == Result.SUCCESS) {
|
||||||
|
value.NullTuple = new ArrayList<(Integer, Long) > ();
|
||||||
|
RowCursor tupleScope = null;
|
||||||
|
TypeArgument tupleType = c.TypeArgs[0];
|
||||||
|
Reference<RowCursor> tempReference_tupleScope =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
while (scope.MoveNext(row, tempReference_tupleScope)) {
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
Reference<RowCursor> tempReference_scope4 =
|
||||||
|
new Reference<RowCursor>(scope);
|
||||||
|
Out<RowCursor> tempOut_tupleScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().ReadScope(row, tempReference_scope4,
|
||||||
|
tempOut_tupleScope));
|
||||||
|
tupleScope = tempOut_tupleScope.get();
|
||||||
|
scope = tempReference_scope4.get();
|
||||||
|
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope2 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Nullable<Integer> item1;
|
||||||
|
Out<TValue> tempOut_item1 = new Out<TValue>();
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope4 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_tupleScope2,
|
||||||
|
tupleType.getTypeArgs().get(0).clone(), tempOut_item1, tempOut_nullableScope4));
|
||||||
|
nullableScope = tempOut_nullableScope4.get();
|
||||||
|
item1 = tempOut_item1.get();
|
||||||
|
tupleScope = tempReference_tupleScope2.get();
|
||||||
|
Reference<RowCursor> tempReference_nullableScope4 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row, tempReference_nullableScope4);
|
||||||
|
nullableScope = tempReference_nullableScope4.get();
|
||||||
|
Reference<RowCursor> tempReference_tupleScope3 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Nullable<Long> item2;
|
||||||
|
Out<TValue> tempOut_item2 = new Out<TValue>();
|
||||||
|
Out<RowCursor> tempOut_nullableScope5 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_tupleScope3,
|
||||||
|
tupleType.getTypeArgs().get(1).clone(), tempOut_item2, tempOut_nullableScope5));
|
||||||
|
nullableScope = tempOut_nullableScope5.get();
|
||||||
|
item2 = tempOut_item2.get();
|
||||||
|
tupleScope = tempReference_tupleScope3.get();
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_nullableScope5 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
assert !RowCursors.moveNext(tupleScope.clone(), row, tempReference_nullableScope5);
|
||||||
|
nullableScope = tempReference_nullableScope5.get();
|
||||||
|
value.NullTuple.add((item1, item2))
|
||||||
|
}
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("nullmap", out c);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutUniqueScope>typeAs().ReadScope(row, ref scope, out scope) == Result.SUCCESS) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: value.NullMap = new Dictionary<GuidCodec, Nullable<byte>>();
|
||||||
|
value.NullMap = new HashMap<UUID, Byte>();
|
||||||
|
RowCursor tupleScope = null;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
TypeArgument tupleType = c.<LayoutUniqueScope>typeAs().FieldType(ref scope);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope4 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
while (scope.MoveNext(row, tempReference_tupleScope4)) {
|
||||||
|
tupleScope = tempReference_tupleScope4.get();
|
||||||
|
Reference<RowCursor> tempReference_scope5 =
|
||||||
|
new Reference<RowCursor>(scope);
|
||||||
|
Out<RowCursor> tempOut_tupleScope2 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().ReadScope(row, tempReference_scope5,
|
||||||
|
tempOut_tupleScope2));
|
||||||
|
tupleScope = tempOut_tupleScope2.get();
|
||||||
|
scope = tempReference_scope5.get();
|
||||||
|
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope5 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Nullable<java.util.UUID> itemKey;
|
||||||
|
Out<TValue> tempOut_itemKey = new Out<TValue>();
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope6 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_tupleScope5,
|
||||||
|
tupleType.getTypeArgs().get(0).clone(), tempOut_itemKey, tempOut_nullableScope6));
|
||||||
|
nullableScope = tempOut_nullableScope6.get();
|
||||||
|
itemKey = tempOut_itemKey.get();
|
||||||
|
tupleScope = tempReference_tupleScope5.get();
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_nullableScope6 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row, tempReference_nullableScope6);
|
||||||
|
nullableScope = tempReference_nullableScope6.get();
|
||||||
|
Reference<RowCursor> tempReference_tupleScope6 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Nullable<Byte> itemValue;
|
||||||
|
Out<TValue> tempOut_itemValue = new Out<TValue>();
|
||||||
|
Out<RowCursor> tempOut_nullableScope7 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.ReadNullable(row, tempReference_tupleScope6,
|
||||||
|
tupleType.getTypeArgs().get(1).clone(), tempOut_itemValue, tempOut_nullableScope7));
|
||||||
|
nullableScope = tempOut_nullableScope7.get();
|
||||||
|
itemValue = tempOut_itemValue.get();
|
||||||
|
tupleScope = tempReference_tupleScope6.get();
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_nullableScope7 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
assert !RowCursors.moveNext(tupleScope.clone(), row, tempReference_nullableScope7);
|
||||||
|
nullableScope = tempReference_nullableScope7.get();
|
||||||
|
value.NullMap.put(itemKey != null ? itemKey : UUID.Empty, itemValue);
|
||||||
|
}
|
||||||
|
tupleScope = tempReference_tupleScope4.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The C# 'struct' constraint has no equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static Result WriteNullable<TValue>(ref RowBuffer row, ref RowCursor scope, TypeArgument
|
||||||
|
// itemType, Nullable<TValue> item, out RowCursor nullableScope) where TValue : struct
|
||||||
|
private static <TValue> Result WriteNullable(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
TValue item, Out<RowCursor> nullableScope) {
|
||||||
|
return NullableUnitTests.WriteNullableImpl(row, scope, itemType.clone(), item != null, item != null ? item :
|
||||||
|
default,nullableScope.clone())
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TValue> Result WriteNullable(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
TValue item, Out<RowCursor> nullableScope) {
|
||||||
|
return NullableUnitTests.WriteNullableImpl(row, scope, itemType.clone(), item != null, item,
|
||||||
|
nullableScope.clone());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TValue> Result WriteNullableImpl(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> scope, TypeArgument itemType,
|
||||||
|
boolean hasValue, TValue item,
|
||||||
|
Out<RowCursor> nullableScope) {
|
||||||
|
Result r = itemType.<LayoutNullable>TypeAs().WriteScope(row, scope, itemType.getTypeArgs().clone(), hasValue,
|
||||||
|
nullableScope);
|
||||||
|
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hasValue) {
|
||||||
|
r = itemType.getTypeArgs().get(0).getType().<LayoutType<TValue>>TypeAs().WriteSparse(row,
|
||||||
|
nullableScope.clone(), item);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteNullables(Reference<RowBuffer> row, Reference<RowCursor> root,
|
||||||
|
Nullables value) {
|
||||||
|
LayoutColumn c;
|
||||||
|
|
||||||
|
if (value.NullBool != null) {
|
||||||
|
Out<LayoutColumn> tempOut_c =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert this.layout.TryFind("nullbool", tempOut_c);
|
||||||
|
c = tempOut_c.get();
|
||||||
|
RowCursor outerScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out outerScope).Find(row, c.path());
|
||||||
|
Reference<RowCursor> tempReference_outerScope =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Out<RowCursor> tempOut_outerScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>typeAs().WriteScope(row, tempReference_outerScope,
|
||||||
|
c.typeArgs().clone(), tempOut_outerScope));
|
||||||
|
outerScope = tempOut_outerScope.get();
|
||||||
|
outerScope = tempReference_outerScope.get();
|
||||||
|
for (Boolean item : value.NullBool) {
|
||||||
|
Reference<RowCursor> tempReference_outerScope2 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
RowCursor innerScope;
|
||||||
|
Out<RowCursor> tempOut_innerScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_outerScope2,
|
||||||
|
c.typeArgs().get(0).clone(), item, tempOut_innerScope));
|
||||||
|
innerScope = tempOut_innerScope.get();
|
||||||
|
outerScope = tempReference_outerScope2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !outerScope.MoveNext(row, ref innerScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.NullArray != null) {
|
||||||
|
Out<LayoutColumn> tempOut_c2 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert this.layout.TryFind("nullarray", tempOut_c2);
|
||||||
|
c = tempOut_c2.get();
|
||||||
|
RowCursor outerScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out outerScope).Find(row, c.path());
|
||||||
|
Reference<RowCursor> tempReference_outerScope3 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Out<RowCursor> tempOut_outerScope2 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>typeAs().WriteScope(row, tempReference_outerScope3,
|
||||||
|
c.typeArgs().clone(), tempOut_outerScope2));
|
||||||
|
outerScope = tempOut_outerScope2.get();
|
||||||
|
outerScope = tempReference_outerScope3.get();
|
||||||
|
for (Float item : value.NullArray) {
|
||||||
|
Reference<RowCursor> tempReference_outerScope4 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
RowCursor innerScope;
|
||||||
|
Out<RowCursor> tempOut_innerScope2 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_outerScope4,
|
||||||
|
c.typeArgs().get(0).clone(), item, tempOut_innerScope2));
|
||||||
|
innerScope = tempOut_innerScope2.get();
|
||||||
|
outerScope = tempReference_outerScope4.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !outerScope.MoveNext(row, ref innerScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.NullSet != null) {
|
||||||
|
Out<LayoutColumn> tempOut_c3 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert this.layout.TryFind("nullset", tempOut_c3);
|
||||||
|
c = tempOut_c3.get();
|
||||||
|
RowCursor outerScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out outerScope).Find(row, c.path());
|
||||||
|
Reference<RowCursor> tempReference_outerScope5 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Out<RowCursor> tempOut_outerScope3 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedSet>typeAs().WriteScope(row, tempReference_outerScope5,
|
||||||
|
c.typeArgs().clone(), tempOut_outerScope3));
|
||||||
|
outerScope = tempOut_outerScope3.get();
|
||||||
|
outerScope = tempReference_outerScope5.get();
|
||||||
|
for (String item : value.NullSet) {
|
||||||
|
RowCursor temp;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
RowCursor.createForAppend(row, out temp).Find(row, "");
|
||||||
|
Reference<RowCursor> tempReference_temp =
|
||||||
|
new Reference<RowCursor>(temp);
|
||||||
|
RowCursor _;
|
||||||
|
Out<RowCursor> tempOut__ =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_temp,
|
||||||
|
c.typeArgs().get(0).clone(), item, tempOut__));
|
||||||
|
_ = tempOut__.get();
|
||||||
|
temp = tempReference_temp.get();
|
||||||
|
Reference<RowCursor> tempReference_outerScope6 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Reference<RowCursor> tempReference_temp2 =
|
||||||
|
new Reference<RowCursor>(temp);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedSet>typeAs().MoveField(row, tempReference_outerScope6,
|
||||||
|
tempReference_temp2));
|
||||||
|
temp = tempReference_temp2.get();
|
||||||
|
outerScope = tempReference_outerScope6.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.NullTuple != null) {
|
||||||
|
Out<LayoutColumn> tempOut_c4 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert this.layout.TryFind("nulltuple", tempOut_c4);
|
||||||
|
c = tempOut_c4.get();
|
||||||
|
RowCursor outerScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out outerScope).Find(row, c.path());
|
||||||
|
Reference<RowCursor> tempReference_outerScope7 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Out<RowCursor> tempOut_outerScope4 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>typeAs().WriteScope(row, tempReference_outerScope7,
|
||||||
|
c.typeArgs().clone(), tempOut_outerScope4));
|
||||||
|
outerScope = tempOut_outerScope4.get();
|
||||||
|
outerScope = tempReference_outerScope7.get();
|
||||||
|
for ((Integer item1,Long item2) :value.NullTuple)
|
||||||
|
{
|
||||||
|
TypeArgument tupleType = c.typeArgs().get(0).clone();
|
||||||
|
RowCursor tupleScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().WriteScope(row, ref outerScope,
|
||||||
|
tupleType.getTypeArgs().clone(), out tupleScope));
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_tupleScope =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_tupleScope,
|
||||||
|
tupleType.getTypeArgs().get(0).clone(), item1, tempOut_nullableScope));
|
||||||
|
nullableScope = tempOut_nullableScope.get();
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert tupleScope.MoveNext(row, ref nullableScope);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope2 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Out<RowCursor> tempOut_nullableScope2 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_tupleScope2,
|
||||||
|
tupleType.getTypeArgs().get(1).clone(), item2, tempOut_nullableScope2));
|
||||||
|
nullableScope = tempOut_nullableScope2.get();
|
||||||
|
tupleScope = tempReference_tupleScope2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !tupleScope.MoveNext(row, ref nullableScope);
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !outerScope.MoveNext(row, ref tupleScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.NullMap != null) {
|
||||||
|
Out<LayoutColumn> tempOut_c5 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert this.layout.TryFind("nullmap", tempOut_c5);
|
||||||
|
c = tempOut_c5.get();
|
||||||
|
RowCursor outerScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out outerScope).Find(row, c.path());
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUniqueScope>typeAs().WriteScope(row, ref outerScope,
|
||||||
|
c.typeArgs().clone(), out outerScope));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: foreach ((GuidCodec key, Nullable<byte> itemValue) in value.NullMap)
|
||||||
|
for ((UUID key,Byte itemValue) :value.NullMap)
|
||||||
|
{
|
||||||
|
Reference<RowCursor> tempReference_outerScope8 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
TypeArgument tupleType = c.<LayoutUniqueScope>typeAs().FieldType(tempReference_outerScope8).clone();
|
||||||
|
outerScope = tempReference_outerScope8.get();
|
||||||
|
RowCursor temp;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
RowCursor.createForAppend(row, out temp).Find(row, "");
|
||||||
|
RowCursor tupleScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(tupleType.<LayoutIndexedScope>TypeAs().WriteScope(row, ref temp,
|
||||||
|
tupleType.getTypeArgs().clone(), out tupleScope));
|
||||||
|
|
||||||
|
UUID itemKey = key.equals(UUID.Empty) ? null : key;
|
||||||
|
Reference<RowCursor> tempReference_tupleScope3 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope3 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_tupleScope3,
|
||||||
|
tupleType.getTypeArgs().get(0).clone(), itemKey, tempOut_nullableScope3));
|
||||||
|
nullableScope = tempOut_nullableScope3.get();
|
||||||
|
tupleScope = tempReference_tupleScope3.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert tupleScope.MoveNext(row, ref nullableScope);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope4 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
Out<RowCursor> tempOut_nullableScope4 =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(NullableUnitTests.WriteNullable(row, tempReference_tupleScope4,
|
||||||
|
tupleType.getTypeArgs().get(1).clone(), itemValue, tempOut_nullableScope4));
|
||||||
|
nullableScope = tempOut_nullableScope4.get();
|
||||||
|
tupleScope = tempReference_tupleScope4.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !tupleScope.MoveNext(row, ref nullableScope);
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_outerScope9 =
|
||||||
|
new Reference<RowCursor>(outerScope);
|
||||||
|
Reference<RowCursor> tempReference_temp3 =
|
||||||
|
new Reference<RowCursor>(temp);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUniqueScope>typeAs().MoveField(row, tempReference_outerScope9,
|
||||||
|
tempReference_temp3));
|
||||||
|
temp = tempReference_temp3.get();
|
||||||
|
outerScope = tempReference_outerScope9.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1401", Justification = "Test types.")] private sealed class Nullables
|
||||||
|
private final static class Nullables {
|
||||||
|
public ArrayList<Float> NullArray;
|
||||||
|
public ArrayList<Boolean> NullBool;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public Dictionary<GuidCodec, Nullable<byte>> NullMap;
|
||||||
|
public HashMap<UUID, Byte> NullMap;
|
||||||
|
public ArrayList<(Integer,Long)>NullTuple
|
||||||
|
public ArrayList<String> NullSet;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tempVar = obj instanceof Nullables;
|
||||||
|
Nullables nullables = tempVar ? (Nullables)obj : null;
|
||||||
|
return tempVar && this.equals(nullables);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = 0;
|
||||||
|
hashCode = (hashCode * 397) ^ (this.NullBool == null ? null : this.NullBool.hashCode() != null ? this.NullBool.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.NullSet == null ? null : this.NullSet.hashCode() != null ? this.NullSet.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.NullArray == null ? null : this.NullArray.hashCode() != null ? this.NullArray.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.NullTuple == null ? null : this.NullTuple.hashCode() != null ? this.NullTuple.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.NullMap == null ? null : this.NullMap.hashCode() != null ? this.NullMap.hashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TKey, TValue> boolean MapEquals(HashMap<TKey, TValue> left, HashMap<TKey, TValue> right) {
|
||||||
|
if (left.size() != right.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<TKey, TValue> item : left.entrySet()) {
|
||||||
|
TValue value;
|
||||||
|
if (!(right.containsKey(item.getKey()) && (value = right.get(item.getKey())) == value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!item.getValue().equals(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Nullables other) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java AbstractList 'equals' is not always identical to LINQ 'SequenceEqual':
|
||||||
|
//ORIGINAL LINE: return (object.ReferenceEquals(this.NullBool, other.NullBool) || ((this.NullBool != null) && (other.NullBool != null) && this.NullBool.SequenceEqual(other.NullBool))) && (object.ReferenceEquals(this.NullSet, other.NullSet) || ((this.NullSet != null) && (other.NullSet != null) && this.NullSet.SequenceEqual(other.NullSet))) && (object.ReferenceEquals(this.NullArray, other.NullArray) || ((this.NullArray != null) && (other.NullArray != null) && this.NullArray.SequenceEqual(other.NullArray))) && (object.ReferenceEquals(this.NullTuple, other.NullTuple) || ((this.NullTuple != null) && (other.NullTuple != null) && this.NullTuple.SequenceEqual(other.NullTuple))) && (object.ReferenceEquals(this.NullMap, other.NullMap) || ((this.NullMap != null) && (other.NullMap != null) && Nullables.MapEquals(this.NullMap, other.NullMap)));
|
||||||
|
return (this.NullBool == other.NullBool || ((this.NullBool != null) && (other.NullBool != null) && this.NullBool.equals(other.NullBool))) && (this.NullSet == other.NullSet || ((this.NullSet != null) && (other.NullSet != null) && this.NullSet.equals(other.NullSet))) && (this.NullArray == other.NullArray || ((this.NullArray != null) && (other.NullArray != null) && this.NullArray.equals(other.NullArray))) && (this.NullTuple == other.NullTuple || ((this.NullTuple != null) && (other.NullTuple != null) && this.NullTuple.equals(other.NullTuple))) && (this.NullMap == other.NullMap || ((this.NullMap != null) && (other.NullMap != null) && Nullables.MapEquals(this.NullMap, other.NullMap)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extension methods for computing permutations of {@link IEnumerable{T}}.
|
||||||
|
*/
|
||||||
|
public final class PermuteExtensions {
|
||||||
|
/**
|
||||||
|
* Generate all permutations of a given enumerable.
|
||||||
|
*/
|
||||||
|
public static <T> java.lang.Iterable<java.lang.Iterable<T>> Permute(java.lang.Iterable<T> list) {
|
||||||
|
int start = 0;
|
||||||
|
for (T element : list) {
|
||||||
|
int index = start;
|
||||||
|
T[] first = { element };
|
||||||
|
java.lang.Iterable<T> rest = list.Where((s, i) -> i != index);
|
||||||
|
if (!rest.Any()) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not have an equivalent to the C# 'yield' keyword:
|
||||||
|
yield return first;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (java.lang.Iterable<T> sub :
|
||||||
|
PermuteExtensions.Permute(rest)) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java does not have an equivalent to the C# 'yield' keyword:
|
||||||
|
yield return first.Concat(sub);
|
||||||
|
}
|
||||||
|
|
||||||
|
start++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class RandomGeneratorUnitTests
|
||||||
|
public class RandomGeneratorUnitTests {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void RangeTest()
|
||||||
|
public final void RangeTest() {
|
||||||
|
int seed = 42;
|
||||||
|
RandomGenerator rand = new RandomGenerator(new Random(seed));
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ulong l1 = rand.NextUInt64();
|
||||||
|
long l1 = rand.NextUInt64();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ulong l2 = rand.NextUInt64();
|
||||||
|
long l2 = rand.NextUInt64();
|
||||||
|
assert l1 != l2;
|
||||||
|
|
||||||
|
System.out.println("Check full range of min/max for ushort.");
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: for (int min = 0; min <= ushort.MaxValue; min++)
|
||||||
|
for (int min = 0; min <= Short.MAX_VALUE; min++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ushort i1 = rand.NextUInt16((ushort)min, ushort.MaxValue);
|
||||||
|
short i1 = rand.NextUInt16((short)min, Short.MAX_VALUE);
|
||||||
|
assert i1 >= min;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println("Check ushort range of min/max for uint.");
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: for (uint min = 0; min <= (uint)ushort.MaxValue; min++)
|
||||||
|
for (int min = 0; min <= (int)Short.MAX_VALUE; min++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: uint i1 = rand.NextUInt32(min, (uint)ushort.MaxValue);
|
||||||
|
int i1 = rand.NextUInt32(min, (int)Short.MAX_VALUE);
|
||||||
|
assert i1 >= min;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Assert.IsTrue(i1 <= ushort.MaxValue);
|
||||||
|
assert i1 <= Short.MAX_VALUE;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean seenMax = false;
|
||||||
|
boolean seenMin = false;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: const ushort maxUShortRange = 10;
|
||||||
|
final short maxUShortRange = 10;
|
||||||
|
System.out.println("Check inclusivity for ushort.");
|
||||||
|
while (!(seenMax && seenMin)) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ushort i1 = rand.NextUInt16(ushort.MinValue, maxUShortRange);
|
||||||
|
short i1 = rand.NextUInt16(Short.MIN_VALUE, maxUShortRange);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: seenMin = seenMin || i1 == ushort.MinValue;
|
||||||
|
seenMin = seenMin || i1 == Short.MIN_VALUE;
|
||||||
|
seenMax = seenMax || i1 == maxUShortRange;
|
||||||
|
assert i1 <= maxUShortRange;
|
||||||
|
}
|
||||||
|
|
||||||
|
seenMax = false;
|
||||||
|
seenMin = false;
|
||||||
|
System.out.println("Check inclusivity for short.");
|
||||||
|
final short minShortRange = -10;
|
||||||
|
final short maxShortRange = 10;
|
||||||
|
while (!(seenMax && seenMin)) {
|
||||||
|
short i1 = rand.NextInt16(minShortRange, maxShortRange);
|
||||||
|
seenMin = seenMin || i1 == -10;
|
||||||
|
seenMax = seenMax || i1 == 10;
|
||||||
|
assert i1 >= minShortRange;
|
||||||
|
assert i1 <= maxShortRange;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,239 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedArray;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal struct ReadRowDispatcher : IDispatcher
|
||||||
|
public final class ReadRowDispatcher implements IDispatcher {
|
||||||
|
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t) {
|
||||||
|
Dispatch(dispatcher, root, col, t, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void Dispatch<TLayout, TValue>(ref RowOperationDispatcher dispatcher, ref RowCursor root,
|
||||||
|
// LayoutColumn col, LayoutType t, TValue expected = default) where TLayout : LayoutType<TValue>
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> root, LayoutColumn col, LayoutType t, TValue expected) {
|
||||||
|
TValue value;
|
||||||
|
switch (col == null ? null : col.getStorage()) {
|
||||||
|
case Fixed:
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Out<TValue> tempOut_value = new Out<TValue>();
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().readFixed(tempReference_Row, root, col, tempOut_value));
|
||||||
|
value = tempOut_value.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
break;
|
||||||
|
case Variable:
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Out<TValue> tempOut_value2 = new Out<TValue>();
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().readVariable(tempReference_Row2, root, col, tempOut_value2));
|
||||||
|
value = tempOut_value2.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Out<TValue> tempOut_value3 = new Out<TValue>();
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().readSparse(tempReference_Row3, root, tempOut_value3));
|
||||||
|
value = tempOut_value3.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (TValue.class.IsArray) {
|
||||||
|
CollectionAssert.AreEqual((Collection)expected, (Collection)value);
|
||||||
|
} else {
|
||||||
|
assert expected == value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchArray(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor arrayScope;
|
||||||
|
Out<RowCursor> tempOut_arrayScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedArray>typeAs().ReadScope(tempReference_Row, scope, tempOut_arrayScope));
|
||||||
|
arrayScope = tempOut_arrayScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
int i = 0;
|
||||||
|
List items = (List)value;
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
while (arrayScope.MoveNext(tempReference_Row2)) {
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref arrayScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), items.get(i++));
|
||||||
|
}
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchMap(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 2);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor mapScope;
|
||||||
|
Out<RowCursor> tempOut_mapScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedMap>typeAs().ReadScope(tempReference_Row, scope, tempOut_mapScope));
|
||||||
|
mapScope = tempOut_mapScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
int i = 0;
|
||||||
|
List items = (List)value;
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
while (mapScope.MoveNext(tempReference_Row2)) {
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref mapScope, null, LayoutType.TypedTuple, typeArgs.clone(),
|
||||||
|
items.get(i++));
|
||||||
|
}
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchNullable(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutNullable>typeAs().ReadScope(tempReference_Row, scope, tempOut_nullableScope));
|
||||||
|
nullableScope = tempOut_nullableScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Reference<RowCursor> tempReference_nullableScope =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
ResultAssert.IsSuccess(LayoutNullable.HasValue(tempReference_Row2, tempReference_nullableScope));
|
||||||
|
nullableScope = tempReference_nullableScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
nullableScope.MoveNext(tempReference_Row3);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref nullableScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), value);
|
||||||
|
} else {
|
||||||
|
Reference<RowBuffer> tempReference_Row4 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Reference<RowCursor> tempReference_nullableScope2 =
|
||||||
|
new Reference<RowCursor>(nullableScope);
|
||||||
|
ResultAssert.NotFound(LayoutNullable.HasValue(tempReference_Row4, tempReference_nullableScope2));
|
||||||
|
nullableScope = tempReference_nullableScope2.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row4.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchObject(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchSet(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor setScope;
|
||||||
|
Out<RowCursor> tempOut_setScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedSet>typeAs().ReadScope(tempReference_Row, scope, tempOut_setScope));
|
||||||
|
setScope = tempOut_setScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
int i = 0;
|
||||||
|
List items = (List)value;
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
while (setScope.MoveNext(tempReference_Row2)) {
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref setScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), items.get(i++));
|
||||||
|
}
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchTuple(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() >= 2);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor tupleScope;
|
||||||
|
Out<RowCursor> tempOut_tupleScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutIndexedScope>typeAs().ReadScope(tempReference_Row, scope, tempOut_tupleScope));
|
||||||
|
tupleScope = tempOut_tupleScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
for (int i = 0; i < typeArgs.count(); i++) {
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
tupleScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
PropertyInfo valueAccessor = value.getClass().GetProperty(String.format("Item%1$s", i + 1));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref tupleScope, null, typeArgs.get(i).type(),
|
||||||
|
typeArgs.get(i).typeArgs().clone(), valueAccessor.GetValue(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchUDT(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
Reference<RowBuffer> tempReference_Row = new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor udtScope;
|
||||||
|
Out<RowCursor> tempOut_udtScope = new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutUDT>typeAs().ReadScope(tempReference_Row, scope, tempOut_udtScope));
|
||||||
|
udtScope = tempOut_udtScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
IDispatchable valueDispatcher = value instanceof IDispatchable ? (IDispatchable)value : null;
|
||||||
|
assert valueDispatcher != null;
|
||||||
|
Reference<RowCursor> tempReference_udtScope = new Reference<RowCursor>(udtScope);
|
||||||
|
valueDispatcher.Dispatch(dispatcher, tempReference_udtScope);
|
||||||
|
udtScope = tempReference_udtScope.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,242 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.recordio.RecordIOStream;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.Segment;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.unit.customerschema.Address;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(RecordIOUnitTests.SchemaFile, "TestData")] public class RecordIOUnitTests
|
||||||
|
public class RecordIOUnitTests {
|
||||||
|
private static final int InitialRowSize = 0;
|
||||||
|
private static final String SchemaFile = "TestData\\CustomerSchema.json";
|
||||||
|
private Layout addressLayout;
|
||||||
|
private Namespace ns;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void LoadSchema()
|
||||||
|
public final void LoadSchema() {
|
||||||
|
LayoutResolver systemResolver = SystemSchema.LayoutResolver;
|
||||||
|
Layout segmentLayout = systemResolver.Resolve(SystemSchema.SegmentSchemaId);
|
||||||
|
assert segmentLayout.getName().equals("Segment");
|
||||||
|
assert segmentLayout.getSchemaId().clone() == SystemSchema.SegmentSchemaId;
|
||||||
|
|
||||||
|
Layout recordLayout = systemResolver.Resolve(SystemSchema.RecordSchemaId);
|
||||||
|
assert recordLayout.getName().equals("Record");
|
||||||
|
assert recordLayout.getSchemaId().clone() == SystemSchema.RecordSchemaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public final void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString(RecordIOUnitTests.SchemaFile);
|
||||||
|
this.ns = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.ns);
|
||||||
|
this.addressLayout = this.resolver.Resolve(tangible.ListHelper.find(this.ns.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Address")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public async Task RoundTripAsync()
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent in Java to the 'async' keyword:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public async Task RoundTripAsync()
|
||||||
|
public final Task RoundTripAsync() {
|
||||||
|
Address tempVar = new Address();
|
||||||
|
tempVar.setStreet("300B Chocolate Hole");
|
||||||
|
tempVar.setCity("Great Cruz Bay");
|
||||||
|
tempVar.setState("VI");
|
||||||
|
PostalCode tempVar2 = new PostalCode();
|
||||||
|
tempVar2.setZip(00830);
|
||||||
|
tempVar2.setPlus4(0001);
|
||||||
|
tempVar.setPostalCode(tempVar2);
|
||||||
|
Address tempVar3 = new Address();
|
||||||
|
tempVar3.setStreet("1 Microsoft Way");
|
||||||
|
tempVar3.setCity("Redmond");
|
||||||
|
tempVar3.setState("WA");
|
||||||
|
PostalCode tempVar4 = new PostalCode();
|
||||||
|
tempVar4.setZip(98052);
|
||||||
|
tempVar3.setPostalCode(tempVar4);
|
||||||
|
Address[] addresses = { tempVar, tempVar3 };
|
||||||
|
|
||||||
|
String sampleComment = "hello there";
|
||||||
|
String sampleSDL = "some SDL";
|
||||||
|
|
||||||
|
try (Stream stm = new MemoryStream()) {
|
||||||
|
// Create a reusable, resizable buffer.
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MemorySpanResizer<byte> resizer = new MemorySpanResizer<byte>(RecordIOUnitTests
|
||||||
|
// .InitialRowSize);
|
||||||
|
MemorySpanResizer<Byte> resizer = new MemorySpanResizer<Byte>(RecordIOUnitTests.InitialRowSize);
|
||||||
|
|
||||||
|
// Write a RecordIO stream.
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'out' keyword - these are
|
||||||
|
// not converted by C# to Java Converter:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: Result r = await stm.WriteRecordIOAsync(new Segment(sampleComment, sampleSDL), (long
|
||||||
|
// index, out ReadOnlyMemory<byte> body) =>
|
||||||
|
Result r = await
|
||||||
|
RecordIOStream.WriteRecordIOAsync(stm,
|
||||||
|
new Segment(sampleComment, sampleSDL), (long index, out ReadOnlyMemory<Byte>body) ->
|
||||||
|
{
|
||||||
|
body = null;
|
||||||
|
if (index >= addresses.length) {
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
Out<ReadOnlyMemory<Byte>> tempOut_body = new Out<ReadOnlyMemory<Byte>>();
|
||||||
|
Task tempVar5 = this.WriteAddress(resizer, addresses[index], tempOut_body);
|
||||||
|
body = tempOut_body.get();
|
||||||
|
return tempVar5;
|
||||||
|
});
|
||||||
|
|
||||||
|
// Read a RecordIO stream.
|
||||||
|
ArrayList<Address> addressesRead = new ArrayList<Address>();
|
||||||
|
stm.Position = 0;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: resizer = new MemorySpanResizer<byte>(1);
|
||||||
|
resizer = new MemorySpanResizer<Byte>(1);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to 'await' in Java:
|
||||||
|
r = await
|
||||||
|
RecordIOStream.ReadRecordIOAsync(stm, record ->
|
||||||
|
{
|
||||||
|
assert !record.IsEmpty;
|
||||||
|
|
||||||
|
Address obj;
|
||||||
|
Out<Address> tempOut_obj = new Out<Address>();
|
||||||
|
r = this.ReadAddress(record, tempOut_obj);
|
||||||
|
obj = tempOut_obj.get();
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
addressesRead.add(obj);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}, segment ->
|
||||||
|
{
|
||||||
|
assert !segment.IsEmpty;
|
||||||
|
|
||||||
|
Segment obj;
|
||||||
|
Out<Segment> tempOut_obj =
|
||||||
|
new Out<Segment>();
|
||||||
|
r = this.ReadSegment(segment, tempOut_obj);
|
||||||
|
obj = tempOut_obj.get();
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
assert obj.comment() == sampleComment;
|
||||||
|
assert obj.sdl() == sampleSDL;
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}, resizer);
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(r);
|
||||||
|
|
||||||
|
// Check that the values all round-tripped.
|
||||||
|
assert addresses.length == addressesRead.size();
|
||||||
|
for (int i = 0; i < addresses.length; i++) {
|
||||||
|
assert addresses[i] == addressesRead.get(i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private Result ReadAddress(Memory<byte> buffer, out Address obj)
|
||||||
|
private Result ReadAddress(Memory<Byte> buffer, Out<Address> obj) {
|
||||||
|
RowBuffer row = new RowBuffer(buffer.Span, HybridRowVersion.V1, this.resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
|
||||||
|
// Use the reader to dump to the screen.
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
String str;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
Result r = DiagnosticConverter.ReaderToString(tempReference_reader, out str);
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
obj.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
// Reset the reader and materialize the object.
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
reader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
Reference<RowReader> tempReference_reader2 =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
Result tempVar = AddressSerializer.Read(tempReference_reader2, obj);
|
||||||
|
reader = tempReference_reader2.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private Result ReadSegment(Memory<byte> buffer, out Segment obj)
|
||||||
|
private Result ReadSegment(Memory<Byte> buffer, Out<Segment> obj) {
|
||||||
|
RowBuffer row = new RowBuffer(buffer.Span, HybridRowVersion.V1, SystemSchema.LayoutResolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
|
||||||
|
// Use the reader to dump to the screen.
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
String str;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
Result r = DiagnosticConverter.ReaderToString(tempReference_reader, out str);
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
obj.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
System.out.println(str);
|
||||||
|
|
||||||
|
// Reset the reader and materialize the object.
|
||||||
|
Reference<RowBuffer> tempReference_row2 = new Reference<RowBuffer>(row);
|
||||||
|
reader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
Reference<RowReader> tempReference_reader2 = new Reference<RowReader>(reader);
|
||||||
|
Result tempVar = SegmentSerializer.Read(tempReference_reader2, obj.clone());
|
||||||
|
reader = tempReference_reader2.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private Result WriteAddress(MemorySpanResizer<byte> resizer, Address obj, out
|
||||||
|
// ReadOnlyMemory<byte> buffer)
|
||||||
|
private Result WriteAddress(MemorySpanResizer<Byte> resizer, Address obj,
|
||||||
|
Out<ReadOnlyMemory<Byte>> buffer) {
|
||||||
|
RowBuffer row = new RowBuffer(RecordIOUnitTests.InitialRowSize, resizer);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.addressLayout, this.resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Result r = RowWriter.WriteBuffer(tempReference_row, obj, AddressSerializer.Write);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
buffer.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
buffer.setAndGet(resizer.getMemory().Slice(0, row.length()));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,80 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
|
||||||
|
public final class ResultAssert {
|
||||||
|
public static void Exists(Result actual) {
|
||||||
|
assert Result.EXISTS == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Exists(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.EXISTS, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void Exists(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.EXISTS, actual, message, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InsufficientPermissions(Result actual) {
|
||||||
|
assert Result.INSUFFICIENT_PERMISSIONS == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InsufficientPermissions(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.INSUFFICIENT_PERMISSIONS, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void InsufficientPermissions(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.INSUFFICIENT_PERMISSIONS, actual, message, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void IsSuccess(Result actual) {
|
||||||
|
assert Result.SUCCESS == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void IsSuccess(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.SUCCESS, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void IsSuccess(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.SUCCESS, actual, message, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NotFound(Result actual) {
|
||||||
|
assert Result.NOT_FOUND == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NotFound(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.NOT_FOUND, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void NotFound(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.NOT_FOUND, actual, message, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeConstraint(Result actual) {
|
||||||
|
assert Result.TYPE_CONSTRAINT == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeConstraint(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.TYPE_CONSTRAINT, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeConstraint(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.TYPE_CONSTRAINT, actual, message, parameters);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeMismatch(Result actual) {
|
||||||
|
assert Result.TYPE_MISMATCH == actual;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeMismatch(Result actual, String message) {
|
||||||
|
Assert.AreEqual(Result.TYPE_MISMATCH, actual, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void TypeMismatch(Result actual, String message, Object... parameters) {
|
||||||
|
Assert.AreEqual(Result.TYPE_MISMATCH, actual, message, parameters);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,70 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class RowBufferUnitTests
|
||||||
|
public class RowBufferUnitTests {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1139:UseLiteralsSuffixNotationInsteadOfCasting", Justification = "Explicit")] public void VarIntTest()
|
||||||
|
public final void VarIntTest() {
|
||||||
|
// Brute force test all signed 16-bit values.
|
||||||
|
for (int i = Short.MIN_VALUE; i <= Short.MAX_VALUE; i++) {
|
||||||
|
short s = (short)i;
|
||||||
|
this.RoundTripVarInt(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test boundary conditions for larger values.
|
||||||
|
this.RoundTripVarInt(0);
|
||||||
|
this.RoundTripVarInt(Integer.MIN_VALUE);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.RoundTripVarInt(unchecked((int)0x80000000ul));
|
||||||
|
this.RoundTripVarInt(0x80000000);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.RoundTripVarInt(unchecked((int)0x7FFFFFFFul));
|
||||||
|
this.RoundTripVarInt(0x7FFFFFFF);
|
||||||
|
this.RoundTripVarInt(Integer.MAX_VALUE);
|
||||||
|
this.RoundTripVarInt(Long.MIN_VALUE);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.RoundTripVarInt(unchecked((long)0x8000000000000000ul));
|
||||||
|
this.RoundTripVarInt((long)0x8000000000000000);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: this.RoundTripVarInt(unchecked((long)0x7FFFFFFFFFFFFFFFul));
|
||||||
|
this.RoundTripVarInt((long)0x7FFFFFFFFFFFFFFF);
|
||||||
|
this.RoundTripVarInt(Long.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RoundTripVarInt(short s) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
|
||||||
|
long encoded = RowBuffer.rotateSignToLsb(s);
|
||||||
|
long decoded = RowBuffer.rotateSignToMsb(encoded);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: short t = unchecked((short)decoded);
|
||||||
|
short t = (short)decoded;
|
||||||
|
Assert.AreEqual(s, t, "Value: {0}", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RoundTripVarInt(int s) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
|
||||||
|
long encoded = RowBuffer.rotateSignToLsb(s);
|
||||||
|
long decoded = RowBuffer.rotateSignToMsb(encoded);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to 'unchecked' in this context:
|
||||||
|
//ORIGINAL LINE: int t = unchecked((int)decoded);
|
||||||
|
int t = (int)decoded;
|
||||||
|
Assert.AreEqual(s, t, "Value: {0}", s);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RoundTripVarInt(long s) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ulong encoded = RowBuffer.RotateSignToLsb(s);
|
||||||
|
long encoded = RowBuffer.rotateSignToLsb(s);
|
||||||
|
long decoded = RowBuffer.rotateSignToMsb(encoded);
|
||||||
|
Assert.AreEqual(s, decoded, "Value: {0}", s);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,437 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Float128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.NullValue;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBinary;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutBoolean;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutDecimal;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutFloat128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutFloat32;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutFloat64;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutGuid;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt16;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt32;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt64;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutInt8;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutMongoDbObjectId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutNull;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutResolver;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt16;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt32;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt64;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUInt8;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUnixDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutUtf8;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutVarInt;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutVarUInt;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1402 // FileMayOnlyContainASingleType
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1201 // OrderingRules
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Public Fields
|
||||||
|
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal ref struct RowOperationDispatcher
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java has no equivalent to the C# ref struct:
|
||||||
|
public final class RowOperationDispatcher {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
public LayoutResolver Resolver;
|
||||||
|
public RowBuffer Row = new RowBuffer();
|
||||||
|
private IDispatcher dispatcher;
|
||||||
|
|
||||||
|
public RowOperationDispatcher() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private RowOperationDispatcher(IDispatcher dispatcher, Layout layout, LayoutResolver resolver) {
|
||||||
|
this.dispatcher = dispatcher;
|
||||||
|
this.Row = new RowBuffer(RowOperationDispatcher.InitialRowSize);
|
||||||
|
this.Resolver = resolver;
|
||||||
|
this.Row.initLayout(HybridRowVersion.V1, layout, this.Resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
private RowOperationDispatcher(IDispatcher dispatcher, LayoutResolver resolver, String expected) {
|
||||||
|
this.dispatcher = dispatcher;
|
||||||
|
this.Row = new RowBuffer(RowOperationDispatcher.InitialRowSize);
|
||||||
|
this.Resolver = resolver;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: byte[] bytes = ByteConverter.ToBytes(expected);
|
||||||
|
byte[] bytes = ByteConverter.ToBytes(expected);
|
||||||
|
this.Row.readFrom(bytes, HybridRowVersion.V1, this.Resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The C# 'struct' constraint has no equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public static RowOperationDispatcher Create<TDispatcher>(Layout layout, LayoutResolver resolver)
|
||||||
|
// where TDispatcher : struct, IDispatcher
|
||||||
|
public static <TDispatcher extends IDispatcher> RowOperationDispatcher Create(Layout layout,
|
||||||
|
LayoutResolver resolver) {
|
||||||
|
return new RowOperationDispatcher(null, layout, resolver);
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowReader GetReader() {
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(this.Row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following line could not be converted:
|
||||||
|
return new RowReader(ref this.Row)
|
||||||
|
this.Row = tempReference_Row.get();
|
||||||
|
return tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(String path, LayoutType type, TypeArgumentList typeArgs) {
|
||||||
|
LayoutCodeSwitch(path, type, typeArgs, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(String path, LayoutType type) {
|
||||||
|
LayoutCodeSwitch(path, type, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(String path) {
|
||||||
|
LayoutCodeSwitch(path, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch() {
|
||||||
|
LayoutCodeSwitch(null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void LayoutCodeSwitch(string path = null, LayoutType type = null, TypeArgumentList
|
||||||
|
// typeArgs = default, object value = null)
|
||||||
|
public void LayoutCodeSwitch(String path, LayoutType type, TypeArgumentList typeArgs, Object value) {
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(this.Row);
|
||||||
|
RowCursor root = RowCursor.create(tempReference_Row);
|
||||||
|
this.Row = tempReference_Row.get();
|
||||||
|
Reference<RowCursor> tempReference_root =
|
||||||
|
new Reference<RowCursor>(root);
|
||||||
|
this.LayoutCodeSwitch(tempReference_root, path, type, typeArgs.clone(), value);
|
||||||
|
root = tempReference_root.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(Reference<RowCursor> scope, String path, LayoutType type,
|
||||||
|
TypeArgumentList typeArgs) {
|
||||||
|
LayoutCodeSwitch(scope, path, type, typeArgs, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(Reference<RowCursor> scope, String path, LayoutType type) {
|
||||||
|
LayoutCodeSwitch(scope, path, type, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(Reference<RowCursor> scope, String path) {
|
||||||
|
LayoutCodeSwitch(scope, path, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void LayoutCodeSwitch(Reference<RowCursor> scope) {
|
||||||
|
LayoutCodeSwitch(scope, null, null, null, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void LayoutCodeSwitch(ref RowCursor scope, string path = null, LayoutType type = null,
|
||||||
|
// TypeArgumentList typeArgs = default, object value = null)
|
||||||
|
public void LayoutCodeSwitch(Reference<RowCursor> scope, String path, LayoutType type,
|
||||||
|
TypeArgumentList typeArgs, Object value) {
|
||||||
|
LayoutColumn col = null;
|
||||||
|
if (type == null) {
|
||||||
|
assert path != null;
|
||||||
|
Out<LayoutColumn> tempOut_col =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert scope.get().getLayout().TryFind(path, tempOut_col);
|
||||||
|
col = tempOut_col.get();
|
||||||
|
assert col != null;
|
||||||
|
type = col.type();
|
||||||
|
typeArgs = col.typeArgs().clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((path != null) && (col == null || col.storage() == StorageKind.SPARSE)) {
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(this.Row);
|
||||||
|
scope.get().Find(tempReference_Row, path);
|
||||||
|
this.Row = tempReference_Row.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type.LayoutCode) {
|
||||||
|
case Null:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutNull, NullValue>Dispatch(tempReference_this, scope, col, type, NullValue.DEFAULT);
|
||||||
|
this = tempReference_this.get();
|
||||||
|
break;
|
||||||
|
case Boolean:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this2 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutBoolean, Boolean>Dispatch(tempReference_this2, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this2.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Int8:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this3 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutInt8, Byte>Dispatch(tempReference_this3, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this3.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Int16:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this4 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutInt16, Short>Dispatch(tempReference_this4, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this4.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Int32:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this5 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutInt32, Integer>Dispatch(tempReference_this5, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this5.get();
|
||||||
|
break;
|
||||||
|
case Int64:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this6 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutInt64, Long>Dispatch(tempReference_this6, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this6.get();
|
||||||
|
break;
|
||||||
|
case UInt8:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this7 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutUInt8, byte>(tempRef_this7, scope, col, type,
|
||||||
|
// (Nullable<byte>)value != null ? value : default);
|
||||||
|
this.dispatcher.<LayoutUInt8, Byte>Dispatch(tempReference_this7, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this7.get();
|
||||||
|
break;
|
||||||
|
case UInt16:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this8 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutUInt16, ushort>(tempRef_this8, scope, col, type,
|
||||||
|
// (Nullable<ushort>)value != null ? value : default);
|
||||||
|
this.dispatcher.<LayoutUInt16, Short>Dispatch(tempReference_this8, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this8.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case UInt32:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this9 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutUInt32, uint>(tempRef_this9, scope, col, type,
|
||||||
|
// (Nullable<uint>)value != null ? value : default);
|
||||||
|
this.dispatcher.<LayoutUInt32, Integer>Dispatch(tempReference_this9, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this9.get();
|
||||||
|
break;
|
||||||
|
case UInt64:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this10 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutUInt64, ulong>(tempRef_this10, scope, col, type,
|
||||||
|
// (Nullable<ulong>)value != null ? value : default);
|
||||||
|
this.dispatcher.<LayoutUInt64, Long>Dispatch(tempReference_this10, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this10.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case VarInt:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this11 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutVarInt, Long>Dispatch(tempReference_this11, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this11.get();
|
||||||
|
break;
|
||||||
|
case VarUInt:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this12 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutVarUInt, ulong>(tempRef_this12, scope, col, type,
|
||||||
|
// (Nullable<ulong>)value != null ? value : default);
|
||||||
|
this.dispatcher.<LayoutVarUInt, Long>Dispatch(tempReference_this12, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this12.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Float32:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this13 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutFloat32, Float>Dispatch(tempReference_this13, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this13.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Float64:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this14 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutFloat64, Double>Dispatch(tempReference_this14, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this14.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Float128:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this15 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutFloat128, Float128>Dispatch(tempReference_this15, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this15.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Decimal:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this16 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutDecimal, BigDecimal>Dispatch(tempReference_this16, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this16.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case DateTime:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this17 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutDateTime, LocalDateTime>Dispatch(tempReference_this17, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this17.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case UnixDateTime:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this18 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutUnixDateTime, UnixDateTime>Dispatch(tempReference_this18, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this18.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Guid:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this19 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutGuid, UUID>Dispatch(tempReference_this19, scope, col, type, value != null ?
|
||||||
|
value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this19.get();
|
||||||
|
break;
|
||||||
|
case MongoDbObjectId:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this20 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutMongoDbObjectId, MongoDbObjectId>Dispatch(tempReference_this20, scope, col, type,
|
||||||
|
value != null ? value :
|
||||||
|
default)
|
||||||
|
this = tempReference_this20.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Utf8:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this21 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.<LayoutUtf8, String>Dispatch(tempReference_this21, scope, col, type, (String)value);
|
||||||
|
this = tempReference_this21.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case Binary:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this22 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: this.dispatcher.Dispatch<LayoutBinary, byte[]>(ref this, ref scope, col, type,
|
||||||
|
// (byte[])value);
|
||||||
|
this.dispatcher.<LayoutBinary, byte[]>Dispatch(tempReference_this22, scope, col, type, (byte[])value);
|
||||||
|
this = tempReference_this22.get();
|
||||||
|
|
||||||
|
break;
|
||||||
|
case ObjectScope:
|
||||||
|
case ImmutableObjectScope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this23 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchObject(tempReference_this23, scope);
|
||||||
|
this = tempReference_this23.get();
|
||||||
|
break;
|
||||||
|
case TypedArrayScope:
|
||||||
|
case ImmutableTypedArrayScope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this24 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchArray(tempReference_this24, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this24.get();
|
||||||
|
break;
|
||||||
|
case TypedSetScope:
|
||||||
|
case ImmutableTypedSetScope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this25 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchSet(tempReference_this25, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this25.get();
|
||||||
|
break;
|
||||||
|
case TypedMapScope:
|
||||||
|
case ImmutableTypedMapScope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this26 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchMap(tempReference_this26, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this26.get();
|
||||||
|
break;
|
||||||
|
case TupleScope:
|
||||||
|
case ImmutableTupleScope:
|
||||||
|
case TypedTupleScope:
|
||||||
|
case ImmutableTypedTupleScope:
|
||||||
|
case TaggedScope:
|
||||||
|
case ImmutableTaggedScope:
|
||||||
|
case Tagged2Scope:
|
||||||
|
case ImmutableTagged2Scope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this27 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchTuple(tempReference_this27, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this27.get();
|
||||||
|
break;
|
||||||
|
case NullableScope:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this28 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchNullable(tempReference_this28, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this28.get();
|
||||||
|
break;
|
||||||
|
case Schema:
|
||||||
|
case ImmutableSchema:
|
||||||
|
Reference<RowOperationDispatcher> tempReference_this29 = new Reference<RowOperationDispatcher>(this);
|
||||||
|
this.dispatcher.DispatchUDT(tempReference_this29, scope, type, typeArgs.clone(), value);
|
||||||
|
this = tempReference_this29.get();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
if (logger.)
|
||||||
|
throw new IllegalStateException(lenientFormat("Unknown type will be ignored: %s", type.LayoutCode));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The C# 'struct' constraint has no equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public static RowOperationDispatcher ReadFrom<TDispatcher>(LayoutResolver resolver, string
|
||||||
|
// expected) where TDispatcher : struct, IDispatcher
|
||||||
|
public static <TDispatcher extends IDispatcher> RowOperationDispatcher ReadFrom(LayoutResolver resolver,
|
||||||
|
String expected) {
|
||||||
|
return new RowOperationDispatcher(null, resolver, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String RowToHex() {
|
||||||
|
try (MemoryStream stm = new MemoryStream()) {
|
||||||
|
this.Row.writeTo(stm);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ReadOnlyMemory<byte> bytes = stm.GetBuffer().AsMemory(0, (int)stm.Position);
|
||||||
|
ReadOnlyMemory<Byte> bytes = stm.GetBuffer().AsMemory(0, (int)stm.Position);
|
||||||
|
return ByteConverter.ToHex(bytes.Span);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowOperationDispatcher clone() {
|
||||||
|
RowOperationDispatcher varCopy = new RowOperationDispatcher();
|
||||||
|
|
||||||
|
varCopy.Resolver = this.Resolver;
|
||||||
|
varCopy.Row = this.Row.clone();
|
||||||
|
varCopy.dispatcher = this.dispatcher;
|
||||||
|
|
||||||
|
return varCopy;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,426 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Float128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.MemorySpanResizer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.NullValue;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Test code.")][DeploymentItem(RowReaderUnitTests
|
||||||
|
// .SchemaFile, "TestData")] public sealed class RowReaderUnitTests
|
||||||
|
public final class RowReaderUnitTests {
|
||||||
|
private static final LocalDateTime SampleDateTime = LocalDateTime.parse("2018-08-14 02:05:00.0000000");
|
||||||
|
private static final Float128 SampleFloat128 = new Float128(0, 42);
|
||||||
|
private static final UUID SampleGuid = UUID.fromString("{2A9C25B9-922E-4611-BB0A-244A9496503C}");
|
||||||
|
private static final MongoDbObjectId SampleMongoDbObjectId = new MongoDbObjectId(0, 42);
|
||||||
|
private static final UnixDateTime SampleUnixDateTime = new UnixDateTime(42);
|
||||||
|
private static final String SchemaFile = "TestData\\ReaderSchema.json";
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString(RowReaderUnitTests.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void PrintReader(Reference<RowReader> reader, int indent) {
|
||||||
|
String str;
|
||||||
|
Out<String> tempOut_str = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(DiagnosticConverter.ReaderToString(reader, tempOut_str));
|
||||||
|
str = tempOut_str.get();
|
||||||
|
System.out.println(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ReadMixed()
|
||||||
|
public void ReadMixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Mixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowOperationDispatcher d = RowOperationDispatcher.<WriteRowDispatcher>Create(layout, this.resolver);
|
||||||
|
d.LayoutCodeSwitch("null");
|
||||||
|
d.LayoutCodeSwitch("bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("float128", value:RowReaderUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("datetime", value:RowReaderUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("unixdatetime", value:RowReaderUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("guid", value:RowReaderUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("mongodbobjectid", value:RowReaderUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("utf8", value:"abc")
|
||||||
|
d.LayoutCodeSwitch("utf8_span", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("binary_span", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("binary_span", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("var_varint", value:-6148914691236517206L)
|
||||||
|
d.LayoutCodeSwitch("var_varuint", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("var_utf8", value:"abc")
|
||||||
|
d.LayoutCodeSwitch("var_utf8_span", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("var_binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("var_binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("var_binary_span", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("var_binary_span", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("sparse_null");
|
||||||
|
d.LayoutCodeSwitch("sparse_bool", value:true)
|
||||||
|
d.LayoutCodeSwitch("sparse_int8", value:(byte)-86)
|
||||||
|
d.LayoutCodeSwitch("sparse_int16", value:(short)-21846)
|
||||||
|
d.LayoutCodeSwitch("sparse_int32", value:-1431655766)
|
||||||
|
d.LayoutCodeSwitch("sparse_int64", value:-6148914691236517206L)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("sparse_uint8", value: (byte)0xAA);
|
||||||
|
d.LayoutCodeSwitch("sparse_uint8", value:(byte)0xAA)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("sparse_uint16", value: (ushort)0xAAAA);
|
||||||
|
d.LayoutCodeSwitch("sparse_uint16", value:(short)0xAAAA)
|
||||||
|
d.LayoutCodeSwitch("sparse_uint32", value:0xAAAAAAAA)
|
||||||
|
d.LayoutCodeSwitch("sparse_uint64", value:0xAAAAAAAAAAAAAAAAL)
|
||||||
|
d.LayoutCodeSwitch("sparse_float32", value:1.0F / 3.0F)
|
||||||
|
d.LayoutCodeSwitch("sparse_float64", value:1.0 / 3.0)
|
||||||
|
d.LayoutCodeSwitch("sparse_float128", value:RowReaderUnitTests.SampleFloat128)
|
||||||
|
d.LayoutCodeSwitch("sparse_decimal", value:java.math.BigDecimal.ONE / 3.0)
|
||||||
|
d.LayoutCodeSwitch("sparse_datetime", value:RowReaderUnitTests.SampleDateTime)
|
||||||
|
d.LayoutCodeSwitch("sparse_unixdatetime", value:RowReaderUnitTests.SampleUnixDateTime)
|
||||||
|
d.LayoutCodeSwitch("sparse_guid", value:RowReaderUnitTests.SampleGuid)
|
||||||
|
d.LayoutCodeSwitch("sparse_mongodbobjectid", value:RowReaderUnitTests.SampleMongoDbObjectId)
|
||||||
|
d.LayoutCodeSwitch("sparse_utf8", value:"abc")
|
||||||
|
d.LayoutCodeSwitch("sparse_utf8_span", value:"abc")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("sparse_binary", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("sparse_binary", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("sparse_binary_span", value: new[] { (byte)0, (byte)1, (byte)2 });
|
||||||
|
d.LayoutCodeSwitch("sparse_binary_span", value:new byte[] { (byte)0, (byte)1, (byte)2 })
|
||||||
|
d.LayoutCodeSwitch("array_t<int8>", value:new byte[] { -86, -86, -86 })
|
||||||
|
d.LayoutCodeSwitch("array_t<array_t<float32>>", value:new float[][]
|
||||||
|
{
|
||||||
|
new float[] { 1, 2, 3 },
|
||||||
|
new float[] { 1, 2, 3 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("array_t<utf8>", value:new String[] { "abc", "def", "hij" })
|
||||||
|
d.LayoutCodeSwitch("tuple<varint,int64>", value:Tuple.Create(-6148914691236517206L, -6148914691236517206L))
|
||||||
|
d.LayoutCodeSwitch("tuple<null,tuple<int8,int8>>", value:
|
||||||
|
Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)))
|
||||||
|
d.LayoutCodeSwitch("tuple<bool,udt>", value:Tuple.Create(false, new Point(1, 2)))
|
||||||
|
d.LayoutCodeSwitch("nullable<int32,int64>", value:Tuple.Create(null, (Long)123L))
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("tagged<utf8>", value: Tuple.Create((byte)3, "hello"));
|
||||||
|
d.LayoutCodeSwitch("tagged<utf8>", value:Tuple.Create((byte)3, "hello"))
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: d.LayoutCodeSwitch("tagged<bool,utf8>", value: Tuple.Create((byte)5, true, "bye"));
|
||||||
|
d.LayoutCodeSwitch("tagged<bool,utf8>", value:Tuple.Create((byte)5, true, "bye"))
|
||||||
|
d.LayoutCodeSwitch("set_t<utf8>", value:new String[] { "abc", "efg", "xzy" })
|
||||||
|
d.LayoutCodeSwitch("set_t<array_t<int8>>", value:new byte[][]
|
||||||
|
{
|
||||||
|
new byte[] { 1, 2, 3 },
|
||||||
|
new byte[] { 4, 5, 6 },
|
||||||
|
new byte[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<set_t<int32>>", value:new int[][]
|
||||||
|
{
|
||||||
|
new int[] { 1, 2, 3 },
|
||||||
|
new int[] { 4, 5, 6 },
|
||||||
|
new int[] { 7, 8, 9 }
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("set_t<udt>", value:new Point[]
|
||||||
|
{
|
||||||
|
new Point(1, 2),
|
||||||
|
new Point(3, 4),
|
||||||
|
new Point(5, 6)
|
||||||
|
})
|
||||||
|
d.LayoutCodeSwitch("map_t<utf8,utf8>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create("Mark", "Luke"), Tuple.Create("Harrison", "Han") })
|
||||||
|
d.LayoutCodeSwitch("map_t<int8,array_t<int8>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((byte)1, new byte[] { 1, 2, 3 }), Tuple.Create((byte)2,
|
||||||
|
new byte[] { 4, 5, 6 }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<int16,map_t<int32,int32>>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create((short)1, new System.Tuple<T1, T2>[] { Tuple.Create(1, 2),
|
||||||
|
Tuple.Create(3, 4) }), Tuple.Create((short)2, new System.Tuple<T1, T2>[] { Tuple.Create(5, 6),
|
||||||
|
Tuple.Create(7, 8) }) })
|
||||||
|
|
||||||
|
d.LayoutCodeSwitch("map_t<float64,udt>", value:
|
||||||
|
new System.Tuple<T1, T2>[] { Tuple.Create(1.0, new Point(1, 2)), Tuple.Create(2.0, new Point(3, 4)),
|
||||||
|
Tuple.Create(3.0, new Point(5, 6)) })
|
||||||
|
|
||||||
|
RowReader reader = d.GetReader().clone();
|
||||||
|
assert reader.length() == d.Row.length();
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
RowReaderUnitTests.PrintReader(tempReference_reader, 0);
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ReadScopes()
|
||||||
|
public void ReadScopes() {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: MemorySpanResizer<byte> resizer = new MemorySpanResizer<byte>(0);
|
||||||
|
MemorySpanResizer<Byte> resizer = new MemorySpanResizer<Byte>(0);
|
||||||
|
RowBuffer row = new RowBuffer(0, resizer);
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Mixed")).SchemaId);
|
||||||
|
row.initLayout(HybridRowVersion.V1, layout, this.resolver);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
ResultAssert.IsSuccess(RowWriter.WriteBuffer(tempReference_row, 2, RowReaderUnitTests.WriteNestedDocument));
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader rowReader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
|
||||||
|
Reference<RowReader> tempReference_rowReader =
|
||||||
|
new Reference<RowReader>(rowReader);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentDelegate(tempReference_rowReader, 0));
|
||||||
|
rowReader = tempReference_rowReader.get();
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
rowReader = new RowReader(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Reference<RowReader> tempReference_rowReader2 =
|
||||||
|
new Reference<RowReader>(rowReader);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentNonDelegate(tempReference_rowReader2, 0));
|
||||||
|
rowReader = tempReference_rowReader2.get();
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
rowReader = new RowReader(tempReference_row4);
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
Reference<RowReader> tempReference_rowReader3 =
|
||||||
|
new Reference<RowReader>(rowReader);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentNonDelegateWithSkipScope(tempReference_rowReader3, 0));
|
||||||
|
rowReader = tempReference_rowReader3.get();
|
||||||
|
|
||||||
|
// SkipScope not okay after advancing parent
|
||||||
|
Reference<RowBuffer> tempReference_row5 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
rowReader = new RowReader(tempReference_row5);
|
||||||
|
row = tempReference_row5.get();
|
||||||
|
assert rowReader.read();
|
||||||
|
assert rowReader.type().LayoutCode == LayoutCode.ObjectScope;
|
||||||
|
RowReader nestedScope = rowReader.readScope().clone();
|
||||||
|
Reference<RowReader> tempReference_nestedScope =
|
||||||
|
new Reference<RowReader>(nestedScope);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentDelegate(tempReference_nestedScope, 0));
|
||||||
|
nestedScope = tempReference_nestedScope.get();
|
||||||
|
assert rowReader.read();
|
||||||
|
Reference<RowReader> tempReference_nestedScope2 =
|
||||||
|
new Reference<RowReader>(nestedScope);
|
||||||
|
Result result = rowReader.skipScope(tempReference_nestedScope2);
|
||||||
|
nestedScope = tempReference_nestedScope2.get();
|
||||||
|
assert Result.SUCCESS != result;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result ReadNestedDocumentDelegate(Reference<RowReader> reader, int context) {
|
||||||
|
while (reader.get().read()) {
|
||||||
|
switch (reader.get().type().LayoutCode) {
|
||||||
|
case TupleScope: {
|
||||||
|
ResultAssert.IsSuccess(reader.get().readScope(0, RowReaderUnitTests.ReadTuplePartial));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectScope: {
|
||||||
|
ResultAssert.IsSuccess(reader.get().readScope(0, RowReaderUnitTests.ReadNestedDocumentDelegate));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result ReadNestedDocumentNonDelegate(Reference<RowReader> reader, int context) {
|
||||||
|
while (reader.get().read()) {
|
||||||
|
switch (reader.get().type().LayoutCode) {
|
||||||
|
case TupleScope: {
|
||||||
|
RowReader nested = reader.get().readScope().clone();
|
||||||
|
Reference<RowReader> tempReference_nested =
|
||||||
|
new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadTuplePartial(tempReference_nested, 0));
|
||||||
|
nested = tempReference_nested.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectScope: {
|
||||||
|
RowReader nested = reader.get().readScope().clone();
|
||||||
|
Reference<RowReader> tempReference_nested2 =
|
||||||
|
new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentNonDelegate(tempReference_nested2, 0));
|
||||||
|
nested = tempReference_nested2.get();
|
||||||
|
ResultAssert.IsSuccess(reader.get().readScope(0, RowReaderUnitTests.ReadNestedDocumentDelegate));
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result ReadNestedDocumentNonDelegateWithSkipScope(Reference<RowReader> reader,
|
||||||
|
int context) {
|
||||||
|
while (reader.get().read()) {
|
||||||
|
switch (reader.get().type().LayoutCode) {
|
||||||
|
case TupleScope: {
|
||||||
|
RowReader nested = reader.get().readScope().clone();
|
||||||
|
Reference<RowReader> tempReference_nested =
|
||||||
|
new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadTuplePartial(tempReference_nested, 0));
|
||||||
|
nested = tempReference_nested.get();
|
||||||
|
Reference<RowReader> tempReference_nested2 =
|
||||||
|
new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(reader.get().skipScope(tempReference_nested2));
|
||||||
|
nested = tempReference_nested2.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
case ObjectScope: {
|
||||||
|
RowReader nested = reader.get().readScope().clone();
|
||||||
|
Reference<RowReader> tempReference_nested3 =
|
||||||
|
new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(RowReaderUnitTests.ReadNestedDocumentNonDelegate(tempReference_nested3, 0));
|
||||||
|
nested = tempReference_nested3.get();
|
||||||
|
ResultAssert.IsSuccess(reader.get().readScope(0, RowReaderUnitTests.ReadNestedDocumentDelegate));
|
||||||
|
Reference<RowReader> tempReference_nested4 = new Reference<RowReader>(nested);
|
||||||
|
ResultAssert.IsSuccess(reader.get().skipScope(tempReference_nested4));
|
||||||
|
nested = tempReference_nested4.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result ReadTuplePartial(Reference<RowReader> reader, int unused) {
|
||||||
|
// Read only part of our tuple
|
||||||
|
assert reader.get().read();
|
||||||
|
assert reader.get().read();
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Result WriteNestedDocument(Reference<RowWriter> writer, TypeArgument typeArgument,
|
||||||
|
int level) {
|
||||||
|
TypeArgument tupleArgument = new TypeArgument(LayoutType.Tuple, new TypeArgumentList(new TypeArgument[]
|
||||||
|
{
|
||||||
|
new TypeArgument(LayoutType.Int32),
|
||||||
|
new TypeArgument(LayoutType.Int32),
|
||||||
|
new TypeArgument(LayoutType.Int32)
|
||||||
|
}));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Local functions are not converted by C# to Java Converter:
|
||||||
|
// Result WriteTuple(ref RowWriter tupleWriter, TypeArgument tupleTypeArgument, int unused)
|
||||||
|
// {
|
||||||
|
// ResultAssert.IsSuccess(tupleWriter.WriteInt32(null, 1));
|
||||||
|
// ResultAssert.IsSuccess(tupleWriter.WriteInt32(null, 2));
|
||||||
|
// ResultAssert.IsSuccess(tupleWriter.WriteInt32(null, 3));
|
||||||
|
// return Result.Success;
|
||||||
|
// }
|
||||||
|
|
||||||
|
if (level == 0) {
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("x", tupleArgument.clone(), 0, WriteTuple));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("a", new TypeArgument(LayoutType.Object), level - 1,
|
||||||
|
RowReaderUnitTests.WriteNestedDocument));
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("x", tupleArgument.clone(), 0, WriteTuple));
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("b", new TypeArgument(LayoutType.Object), level - 1,
|
||||||
|
RowReaderUnitTests.WriteNestedDocument));
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("y", tupleArgument.clone(), 0, WriteTuple));
|
||||||
|
ResultAssert.IsSuccess(writer.get().WriteScope("c", new TypeArgument(LayoutType.Object), level - 1,
|
||||||
|
RowReaderUnitTests.WriteNestedDocument));
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1401", Justification = "Test types.")] internal sealed class Point : IDispatchable, IRowSerializable
|
||||||
|
public final static class Point implements IDispatchable, IRowSerializable {
|
||||||
|
public int X;
|
||||||
|
public int Y;
|
||||||
|
|
||||||
|
public Point(int x, int y) {
|
||||||
|
this.X = x;
|
||||||
|
this.Y = y;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> scope) {
|
||||||
|
dispatcher.get().LayoutCodeSwitch(scope, "x", value:this.X)
|
||||||
|
dispatcher.get().LayoutCodeSwitch(scope, "y", value:this.Y)
|
||||||
|
}
|
||||||
|
|
||||||
|
public Result Write(Reference<RowWriter> writer, TypeArgument typeArg) {
|
||||||
|
Result result = writer.get().WriteInt32("x", this.X);
|
||||||
|
if (result != Result.SUCCESS) {
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
return writer.get().WriteInt32("y", this.Y);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj instanceof Point && this.equals((Point)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
return ((new Integer(this.X)).hashCode() * 397) ^ (new Integer(this.Y)).hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Point other) {
|
||||||
|
return this.X == other.X && this.Y == other.Y;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,509 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Float128;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.NullValue;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.UnixDateTime;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutColumn;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("StyleCop.CSharp.ReadabilityRules",
|
||||||
|
// "SA1118:ParameterMustNotSpanMultipleLines", Justification = "Test code.")][DeploymentItem(RowWriterUnitTests
|
||||||
|
// .SchemaFile, "TestData")] public sealed class RowWriterUnitTests
|
||||||
|
public final class RowWriterUnitTests {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
private static final LocalDateTime SampleDateTime = LocalDateTime.parse("2018-08-14 02:05:00.0000000");
|
||||||
|
private static final Float128 SampleFloat128 = new Float128(0, 42);
|
||||||
|
private static final UUID SampleGuid = UUID.fromString("{2A9C25B9-922E-4611-BB0A-244A9496503C}");
|
||||||
|
private static final MongoDbObjectId SampleMongoDbObjectId = new MongoDbObjectId(0, 42);
|
||||||
|
private static final UnixDateTime SampleUnixDateTime = new UnixDateTime(42);
|
||||||
|
private static final String SchemaFile = "TestData\\ReaderSchema.json";
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void TestInitialize()
|
||||||
|
public void TestInitialize() {
|
||||||
|
String json = Files.readString(RowWriterUnitTests.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void WriteMixed()
|
||||||
|
public void WriteMixed() {
|
||||||
|
Layout layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"Mixed")).SchemaId);
|
||||||
|
assert layout != null;
|
||||||
|
|
||||||
|
RowBuffer row = new RowBuffer(RowWriterUnitTests.InitialRowSize);
|
||||||
|
row.initLayout(HybridRowVersion.V1, layout, this.resolver);
|
||||||
|
|
||||||
|
int writerLength = 0;
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not
|
||||||
|
// converted by C# to Java Converter:
|
||||||
|
ResultAssert.IsSuccess(RowWriter.writeBuffer(tempReference_row, null, (RowWriter RowWriter writer,
|
||||||
|
TypeArgument rootTypeArg, Object ignored) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer.WriteNull("null"));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBool("bool", true));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt8("int8", (byte)-86));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt16("int16", (short)-21846));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt32("int32", -1431655766));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt64("int64", -6148914691236517206L));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt8("uint8", (byte)0xAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt16("uint16", (short)0xAAAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt32("uint32", 0xAAAAAAAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt64("uint64", 0xAAAAAAAAAAAAAAAAL));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat32("float32", 1.0F / 3.0F));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat64("float64", 1.0 / 3.0));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat128("float128", RowWriterUnitTests.SampleFloat128));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteDecimal("decimal", java.math.BigDecimal.ONE / 3.0));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteDateTime("datetime", RowWriterUnitTests.SampleDateTime));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUnixDateTime("unixdatetime", RowWriterUnitTests.SampleUnixDateTime));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteGuid("guid", RowWriterUnitTests.SampleGuid));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteMongoDbObjectId("mongodbobjectid",
|
||||||
|
RowWriterUnitTests.SampleMongoDbObjectId));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("utf8", "abc"));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("utf8_span", Utf8Span.TranscodeUtf16("abc")));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("binary", new byte[] { (byte)0, (byte)1, (byte)2 }));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("binary_span",
|
||||||
|
new byte[] { (byte)0, (byte)1, (byte)2 }.AsSpan()));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("binary_sequence",
|
||||||
|
new ReadOnlySequence<Byte>(new byte[] { (byte)0, (byte)1, (byte)2 })));
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(writer.WriteVarInt("var_varint", -6148914691236517206L));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteVarUInt("var_varuint", 0xAAAAAAAAAAAAAAAAL));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("var_utf8", "abc"));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("var_utf8_span", Utf8Span.TranscodeUtf16("abc")));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("var_binary", new byte[] { (byte)0, (byte)1, (byte)2 }));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("var_binary_span",
|
||||||
|
new byte[] { (byte)0, (byte)1, (byte)2 }.AsSpan()));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("var_binary_sequence",
|
||||||
|
new ReadOnlySequence<Byte>(new byte[] { (byte)0, (byte)1, (byte)2 })));
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(writer.WriteNull("sparse_null"));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBool("sparse_bool", true));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt8("sparse_int8", (byte)-86));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt16("sparse_int16", (short)-21846));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt32("sparse_int32", -1431655766));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteInt64("sparse_int64", -6148914691236517206L));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt8("sparse_uint8", (byte)0xAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt16("sparse_uint16", (short)0xAAAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt32("sparse_uint32", 0xAAAAAAAA));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUInt64("sparse_uint64", 0xAAAAAAAAAAAAAAAAL));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat32("sparse_float32", 1.0F / 3.0F));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat64("sparse_float64", 1.0 / 3.0));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteFloat128("sparse_float128", RowWriterUnitTests.SampleFloat128));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteDecimal("sparse_decimal", java.math.BigDecimal.ONE / 3.0));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteDateTime("sparse_datetime", RowWriterUnitTests.SampleDateTime));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteUnixDateTime("sparse_unixdatetime",
|
||||||
|
RowWriterUnitTests.SampleUnixDateTime));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteGuid("sparse_guid", RowWriterUnitTests.SampleGuid));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteMongoDbObjectId("sparse_mongodbobjectid",
|
||||||
|
RowWriterUnitTests.SampleMongoDbObjectId));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("sparse_utf8", "abc"));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteString("sparse_utf8_span", Utf8Span.TranscodeUtf16("abc")));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("sparse_binary", new byte[] { (byte)0, (byte)1, (byte)2 }));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("sparse_binary_span",
|
||||||
|
new byte[] { (byte)0, (byte)1, (byte)2 }.AsSpan()));
|
||||||
|
ResultAssert.IsSuccess(writer.WriteBinary("sparse_binary_sequence",
|
||||||
|
new ReadOnlySequence<Byte>(new byte[] { (byte)0, (byte)1, (byte)2 })));
|
||||||
|
|
||||||
|
LayoutColumn col;
|
||||||
|
Out<LayoutColumn> tempOut_col =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("array_t<int8>", tempOut_col);
|
||||||
|
col = tempOut_col.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new byte[] { -86, -87,
|
||||||
|
-88 }, (ref RowWriter writer2, TypeArgument typeArg, byte[] values) ->
|
||||||
|
{
|
||||||
|
for (byte value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteInt8(null, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col2 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("array_t<array_t<float32>>", tempOut_col2);
|
||||||
|
col = tempOut_col2.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new float[][]
|
||||||
|
{
|
||||||
|
new float[] { 1, 2, 3 },
|
||||||
|
new float[] { 1, 2, 3 }
|
||||||
|
}, (ref RowWriter writer2, TypeArgument typeArg, float[][] values) ->
|
||||||
|
{
|
||||||
|
for (float[] value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), value,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, float[] values2) ->
|
||||||
|
{
|
||||||
|
for (float value2 : values2) {
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteFloat32(null, value2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col3 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("array_t<utf8>", tempOut_col3);
|
||||||
|
col = tempOut_col3.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new String[] { "abc",
|
||||||
|
"def", "hij" }, (ref RowWriter writer2, TypeArgument typeArg, String[] values) ->
|
||||||
|
{
|
||||||
|
for (String value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteString(null, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col4 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("tuple<varint,int64>", tempOut_col4);
|
||||||
|
col = tempOut_col4.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(),
|
||||||
|
Tuple.Create(-6148914691236517206L, -6148914691236517206L), (ref RowWriter writer2,
|
||||||
|
TypeArgument typeArg,
|
||||||
|
Tuple<Long, Long> values) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteVarInt(null, values.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteInt64(null, values.Item2));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col5 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("tuple<null,tuple<int8,int8>>", tempOut_col5);
|
||||||
|
col = tempOut_col5.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(),
|
||||||
|
Tuple.Create(NullValue.DEFAULT, Tuple.Create((byte)-86, (byte)-86)), (ref RowWriter writer2,
|
||||||
|
TypeArgument typeArg,
|
||||||
|
Tuple<NullValue, Tuple<Byte,
|
||||||
|
Byte>> values) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteNull(null));
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(1).clone(), values.Item2,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, Tuple<Byte, Byte> values2) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt8(null, values2.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt8(null, values2.Item2));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col6 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("tuple<bool,udt>", tempOut_col6);
|
||||||
|
col = tempOut_col6.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(false,
|
||||||
|
new RowReaderUnitTests.Point(1, 2)), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Boolean,
|
||||||
|
RowReaderUnitTests.Point> values) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteBool(null, values.Item1));
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer3 =
|
||||||
|
new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer3);
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(1).clone(), values.Item2,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, IRowSerializable values2) -> values2.Write(tempReference_writer3, typeArg2.clone())));
|
||||||
|
writer3 = tempReference_writer3.get();
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col7 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("nullable<int32,int64>", tempOut_col7);
|
||||||
|
col = tempOut_col7.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create(null,
|
||||||
|
(Long)123L), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Integer, Long> values) ->
|
||||||
|
{
|
||||||
|
RowWriter.WriterFunc<Integer> f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg,
|
||||||
|
Integer context) -> null.invoke(writer, typeArg.clone(), context);
|
||||||
|
if (values.Item1 != null) {
|
||||||
|
f0 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Integer value) -> writer3.WriteInt32(null,
|
||||||
|
value.intValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), values.Item1,
|
||||||
|
f0));
|
||||||
|
|
||||||
|
RowWriter.WriterFunc<Long> f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter writer, TypeArgument typeArg,
|
||||||
|
Long context) -> null.invoke(writer, typeArg.clone(), context);
|
||||||
|
if (values.Item2 != null) {
|
||||||
|
f1 = (com.azure.data.cosmos.serialization.hybridrow.io.RowWriter RowWriter writer3, TypeArgument typeArg2, Long value) -> writer3.WriteInt64(null,
|
||||||
|
value.longValue());
|
||||||
|
}
|
||||||
|
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(1).clone(), values.Item2,
|
||||||
|
f1));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col8 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("tagged<utf8>", tempOut_col8);
|
||||||
|
col = tempOut_col8.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create((byte)3,
|
||||||
|
"hello"), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Byte, String> values) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteUInt8(null, values.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteString(null, values.Item2));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col9 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("tagged<bool,utf8>", tempOut_col9);
|
||||||
|
col = tempOut_col9.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), Tuple.Create((byte)5,
|
||||||
|
true, "bye"), (ref RowWriter writer2, TypeArgument typeArg, Tuple<Byte, Boolean, String> values) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteUInt8(null, values.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteBool(null, values.Item2));
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteString(null, values.Item3));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col10 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("set_t<utf8>", tempOut_col10);
|
||||||
|
col = tempOut_col10.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new String[] { "abc",
|
||||||
|
"xzy", "efg" }, (ref RowWriter writer2, TypeArgument typeArg, String[] values) ->
|
||||||
|
{
|
||||||
|
for (String value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteString(null, value));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col11 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("set_t<array_t<int8>>", tempOut_col11);
|
||||||
|
col = tempOut_col11.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new byte[][]
|
||||||
|
{
|
||||||
|
new byte[] { 7, 8, 9 },
|
||||||
|
new byte[] { 4, 5, 6 },
|
||||||
|
new byte[] { 1, 2, 3 }
|
||||||
|
}, (ref RowWriter writer2, TypeArgument typeArg, byte[][] values) ->
|
||||||
|
{
|
||||||
|
for (byte[] value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), value,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, byte[] values2) ->
|
||||||
|
{
|
||||||
|
for (byte value2 : values2) {
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt8(null, value2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col12 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("set_t<set_t<int32>>", tempOut_col12);
|
||||||
|
col = tempOut_col12.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new int[][]
|
||||||
|
{
|
||||||
|
new int[] { 4, 5, 6 },
|
||||||
|
new int[] { 7, 8, 9 },
|
||||||
|
new int[] { 1, 2, 3 }
|
||||||
|
}, (ref RowWriter writer2, TypeArgument typeArg, int[][] values) ->
|
||||||
|
{
|
||||||
|
for (int[] value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), value,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, int[] values2) ->
|
||||||
|
{
|
||||||
|
for (int value2 : values2) {
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt32(null, value2));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col13 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("set_t<udt>", tempOut_col13);
|
||||||
|
col = tempOut_col13.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(),
|
||||||
|
new RowReaderUnitTests.Point[]
|
||||||
|
{
|
||||||
|
new RowReaderUnitTests.Point(1, 2),
|
||||||
|
new RowReaderUnitTests.Point(3, 4),
|
||||||
|
new RowReaderUnitTests.Point(5, 6)
|
||||||
|
}, (ref RowWriter writer2, TypeArgument typeArg, RowReaderUnitTests.Point[] values) ->
|
||||||
|
{
|
||||||
|
for (RowReaderUnitTests.Point value : values) {
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer3 =
|
||||||
|
new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer3);
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, typeArg.getTypeArgs().get(0).clone(), value,
|
||||||
|
(ref RowWriter writer3, TypeArgument typeArg2, IRowSerializable values2) -> values2.Write(tempReference_writer3, typeArg2.clone())));
|
||||||
|
writer3 = tempReference_writer3.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col14 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("map_t<utf8,utf8>", tempOut_col14);
|
||||||
|
col = tempOut_col14.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new System.Tuple<T1,
|
||||||
|
T2>[] { Tuple.Create("Harrison", "Han"), Tuple.Create("Mark", "Luke") }, (ref RowWriter writer2,
|
||||||
|
TypeArgument typeArg,
|
||||||
|
Tuple<String, String>[] values) ->
|
||||||
|
{
|
||||||
|
for (Tuple<String, String> value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, new TypeArgument(LayoutType.TypedTuple,
|
||||||
|
typeArg.getTypeArgs().clone()), value, (ref RowWriter writer3, TypeArgument typeArg2,
|
||||||
|
Tuple<String, String> values2) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteString(null, values2.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteString(null, values2.Item2));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col15 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("map_t<int8,array_t<int8>>", tempOut_col15);
|
||||||
|
col = tempOut_col15.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new System.Tuple<T1,
|
||||||
|
T2>[] { Tuple.Create((byte)2, new byte[] { 4, 5, 6 }),
|
||||||
|
Tuple.Create((byte)1, new byte[] { 1, 2, 3 }) }, (ref RowWriter writer2, TypeArgument typeArg,
|
||||||
|
Tuple<Byte, byte[]>[] values) ->
|
||||||
|
{
|
||||||
|
for (Tuple<Byte, byte[]> value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, new TypeArgument(LayoutType.TypedTuple,
|
||||||
|
typeArg.getTypeArgs().clone()), value, (ref RowWriter writer3, TypeArgument typeArg2,
|
||||||
|
Tuple<Byte, byte[]> values2) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt8(null, values2.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteScope(null, typeArg2.getTypeArgs().get(1).clone(),
|
||||||
|
values2.Item2, (ref RowWriter writer4, TypeArgument typeArg3, byte[] values3) ->
|
||||||
|
{
|
||||||
|
for (byte value3 : values3) {
|
||||||
|
ResultAssert.IsSuccess(writer4.WriteInt8(null, value3));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col16 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("map_t<int16,map_t<int32,int32>>", tempOut_col16);
|
||||||
|
col = tempOut_col16.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new System.Tuple<T1,
|
||||||
|
T2>[] { Tuple.Create((short)2, new System.Tuple<T1, T2>[] { Tuple.Create(7, 8), Tuple.Create(5, 6) })
|
||||||
|
, Tuple.Create((short)1, new System.Tuple<T1, T2>[] { Tuple.Create(3, 4), Tuple.Create(1, 2) }) },
|
||||||
|
(ref RowWriter writer2, TypeArgument typeArg, Tuple<Short, Tuple<Integer, Integer>[]>[] values) ->
|
||||||
|
{
|
||||||
|
for (Tuple<Short, Tuple<Integer, Integer>[]> value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, new TypeArgument(LayoutType.TypedTuple,
|
||||||
|
typeArg.getTypeArgs().clone()), value, (ref RowWriter writer3, TypeArgument typeArg2,
|
||||||
|
Tuple<Short, Tuple<Integer, Integer>[]> values2) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteInt16(null, values2.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteScope(null, typeArg2.getTypeArgs().get(1).clone(),
|
||||||
|
values2.Item2, (ref RowWriter writer4, TypeArgument typeArg3,
|
||||||
|
Tuple<Integer, Integer>[] values3) ->
|
||||||
|
{
|
||||||
|
for (Tuple<Integer, Integer> value3 : values3) {
|
||||||
|
ResultAssert.IsSuccess(writer4.WriteScope(null,
|
||||||
|
new TypeArgument(LayoutType.TypedTuple, typeArg3.getTypeArgs().clone()), value3,
|
||||||
|
(ref RowWriter writer5, TypeArgument typeArg4, Tuple<Integer, Integer> values4) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer5.WriteInt32(null, values4.Item1));
|
||||||
|
ResultAssert.IsSuccess(writer5.WriteInt32(null, values4.Item2));
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
Out<LayoutColumn> tempOut_col17 =
|
||||||
|
new Out<LayoutColumn>();
|
||||||
|
assert layout.TryFind("map_t<float64,udt>", tempOut_col17);
|
||||||
|
col = tempOut_col17.get();
|
||||||
|
ResultAssert.IsSuccess(writer.WriteScope(col.path(), col.typeArg().clone(), new System.Tuple<T1, T2>[] { Tuple.Create(1.0, new RowReaderUnitTests.Point(1, 2)), Tuple.Create(2.0, new RowReaderUnitTests.Point(3, 4)), Tuple.Create(3.0, new RowReaderUnitTests.Point(5, 6)) }, (ref RowWriter writer2, TypeArgument typeArg, Tuple<Double, RowReaderUnitTests.Point>[] values) ->
|
||||||
|
{
|
||||||
|
for (Tuple<Double, RowReaderUnitTests.Point> value : values) {
|
||||||
|
ResultAssert.IsSuccess(writer2.WriteScope(null, new TypeArgument(LayoutType.TypedTuple, typeArg.getTypeArgs().clone()), value, (ref RowWriter writer3, TypeArgument typeArg2, Tuple<Double, RowReaderUnitTests.Point> values2) ->
|
||||||
|
{
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteFloat64(null, values2.Item1));
|
||||||
|
Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter> tempReference_writer4 = new Reference<com.azure.data.cosmos.serialization.hybridrow.io.RowWriter>(writer4);
|
||||||
|
ResultAssert.IsSuccess(writer3.WriteScope(null, typeArg2.getTypeArgs().get(1).clone(), values2.Item2, (ref RowWriter writer4, TypeArgument typeArg3, IRowSerializable values3) -> values3.Write(tempReference_writer4, typeArg3.clone())));
|
||||||
|
writer4 = tempReference_writer4.get();
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
|
||||||
|
// Save the RowWriter length after everything is written for later comparison.
|
||||||
|
writerLength = writer.Length;
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}));
|
||||||
|
row = tempReference_row.get();
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row2 = new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
assert reader.length() == writerLength;
|
||||||
|
Reference<RowReader> tempReference_reader = new Reference<RowReader>(reader);
|
||||||
|
RowReaderUnitTests.PrintReader(tempReference_reader, 0);
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,272 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.PropertyType;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(SchemaHashUnitTests.SchemaFile, "TestData")] public class
|
||||||
|
// SchemaHashUnitTests
|
||||||
|
public class SchemaHashUnitTests {
|
||||||
|
private static final String SchemaFile = "TestData\\SchemaHashCoverageSchema.json";
|
||||||
|
private Namespace ns;
|
||||||
|
private Schema tableSchema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void InitializeSuite()
|
||||||
|
public final void InitializeSuite() {
|
||||||
|
String json = Files.readString(SchemaHashUnitTests.SchemaFile);
|
||||||
|
this.ns = Namespace.Parse(json);
|
||||||
|
this.tableSchema = tangible.ListHelper.find(this.ns.getSchemas(), s -> s.Name.equals("Table"));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void SchemaHashCompileTest()
|
||||||
|
public final void SchemaHashCompileTest() {
|
||||||
|
Layout layout = this.tableSchema.Compile(this.ns);
|
||||||
|
assert layout != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void SchemaHashTest()
|
||||||
|
public final void SchemaHashTest() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Tuple variables are not converted by C# to Java Converter:
|
||||||
|
( long low, long high)hash = SchemaHash.ComputeHash(this.ns, this.tableSchema);
|
||||||
|
assert (0,0) !=hash;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Tuple variables are not converted by C# to Java Converter:
|
||||||
|
( long low, long high)hash2 = SchemaHash.ComputeHash(this.ns, this.tableSchema, (1, 1))
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test clone are the same.
|
||||||
|
Schema clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2;
|
||||||
|
|
||||||
|
// Test Schema changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.setName("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2; // Name not part of the hash
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.setComment("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2; // Comment not part of the hash
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.setVersion(SchemaLanguageVersion.forValue((byte)1));
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2; // Encoding version not part of the hash
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.setSchemaId(new SchemaId(42));
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.setType(TypeKind.Int8);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Options changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getOptions().setEnablePropertyLevelTimestamp(!clone.getOptions().getEnablePropertyLevelTimestamp());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getOptions().setDisallowUnschematized(!clone.getOptions().getDisallowUnschematized());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Partition Keys changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getPartitionKeys().get(0).setPath("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Primary Sort Keys changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getPrimarySortKeys().get(0).setPath("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getPrimarySortKeys().get(0).setDirection(SortDirection.Descending);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Static Keys changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getStaticKeys().get(0).setPath("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Properties changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getProperties().get(0).setComment("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2; // Comment not part of the hash
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getProperties().get(0).setPath("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getProperties().get(0).getPropertyType().setApiType("something else");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getProperties().get(0).getPropertyType().setType(TypeKind.Binary);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
clone.getProperties().get(0).getPropertyType().setNullable(!clone.getProperties().get(0).getPropertyType().getNullable());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Primitive Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar =
|
||||||
|
clone.getProperties().get(0).getPropertyType();
|
||||||
|
(tempVar instanceof PrimitivePropertyType ? (PrimitivePropertyType)tempVar : null).setLength(42);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar2 =
|
||||||
|
clone.getProperties().get(0).getPropertyType();
|
||||||
|
(tempVar2 instanceof PrimitivePropertyType ? (PrimitivePropertyType)tempVar2 : null).setStorage(StorageKind.Variable);
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Scope Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar3 =
|
||||||
|
clone.getProperties().get(1).getPropertyType();
|
||||||
|
PropertyType tempVar4 =
|
||||||
|
clone.getProperties().get(1).getPropertyType();
|
||||||
|
(tempVar3 instanceof ScopePropertyType ? (ScopePropertyType)tempVar3 : null).setImmutable(!(tempVar4 instanceof ScopePropertyType ? (ScopePropertyType)tempVar4 : null).getImmutable());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Array Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar5 =
|
||||||
|
clone.getProperties().get(1).getPropertyType();
|
||||||
|
(tempVar5 instanceof ArrayPropertyType ? (ArrayPropertyType)tempVar5 : null).setItems(clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Object Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar6 =
|
||||||
|
clone.getProperties().get(2).getPropertyType();
|
||||||
|
(tempVar6 instanceof ObjectPropertyType ? (ObjectPropertyType)tempVar6 : null).getProperties().set(0,
|
||||||
|
clone.getProperties().get(0));
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Map Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar7 =
|
||||||
|
clone.getProperties().get(3).getPropertyType();
|
||||||
|
(tempVar7 instanceof MapPropertyType ? (MapPropertyType)tempVar7 : null).setKeys(clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar8 =
|
||||||
|
clone.getProperties().get(3).getPropertyType();
|
||||||
|
(tempVar8 instanceof MapPropertyType ? (MapPropertyType)tempVar8 : null).setValues(clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Set Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar9 =
|
||||||
|
clone.getProperties().get(4).getPropertyType();
|
||||||
|
(tempVar9 instanceof SetPropertyType ? (SetPropertyType)tempVar9 : null).setItems(clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Tagged Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar10 =
|
||||||
|
clone.getProperties().get(5).getPropertyType();
|
||||||
|
(tempVar10 instanceof TaggedPropertyType ? (TaggedPropertyType)tempVar10 : null).getItems().set(0,
|
||||||
|
clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test Tuple Property Type changes
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar11 =
|
||||||
|
clone.getProperties().get(6).getPropertyType();
|
||||||
|
(tempVar11 instanceof TuplePropertyType ? (TuplePropertyType)tempVar11 : null).getItems().set(0,
|
||||||
|
clone.getProperties().get(0).getPropertyType());
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Test UDT Property Type changes
|
||||||
|
try {
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar12 =
|
||||||
|
clone.getProperties().get(7).getPropertyType();
|
||||||
|
(tempVar12 instanceof UdtPropertyType ? (UdtPropertyType)tempVar12 : null).setName("some non-existing UDT" +
|
||||||
|
" name");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
Assert.Fail("Should have thrown an exception.");
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
assert ex != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar13 =
|
||||||
|
clone.getProperties().get(7).getPropertyType();
|
||||||
|
(tempVar13 instanceof UdtPropertyType ? (UdtPropertyType)tempVar13 : null).setName("Table");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
Assert.Fail("Should have thrown an exception.");
|
||||||
|
} catch (RuntimeException ex) {
|
||||||
|
assert ex != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar14 =
|
||||||
|
clone.getProperties().get(7).getPropertyType();
|
||||||
|
(tempVar14 instanceof UdtPropertyType ? (UdtPropertyType)tempVar14 : null).setName("Table");
|
||||||
|
PropertyType tempVar15 =
|
||||||
|
clone.getProperties().get(7).getPropertyType();
|
||||||
|
(tempVar15 instanceof UdtPropertyType ? (UdtPropertyType)tempVar15 : null).setSchemaId(new SchemaId(2));
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash != hash2;
|
||||||
|
|
||||||
|
// Renaming an UDT is not a breaking change as long as the SchemaId has not changed.
|
||||||
|
this.ns.getSchemas().get(0).setName("RenameActualUDT");
|
||||||
|
clone = SchemaHashUnitTests.Clone(this.tableSchema);
|
||||||
|
PropertyType tempVar16 = clone.getProperties().get(7).getPropertyType();
|
||||||
|
(tempVar16 instanceof UdtPropertyType ? (UdtPropertyType)tempVar16 : null).setName("RenameActualUDT");
|
||||||
|
hash2 = SchemaHash.ComputeHash(this.ns, clone);
|
||||||
|
assert hash == hash2;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Schema Clone(Schema s) {
|
||||||
|
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||||
|
settings.NullValueHandling = NullValueHandling.Ignore;
|
||||||
|
settings.Formatting = Formatting.Indented;
|
||||||
|
settings.CheckAdditionalContent = true;
|
||||||
|
|
||||||
|
String json = JsonConvert.SerializeObject(s, settings);
|
||||||
|
return JsonConvert.<Schema>DeserializeObject(json, settings);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,44 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class SchemaIdUnitTests
|
||||||
|
public class SchemaIdUnitTests {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void SchemaIdTest()
|
||||||
|
public final void SchemaIdTest() {
|
||||||
|
SchemaId a = new SchemaId(1);
|
||||||
|
SchemaId b = new SchemaId(2);
|
||||||
|
SchemaId c = new SchemaId();
|
||||||
|
|
||||||
|
assert 1 == a.value();
|
||||||
|
assert 2 == b.value();
|
||||||
|
assert SchemaId.INVALID == c.clone();
|
||||||
|
assert 2 != a.value();
|
||||||
|
assert a.clone() != b.clone();
|
||||||
|
assert SchemaId.opEquals(a.clone(), a.clone());
|
||||||
|
assert SchemaId.opNotEquals(a.clone(), b.clone());
|
||||||
|
assert !a.equals(null);
|
||||||
|
assert a.hashCode() == (new SchemaId(1)).hashCode();
|
||||||
|
assert a.hashCode() != (new SchemaId(-1)).hashCode();
|
||||||
|
|
||||||
|
String json = JsonConvert.SerializeObject(a.clone());
|
||||||
|
assert "1" == json;
|
||||||
|
assert "1" == a.toString();
|
||||||
|
|
||||||
|
assert a.clone() == JsonConvert.<SchemaId>DeserializeObject(json);
|
||||||
|
json = JsonConvert.SerializeObject(b.clone());
|
||||||
|
assert "2" == json;
|
||||||
|
assert "2" == b.toString();
|
||||||
|
assert b.clone() == JsonConvert.<SchemaId>DeserializeObject(json);
|
||||||
|
json = JsonConvert.SerializeObject(c.clone());
|
||||||
|
assert "0" == json;
|
||||||
|
assert "0" == c.toString();
|
||||||
|
assert c.clone() == JsonConvert.<SchemaId>DeserializeObject(json);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,994 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import Newtonsoft.Json.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.SortDirection;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.StorageKind;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.TypeKind;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][SuppressMessage("Naming", "DontUseVarForVariableTypes", Justification = "The types here
|
||||||
|
// are anonymous.")] public class SchemaUnitTests
|
||||||
|
public class SchemaUnitTests {
|
||||||
|
PrimitivePropertyType sp = (PrimitivePropertyType)p.getPropertyType();
|
||||||
|
String tableSchema = String.format("{'name': 'table', 'id': -1, 'type': 'schema', 'properties': [%1$s]}",
|
||||||
|
columnSchema);
|
||||||
|
Schema s = Schema.Parse(tableSchema);)
|
||||||
|
Property p = s.getProperties().get(0);
|
||||||
|
|
||||||
|
{
|
||||||
|
case Utf8:
|
||||||
|
case Binary:
|
||||||
|
switch (sp.getStorage()) {
|
||||||
|
case Fixed:
|
||||||
|
case Variable:
|
||||||
|
case Sparse:
|
||||||
|
Assert.AreEqual(expected.Len, sp.getLength(), "Json: {0}", expected.Json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert.Fail("Json: {0}", expected.Json);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
Assert.AreEqual(1,s.getProperties().
|
||||||
|
|
||||||
|
getType(), "Json: {0}",expected.Json)
|
||||||
|
|
||||||
|
getType()
|
||||||
|
Assert.AreEqual(expected.Type,p.getPropertyType().
|
||||||
|
|
||||||
|
size(), "Json: {0}",expected.Json)
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseNamespace()
|
||||||
|
public final void ParseNamespace() {
|
||||||
|
{
|
||||||
|
// Test empty schemas.
|
||||||
|
String[] emptyNamespaceJsonInput = { "{ }", "{'schemas': [ ] }", "{'name': null }", "{'name': null, " +
|
||||||
|
"'schemas': null }", "{'version': 'v1', 'name': null, 'schemas': null }" };
|
||||||
|
|
||||||
|
for (String json : emptyNamespaceJsonInput) {
|
||||||
|
Namespace n1 = Namespace.Parse(json);
|
||||||
|
Assert.IsNull(n1.getName(), "Got: {0}, Json: {1}", n1.getName(), json);
|
||||||
|
Assert.IsNotNull(n1.getSchemas(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(0, n1.getSchemas().size(), "Got: {0}, Json: {1}", n1.getSchemas(), json);
|
||||||
|
assert SchemaLanguageVersion.V1 == n1.getVersion();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test simple schemas and schema options.
|
||||||
|
String json = "{'name': 'myschema', 'schemas': null }";
|
||||||
|
Namespace n1 = Namespace.Parse(json);
|
||||||
|
Assert.AreEqual("myschema", n1.getName(), "Json: {0}", json);
|
||||||
|
Assert.IsNotNull(n1.getSchemas(), "Json: {0}", json);
|
||||||
|
|
||||||
|
// Version defaults propertly when NOT specified.
|
||||||
|
assert SchemaLanguageVersion.V1 == n1.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
String json = "{'name': 'myschema', 'schemas': [" + "\r\n" +
|
||||||
|
" {'version': 'v1', 'name': 'emptyTable', 'id': -1, 'type': 'schema', " + "\r\n" +
|
||||||
|
" 'options': { 'disallowUnschematized': true }, 'properties': null } ] }";
|
||||||
|
|
||||||
|
Namespace n1 = Namespace.Parse(json);
|
||||||
|
Assert.AreEqual("myschema", n1.getName(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(1, n1.getSchemas().size(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual("emptyTable", n1.getSchemas().get(0).getName(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(new SchemaId(-1), n1.getSchemas().get(0).getSchemaId().clone(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(TypeKind.SCHEMA, n1.getSchemas().get(0).getType(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(true, n1.getSchemas().get(0).getOptions().getDisallowUnschematized(), "Json: {0}", json);
|
||||||
|
Assert.IsNotNull(n1.getSchemas().get(0).getProperties().size(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(0, n1.getSchemas().get(0).getProperties().size(), "Json: {0}", json);
|
||||||
|
assert SchemaLanguageVersion.V1 == n1.getVersion();
|
||||||
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
// Test basic schema with primitive columns.
|
||||||
|
String json = "{'name': 'myschema', 'schemas': [" + "\r\n" +
|
||||||
|
" {'name': 'myUDT', 'id': 1, 'type': 'schema', 'options': { " +
|
||||||
|
"'disallowUnschematized': false }, " + "\r\n" +
|
||||||
|
" 'properties': [ " + "\r\n" +
|
||||||
|
" { 'path': 'a', 'type': { 'type': 'int8', 'storage': 'fixed' }}, " + "\r\n" +
|
||||||
|
" { 'path': 'b', 'type': { 'type': 'utf8', 'storage': 'variable' }} " + "\r\n" +
|
||||||
|
" ] }" + "\r\n" +
|
||||||
|
" ] }";
|
||||||
|
|
||||||
|
Namespace n1 = Namespace.Parse(json);
|
||||||
|
Assert.AreEqual(1, n1.getSchemas().size(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual("myUDT", n1.getSchemas().get(0).getName(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(new SchemaId(1), n1.getSchemas().get(0).getSchemaId().clone(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(TypeKind.SCHEMA, n1.getSchemas().get(0).getType(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(false, n1.getSchemas().get(0).getOptions().getDisallowUnschematized(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(2, n1.getSchemas().get(0).getProperties().size(), "Json: {0}", json);
|
||||||
|
|
||||||
|
class AnonymousType {
|
||||||
|
public String Path;
|
||||||
|
public StorageKind Storage;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType(String _Path,
|
||||||
|
TypeKind _Type,
|
||||||
|
StorageKind _Storage) {
|
||||||
|
Path = _Path;
|
||||||
|
Type = _Type;
|
||||||
|
Storage = _Storage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String Path;
|
||||||
|
public StorageKind Storage;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType2(String _Path,
|
||||||
|
TypeKind _Type,
|
||||||
|
StorageKind _Storage) {
|
||||||
|
Path = _Path;
|
||||||
|
Type = _Type;
|
||||||
|
Storage = _Storage;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Object[] expectedProps = new Object[] { AnonymousType("a", TypeKind.INT_8, StorageKind.FIXED),
|
||||||
|
AnonymousType2("b", TypeKind.UTF_8, StorageKind.VARIABLE) };
|
||||||
|
|
||||||
|
for (int i = 0; i < n1.getSchemas().get(0).getProperties().size(); i++) {
|
||||||
|
Property p = n1.getSchemas().get(0).getProperties().get(i);
|
||||||
|
Assert.AreEqual(expectedProps[i].Path, p.getPath(), "Json: {0}", json);
|
||||||
|
Assert.AreEqual(expectedProps[i].Type, p.getPropertyType().getType(), "Json: {0}", json);
|
||||||
|
PrimitivePropertyType sp = (PrimitivePropertyType)p.getPropertyType();
|
||||||
|
Assert.AreEqual(expectedProps[i].Storage, sp.getStorage(), "Json: {0}", json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
switch(p.getPropertyType().
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")][DeploymentItem("TestData\\CoverageSchema.json", "TestData")]
|
||||||
|
// public void ParseNamespaceExample()
|
||||||
|
public final void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString("TestData\\CoverageSchema.json");
|
||||||
|
Namespace n1 = Namespace.Parse(json);
|
||||||
|
JsonSerializerSettings settings = new JsonSerializerSettings();
|
||||||
|
settings.NullValueHandling = NullValueHandling.Ignore;
|
||||||
|
settings.Formatting = Formatting.Indented;
|
||||||
|
|
||||||
|
String json2 = JsonConvert.SerializeObject(n1, settings);
|
||||||
|
Namespace n2 = Namespace.Parse(json2);
|
||||||
|
String json3 = JsonConvert.SerializeObject(n2, settings);
|
||||||
|
assert json2 == json3;
|
||||||
|
})
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseSchemaPrimitives()
|
||||||
|
public final void ParseSchemaPrimitives() {
|
||||||
|
// Test all primitive column types.
|
||||||
|
class AnonymousType {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType10 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType10(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType11 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType11(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType12 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType12(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType13 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType13(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType14 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType14(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType15 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType15(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType16 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType16(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType17 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType17(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType18 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType18(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType19 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType19(String _Json,
|
||||||
|
TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType2(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType20 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType20(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType21 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType21(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType22 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType22(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType23 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType23(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType24 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType24(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType25 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType25(String _Json,
|
||||||
|
TypeKind _Type, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType3 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType3(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType4 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType4(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType5 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType5(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType6 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType6(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType7 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType7(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType8 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType8(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType9 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType9(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to the C# 'dynamic' keyword:
|
||||||
|
dynamic[] expectedSchemas = { AnonymousType("{'type': 'bool', 'storage': 'fixed'}", TypeKind.BOOLEAN),
|
||||||
|
AnonymousType2("{'type': 'int8', 'storage': 'fixed'}", TypeKind.INT_8), AnonymousType3("{'type': 'int16', " +
|
||||||
|
"'storage': 'fixed'}", TypeKind.INT_16), AnonymousType4("{'type': 'int32', 'storage': 'fixed'}",
|
||||||
|
TypeKind.INT_32), AnonymousType5("{'type': 'int64', 'storage': 'fixed'}", TypeKind.INT_64), AnonymousType6(
|
||||||
|
"{'type': 'uint8', 'storage': 'fixed'}", TypeKind.UINT_8), AnonymousType7("{'type': 'uint16', " +
|
||||||
|
"'storage': 'fixed'}", TypeKind.UINT_16), AnonymousType8("{'type': 'uint32', 'storage': 'fixed'}",
|
||||||
|
TypeKind.UINT_32), AnonymousType9("{'type': 'uint64', 'storage': 'fixed'}", TypeKind.UINT_64),
|
||||||
|
AnonymousType10("{'type': 'float32', 'storage': 'fixed'}", TypeKind.FLOAT_32), AnonymousType11("{'type': " +
|
||||||
|
"'float64', 'storage': 'fixed'}", TypeKind.FLOAT_64), AnonymousType12("{'type': 'float128', 'storage': " +
|
||||||
|
"'fixed'}", TypeKind.FLOAT_128), AnonymousType13("{'type': 'decimal', 'storage': 'fixed'}",
|
||||||
|
TypeKind.DECIMAL), AnonymousType14("{'type': 'datetime', 'storage': 'fixed'}", TypeKind.DATE_TIME),
|
||||||
|
AnonymousType15("{'type': 'unixdatetime', 'storage': 'fixed'}", TypeKind.UNIX_DATE_TIME), AnonymousType16(
|
||||||
|
"{'type': 'guid', 'storage': 'fixed'}", TypeKind.GUID), AnonymousType17("{'type': 'mongodbobjectid', " +
|
||||||
|
"'storage': 'fixed'}", TypeKind.MONGODB_OBJECT_ID), AnonymousType18("{'type': 'varint', 'storage': " +
|
||||||
|
"'variable'}", TypeKind.VAR_INT), AnonymousType19("{'type': 'varuint', 'storage': 'variable'}",
|
||||||
|
TypeKind.VAR_UINT), AnonymousType20("{'type': 'utf8', 'storage': 'fixed', 'length': 2}", TypeKind.UTF_8, 2)
|
||||||
|
, AnonymousType21("{'type': 'binary', 'storage': 'fixed', 'length': 2}", TypeKind.BINARY, 2),
|
||||||
|
AnonymousType22("{'type': 'utf8', 'storage': 'variable', 'length': 100}", TypeKind.UTF_8, 100),
|
||||||
|
AnonymousType23("{'type': 'binary', 'storage': 'variable', 'length': 100}", TypeKind.BINARY, 100),
|
||||||
|
AnonymousType24("{'type': 'utf8', 'sparse': 'variable', 'length': 1000}", TypeKind.UTF_8, 1000),
|
||||||
|
AnonymousType25("{'type': 'binary', 'sparse': 'variable', 'length': 1000}", TypeKind.BINARY, 1000) };
|
||||||
|
|
||||||
|
for (dynamic expected : expectedSchemas) {
|
||||||
|
String columnSchema = String.format("{'path': 'a', 'type': %1$s", expected.Json
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseSchemaArray()
|
||||||
|
public final void ParseSchemaArray()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Test array types include nested arrays.
|
||||||
|
class AnonymousType {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType2(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType3 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
|
||||||
|
public AnonymousType3(String _Json, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType4 {
|
||||||
|
public String Json;
|
||||||
|
public String Name;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no Java equivalent to the C# 'dynamic' keyword:
|
||||||
|
dynamic[] expectedSchemas = { AnonymousType("{'type': 'int8' }", TypeKind.INT_8), AnonymousType2("{'type': " +
|
||||||
|
"'array', 'items': {'type': 'int32'}}", TypeKind.INT_32), AnonymousType3("{'type': 'object', 'properties': " +
|
||||||
|
"null}", 0), AnonymousType4("{'type': 'schema', 'name': 'myUDT'}", "myUDT") };
|
||||||
|
|
||||||
|
public AnonymousType4(String _Json, String _Name) {
|
||||||
|
Json = _Json;
|
||||||
|
Name = _Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for(dynamic expected:expectedSchemas)
|
||||||
|
{
|
||||||
|
String arrayColumnSchema=String.format("{'path': 'a', 'type': {'type': 'array', 'items': %1$s } }",
|
||||||
|
expected.Json);
|
||||||
|
String tableSchema=String.format("{'name': 'table', 'id': -1, 'type': 'schema', 'properties': [%1$s] }",
|
||||||
|
arrayColumnSchema);
|
||||||
|
Schema s=Schema.Parse(tableSchema);
|
||||||
|
Assert.AreEqual(1,s.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
Property p=s.getProperties().get(0);
|
||||||
|
Assert.AreEqual(TypeKind.Array,p.getPropertyType().getType(),"Json: {0}",expected.Json);
|
||||||
|
ArrayPropertyType pt=(ArrayPropertyType)p.getPropertyType();
|
||||||
|
Assert.IsNotNull(pt.getItems(),"Json: {0}",expected.Json);
|
||||||
|
switch(pt.getItems().getType())
|
||||||
|
{
|
||||||
|
case Array:
|
||||||
|
ArrayPropertyType subArray=(ArrayPropertyType)pt.getItems();
|
||||||
|
Assert.AreEqual(expected.Type,subArray.getItems().getType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
case Object:
|
||||||
|
ObjectPropertyType subObj=(ObjectPropertyType)pt.getItems();
|
||||||
|
Assert.AreEqual(expected.Len,subObj.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
case Schema:
|
||||||
|
UdtPropertyType subRow=(UdtPropertyType)pt.getItems();
|
||||||
|
Assert.AreEqual(expected.Name,subRow.getName(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert.AreEqual(expected.Type,pt.getItems().getType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseSchemaObject()
|
||||||
|
public final void ParseSchemaObject()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Test object types include nested objects.
|
||||||
|
class AnonymousType {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String Json;
|
||||||
|
public TypeKind Type;
|
||||||
|
|
||||||
|
public AnonymousType2(String _Json, TypeKind _Type) {
|
||||||
|
Json = _Json;
|
||||||
|
Type = _Type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType3 {
|
||||||
|
public String Json;
|
||||||
|
public int Len;
|
||||||
|
|
||||||
|
public AnonymousType3(String _Json, int _Len) {
|
||||||
|
Json = _Json;
|
||||||
|
Len = _Len;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType4 {
|
||||||
|
public String Json;
|
||||||
|
public String Name;
|
||||||
|
|
||||||
|
publ TO JAVA CONVERTER TODO TASK: There is no Java equivalent to the C# 'dynamic' keyword:
|
||||||
|
dynamic[] expectedSchemas = { AnonymousType("{'path': 'b', 'type': {'type': 'int8', 'storage': 'fixed'}}",
|
||||||
|
TypeKind.INT_8), AnonymousType2("{'path': 'b', 'type': {'type': 'array', 'items': {'type': 'int32'}}}",
|
||||||
|
TypeKind.INT_32), AnonymousType3("{'path': 'b', 'type': {'type': 'object', 'properties': [{'path': 'c', " +
|
||||||
|
"'type': {'type': 'bool'}}]}}", 1), AnonymousType4("{'path': 'b', 'type': {'type': 'schema', 'name': " +
|
||||||
|
"'myUDT'}}", "myUDT") };
|
||||||
|
|
||||||
|
for(/C#ic AnonymousType4(String _Json, String _Name) {
|
||||||
|
Json = _Json;
|
||||||
|
Name = _Name;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/dynamic expected:expectedSchemas)
|
||||||
|
{
|
||||||
|
String objectColumnSchema=String.format("{'path': 'a', 'type': {'type': 'object', 'properties': [%1$s] } " +
|
||||||
|
"}",expected.Json);
|
||||||
|
String tableSchema=String.format("{'name': 'table', 'id': -2, 'type': 'schema', 'properties': [%1$s] }",
|
||||||
|
objectColumnSchema);
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Schema s=Schema.Parse(tableSchema);
|
||||||
|
Assert.AreEqual(1,s.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
Property pa=s.getProperties().get(0);
|
||||||
|
Assert.AreEqual(TypeKind.Object,pa.getPropertyType().getType(),"Json: {0}",expected.Json);
|
||||||
|
ObjectPropertyType pt=(ObjectPropertyType)pa.getPropertyType();
|
||||||
|
Assert.AreEqual(1,pt.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
Property pb=pt.getProperties().get(0);
|
||||||
|
switch(pb.getPropertyType().getType())
|
||||||
|
{
|
||||||
|
case Array:
|
||||||
|
ArrayPropertyType subArray=(ArrayPropertyType)pb.getPropertyType();
|
||||||
|
Assert.AreEqual(expected.Type,subArray.getItems().getType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
case Object:
|
||||||
|
ObjectPropertyType subObj=(ObjectPropertyType)pb.getPropertyType();
|
||||||
|
Assert.AreEqual(expected.Len,subObj.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
case Schema:
|
||||||
|
UdtPropertyType subRow=(UdtPropertyType)pb.getPropertyType();
|
||||||
|
Assert.AreEqual(expected.Name,subRow.getName(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert.AreEqual(expected.Type,pb.getPropertyType().getType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(RuntimeException ex)
|
||||||
|
{
|
||||||
|
Assert.Fail("Exception: {0}, Json: {1}",ex,expected.Json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseSchemaPartitionPrimaryKeys()
|
||||||
|
public final void ParseSchemaPartitionPrimaryKeys()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Test parsing both partition and primary sort keys.
|
||||||
|
class AnonymousType {
|
||||||
|
public Object[] CK;
|
||||||
|
|
||||||
|
pulic String JsonCK
|
||||||
|
public String JsonPK;
|
||||||
|
public String[] PK;
|
||||||
|
pubblic AnonymousType(String _JsonPK, String _JsonCK, String[] _PK, Object[] _CK) {
|
||||||
|
JsonPK = _JsonPK;
|
||||||
|
JsonCK = _JsonCK;
|
||||||
|
PK = _PK;
|
||||||
|
CK = _CK;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public SortDirection Dir;
|
||||||
|
|
||||||
|
pulic String Path
|
||||||
|
|
||||||
|
pubblic AnonymousType2(String _Path, SortDirection _Dir) {
|
||||||
|
Path = _Path;
|
||||||
|
Dir = _Dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType3 {
|
||||||
|
public SortDirection Dir;
|
||||||
|
|
||||||
|
pulic String Path
|
||||||
|
pubblct[] expectedSchemas = new Object[] { AnonymousType("{'path': 'a'}", "{'path': 'b', 'direction': 'desc'}, " +
|
||||||
|
"{'path': 'c'}", new String[] { "a" }, new Object[] { AnonymousType2("b", SortDirection.DESCENDING),
|
||||||
|
AnonymousType3("c", SortDirection.ASCENDING) }) };
|
||||||
|
|
||||||
|
for(bjeic AnonymousType3(String _Path, SortDirection _Dir) {
|
||||||
|
Path = _Path;
|
||||||
|
Dir = _Dir;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OObject expected:expectedSchemas)
|
||||||
|
{
|
||||||
|
String tableSchema=String.format("{{"+"\r\n"+
|
||||||
|
" 'name': 'table', "+"\r\n"+
|
||||||
|
" 'id': -3,"+"\r\n"+
|
||||||
|
" 'type': 'schema', "+"\r\n"+
|
||||||
|
" 'properties': ["+"\r\n"+
|
||||||
|
" {{'path': 'a', 'type': {{'type': 'int8', 'storage': 'fixed'}}}},")+"\r\n"+
|
||||||
|
" {{'path': 'b', 'type': {{'type': 'utf8', 'storage': 'variable', 'length': 2}}}},"
|
||||||
|
+"\r\n"+
|
||||||
|
" {{'path': 'c', 'type': {{'type': 'datetime', 'storage': 'fixed'}}}},"+"\r\n"+
|
||||||
|
" ],"+"\r\n"+
|
||||||
|
" 'partitionkeys': [{expected.JsonPK}],"+"\r\n"+
|
||||||
|
" 'primarykeys': [{expected.JsonCK}]"+"\r\n"+
|
||||||
|
" }}";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Schema s=Schema.Parse(tableSchema);
|
||||||
|
Assert.AreEqual(3,s.getProperties().size(),"PK: {0}, CK: {1}",expected.JsonPK,expected.JsonCK);
|
||||||
|
for(int i=0;i<s.getPartitionKeys().size();i++)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(expected.PK[i],s.getPartitionKeys().get(i).getPath(),"PK: {0}, CK: {1}",expected.JsonPK,
|
||||||
|
expected.JsonCK);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(int i=0;i<s.getPrimarySortKeys().size();i++)
|
||||||
|
{
|
||||||
|
Assert.AreEqual(expected.CK[i].Path,s.getPrimarySortKeys().get(i).getPath(),"PK: {0}, CK: {1}",expected.JsonPK,
|
||||||
|
expected.JsonCK);
|
||||||
|
Assert.AreEqual(expected.CK[i].Dir,s.getPrimarySortKeys().get(i).getDirection(),"PK: {0}, CK: {1}",
|
||||||
|
expected.JsonPK,expected.JsonCK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(RuntimeException ex)
|
||||||
|
{
|
||||||
|
Assert.Fail("Exception: {0}, PK: {1}, CK: {2}",ex,expected.JsonPK,expected.JsonCK);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("vahemesw")] public void ParseSchemaStaticKeys()
|
||||||
|
public final void ParseSchemaStaticKeys()
|
||||||
|
{
|
||||||
|
|
||||||
|
class AnonymousType {
|
||||||
|
public String JsonStaticKeys;
|
||||||
|
public int NumberOfPaths;
|
||||||
|
public Object[] StaticKeys;
|
||||||
|
|
||||||
|
public AnonymousType(int _NumberOfPaths, String _JsonStaticKeys, Object[] _StaticKeys) {
|
||||||
|
NumberOfPaths = _NumberOfPaths;
|
||||||
|
JsonStaticKeys = _JsonStaticKeys;
|
||||||
|
StaticKeys = _StaticKeys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String Path;
|
||||||
|
|
||||||
|
public AnonymousType2(String _Path) {
|
||||||
|
Path = _Path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType3 {
|
||||||
|
public String JsonStaticKeys;
|
||||||
|
public int NumberOfPaths;
|
||||||
|
public Object[] StaticKeys;
|
||||||
|
|
||||||
|
public AnonymousType3(int _NumberOfPaths, String _JsonStaticKeys, Object[] _StaticKeys) {
|
||||||
|
NumberOfPaths = _NumberOfPaths;
|
||||||
|
JsonStaticKeys = _JsonStaticKeys;
|
||||||
|
StaticKeys = _StaticKeys;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType4 {
|
||||||
|
public String Path;
|
||||||
|
|
||||||
|
public AnonymousType4(String _Path) {
|
||||||
|
Path = _Path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType5 {
|
||||||
|
public String Path;
|
||||||
|
|
||||||
|
publct[] expectedSchemas = new Object[] { AnonymousType(1, "{'path': 'c'}", new Object[] { AnonymousType2("c") })
|
||||||
|
, AnonymousType3(2, "{'path': 'c'}, {'path': 'd'}",
|
||||||
|
new Object[] { AnonymousType4("c"), AnonymousType5("d") }) };
|
||||||
|
|
||||||
|
for(bjeic AnonymousType5(String _Path) {
|
||||||
|
Path = _Path;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OObject expected:expectedSchemas)
|
||||||
|
{
|
||||||
|
String tableSchema=String.format("{{"+"\r\n"+
|
||||||
|
" 'name': 'table', "+"\r\n"+
|
||||||
|
" 'id': -3,"+"\r\n"+
|
||||||
|
" 'type': 'schema', "+"\r\n"+
|
||||||
|
" 'properties': ["+"\r\n"+
|
||||||
|
" {{'path': 'a', 'type': {{'type': 'int8', 'storage': 'fixed'}}}},")+"\r\n"+
|
||||||
|
" {{'path': 'b', 'type': {{'type': 'utf8', 'storage': 'variable', 'length': 2}}}},"
|
||||||
|
+"\r\n"+
|
||||||
|
" {{'path': 'c', 'type': {{'type': 'datetime', 'storage': 'fixed'}}}},"+"\r\n"+
|
||||||
|
" {{'path': 'd', 'type': {{'type': 'int8', 'storage': 'fixed'}}}},"+"\r\n"+
|
||||||
|
" ],"+"\r\n"+
|
||||||
|
" 'partitionkeys': [{{'path': 'a'}}],"+"\r\n"+
|
||||||
|
" 'primarykeys': [{{'path': 'b', 'direction': 'desc'}}],"+"\r\n"+
|
||||||
|
" 'statickeys': [{expected.JsonStaticKeys}]"+"\r\n"+
|
||||||
|
" }}";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Schema s=Schema.Parse(tableSchema);
|
||||||
|
assert expected.NumberOfPaths==s.getStaticKeys().size();
|
||||||
|
for(int i=0;i<s.getStaticKeys().size();i++)
|
||||||
|
{
|
||||||
|
assert expected.StaticKeys[i].Path==s.getStaticKeys().get(i).getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(RuntimeException ex)
|
||||||
|
{
|
||||||
|
Assert.Fail("Exception: {0}, Caught exception when deserializing the schema",ex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void ParseSchemaApiType()
|
||||||
|
public final void ParseSchemaApiType()
|
||||||
|
{
|
||||||
|
|
||||||
|
// Test api type specifications include elements of complex types.
|
||||||
|
class AnonymousType {
|
||||||
|
public String ApiType;
|
||||||
|
|
||||||
|
pulic String Json
|
||||||
|
|
||||||
|
pubblic AnonymousType(String _Json, String _ApiType) {
|
||||||
|
Json = _Json;
|
||||||
|
ApiType = _ApiType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class AnonymousType2 {
|
||||||
|
public String ApiType;
|
||||||
|
|
||||||
|
pulic String Json
|
||||||
|
pubblct[] expectedSchemas = new Object[] { AnonymousType("{'type': 'int64', 'apitype': 'counter'}", "counter"),
|
||||||
|
AnonymousType2("{'type': 'array', 'items': {'type': 'int64', 'apitype': 'timestamp'}}", "timestamp") };
|
||||||
|
|
||||||
|
for(bjeic AnonymousType2(String _Json, String _ApiType) {
|
||||||
|
Json = _Json;
|
||||||
|
ApiType = _ApiType;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
OObject expected:expectedSchemas)
|
||||||
|
{
|
||||||
|
String columnSchema=String.format("{'path': 'a', 'type': %1$s",expected.Json}});
|
||||||
|
String tableSchema=String.format("{'name': 'table', 'id': -4, 'type': 'schema', 'properties': [%1$s]}",
|
||||||
|
columnSchema);
|
||||||
|
Schema s=Schema.Parse(tableSchema);
|
||||||
|
Assert.AreEqual(1,s.getProperties().size(),"Json: {0}",expected.Json);
|
||||||
|
Property p=s.getProperties().get(0);
|
||||||
|
switch(p.getPropertyType().getType())
|
||||||
|
{
|
||||||
|
case Array:
|
||||||
|
ArrayPropertyType subArray=(ArrayPropertyType)p.getPropertyType();
|
||||||
|
Assert.AreEqual(expected.ApiType,subArray.getItems().getApiType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Assert.AreEqual(expected.ApiType,p.getPropertyType().getApiType(),"Json: {0}",expected.Json);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void SchemaRef()
|
||||||
|
public final void SchemaRef()
|
||||||
|
{
|
||||||
|
NamespaceParserTest tempVar=new NamespaceParserTest();
|
||||||
|
tempVar.setName("SchemaNameOnlyRef");
|
||||||
|
tempVar.setJson("{'schemas': [ { 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 2, 'type': " +
|
||||||
|
"'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A'}} ]} ]}");
|
||||||
|
NamespaceParserTest tempVar2=new NamespaceParserTest();
|
||||||
|
tempVar2.setName("SchemaNameAndIdRef");
|
||||||
|
tempVar2.setJson("{'schemas': [ { 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 2, 'type': " +
|
||||||
|
"'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A', 'id': 1}} ]} ]}");
|
||||||
|
NamespaceParserTest tempVar3=new NamespaceParserTest();
|
||||||
|
tempVar3.setName("SchemaMultipleVersionNameAndIdRef");
|
||||||
|
tempVar3.setJson("{'schemas': [ { 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 2, 'type': " +
|
||||||
|
"'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A', 'id': 3}} ]}, { 'name': 'A', " +
|
||||||
|
"'id': 3, 'type': 'schema'} ]}");
|
||||||
|
NamespaceParserTest[]tests=new NamespaceParserTest[]{tempVar,tempVar2,tempVar3};
|
||||||
|
|
||||||
|
for(NamespaceParserTest t:tests)
|
||||||
|
{
|
||||||
|
System.out.println(t.getName());
|
||||||
|
Namespace.Parse(t.getJson());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void NegativeNamespaceParser()
|
||||||
|
public final void NegativeNamespaceParser()
|
||||||
|
{
|
||||||
|
NamespaceParserTest tempVar=new NamespaceParserTest();
|
||||||
|
tempVar.setName("InvalidId");
|
||||||
|
tempVar.setJson("{'schemas': [{ 'name': 'A', 'id': 0, 'type': 'schema'}]}");
|
||||||
|
NamespaceParserTest tempVar2=new NamespaceParserTest();
|
||||||
|
tempVar2.setName("InvalidNameEmpty");
|
||||||
|
tempVar2.setJson("{'schemas': [{ 'name': '', 'id': 1, 'type': 'schema'}]}");
|
||||||
|
NamespaceParserTest tempVar3=new NamespaceParserTest();
|
||||||
|
tempVar3.setName("InvalidNameWhitespace");
|
||||||
|
tempVar3.setJson("{'schemas': [{ 'name': ' ', 'id': 1, 'type': 'schema'}]}");
|
||||||
|
NamespaceParserTest tempVar4=new NamespaceParserTest();
|
||||||
|
tempVar4.setName("DuplicateId");
|
||||||
|
tempVar4.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 1, 'type': " +
|
||||||
|
"'schema'} ]}");
|
||||||
|
NamespaceParserTest tempVar5=new NamespaceParserTest();
|
||||||
|
tempVar5.setName("DuplicatePropertyName");
|
||||||
|
tempVar5.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': " +
|
||||||
|
"{'type': 'bool'}}, {'path': 'b', 'type': {'type': 'int8'}}, ]}]}");
|
||||||
|
NamespaceParserTest tempVar6=new NamespaceParserTest();
|
||||||
|
tempVar6.setName("MissingPK");
|
||||||
|
tempVar6.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'partitionkeys': [{'path': 'b'}]}]}");
|
||||||
|
NamespaceParserTest tempVar7=new NamespaceParserTest();
|
||||||
|
tempVar7.setName("MissingPS");
|
||||||
|
tempVar7.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'primarykeys': [{'path': 'b'}]}]}");
|
||||||
|
NamespaceParserTest tempVar8=new NamespaceParserTest();
|
||||||
|
tempVar8.setName("MissingStaticKey");
|
||||||
|
tempVar8.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'statickeys': [{'path': 'b'}]}]}");
|
||||||
|
NamespaceParserTest tempVar9=new NamespaceParserTest();
|
||||||
|
tempVar9.setName("InvalidPropertyName");
|
||||||
|
tempVar9.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [{'path': '', 'type': {'type': 'bool'}}]}]}");
|
||||||
|
NamespaceParserTest tempVar10=new NamespaceParserTest();
|
||||||
|
tempVar10.setName("InvalidLength");
|
||||||
|
tempVar10.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'utf8', 'length': -1}} ]}]}");
|
||||||
|
NamespaceParserTest tempVar11=new NamespaceParserTest();
|
||||||
|
tempVar11.setName("InvalidStorage");
|
||||||
|
tempVar11.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'array', 'items': {'type': 'utf8', 'storage': 'fixed'}}} ]}]}");
|
||||||
|
NamespaceParserTest tempVar12=new NamespaceParserTest();
|
||||||
|
tempVar12.setName("DuplicateObjectProperties");
|
||||||
|
tempVar12.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'object', 'properties': [ {'path': 'c', 'type': {'type': 'bool'}}, {'path': 'c', 'type': {'type': 'int8'}} ]}} ]}]}");
|
||||||
|
NamespaceParserTest tempVar13=new NamespaceParserTest();
|
||||||
|
tempVar13.setName("MissingUDTName");
|
||||||
|
tempVar13.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'B'}} ]}]}");
|
||||||
|
NamespaceParserTest tempVar14=new NamespaceParserTest();
|
||||||
|
tempVar14.setName("MissingUDTId");
|
||||||
|
tempVar14.setJson("{'schemas': [{ 'name': 'A', 'id': 1, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A', 'id': 3}} ]}]}");
|
||||||
|
NamespaceParserTest tempVar15=new NamespaceParserTest();
|
||||||
|
tempVar15.setName("MismatchedSchemaRef");
|
||||||
|
tempVar15.setJson("{'schemas': [ { 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 2, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A', 'id': 2}} ]} ]}");
|
||||||
|
NamespaceParserTest tempVar16=new NamespaceParserTest();
|
||||||
|
tempVar16.setName("AmbiguousSchemaRef");
|
||||||
|
tempVar16.setJson("{'schemas': [ { 'name': 'A', 'id': 1, 'type': 'schema'}, { 'name': 'B', 'id': 2, 'type': 'schema', 'properties': [ {'path': 'b', 'type': {'type': 'schema', 'name': 'A'}} ]}, { 'name': 'A', 'id': 3, 'type': 'schema'} ]}");
|
||||||
|
NamespaceParserTest[]tests=new NamespaceParserTest[]{tempVar,tempVar2,tempVar3,tempVar4,tempVar5,tempVar6,tempVar7,tempVar8,tempVar9,tempVar10,tempVar11,tempVar12,tempVar13,tempVar14,tempVar15,tempVar16};
|
||||||
|
|
||||||
|
for(NamespaceParserTest t:tests)
|
||||||
|
{
|
||||||
|
System.out.println(t.getName());
|
||||||
|
AssertThrowsException.<SchemaException>ThrowsException(()->Namespace.Parse(t.getJson()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ from the original:
|
||||||
|
//ORIGINAL LINE: private struct NamespaceParserTest
|
||||||
|
private final static class NamespaceParserTest {
|
||||||
|
private String Name;
|
||||||
|
|
||||||
|
publblivate String Json
|
||||||
|
|
||||||
|
publ
|
||||||
|
ic String getName() {
|
||||||
|
return Name;
|
||||||
|
}
|
||||||
|
|
||||||
|
puic String getJson() {
|
||||||
|
return Json;
|
||||||
|
}
|
||||||
|
|
||||||
|
publ
|
||||||
|
ic void setName(String value) {
|
||||||
|
Name = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
pric void setJson(String value) {
|
||||||
|
Json = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,317 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReaderExtensions;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1201 // Elements should appear in the correct order
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1204 // Elements should appear in the correct order
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable CA1034 // Nested types should not be visible
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable CA1051 // Do not declare visible instance fields
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(SerializerUnitTest.SchemaFile, "TestData")] public sealed class
|
||||||
|
// SerializerUnitTest
|
||||||
|
public final class SerializerUnitTest {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
private static final String SchemaFile = "TestData\\BatchApiSchema.json";
|
||||||
|
private Layout layout;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateBatchRequest()
|
||||||
|
public void CreateBatchRequest() {
|
||||||
|
BatchRequest request = new BatchRequest();
|
||||||
|
BatchOperation tempVar = new BatchOperation();
|
||||||
|
tempVar.OperationType = 3;
|
||||||
|
tempVar.Headers = new BatchRequestHeaders();
|
||||||
|
tempVar.Headers.SampleRequestHeader = 12345L;
|
||||||
|
tempVar.ResourceType = 1;
|
||||||
|
tempVar.ResourcePath = "/some/url/path";
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: tempVar.ResourceBody = new byte[] { 1, 2, 3 };
|
||||||
|
tempVar.ResourceBody = new byte[] { 1, 2, 3 };
|
||||||
|
BatchOperation tempVar2 = new BatchOperation();
|
||||||
|
tempVar2.OperationType = 2;
|
||||||
|
tempVar2.Headers = new BatchRequestHeaders();
|
||||||
|
tempVar2.Headers.SampleRequestHeader = 98746L;
|
||||||
|
tempVar2.ResourceType = 2;
|
||||||
|
tempVar2.ResourcePath = "/some/other/url/path";
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: tempVar2.ResourceBody = new byte[] { 3, 2, 1 };
|
||||||
|
tempVar2.ResourceBody = new byte[] { 3, 2, 1 };
|
||||||
|
request.Operations = new ArrayList<BatchOperation>(Arrays.asList(tempVar, tempVar2));
|
||||||
|
|
||||||
|
// Write the request by serializing it to a row.
|
||||||
|
RowBuffer row = new RowBuffer(SerializerUnitTest.InitialRowSize);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.layout, this.resolver);
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Result r = RowWriter.WriteBuffer(tempReference_row, request, BatchRequestSerializer.Write);
|
||||||
|
row = tempReference_row.get();
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
System.out.printf("Length of serialized row: %1$s" + "\r\n", row.length());
|
||||||
|
|
||||||
|
// Read the row back again.
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowReader reader = new RowReader(tempReference_row2);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
Reference<RowReader> tempReference_reader =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
BatchRequest _;
|
||||||
|
Out<BatchRequest> tempOut__ = new Out<BatchRequest>();
|
||||||
|
r = BatchRequestSerializer.Read(tempReference_reader, tempOut__);
|
||||||
|
_ = tempOut__.get();
|
||||||
|
reader = tempReference_reader.get();
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
|
||||||
|
// Dump the materialized request to the console.
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
reader = new RowReader(tempReference_row3);
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
Reference<RowReader> tempReference_reader2 =
|
||||||
|
new Reference<RowReader>(reader);
|
||||||
|
String dumpStr;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
r = DiagnosticConverter.ReaderToString(tempReference_reader2, out dumpStr);
|
||||||
|
reader = tempReference_reader2.get();
|
||||||
|
assert Result.SUCCESS == r;
|
||||||
|
System.out.println(dumpStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void InitTestSuite()
|
||||||
|
public void InitTestSuite() {
|
||||||
|
String json = Files.readString(SerializerUnitTest.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
this.layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"BatchRequest")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchOperation {
|
||||||
|
public BatchRequestHeaders Headers;
|
||||||
|
public int OperationType;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ResourceBody;
|
||||||
|
public byte[] ResourceBody;
|
||||||
|
public String ResourcePath;
|
||||||
|
public int ResourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchOperationResponse {
|
||||||
|
public BatchResponseHeaders Headers;
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public byte[] ResourceBody;
|
||||||
|
public byte[] ResourceBody;
|
||||||
|
public int StatusCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BatchOperationSerializer {
|
||||||
|
public static final TypeArgument TypeArg = new TypeArgument(LayoutType.UDT,
|
||||||
|
new TypeArgumentList(new SchemaId(2)));
|
||||||
|
|
||||||
|
public static Result Read(Reference<RowReader> reader, Out<BatchOperation> operation) {
|
||||||
|
BatchOperation retval = new BatchOperation();
|
||||||
|
operation.setAndGet(null);
|
||||||
|
while (reader.get().read()) {
|
||||||
|
Result r;
|
||||||
|
switch (reader.get().path()) {
|
||||||
|
case "operationType":
|
||||||
|
Out<Integer> tempOut_OperationType = new Out<Integer>();
|
||||||
|
r = reader.get().readInt32(tempOut_OperationType);
|
||||||
|
retval.OperationType = tempOut_OperationType.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "headers":
|
||||||
|
Reference<RowReader> tempReference_child = new Reference<RowReader>(child);
|
||||||
|
Out<BatchRequestHeaders> tempOut_Headers = new Out<BatchRequestHeaders>();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword
|
||||||
|
// - these are not converted by C# to Java Converter:
|
||||||
|
r = reader.get().readScope(retval,
|
||||||
|
(RowReader RowReader child, BatchOperation parent) -> BatchRequestHeadersSerializer.Read(tempReference_child, tempOut_Headers));
|
||||||
|
parent.Headers = tempOut_Headers.get();
|
||||||
|
child = tempReference_child.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "resourceType":
|
||||||
|
Out<Integer> tempOut_ResourceType = new Out<Integer>();
|
||||||
|
r = reader.get().readInt32(tempOut_ResourceType);
|
||||||
|
retval.ResourceType = tempOut_ResourceType.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "resourcePath":
|
||||||
|
Out<String> tempOut_ResourcePath = new Out<String>();
|
||||||
|
r = reader.get().readUtf8String(tempOut_ResourcePath);
|
||||||
|
retval.ResourcePath = tempOut_ResourcePath.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "resourceBody":
|
||||||
|
Out<Byte> tempOut_ResourceBody = new Out<Byte>();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: r = reader.ReadBinary(out retval.ResourceBody);
|
||||||
|
r = reader.get().ReadBinary(tempOut_ResourceBody);
|
||||||
|
retval.ResourceBody = tempOut_ResourceBody.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
operation.setAndGet(retval);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg,
|
||||||
|
BatchOperation operation) {
|
||||||
|
Result r = writer.get().WriteInt32("operationType", operation.OperationType);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = writer.get().WriteScope("headers", BatchRequestHeadersSerializer.TypeArg, operation.Headers,
|
||||||
|
BatchRequestHeadersSerializer.Write);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = writer.get().WriteInt32("resourceType", operation.ResourceType);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = writer.get().WriteString("resourcePath", operation.ResourcePath);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
r = writer.get().WriteBinary("resourceBody", operation.ResourceBody);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchRequest {
|
||||||
|
public ArrayList<BatchOperation> Operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchRequestHeaders {
|
||||||
|
public long SampleRequestHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BatchRequestHeadersSerializer {
|
||||||
|
public static final TypeArgument TypeArg = new TypeArgument(LayoutType.UDT,
|
||||||
|
new TypeArgumentList(new SchemaId(1)));
|
||||||
|
|
||||||
|
public static Result Read(Reference<RowReader> reader,
|
||||||
|
Out<BatchRequestHeaders> header) {
|
||||||
|
BatchRequestHeaders retval = new BatchRequestHeaders();
|
||||||
|
header.setAndGet(null);
|
||||||
|
while (reader.get().read()) {
|
||||||
|
switch (reader.get().path()) {
|
||||||
|
case "sampleRequestHeader":
|
||||||
|
Out<Long> tempOut_SampleRequestHeader = new Out<Long>();
|
||||||
|
Result r = reader.get().readInt64(tempOut_SampleRequestHeader);
|
||||||
|
retval.SampleRequestHeader = tempOut_SampleRequestHeader.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
header.setAndGet(retval);
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg,
|
||||||
|
BatchRequestHeaders header) {
|
||||||
|
Result r = writer.get().WriteInt64("sampleRequestHeader", header.SampleRequestHeader);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class BatchRequestSerializer {
|
||||||
|
public static final TypeArgument OperationsTypeArg = new TypeArgument(LayoutType.TypedArray, new TypeArgumentList(new TypeArgument[] { BatchOperationSerializer.TypeArg }));
|
||||||
|
|
||||||
|
public static Result Read(Reference<RowReader> reader, Out<BatchRequest> request) {
|
||||||
|
assert reader.get().read();
|
||||||
|
checkState(reader.get().path().equals("operations"));
|
||||||
|
|
||||||
|
java.util.ArrayList<BatchOperation> operations;
|
||||||
|
Out<ArrayList<TItem>> tempOut_operations = new Out<ArrayList<TItem>>();
|
||||||
|
Result r = RowReaderExtensions.readList(reader.get().clone(), BatchOperationSerializer.Read, tempOut_operations);
|
||||||
|
operations = tempOut_operations.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
request.setAndGet(null);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
request.setAndGet(new BatchRequest());
|
||||||
|
request.get().Operations = operations;
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, BatchRequest request) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
return writer.get().WriteScope("operations", BatchRequestSerializer.OperationsTypeArg, request.Operations, (ref RowWriter writer2, TypeArgument typeArg2, ArrayList<BatchOperation> operations) ->
|
||||||
|
{
|
||||||
|
for (BatchOperation operation : operations) {
|
||||||
|
Result r = writer2.WriteScope(null, BatchOperationSerializer.TypeArg, operation, BatchOperationSerializer.Write);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchResponse {
|
||||||
|
public ArrayList<BatchOperationResponse> Operations;
|
||||||
|
}
|
||||||
|
|
||||||
|
public final static class BatchResponseHeaders {
|
||||||
|
public String SampleResponseHeader;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,256 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(TaggedUnitTests.SchemaFile, "TestData")] public sealed class TaggedUnitTests
|
||||||
|
public final class TaggedUnitTests {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
private static final String SchemaFile = "TestData\\TaggedApiSchema.json";
|
||||||
|
private Layout layout;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
private Namespace schema;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateTaggedApi()
|
||||||
|
public void CreateTaggedApi() {
|
||||||
|
RowBuffer row = new RowBuffer(TaggedUnitTests.InitialRowSize);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.layout, this.resolver);
|
||||||
|
|
||||||
|
TaggedApi c1 = new TaggedApi();
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: c1.Tag1 = ((byte)1, "hello");
|
||||||
|
c1.Tag1 = ((byte)1, "hello")
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: c1.Tag2 = ((byte)2, 28, 1974L);
|
||||||
|
c1.Tag2 = ((byte)2, 28, 1974L)
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
this.WriteTaggedApi(tempReference_row, RowCursor.create(tempReference_row2, out _), c1);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
TaggedApi c2 = this.ReadTaggedApi(tempReference_row3, RowCursor.create(tempReference_row4, out _));
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
assert c1 == c2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString(TaggedUnitTests.SchemaFile);
|
||||||
|
this.schema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.schema);
|
||||||
|
this.layout = this.resolver.Resolve(tangible.ListHelper.find(this.schema.getSchemas(), x -> x.Name.equals(
|
||||||
|
"TaggedApi")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private TaggedApi ReadTaggedApi(Reference<RowBuffer> row, Reference<RowCursor> root) {
|
||||||
|
TaggedApi pc = new TaggedApi();
|
||||||
|
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("tag1", out c);
|
||||||
|
assert c.Type.Immutable;
|
||||||
|
RowCursor tag1Scope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out tag1Scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutIndexedScope>TypeAs().ReadScope(row, ref tag1Scope, out tag1Scope) == Result.SUCCESS) {
|
||||||
|
assert tag1Scope.Immutable;
|
||||||
|
assert tag1Scope.MoveNext(row);
|
||||||
|
byte apiCode;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ResultAssert.IsSuccess(c.TypeArgs[0].Type.TypeAs<LayoutUInt8>().ReadSparse(ref row, ref
|
||||||
|
// tag1Scope, out byte apiCode));
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUInt8>TypeAs().ReadSparse(row, ref tag1Scope,
|
||||||
|
out apiCode));
|
||||||
|
assert tag1Scope.MoveNext(row);
|
||||||
|
String str;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[1].Type.<LayoutUtf8>TypeAs().ReadSparse(row, ref tag1Scope, out str));
|
||||||
|
pc.Tag1 = (apiCode, str)
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("tag2", out c);
|
||||||
|
assert !c.Type.Immutable;
|
||||||
|
RowCursor tag2Scope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out tag2Scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutIndexedScope>TypeAs().ReadScope(row, ref tag2Scope, out tag2Scope) == Result.SUCCESS) {
|
||||||
|
assert !tag2Scope.Immutable;
|
||||||
|
assert tag2Scope.MoveNext(row);
|
||||||
|
byte apiCode;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: ResultAssert.IsSuccess(c.TypeArgs[0].Type.TypeAs<LayoutUInt8>().ReadSparse(ref row, ref
|
||||||
|
// tag2Scope, out byte apiCode));
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUInt8>TypeAs().ReadSparse(row, ref tag2Scope,
|
||||||
|
out apiCode));
|
||||||
|
assert tag2Scope.MoveNext(row);
|
||||||
|
int val1;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[1].Type.<LayoutInt32>TypeAs().ReadSparse(row, ref tag2Scope, out val1));
|
||||||
|
assert tag2Scope.MoveNext(row);
|
||||||
|
long val2;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[2].Type.<LayoutInt64>TypeAs().ReadSparse(row, ref tag2Scope, out val2));
|
||||||
|
pc.Tag2 = (apiCode, val1, val2)
|
||||||
|
}
|
||||||
|
|
||||||
|
return pc;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteTaggedApi(Reference<RowBuffer> row, Reference<RowCursor> root, TaggedApi pc) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("tag1", out c);
|
||||||
|
RowCursor tag1Scope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out tag1Scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutIndexedScope>TypeAs().WriteScope(row, ref tag1Scope, c.TypeArgs,
|
||||||
|
out tag1Scope));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUInt8>TypeAs().WriteSparse(row, ref tag1Scope, pc.Tag1.Item1));
|
||||||
|
assert tag1Scope.MoveNext(row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[1].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref tag1Scope, pc.Tag1.Item2));
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("tag2", out c);
|
||||||
|
RowCursor tag2Scope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out tag2Scope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutIndexedScope>TypeAs().WriteScope(row, ref tag2Scope, c.TypeArgs,
|
||||||
|
out tag2Scope));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUInt8>TypeAs().WriteSparse(row, ref tag2Scope, pc.Tag2.Item1));
|
||||||
|
assert tag2Scope.MoveNext(row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[1].Type.<LayoutInt32>TypeAs().WriteSparse(row, ref tag2Scope, pc.Tag2.Item2));
|
||||||
|
assert tag2Scope.MoveNext(row);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[2].Type.<LayoutInt64>TypeAs().WriteSparse(row, ref tag2Scope, pc.Tag2.Item3));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1401", Justification = "Test
|
||||||
|
// types.")] private sealed class TaggedApi
|
||||||
|
private final static class TaggedApi {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public (byte, string) Tag1;
|
||||||
|
public (byte,String)Tag1
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: public (byte, int, long) Tag2;
|
||||||
|
public (byte,int,long)Tag2
|
||||||
|
|
||||||
|
// ReSharper disable once MemberCanBePrivate.Local
|
||||||
|
public boolean equals(TaggedApi other) {
|
||||||
|
return this.Tag1.equals(other.Tag1) && this.Tag2.equals(other.Tag2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tempVar = obj instanceof TaggedApi;
|
||||||
|
TaggedApi taggedApi = tempVar ? (TaggedApi)obj : null;
|
||||||
|
return tempVar && this.equals(taggedApi);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = 0;
|
||||||
|
hashCode = (hashCode * 397) ^ this.Tag1.hashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ this.Tag2.hashCode();
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,663 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.HybridRowVersion;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursors;
|
||||||
|
|
||||||
|
import java.nio.file.Files;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
// ReSharper disable StringLiteralTypo
|
||||||
|
// ReSharper disable IdentifierTypo
|
||||||
|
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass][DeploymentItem(TypedArrayUnitTests.SchemaFile, "TestData")] public sealed class
|
||||||
|
// TypedArrayUnitTests
|
||||||
|
public final class TypedArrayUnitTests {
|
||||||
|
private static final int InitialRowSize = 2 * 1024 * 1024;
|
||||||
|
private static final String SchemaFile = "TestData\\TagSchema.json";
|
||||||
|
private Namespace counterSchema;
|
||||||
|
private Layout layout;
|
||||||
|
private LayoutResolver resolver;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void CreateTags()
|
||||||
|
public void CreateTags() {
|
||||||
|
RowBuffer row = new RowBuffer(TypedArrayUnitTests.InitialRowSize);
|
||||||
|
row.initLayout(HybridRowVersion.V1, this.layout, this.resolver);
|
||||||
|
|
||||||
|
Tagged t1 = new Tagged();
|
||||||
|
t1.Title = "Thriller";
|
||||||
|
t1.Tags = new ArrayList<String>(Arrays.asList("classic", "Post-disco", "funk"));
|
||||||
|
t1.Options = new ArrayList<Integer>(Arrays.asList(8, null, 9));
|
||||||
|
t1.Ratings = new ArrayList<ArrayList<Double>>(Arrays.asList(new ArrayList<Double>(Arrays.asList(1.2, 3.0)),
|
||||||
|
new ArrayList<Double>(Arrays.asList(4.1, 5.7)), new ArrayList<Double>(Arrays.asList(7.3, 8.12, 9.14))));
|
||||||
|
SimilarMatch tempVar = new SimilarMatch();
|
||||||
|
tempVar.Thumbprint = "TRABACN128F425B784";
|
||||||
|
tempVar.Score = 0.87173699999999998;
|
||||||
|
SimilarMatch tempVar2 = new SimilarMatch();
|
||||||
|
tempVar2.Thumbprint = "TRJYGLF12903CB4952";
|
||||||
|
tempVar2.Score = 0.75105200000000005;
|
||||||
|
SimilarMatch tempVar3 = new SimilarMatch();
|
||||||
|
tempVar3.Thumbprint = "TRWJMMB128F429D550";
|
||||||
|
tempVar3.Score = 0.50866100000000003;
|
||||||
|
t1.Similars = new ArrayList<SimilarMatch>(Arrays.asList(tempVar, tempVar2, tempVar3));
|
||||||
|
t1.Priority = new ArrayList<Tuple<String, Long>>(Arrays.asList(Tuple.Create("80's", 100L), Tuple.Create(
|
||||||
|
"classics", 100L), Tuple.Create("pop", 50L)));
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_row =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row2 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
this.WriteTagged(tempReference_row, RowCursor.create(tempReference_row2, out _), t1);
|
||||||
|
row = tempReference_row2.get();
|
||||||
|
row = tempReference_row.get();
|
||||||
|
Reference<RowBuffer> tempReference_row3 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
Reference<RowBuffer> tempReference_row4 =
|
||||||
|
new Reference<RowBuffer>(row);
|
||||||
|
RowCursor _;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
Tagged t2 = this.ReadTagged(tempReference_row3, RowCursor.create(tempReference_row4, out _));
|
||||||
|
row = tempReference_row4.get();
|
||||||
|
row = tempReference_row3.get();
|
||||||
|
assert t1 == t2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestInitialize] public void ParseNamespaceExample()
|
||||||
|
public void ParseNamespaceExample() {
|
||||||
|
String json = Files.readString(TypedArrayUnitTests.SchemaFile);
|
||||||
|
this.counterSchema = Namespace.Parse(json);
|
||||||
|
this.resolver = new LayoutResolverNamespace(this.counterSchema);
|
||||||
|
this.layout = this.resolver.Resolve(tangible.ListHelper.find(this.counterSchema.getSchemas(),
|
||||||
|
x -> x.Name.equals("Tagged")).SchemaId);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static SimilarMatch ReadSimilarMatch(Reference<RowBuffer> row,
|
||||||
|
Reference<RowCursor> matchScope) {
|
||||||
|
Layout matchLayout = matchScope.get().getLayout();
|
||||||
|
SimilarMatch m = new SimilarMatch();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert matchLayout.TryFind("thumbprint", out c);
|
||||||
|
Out<String> tempOut_Thumbprint = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadFixed(row, matchScope, c, tempOut_Thumbprint));
|
||||||
|
m.Thumbprint = tempOut_Thumbprint.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert matchLayout.TryFind("score", out c);
|
||||||
|
Out<Double> tempOut_Score = new Out<Double>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutFloat64>TypeAs().ReadFixed(row, matchScope, c, tempOut_Score));
|
||||||
|
m.Score = tempOut_Score.get();
|
||||||
|
return m;
|
||||||
|
}
|
||||||
|
|
||||||
|
private Tagged ReadTagged(Reference<RowBuffer> row, Reference<RowCursor> root) {
|
||||||
|
Tagged value = new Tagged();
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("title", out c);
|
||||||
|
Out<String> tempOut_Title = new Out<String>();
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().ReadVariable(row, root, c, tempOut_Title));
|
||||||
|
value.Title = tempOut_Title.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("tags", out c);
|
||||||
|
RowCursor tagsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out tagsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref tagsScope, out tagsScope) == Result.SUCCESS) {
|
||||||
|
value.Tags = new ArrayList<String>();
|
||||||
|
while (tagsScope.MoveNext(row)) {
|
||||||
|
String item;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().ReadSparse(row, ref tagsScope,
|
||||||
|
out item));
|
||||||
|
value.Tags.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("options", out c);
|
||||||
|
RowCursor optionsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out optionsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref optionsScope, out optionsScope) == Result.SUCCESS) {
|
||||||
|
value.Options = new ArrayList<Integer>();
|
||||||
|
while (optionsScope.MoveNext(row)) {
|
||||||
|
TypeArgument itemType = c.TypeArgs[0];
|
||||||
|
Reference<RowCursor> tempReference_optionsScope =
|
||||||
|
new Reference<RowCursor>(optionsScope);
|
||||||
|
RowCursor nullableScope;
|
||||||
|
Out<RowCursor> tempOut_nullableScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(itemType.getType().<LayoutNullable>TypeAs().ReadScope(row,
|
||||||
|
tempReference_optionsScope, tempOut_nullableScope));
|
||||||
|
nullableScope = tempOut_nullableScope.get();
|
||||||
|
optionsScope = tempReference_optionsScope.get();
|
||||||
|
|
||||||
|
if (nullableScope.MoveNext(row)) {
|
||||||
|
Reference<RowCursor> tempReference_nullableScope = new Reference<RowCursor>(nullableScope);
|
||||||
|
ResultAssert.IsSuccess(LayoutNullable.HasValue(row, tempReference_nullableScope));
|
||||||
|
nullableScope = tempReference_nullableScope.get();
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_nullableScope2 = new Reference<RowCursor>(nullableScope);
|
||||||
|
int itemValue;
|
||||||
|
Out<Integer> tempOut_itemValue = new Out<Integer>();
|
||||||
|
ResultAssert.IsSuccess(itemType.getTypeArgs().get(0).getType().<LayoutInt32>TypeAs().ReadSparse(row, tempReference_nullableScope2, tempOut_itemValue));
|
||||||
|
itemValue = tempOut_itemValue.get();
|
||||||
|
nullableScope = tempReference_nullableScope2.get();
|
||||||
|
|
||||||
|
value.Options.add(itemValue);
|
||||||
|
} else {
|
||||||
|
Reference<RowCursor> tempReference_nullableScope3 = new Reference<RowCursor>(nullableScope);
|
||||||
|
ResultAssert.NotFound(LayoutNullable.HasValue(row, tempReference_nullableScope3));
|
||||||
|
nullableScope = tempReference_nullableScope3.get();
|
||||||
|
|
||||||
|
value.Options.add(null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("ratings", out c);
|
||||||
|
RowCursor ratingsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out ratingsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref ratingsScope, out ratingsScope) == Result.SUCCESS) {
|
||||||
|
value.Ratings = new ArrayList<ArrayList<Double>>();
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutTypedArray innerLayout = innerType.getType().<LayoutTypedArray>TypeAs();
|
||||||
|
RowCursor innerScope = null;
|
||||||
|
Reference<RowCursor> tempReference_innerScope =
|
||||||
|
new Reference<RowCursor>(innerScope);
|
||||||
|
while (ratingsScope.MoveNext(row, tempReference_innerScope)) {
|
||||||
|
innerScope = tempReference_innerScope.get();
|
||||||
|
ArrayList<Double> item = new ArrayList<Double>();
|
||||||
|
Reference<RowCursor> tempReference_ratingsScope =
|
||||||
|
new Reference<RowCursor>(ratingsScope);
|
||||||
|
Out<RowCursor> tempOut_innerScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(innerLayout.ReadScope(row, tempReference_ratingsScope, tempOut_innerScope));
|
||||||
|
innerScope = tempOut_innerScope.get();
|
||||||
|
ratingsScope = tempReference_ratingsScope.get();
|
||||||
|
while (RowCursors.moveNext(innerScope.clone()
|
||||||
|
, row)) {
|
||||||
|
LayoutFloat64 itemLayout = innerType.getTypeArgs().get(0).getType().<LayoutFloat64>TypeAs();
|
||||||
|
Reference<RowCursor> tempReference_innerScope2
|
||||||
|
= new Reference<RowCursor>(innerScope);
|
||||||
|
double innerItem;
|
||||||
|
Out<Double> tempOut_innerItem = new Out<Double>();
|
||||||
|
ResultAssert.IsSuccess(itemLayout.ReadSparse(row, tempReference_innerScope2, tempOut_innerItem));
|
||||||
|
innerItem = tempOut_innerItem.get();
|
||||||
|
innerScope = tempReference_innerScope2.get();
|
||||||
|
item.add(innerItem);
|
||||||
|
}
|
||||||
|
|
||||||
|
value.Ratings.add(item);
|
||||||
|
}
|
||||||
|
innerScope = tempReference_innerScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("similars", out c);
|
||||||
|
RowCursor similarsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out similarsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref similarsScope, out similarsScope) == Result.SUCCESS) {
|
||||||
|
value.Similars = new ArrayList<SimilarMatch>();
|
||||||
|
while (similarsScope.MoveNext(row)) {
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutUDT innerLayout = innerType.getType().<LayoutUDT>TypeAs();
|
||||||
|
Reference<RowCursor> tempReference_similarsScope =
|
||||||
|
new Reference<RowCursor>(similarsScope);
|
||||||
|
RowCursor matchScope;
|
||||||
|
Out<RowCursor> tempOut_matchScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(innerLayout.ReadScope(row, tempReference_similarsScope, tempOut_matchScope));
|
||||||
|
matchScope = tempOut_matchScope.get();
|
||||||
|
similarsScope = tempReference_similarsScope.get();
|
||||||
|
Reference<RowCursor> tempReference_matchScope =
|
||||||
|
new Reference<RowCursor>(matchScope);
|
||||||
|
SimilarMatch item = TypedArrayUnitTests.ReadSimilarMatch(row, tempReference_matchScope);
|
||||||
|
matchScope = tempReference_matchScope.get();
|
||||||
|
value.Similars.add(item);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("priority", out c);
|
||||||
|
RowCursor priorityScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
root.get().Clone(out priorityScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being modified:
|
||||||
|
if (c.<LayoutTypedArray>TypeAs().ReadScope(row, ref priorityScope, out priorityScope) == Result.SUCCESS) {
|
||||||
|
value.Priority = new ArrayList<Tuple<String, Long>>();
|
||||||
|
RowCursor tupleScope = null;
|
||||||
|
Reference<RowCursor> tempReference_tupleScope =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
while (priorityScope.MoveNext(row, tempReference_tupleScope)) {
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutIndexedScope innerLayout = innerType.getType().<LayoutIndexedScope>TypeAs();
|
||||||
|
|
||||||
|
Reference<RowCursor> tempReference_priorityScope =
|
||||||
|
new Reference<RowCursor>(priorityScope);
|
||||||
|
Out<RowCursor> tempOut_tupleScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(innerLayout.ReadScope(row, tempReference_priorityScope, tempOut_tupleScope));
|
||||||
|
tupleScope = tempOut_tupleScope.get();
|
||||||
|
priorityScope = tempReference_priorityScope.get();
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope2 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
String item1;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(innerType.getTypeArgs().get(0).getType().<LayoutUtf8>TypeAs().ReadSparse(row,
|
||||||
|
tempReference_tupleScope2, out item1));
|
||||||
|
tupleScope = tempReference_tupleScope2.get();
|
||||||
|
|
||||||
|
assert RowCursors.moveNext(tupleScope.clone()
|
||||||
|
, row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope3 =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
long item2;
|
||||||
|
Out<Long> tempOut_item2 = new Out<Long>();
|
||||||
|
ResultAssert.IsSuccess(innerType.getTypeArgs().get(1).getType().<LayoutInt64>TypeAs().ReadSparse(row,
|
||||||
|
tempReference_tupleScope3, tempOut_item2));
|
||||||
|
item2 = tempOut_item2.get();
|
||||||
|
tupleScope = tempReference_tupleScope3.get();
|
||||||
|
|
||||||
|
value.Priority.add(Tuple.Create(item1, item2));
|
||||||
|
}
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void WriteSimilarMatch(Reference<RowBuffer> row, Reference<RowCursor> matchScope
|
||||||
|
, TypeArgumentList typeArgs, SimilarMatch m) {
|
||||||
|
Layout matchLayout = row.get().resolver().resolve(typeArgs.getSchemaId().clone());
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert matchLayout.TryFind("thumbprint", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteFixed(row, matchScope, c, m.Thumbprint));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert matchLayout.TryFind("score", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutFloat64>TypeAs().WriteFixed(row, matchScope, c, m.Score));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void WriteTagged(Reference<RowBuffer> row, Reference<RowCursor> root, Tagged value) {
|
||||||
|
LayoutColumn c;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
assert this.layout.TryFind("title", out c);
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutUtf8>TypeAs().WriteVariable(row, root, c, value.Title));
|
||||||
|
|
||||||
|
if (value.Tags != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.layout.TryFind("tags", out c);
|
||||||
|
RowCursor tagsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out tagsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, ref tagsScope, c.TypeArgs,
|
||||||
|
out tagsScope));
|
||||||
|
for (String item : value.Tags) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(c.TypeArgs[0].Type.<LayoutUtf8>TypeAs().WriteSparse(row, ref tagsScope, item));
|
||||||
|
assert !tagsScope.MoveNext(row);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.Options != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.layout.TryFind("options", out c);
|
||||||
|
RowCursor optionsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out optionsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, ref optionsScope, c.TypeArgs,
|
||||||
|
out optionsScope));
|
||||||
|
for (Integer item : value.Options) {
|
||||||
|
TypeArgument itemType = c.TypeArgs[0];
|
||||||
|
RowCursor nullableScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(itemType.getType().<LayoutNullable>TypeAs().WriteScope(row, ref optionsScope,
|
||||||
|
itemType.getTypeArgs().clone(), item != null, out nullableScope));
|
||||||
|
|
||||||
|
if (item != null) {
|
||||||
|
Reference<RowCursor> tempReference_nullableScope = new Reference<RowCursor>(nullableScope);
|
||||||
|
ResultAssert.IsSuccess(itemType.getTypeArgs().get(0).getType().<LayoutInt32>TypeAs().WriteSparse(row, tempReference_nullableScope, item.intValue()));
|
||||||
|
nullableScope = tempReference_nullableScope.get();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !optionsScope.MoveNext(row, ref nullableScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.Ratings != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.layout.TryFind("ratings", out c);
|
||||||
|
RowCursor ratingsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out ratingsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, ref ratingsScope, c.TypeArgs,
|
||||||
|
out ratingsScope));
|
||||||
|
for (ArrayList<Double> item : value.Ratings) {
|
||||||
|
assert item != null;
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutTypedArray innerLayout = innerType.getType().<LayoutTypedArray>TypeAs();
|
||||||
|
Reference<RowCursor> tempReference_ratingsScope =
|
||||||
|
new Reference<RowCursor>(ratingsScope);
|
||||||
|
RowCursor innerScope;
|
||||||
|
Out<RowCursor> tempOut_innerScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(innerLayout.WriteScope(row, tempReference_ratingsScope,
|
||||||
|
innerType.getTypeArgs().clone(), tempOut_innerScope));
|
||||||
|
innerScope = tempOut_innerScope.get();
|
||||||
|
ratingsScope = tempReference_ratingsScope.get();
|
||||||
|
for (double innerItem : item) {
|
||||||
|
LayoutFloat64 itemLayout = innerType.getTypeArgs().get(0).getType().<LayoutFloat64>TypeAs();
|
||||||
|
Reference<RowCursor> tempReference_innerScope =
|
||||||
|
new Reference<RowCursor>(innerScope);
|
||||||
|
ResultAssert.IsSuccess(itemLayout.WriteSparse(row, tempReference_innerScope, innerItem));
|
||||||
|
innerScope = tempReference_innerScope.get();
|
||||||
|
assert !innerScope.MoveNext(row);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !ratingsScope.MoveNext(row, ref innerScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.Similars != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.layout.TryFind("similars", out c);
|
||||||
|
RowCursor similarsScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out similarsScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, ref similarsScope, c.TypeArgs,
|
||||||
|
out similarsScope));
|
||||||
|
for (SimilarMatch item : value.Similars) {
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutUDT innerLayout = innerType.getType().<LayoutUDT>TypeAs();
|
||||||
|
Reference<RowCursor> tempReference_similarsScope =
|
||||||
|
new Reference<RowCursor>(similarsScope);
|
||||||
|
RowCursor matchScope;
|
||||||
|
Out<RowCursor> tempOut_matchScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(innerLayout.WriteScope(row, tempReference_similarsScope,
|
||||||
|
innerType.getTypeArgs().clone(), tempOut_matchScope));
|
||||||
|
matchScope = tempOut_matchScope.get();
|
||||||
|
similarsScope = tempReference_similarsScope.get();
|
||||||
|
Reference<RowCursor> tempReference_matchScope =
|
||||||
|
new Reference<RowCursor>(matchScope);
|
||||||
|
TypedArrayUnitTests.WriteSimilarMatch(row, tempReference_matchScope, innerType.getTypeArgs().clone(), item);
|
||||||
|
matchScope = tempReference_matchScope.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !similarsScope.MoveNext(row, ref matchScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.Priority != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
assert this.layout.TryFind("priority", out c);
|
||||||
|
RowCursor priorityScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
root.get().Clone(out priorityScope).Find(row, c.Path);
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
ResultAssert.IsSuccess(c.<LayoutTypedArray>TypeAs().WriteScope(row, ref priorityScope, c.TypeArgs,
|
||||||
|
out priorityScope));
|
||||||
|
for (Tuple<String, Long> item : value.Priority) {
|
||||||
|
TypeArgument innerType = c.TypeArgs[0];
|
||||||
|
LayoutIndexedScope innerLayout = innerType.getType().<LayoutIndexedScope>TypeAs();
|
||||||
|
RowCursor tupleScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword -
|
||||||
|
// these cannot be converted using the 'Out' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(innerLayout.WriteScope(row, ref priorityScope, innerType.getTypeArgs().clone()
|
||||||
|
, out tupleScope));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
ResultAssert.IsSuccess(innerType.getTypeArgs().get(0).getType().<LayoutUtf8>TypeAs().WriteSparse(row,
|
||||||
|
ref tupleScope, item.Item1));
|
||||||
|
assert tupleScope.MoveNext(row);
|
||||||
|
Reference<RowCursor> tempReference_tupleScope =
|
||||||
|
new Reference<RowCursor>(tupleScope);
|
||||||
|
ResultAssert.IsSuccess(innerType.getTypeArgs().get(1).getType().<LayoutInt64>TypeAs().WriteSparse(row
|
||||||
|
, tempReference_tupleScope, item.Item2));
|
||||||
|
tupleScope = tempReference_tupleScope.get();
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword -
|
||||||
|
// these cannot be converted using the 'Ref' helper class unless the method is within the code
|
||||||
|
// being modified:
|
||||||
|
assert !priorityScope.MoveNext(row, ref tupleScope);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1401", Justification = "Test types.")] private sealed class SimilarMatch
|
||||||
|
private final static class SimilarMatch {
|
||||||
|
public double Score;
|
||||||
|
public String Thumbprint;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tempVar = obj instanceof SimilarMatch;
|
||||||
|
SimilarMatch match = tempVar ? (SimilarMatch)obj : null;
|
||||||
|
return tempVar && this.equals(match);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
return (this.Thumbprint.hashCode() * 397) ^ (new Double(this.Score)).hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(SimilarMatch other) {
|
||||||
|
// ReSharper disable once CompareOfFloatsByEqualityOperator
|
||||||
|
return this.Thumbprint.equals(other.Thumbprint) && this.Score == other.Score;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [SuppressMessage("Microsoft.StyleCop.CSharp.OrderingRules", "SA1401", Justification = "Test
|
||||||
|
// types.")] private sealed class Tagged
|
||||||
|
private final static class Tagged {
|
||||||
|
public ArrayList<Integer> Options;
|
||||||
|
public ArrayList<Tuple<String, Long>> Priority;
|
||||||
|
public ArrayList<ArrayList<Double>> Ratings;
|
||||||
|
public ArrayList<SimilarMatch> Similars;
|
||||||
|
public ArrayList<String> Tags;
|
||||||
|
public String Title;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
boolean tempVar = obj instanceof Tagged;
|
||||||
|
Tagged tagged = tempVar ? (Tagged)obj : null;
|
||||||
|
return tempVar && this.equals(tagged);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = this.Title == null ? null : this.Title.hashCode() != null ? this.Title.hashCode() : 0;
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Tags == null ? null : this.Tags.hashCode() != null ?
|
||||||
|
this.Tags.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Options == null ? null : this.Options.hashCode() != null ?
|
||||||
|
this.Options.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Ratings == null ? null : this.Ratings.hashCode() != null ? this.Ratings.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Similars == null ? null : this.Similars.hashCode() != null ? this.Similars.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Priority == null ? null : this.Priority.hashCode() != null ? this.Priority.hashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> boolean NestedSequenceEquals(ArrayList<ArrayList<T>> left, ArrayList<ArrayList<T>> right) {
|
||||||
|
if (left.size() != right.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < left.size(); i++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java AbstractList 'equals' is not always identical to LINQ 'SequenceEqual':
|
||||||
|
//ORIGINAL LINE: if (!left[i].SequenceEqual(right[i]))
|
||||||
|
if (!left.get(i).equals(right.get(i))) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Tagged other) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java AbstractList 'equals' is not always identical to LINQ 'SequenceEqual':
|
||||||
|
//ORIGINAL LINE: return string.Equals(this.Title, other.Title) && (object.ReferenceEquals(this.Tags, other.Tags) || ((this.Tags != null) && (other.Tags != null) && this.Tags.SequenceEqual(other.Tags))) && (object.ReferenceEquals(this.Options, other.Options) || ((this.Options != null) && (other.Options != null) && this.Options.SequenceEqual(other.Options))) && (object.ReferenceEquals(this.Ratings, other.Ratings) || ((this.Ratings != null) && (other.Ratings != null) && Tagged.NestedSequenceEquals(this.Ratings, other.Ratings))) && (object.ReferenceEquals(this.Similars, other.Similars) || ((this.Similars != null) && (other.Similars != null) && this.Similars.SequenceEqual(other.Similars))) && (object.ReferenceEquals(this.Priority, other.Priority) || ((this.Priority != null) && (other.Priority != null) && this.Priority.SequenceEqual(other.Priority)));
|
||||||
|
return this.Title.equals(other.Title) && (this.Tags == other.Tags || ((this.Tags != null) && (other.Tags != null) && this.Tags.equals(other.Tags))) && (this.Options == other.Options || ((this.Options != null) && (other.Options != null) && this.Options.equals(other.Options))) && (this.Ratings == other.Ratings || ((this.Ratings != null) && (other.Ratings != null) && Tagged.NestedSequenceEquals(this.Ratings, other.Ratings))) && (this.Similars == other.Similars || ((this.Similars != null) && (other.Similars != null) && this.Similars.equals(other.Similars))) && (this.Priority == other.Priority || ((this.Priority != null) && (other.Priority != null) && this.Priority.equals(other.Priority)));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,20 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowOptions;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class UpdateOptionsUnitTests
|
||||||
|
public class UpdateOptionsUnitTests {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestMethod][Owner("jthunter")] public void UpdateOptionsTest()
|
||||||
|
public final void UpdateOptionsTest() {
|
||||||
|
assert RowOptions.NONE.value() == UpdateOptions.None.getValue();
|
||||||
|
assert RowOptions.UPDATE.value() == UpdateOptions.Update.getValue();
|
||||||
|
assert RowOptions.INSERT.value() == UpdateOptions.Insert.getValue();
|
||||||
|
assert RowOptions.UPSERT.value() == UpdateOptions.Upsert.getValue();
|
||||||
|
assert RowOptions.INSERT_AT.value() == UpdateOptions.InsertAt.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,247 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowBuffer;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.RowCursor;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypedArray;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java does not allow user-defined value types. The behavior of this class may differ
|
||||||
|
// from the original:
|
||||||
|
//ORIGINAL LINE: internal struct WriteRowDispatcher : IDispatcher
|
||||||
|
public final class WriteRowDispatcher implements IDispatcher {
|
||||||
|
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> field, LayoutColumn col, LayoutType t) {
|
||||||
|
Dispatch(dispatcher, field, col, t, null);
|
||||||
|
}
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER NOTE: Java does not support optional parameters. Overloaded method(s) are created above:
|
||||||
|
//ORIGINAL LINE: public void Dispatch<TLayout, TValue>(ref RowOperationDispatcher dispatcher, ref RowCursor
|
||||||
|
// field, LayoutColumn col, LayoutType t, TValue value = default) where TLayout : LayoutType<TValue>
|
||||||
|
public <TLayout extends LayoutType<TValue>, TValue> void Dispatch(Reference<RowOperationDispatcher> dispatcher, Reference<RowCursor> field, LayoutColumn col, LayoutType t, TValue value) {
|
||||||
|
switch (col == null ? null : col.getStorage()) {
|
||||||
|
case Fixed:
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().writeFixed(tempReference_Row, field, col, value));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
break;
|
||||||
|
case Variable:
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().writeVariable(tempReference_Row2, field, col, value));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
ResultAssert.IsSuccess(t.<TLayout>typeAs().writeSparse(tempReference_Row3, field, value));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchArray(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor arrayScope;
|
||||||
|
Out<RowCursor> tempOut_arrayScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedArray>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(),
|
||||||
|
tempOut_arrayScope));
|
||||||
|
arrayScope = tempOut_arrayScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
List items = (List)value;
|
||||||
|
for (Object item : items) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref arrayScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), item);
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
arrayScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchMap(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 2);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor mapScope;
|
||||||
|
Out<RowCursor> tempOut_mapScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedMap>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(),
|
||||||
|
tempOut_mapScope));
|
||||||
|
mapScope = tempOut_mapScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
Reference<RowCursor> tempReference_mapScope =
|
||||||
|
new Reference<RowCursor>(mapScope);
|
||||||
|
TypeArgument fieldType = t.<LayoutUniqueScope>typeAs().FieldType(tempReference_mapScope).clone();
|
||||||
|
mapScope = tempReference_mapScope.get();
|
||||||
|
List pairs = (List)value;
|
||||||
|
for (Object pair : pairs) {
|
||||||
|
String elmPath = UUID.NewGuid().toString();
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor tempCursor;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
RowCursor.createForAppend(tempReference_Row2, out tempCursor);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref tempCursor, elmPath, fieldType.getType(),
|
||||||
|
fieldType.getTypeArgs().clone(), pair);
|
||||||
|
|
||||||
|
// Move item into the map.
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Reference<RowCursor> tempReference_mapScope2 =
|
||||||
|
new Reference<RowCursor>(mapScope);
|
||||||
|
Reference<RowCursor> tempReference_tempCursor =
|
||||||
|
new Reference<RowCursor>(tempCursor);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedMap>typeAs().MoveField(tempReference_Row3, tempReference_mapScope2,
|
||||||
|
tempReference_tempCursor));
|
||||||
|
tempCursor = tempReference_tempCursor.get();
|
||||||
|
mapScope = tempReference_mapScope2.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchNullable(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor nullableScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutNullable>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(),
|
||||||
|
value != null, out nullableScope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
if (value != null) {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref nullableScope, null, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchObject(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchSet(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() == 1);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor setScope;
|
||||||
|
Out<RowCursor> tempOut_setScope =
|
||||||
|
new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedSet>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(),
|
||||||
|
tempOut_setScope));
|
||||||
|
setScope = tempOut_setScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
List items = (List)value;
|
||||||
|
for (Object item : items) {
|
||||||
|
String elmPath = UUID.NewGuid().toString();
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor tempCursor;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
RowCursor.createForAppend(tempReference_Row2, out tempCursor);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref tempCursor, elmPath, typeArgs.get(0).type(),
|
||||||
|
typeArgs.get(0).typeArgs().clone(), item);
|
||||||
|
|
||||||
|
// Move item into the set.
|
||||||
|
Reference<RowBuffer> tempReference_Row3 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
Reference<RowCursor> tempReference_setScope =
|
||||||
|
new Reference<RowCursor>(setScope);
|
||||||
|
Reference<RowCursor> tempReference_tempCursor =
|
||||||
|
new Reference<RowCursor>(tempCursor);
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutTypedSet>typeAs().MoveField(tempReference_Row3, tempReference_setScope,
|
||||||
|
tempReference_tempCursor));
|
||||||
|
tempCursor = tempReference_tempCursor.get();
|
||||||
|
setScope = tempReference_setScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row3.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchTuple(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
checkArgument(typeArgs.count() >= 2);
|
||||||
|
|
||||||
|
Reference<RowBuffer> tempReference_Row =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor tupleScope;
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'out' keyword - these
|
||||||
|
// cannot be converted using the 'Out' helper class unless the method is within the code being modified:
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutIndexedScope>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(),
|
||||||
|
out tupleScope));
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
|
||||||
|
for (int i = 0; i < typeArgs.count(); i++) {
|
||||||
|
PropertyInfo valueAccessor = value.getClass().GetProperty(String.format("Item%1$s", i + 1));
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following method call contained an unresolved 'ref' keyword - these
|
||||||
|
// cannot be converted using the 'Ref' helper class unless the method is within the code being
|
||||||
|
// modified:
|
||||||
|
dispatcher.get().LayoutCodeSwitch(ref tupleScope, null, typeArgs.get(i).type(),
|
||||||
|
typeArgs.get(i).typeArgs().clone(), valueAccessor.GetValue(value));
|
||||||
|
Reference<RowBuffer> tempReference_Row2 =
|
||||||
|
new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
tupleScope.MoveNext(tempReference_Row2);
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row2.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void DispatchUDT(Reference<RowOperationDispatcher> dispatcher,
|
||||||
|
Reference<RowCursor> scope, LayoutType t, TypeArgumentList typeArgs,
|
||||||
|
Object value) {
|
||||||
|
Reference<RowBuffer> tempReference_Row = new Reference<RowBuffer>(dispatcher.get().Row);
|
||||||
|
RowCursor udtScope;
|
||||||
|
Out<RowCursor> tempOut_udtScope = new Out<RowCursor>();
|
||||||
|
ResultAssert.IsSuccess(t.<LayoutUDT>typeAs().WriteScope(tempReference_Row, scope, typeArgs.clone(), tempOut_udtScope));
|
||||||
|
udtScope = tempOut_udtScope.get();
|
||||||
|
dispatcher.get().argValue.Row = tempReference_Row.get();
|
||||||
|
IDispatchable valueDispatcher = value instanceof IDispatchable ? (IDispatchable)value : null;
|
||||||
|
assert valueDispatcher != null;
|
||||||
|
Reference<RowCursor> tempReference_udtScope = new Reference<RowCursor>(udtScope);
|
||||||
|
valueDispatcher.Dispatch(dispatcher, tempReference_udtScope);
|
||||||
|
udtScope = tempReference_udtScope.get();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public final class Address {
|
||||||
|
public String City;
|
||||||
|
public PostalCode PostalCode;
|
||||||
|
public String State;
|
||||||
|
public String Street;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj instanceof Address && this.equals((Address)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = this.Street != null ? this.Street.hashCode() : 0;
|
||||||
|
hashCode = (hashCode * 397) ^ (this.City != null ? this.City.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.State != null ? this.State.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.PostalCode != null ? this.PostalCode.hashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Address other) {
|
||||||
|
return this.Street.equals(other.Street) && this.City.equals(other.City) && this.State.equals(other.State) && this.PostalCode.equals(other.PostalCode);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,96 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
|
||||||
|
public final class AddressSerializer {
|
||||||
|
public static Result Read(Reference<RowReader> reader, Out<Address> obj) {
|
||||||
|
obj.setAndGet(new Address());
|
||||||
|
while (reader.get().read()) {
|
||||||
|
Result r;
|
||||||
|
switch (reader.get().path()) {
|
||||||
|
case "street":
|
||||||
|
Out<String> tempOut_Street = new Out<String>();
|
||||||
|
r = reader.get().readUtf8String(tempOut_Street);
|
||||||
|
obj.get().argValue.Street = tempOut_Street.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "city":
|
||||||
|
Out<String> tempOut_City = new Out<String>();
|
||||||
|
r = reader.get().readUtf8String(tempOut_City);
|
||||||
|
obj.get().argValue.City = tempOut_City.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "state":
|
||||||
|
Out<String> tempOut_State = new Out<String>();
|
||||||
|
r = reader.get().readUtf8String(tempOut_State);
|
||||||
|
obj.get().argValue.State = tempOut_State.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "postal_code":
|
||||||
|
Reference<RowReader> tempReference_child =
|
||||||
|
new Reference<RowReader>(child);
|
||||||
|
Out<PostalCode> tempOut_PostalCode = new Out<PostalCode>();
|
||||||
|
// TODO: C# TO JAVA CONVERTER: The following lambda contained an unresolved 'ref' keyword - these are not converted by C# to Java Converter:
|
||||||
|
r = reader.get().readScope(obj.get(), (RowReader RowReader child, Address parent) -> PostalCodeSerializer.Read(tempReference_child, tempOut_PostalCode));
|
||||||
|
parent.PostalCode = tempOut_PostalCode.get();
|
||||||
|
child = tempReference_child.get();
|
||||||
|
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, Address obj) {
|
||||||
|
Result r;
|
||||||
|
if (obj.Street != null) {
|
||||||
|
r = writer.get().WriteString("street", obj.Street);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.City != null) {
|
||||||
|
r = writer.get().WriteString("city", obj.City);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.State != null) {
|
||||||
|
r = writer.get().WriteString("state", obj.State);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.PostalCode != null) {
|
||||||
|
r = writer.get().WriteScope("postal_code", PostalCodeSerializer.TypeArg, obj.PostalCode,
|
||||||
|
PostalCodeSerializer.Write);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,94 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public final class Guest {
|
||||||
|
public Map<String, Address> Addresses;
|
||||||
|
public String ConfirmNumber;
|
||||||
|
public Set<String> Emails;
|
||||||
|
public String FirstName;
|
||||||
|
public UUID Id;
|
||||||
|
public String LastName;
|
||||||
|
public List<String> PhoneNumbers;
|
||||||
|
public String Title;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj instanceof Guest && this.equals((Guest)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = this.Id.hashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ (this.FirstName != null ? this.FirstName.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.LastName != null ? this.LastName.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Title != null ? this.Title.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Emails != null ? this.Emails.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.PhoneNumbers != null ? this.PhoneNumbers.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Addresses != null ? this.Addresses.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.ConfirmNumber != null ? this.ConfirmNumber.hashCode() : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <TKey, TValue> boolean DictionaryEquals(Map<TKey, TValue> left, Map<TKey, TValue> right) {
|
||||||
|
if (left == right) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((left == null) || (right == null)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (left.size() != right.size()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (Map.Entry<TKey, TValue> p : left.entrySet()) {
|
||||||
|
TValue value;
|
||||||
|
if (!(right.containsKey(p.getKey()) && (value = right.get(p.getKey())) == value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!p.getValue().equals(value)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(Guest other) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Java AbstractList 'equals' is not always identical to LINQ 'SequenceEqual':
|
||||||
|
//ORIGINAL LINE: return this.Id.Equals(other.Id) && string.Equals(this.FirstName, other.FirstName) && string
|
||||||
|
// .Equals(this.LastName, other.LastName) && string.Equals(this.Title, other.Title) && string.Equals(this
|
||||||
|
// .ConfirmNumber, other.ConfirmNumber) && ((this.Emails == other.Emails) || ((this.Emails != null) && (other
|
||||||
|
// .Emails != null) && this.Emails.SetEquals(other.Emails))) && ((this.PhoneNumbers == other.PhoneNumbers) ||
|
||||||
|
// ((this.PhoneNumbers != null) && (other.PhoneNumbers != null) && this.PhoneNumbers.SequenceEqual(other
|
||||||
|
// .PhoneNumbers))) && Guest.DictionaryEquals(this.Addresses, other.Addresses);
|
||||||
|
return this.Id.equals(other.Id) && this.FirstName.equals(other.FirstName) && this.LastName.equals(other.LastName) && this.Title.equals(other.Title) && this.ConfirmNumber.equals(other.ConfirmNumber) && ((this.Emails == other.Emails) || ((this.Emails != null) && (other.Emails != null) && this.Emails.equals(other.Emails))) && ((this.PhoneNumbers == other.PhoneNumbers) || ((this.PhoneNumbers != null) && (other.PhoneNumbers != null) && this.PhoneNumbers.equals(other.PhoneNumbers))) && Guest.DictionaryEquals(this.Addresses, other.Addresses);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public final class Hotel {
|
||||||
|
public Address Address;
|
||||||
|
public String Id;
|
||||||
|
public String Name;
|
||||||
|
public String Phone;
|
||||||
|
|
||||||
|
public boolean equals(Hotel other) {
|
||||||
|
return this.Id.equals(other.Id) && this.Name.equals(other.Name) && this.Phone.equals(other.Phone) && this.Address.equals(other.Address);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj instanceof Hotel && this.equals((Hotel)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
int hashCode = this.Id == null ? null : this.Id.hashCode() != null ? this.Id.hashCode() : 0;
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Name == null ? null : this.Name.hashCode() != null ?
|
||||||
|
this.Name.hashCode() : 0);
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Phone == null ? null : this.Phone.hashCode() != null ?
|
||||||
|
this.Phone.hashCode() : 0);
|
||||||
|
int tempVar = this.Address.GetHashCode();
|
||||||
|
hashCode = (hashCode * 397) ^ (this.Address == null ? null : tempVar != null ? tempVar : 0);
|
||||||
|
return hashCode;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public final class PostalCode {
|
||||||
|
public Short Plus4;
|
||||||
|
public int Zip;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (null == obj) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this == obj) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return obj instanceof PostalCode && this.equals((PostalCode)obj);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no equivalent to an 'unchecked' block in Java:
|
||||||
|
unchecked
|
||||||
|
{
|
||||||
|
return (this.Zip * 397) ^ this.Plus4.hashCode();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean equals(PostalCode other) {
|
||||||
|
return this.Zip == other.Zip && this.Plus4 == other.Plus4;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.customerschema;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.Out;
|
||||||
|
import com.azure.data.cosmos.core.Reference;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.Result;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.SchemaId;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowReader;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.io.RowWriter;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
import azure.data.cosmos.serialization.hybridrow.unit.*;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: There is no preprocessor in Java:
|
||||||
|
///#pragma warning disable SA1401 // Fields should be private
|
||||||
|
|
||||||
|
|
||||||
|
public final class PostalCodeSerializer {
|
||||||
|
public static TypeArgument TypeArg = new TypeArgument(LayoutType.UDT, new TypeArgumentList(new SchemaId(1)));
|
||||||
|
|
||||||
|
public static Result Read(Reference<RowReader> reader, Out<PostalCode> obj) {
|
||||||
|
obj.setAndGet(new PostalCode());
|
||||||
|
while (reader.get().read()) {
|
||||||
|
Result r;
|
||||||
|
switch (reader.get().path()) {
|
||||||
|
case "zip":
|
||||||
|
Out<Integer> tempOut_Zip = new Out<Integer>();
|
||||||
|
r = reader.get().readInt32(tempOut_Zip);
|
||||||
|
obj.get().argValue.Zip = tempOut_Zip.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
break;
|
||||||
|
case "plus4":
|
||||||
|
short value;
|
||||||
|
Out<Short> tempOut_value = new Out<Short>();
|
||||||
|
r = reader.get().readInt16(tempOut_value);
|
||||||
|
value = tempOut_value.get();
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
obj.get().Plus4 = value;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result Write(Reference<RowWriter> writer, TypeArgument typeArg, PostalCode obj) {
|
||||||
|
Result r;
|
||||||
|
r = writer.get().writeInt32("zip", obj.Zip);
|
||||||
|
if (r != Result.SUCCESS) {
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj.Plus4.HasValue) {
|
||||||
|
r = writer.get().writeInt16("plus4", obj.Plus4.Value);
|
||||||
|
return r;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Result.SUCCESS;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,126 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.unit.internal;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.internal.Murmur3Hash;
|
||||||
|
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [TestClass] public class MurmurHash3UnitTests
|
||||||
|
public class MurmurHash3UnitTests {
|
||||||
|
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: private static readonly(ulong low, ulong high)[] Expected = new[] { (0x56F1549659CBEE1AUL,
|
||||||
|
// 0xCEB3EE124C3E3855UL), (0xFE84B58886F9D717UL, 0xD24C5DE024F5EA6BUL), (0x89F6250648BB11BFUL,
|
||||||
|
// 0x95595FB9D4CF58B0UL), (0xC76AFDB39EDC6262UL, 0xB9286AF4FADAF497UL), (0xC2CB4D9B3C9C247EUL,
|
||||||
|
// 0xB465D40116B8B7A2UL), (0x317178F5B26D0B35UL, 0x1D564F53E2E468ADUL), (0xE8D75F7C05F43F09UL,
|
||||||
|
// 0xA81CEA052AE92D6FUL), (0x8F837665508C08A8UL, 0x2A74E6E47E5497BCUL), (0x609778FDA1AFD731UL,
|
||||||
|
// 0x3EB1A0E3BFC653E4UL), (0x0F59B8965FA49D1AUL, 0xCB3BC158243A5DEEUL), (0x7A6D0AC9C98F5908UL,
|
||||||
|
// 0xBC93D3042C3E7178UL), (0x863FE5AEBA9A3DFAUL, 0xDF42416658CB87C5UL), (0xDB4C82337C8FB216UL,
|
||||||
|
// 0xCA7616B64ABF6B3DUL), (0x0049223177425B48UL, 0x25510D7246BC3C2CUL), (0x31AC129B24F82CABUL,
|
||||||
|
// 0xCD7174C2040E9834UL), (0xCE39465288116345UL, 0x1CE6A26BA2E9E67DUL), (0xD2BE55791E13DB17UL,
|
||||||
|
// 0xCF30BF3D93B3A9FAUL), (0x43E323DD0F079145UL, 0xF06721555571ABBAUL), (0xB0CE9F170A96F5BCUL,
|
||||||
|
// 0x18EE95960369D702UL), (0xBFFAF6BEBC84A2A9UL, 0xE0612B6FC0C9D502UL), (0x33E2D699697BC2DAUL,
|
||||||
|
// 0xB7E9CD6313DE05EEUL), (0xCBFD7D8DA2A962BFUL, 0xCF4C281A7750E88AUL), (0xBD8D863F83863088UL,
|
||||||
|
// 0x01AFFBDE3D405D35UL), (0xBA2E05DF3328C7DBUL, 0x9620867ADDFE6579UL), (0xC57BD1FB63CA0947UL,
|
||||||
|
// 0xE1391F8454D4EA9FUL), (0x6AB710460A5BF9BAUL, 0x11D7E13FBEF63775UL), (0x55C2C7C95F41C483UL,
|
||||||
|
// 0xA4DCC9F547A89563UL), (0x8AA5A2031027F216UL, 0x1653FC7AD6CC6104UL), (0xAD8A899FF093D9A5UL,
|
||||||
|
// 0x0EB26F6D1CCEB258UL), (0xA3B6D57EBEB965D1UL, 0xE8078FCC5D8C2E3EUL), (0x91ABF587B38224F6UL,
|
||||||
|
// 0x35899665A8A9252CUL), (0xF05B1AF0487EE2D4UL, 0x5D7496C1665DDE12UL)};
|
||||||
|
|
||||||
|
private static final Murmur3Hash.HashCode128[] EXPECTED_VALUES = new Murmur3Hash.HashCode128[] {
|
||||||
|
new Murmur3Hash.HashCode128(0x56F1549659CBEE1AL, 0xCEB3EE124C3E3855L),
|
||||||
|
new Murmur3Hash.HashCode128(0xFE84B58886F9D717L, 0xD24C5DE024F5EA6BL),
|
||||||
|
new Murmur3Hash.HashCode128(0x89F6250648BB11BFL, 0x95595FB9D4CF58B0L),
|
||||||
|
new Murmur3Hash.HashCode128(0xC76AFDB39EDC6262L, 0xB9286AF4FADAF497L),
|
||||||
|
new Murmur3Hash.HashCode128(0xC2CB4D9B3C9C247EL, 0xB465D40116B8B7A2L),
|
||||||
|
new Murmur3Hash.HashCode128(0x317178F5B26D0B35L, 0x1D564F53E2E468ADL),
|
||||||
|
new Murmur3Hash.HashCode128(0xE8D75F7C05F43F09L, 0xA81CEA052AE92D6FL),
|
||||||
|
new Murmur3Hash.HashCode128(0x8F837665508C08A8L, 0x2A74E6E47E5497BCL),
|
||||||
|
new Murmur3Hash.HashCode128(0x609778FDA1AFD731L, 0x3EB1A0E3BFC653E4L),
|
||||||
|
new Murmur3Hash.HashCode128(0x0F59B8965FA49D1AL, 0xCB3BC158243A5DEEL),
|
||||||
|
new Murmur3Hash.HashCode128(0x7A6D0AC9C98F5908L, 0xBC93D3042C3E7178L),
|
||||||
|
new Murmur3Hash.HashCode128(0x863FE5AEBA9A3DFAL, 0xDF42416658CB87C5L),
|
||||||
|
new Murmur3Hash.HashCode128(0xDB4C82337C8FB216L, 0xCA7616B64ABF6B3DL),
|
||||||
|
new Murmur3Hash.HashCode128(0x0049223177425B48L, 0x25510D7246BC3C2CL),
|
||||||
|
new Murmur3Hash.HashCode128(0x31AC129B24F82CABL, 0xCD7174C2040E9834L),
|
||||||
|
new Murmur3Hash.HashCode128(0xCE39465288116345L, 0x1CE6A26BA2E9E67DL),
|
||||||
|
new Murmur3Hash.HashCode128(0xD2BE55791E13DB17L, 0xCF30BF3D93B3A9FAL),
|
||||||
|
new Murmur3Hash.HashCode128(0x43E323DD0F079145L, 0xF06721555571ABBAL),
|
||||||
|
new Murmur3Hash.HashCode128(0xB0CE9F170A96F5BCL, 0x18EE95960369D702L),
|
||||||
|
new Murmur3Hash.HashCode128(0xBFFAF6BEBC84A2A9L, 0xE0612B6FC0C9D502L),
|
||||||
|
new Murmur3Hash.HashCode128(0x33E2D699697BC2DAL, 0xB7E9CD6313DE05EEL),
|
||||||
|
new Murmur3Hash.HashCode128(0xCBFD7D8DA2A962BFL, 0xCF4C281A7750E88AL),
|
||||||
|
new Murmur3Hash.HashCode128(0xBD8D863F83863088L, 0x01AFFBDE3D405D35L),
|
||||||
|
new Murmur3Hash.HashCode128(0xBA2E05DF3328C7DBL, 0x9620867ADDFE6579L),
|
||||||
|
new Murmur3Hash.HashCode128(0xC57BD1FB63CA0947L, 0xE1391F8454D4EA9FL),
|
||||||
|
new Murmur3Hash.HashCode128(0x6AB710460A5BF9BAL, 0x11D7E13FBEF63775L),
|
||||||
|
new Murmur3Hash.HashCode128(0x55C2C7C95F41C483L, 0xA4DCC9F547A89563L),
|
||||||
|
new Murmur3Hash.HashCode128(0x8AA5A2031027F216L, 0x1653FC7AD6CC6104L),
|
||||||
|
new Murmur3Hash.HashCode128(0xAD8A899FF093D9A5L, 0x0EB26F6D1CCEB258L),
|
||||||
|
new Murmur3Hash.HashCode128(0xA3B6D57EBEB965D1L, 0xE8078FCC5D8C2E3EL),
|
||||||
|
new Murmur3Hash.HashCode128(0x91ABF587B38224F6L, 0x35899665A8A9252CL),
|
||||||
|
new Murmur3Hash.HashCode128(0xF05B1AF0487EE2D4L, 0x5D7496C1665DDE12L) };
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
// ORIGINAL LINE:
|
||||||
|
// [TestMethod][Owner("jthunter")] public void Hash128Check()
|
||||||
|
public final void Hash128Check() {
|
||||||
|
// Generate deterministic data for which the Murmur3Hash is known (see Expected).
|
||||||
|
Random rand = new Random(42);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: byte[][] samples = new byte[MurmurHash3UnitTests.Expected.Length][];
|
||||||
|
byte[][] samples = new byte[MurmurHash3UnitTests.EXPECTED_VALUES.length][];
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
int sampleLength = rand.nextInt(10 * 1024);
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: samples[i] = new byte[sampleLength];
|
||||||
|
samples[i] = new byte[sampleLength];
|
||||||
|
rand.nextBytes(samples[i]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Warm up the loop and verify correctness.
|
||||||
|
for (int i = 0; i < samples.length; i++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: byte[] sample = samples[i];
|
||||||
|
byte[] sample = samples[i];
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java has no equivalent to C# deconstruction declarations:
|
||||||
|
( long low, long high) = Murmur3Hash.Hash128(sample, (0, 0))
|
||||||
|
System.out.println(String.format("(0x%016XUL, 0x%1.16XUL),", high, low));
|
||||||
|
assert MurmurHash3UnitTests.EXPECTED_VALUES[i].high == high;
|
||||||
|
assert MurmurHash3UnitTests.EXPECTED_VALUES[i].low == low;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Measure performance.
|
||||||
|
long ticks = MurmurHash3UnitTests.MeasureLoop(samples);
|
||||||
|
System.out.println(String.format("Murmur3Hash: %1$s", ticks));
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: C# TO JAVA CONVERTER: Java annotations will not correspond to .NET attributes:
|
||||||
|
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.NoInlining)][SuppressMessage("Microsoft.Reliability",
|
||||||
|
// "CA2001:Avoid calling problematic methods", Justification = "Perf Benchmark")] private static long MeasureLoop
|
||||||
|
// (byte[][] samples)
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: [MethodImpl(MethodImplOptions.NoInlining)][SuppressMessage("Microsoft.Reliability",
|
||||||
|
// "CA2001:Avoid calling problematic methods", Justification = "Perf Benchmark")] private static long MeasureLoop
|
||||||
|
// (byte[][] samples)
|
||||||
|
private static long MeasureLoop(byte[][] samples) {
|
||||||
|
final int outerLoopCount = 10000;
|
||||||
|
System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch();
|
||||||
|
|
||||||
|
System.gc();
|
||||||
|
watch.Start();
|
||||||
|
for (int j = 0; j < outerLoopCount; j++) {
|
||||||
|
//C# TO JAVA CONVERTER WARNING: Unsigned integer types have no direct equivalent in Java:
|
||||||
|
//ORIGINAL LINE: foreach (byte[] sample in samples)
|
||||||
|
for (byte[] sample : samples) {
|
||||||
|
Murmur3Hash.Hash128(sample, (0, 0))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
watch.Stop();
|
||||||
|
return watch.ElapsedTicks;
|
||||||
|
}
|
||||||
|
}
|
||||||
293
java/pom.xml
Normal file
293
java/pom.xml
Normal file
@@ -0,0 +1,293 @@
|
|||||||
|
<!--
|
||||||
|
Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
Licensed under the MIT License.
|
||||||
|
-->
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
|
<groupId>com.azure.data</groupId>
|
||||||
|
<artifactId>azure-cosmos-serialization</artifactId>
|
||||||
|
<version>2.9.5-SNAPSHOT</version>
|
||||||
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
<name>Microsoft Azure Cosmos Serialization API</name>
|
||||||
|
<description>This package contains Microsoft Azure Serialization API for Azure Cosmos DB</description>
|
||||||
|
<url>https://github.com/microsoft/HybridRow</url>
|
||||||
|
<licenses>
|
||||||
|
<license>
|
||||||
|
<name>MIT License</name>
|
||||||
|
<url>http://www.opensource.org/licenses/mit-license.php</url>
|
||||||
|
</license>
|
||||||
|
</licenses>
|
||||||
|
|
||||||
|
<developers>
|
||||||
|
<developer>
|
||||||
|
<id>microsoft</id>
|
||||||
|
<name>Microsoft Corporation</name>
|
||||||
|
</developer>
|
||||||
|
</developers>
|
||||||
|
|
||||||
|
<distributionManagement>
|
||||||
|
<repository>
|
||||||
|
<name>azure-cosmos-serialization</name>
|
||||||
|
<layout>default</layout>
|
||||||
|
<id>dev-azure-com-azure-cosmos-java-azure-cosmos-serialization</id>
|
||||||
|
<url>https://pkgs.dev.azure.com/azure-cosmos-java/_packaging/azure-cosmos-serialization/maven/v1</url>
|
||||||
|
</repository>
|
||||||
|
<site>
|
||||||
|
<id>azure-java-build-docs</id>
|
||||||
|
<url>${site.url}/site/${project.artifactId}</url>
|
||||||
|
</site>
|
||||||
|
</distributionManagement>
|
||||||
|
|
||||||
|
<repositories>
|
||||||
|
<repository>
|
||||||
|
<id>dev-azure-com-azure-cosmos-java-azure-cosmos-serialization</id>
|
||||||
|
<url>https://pkgs.dev.azure.com/azure-cosmos-java/_packaging/azure-cosmos-serialization/maven/v1</url>
|
||||||
|
<releases>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</releases>
|
||||||
|
<snapshots>
|
||||||
|
<enabled>true</enabled>
|
||||||
|
</snapshots>
|
||||||
|
</repository>
|
||||||
|
</repositories>
|
||||||
|
|
||||||
|
<scm>
|
||||||
|
<url>https://github.com/microsoft/HybridRow</url>
|
||||||
|
</scm>
|
||||||
|
|
||||||
|
<properties>
|
||||||
|
<collectedArtifactsForReleaseLocation>${project.basedir}/target/collectedArtifactsForRelease
|
||||||
|
</collectedArtifactsForReleaseLocation>
|
||||||
|
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||||
|
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
|
||||||
|
<site.url/>
|
||||||
|
<test.groups>unit</test.groups>
|
||||||
|
<javadoc.opts/>
|
||||||
|
<fastutil.version>8.3.0</fastutil.version>
|
||||||
|
<guava.version>28.0-jre</guava.version>
|
||||||
|
<jackson.version>2.9.9</jackson.version>
|
||||||
|
<mockito.version>1.10.19</mockito.version>
|
||||||
|
<mongodb.version>3.11.0</mongodb.version>
|
||||||
|
<netty.version>4.1.42.Final</netty.version>
|
||||||
|
<protobuf.version>3.9.1</protobuf.version>
|
||||||
|
<slf4j.version>1.7.28</slf4j.version>
|
||||||
|
<testng.version>7.0.0</testng.version>
|
||||||
|
</properties>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.fasterxml.jackson.core</groupId>
|
||||||
|
<artifactId>jackson-databind</artifactId>
|
||||||
|
<version>${jackson.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.guava</groupId>
|
||||||
|
<artifactId>guava</artifactId>
|
||||||
|
<version>${guava.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java</artifactId>
|
||||||
|
<version>${protobuf.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.protobuf</groupId>
|
||||||
|
<artifactId>protobuf-java-util</artifactId>
|
||||||
|
<version>${protobuf.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.netty</groupId>
|
||||||
|
<artifactId>netty-buffer</artifactId>
|
||||||
|
<version>${netty.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>it.unimi.dsi</groupId>
|
||||||
|
<artifactId>fastutil</artifactId>
|
||||||
|
<version>${fastutil.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mockito</groupId>
|
||||||
|
<artifactId>mockito-core</artifactId>
|
||||||
|
<version>${mockito.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.mongodb</groupId>
|
||||||
|
<artifactId>bson</artifactId>
|
||||||
|
<version>${mongodb.version}</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.slf4j</groupId>
|
||||||
|
<artifactId>slf4j-api</artifactId>
|
||||||
|
<version>${slf4j.version}</version>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.testng</groupId>
|
||||||
|
<artifactId>testng</artifactId>
|
||||||
|
<version>7.0.0</version>
|
||||||
|
<scope>test</scope>
|
||||||
|
</dependency>
|
||||||
|
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<!-- unit test -->
|
||||||
|
<id>unit</id>
|
||||||
|
<properties>
|
||||||
|
<env>default</env>
|
||||||
|
<test.groups>unit</test.groups>
|
||||||
|
</properties>
|
||||||
|
<activation>
|
||||||
|
<activeByDefault>true</activeByDefault>
|
||||||
|
</activation>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<version>3.0.0-M3</version>
|
||||||
|
<configuration>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<groups>unit</groups>
|
||||||
|
<includes>
|
||||||
|
<include>%regex[.*]</include>
|
||||||
|
</includes>
|
||||||
|
<properties>
|
||||||
|
<property>
|
||||||
|
<name>surefire.testng.verbose</name>
|
||||||
|
<value>2</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>%regex[.*]</include>
|
||||||
|
</includes>
|
||||||
|
<properties>
|
||||||
|
<property>
|
||||||
|
<name>surefire.testng.verbose</name>
|
||||||
|
<value>2</value>
|
||||||
|
</property>
|
||||||
|
</properties>
|
||||||
|
<groups>${test.groups}</groups>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
<goal>verify</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</pluginManagement>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-compiler-plugin</artifactId>
|
||||||
|
<version>3.8.1</version>
|
||||||
|
<configuration>
|
||||||
|
<source>1.8</source>
|
||||||
|
<target>1.8</target>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-eclipse-plugin</artifactId>
|
||||||
|
<version>2.10</version>
|
||||||
|
<configuration>
|
||||||
|
<classpathContainers>
|
||||||
|
<classpathContainer>
|
||||||
|
org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8
|
||||||
|
</classpathContainer>
|
||||||
|
</classpathContainers>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
|
<version>3.1.1</version>
|
||||||
|
<!--inherited>true</inherited-->
|
||||||
|
<configuration>
|
||||||
|
<quiet>true</quiet>
|
||||||
|
<verbose>false</verbose>
|
||||||
|
<additionalOptions>${javadoc.opts}</additionalOptions>
|
||||||
|
<sourceFileExcludes>
|
||||||
|
<sourceFileExclude>**/internal/**/*.java</sourceFileExclude>
|
||||||
|
<sourceFileExclude>**/*BridgeInternal.java</sourceFileExclude>
|
||||||
|
</sourceFileExcludes>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-javadocs</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
|
<version>3.1.0</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>attach-sources</id>
|
||||||
|
<goals>
|
||||||
|
<goal>jar-no-fork</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<filtering>false</filtering>
|
||||||
|
<directory>${project.basedir}/../schemas</directory>
|
||||||
|
<includes>
|
||||||
|
<include>SystemSchema.json</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<modules/>
|
||||||
|
|
||||||
|
</project>
|
||||||
74
java/src/main/java/com/azure/data/cosmos/core/Json.java
Normal file
74
java/src/main/java/com/azure/data/cosmos/core/Json.java
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.core;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonFactory;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectReader;
|
||||||
|
import com.fasterxml.jackson.databind.ObjectWriter;
|
||||||
|
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
public final class Json {
|
||||||
|
|
||||||
|
private static final Logger logger = LoggerFactory.getLogger(Json.class);
|
||||||
|
|
||||||
|
private static final ObjectMapper mapper = new ObjectMapper(new JsonFactory()
|
||||||
|
.enable(JsonParser.Feature.ALLOW_COMMENTS));
|
||||||
|
|
||||||
|
private static final ObjectReader reader = mapper.reader()
|
||||||
|
.withFeatures(DeserializationFeature.READ_ENUMS_USING_TO_STRING);
|
||||||
|
|
||||||
|
private static final ObjectWriter writer = mapper.writer()
|
||||||
|
.withFeatures(SerializationFeature.WRITE_ENUMS_USING_TO_STRING);
|
||||||
|
|
||||||
|
private Json() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Optional<T> parse(File file, Class<T> type) {
|
||||||
|
try {
|
||||||
|
return Optional.of(reader.forType(type).readValue(file));
|
||||||
|
} catch (IOException error) {
|
||||||
|
logger.error("failed to parse {} due to ", type.getName(), error);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Optional<T> parse(InputStream stream, Class<T> type) {
|
||||||
|
try {
|
||||||
|
return Optional.of(reader.forType(type).readValue(stream));
|
||||||
|
} catch (IOException error) {
|
||||||
|
logger.error("failed to parse {} due to ", type.getName(), error);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Optional<T> parse(String value, Class<T> type) {
|
||||||
|
try {
|
||||||
|
return Optional.of(reader.forType(type).readValue(value));
|
||||||
|
} catch (IOException error) {
|
||||||
|
logger.error("", error);
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String toString(Object object) {
|
||||||
|
try {
|
||||||
|
return writer.writeValueAsString(object);
|
||||||
|
} catch (JsonProcessingException error) {
|
||||||
|
return lenientFormat("{\"error\": \"%s\"}", error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
86
java/src/main/java/com/azure/data/cosmos/core/Out.java
Normal file
86
java/src/main/java/com/azure/data/cosmos/core/Out.java
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.core;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A container object which may or may not contain a non-null value
|
||||||
|
*
|
||||||
|
* This is a value-based class and as such use of identity-sensitive operations--including reference equality
|
||||||
|
* ({@code ==}), identity hash code, or synchronization--on instances of {@code Out} may have unpredictable results and
|
||||||
|
* should be avoided.
|
||||||
|
*
|
||||||
|
* @param <T> type of the referent.
|
||||||
|
*/
|
||||||
|
public final class Out<T> {
|
||||||
|
|
||||||
|
private volatile T value;
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(T value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public T setAndGet(T value) {
|
||||||
|
return this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if there is a value present, otherwise {@code false}
|
||||||
|
* <p>
|
||||||
|
* This is equivalent to evaluating the expression {@code out.get() == null}.
|
||||||
|
*
|
||||||
|
* @return {@code true} if there is a value present, otherwise {@code false}
|
||||||
|
*/
|
||||||
|
public boolean isPresent() {
|
||||||
|
return this.value != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some other object is equal to this {@link Out} value.
|
||||||
|
* <p>
|
||||||
|
* The other object is considered equal if:
|
||||||
|
* <ul>
|
||||||
|
* <li>it is also an {@link Out} and;
|
||||||
|
* <li>both instances have no value present or;
|
||||||
|
* <li>the present values are equal to each other as determined by {@code T.equals(Object)}}.
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param other an object to be tested for equality
|
||||||
|
* @return {code true} if the other object is equal to this object; otherwise {@code false}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.getClass() != Out.class) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Objects.equals(this.value, ((Out)other).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hash code value of the present value, if any, or 0 (zero) if
|
||||||
|
* no value is present.
|
||||||
|
*
|
||||||
|
* @return hash code value of the present value or 0 if no value is present
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.value == null ? "null" : this.value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
79
java/src/main/java/com/azure/data/cosmos/core/Reference.java
Normal file
79
java/src/main/java/com/azure/data/cosmos/core/Reference.java
Normal file
@@ -0,0 +1,79 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.core;
|
||||||
|
|
||||||
|
import java.util.Objects;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A container object which may or may not contain a non-null value.
|
||||||
|
*
|
||||||
|
* This is a value-based class and as such use of identity-sensitive operations--including reference equality
|
||||||
|
* ({@code ==}), identity hash code, or synchronization--on instances of {@link Reference} may have unpredictable
|
||||||
|
* results and should be avoided.
|
||||||
|
*
|
||||||
|
* @param <T> type of the referent.
|
||||||
|
*/
|
||||||
|
public final class Reference<T> {
|
||||||
|
|
||||||
|
private volatile T value;
|
||||||
|
|
||||||
|
public Reference(T value) {
|
||||||
|
this.setAndGet(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public T get() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(T value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
public T setAndGet(T value) {
|
||||||
|
return this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if there is a value present, otherwise {@code false}.
|
||||||
|
*
|
||||||
|
* This is equivalent to evaluating the expression {@code ref.get() == null}.
|
||||||
|
*
|
||||||
|
* @return {@code true} if there is a value present, otherwise {@code false}
|
||||||
|
*/
|
||||||
|
public boolean isPresent() {
|
||||||
|
return this.value != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether some other object is equal to this {@link Reference} value.
|
||||||
|
* <p>
|
||||||
|
* The other object is considered equal if:
|
||||||
|
* <ul>
|
||||||
|
* <li>it is also an {@link Reference} and;
|
||||||
|
* <li>both instances have no value present or;
|
||||||
|
* <li>the present values are equal to each other as determined by {@code T.equals(Object)}}.
|
||||||
|
* </ul>
|
||||||
|
*
|
||||||
|
* @param other an object to be tested for equality
|
||||||
|
* @return {code true} if the other object is equal to this object; otherwise {@code false}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.getClass() != Reference.class) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return Objects.equals(this.value, ((Reference)other).value);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return this.value == null ? "null" : this.value.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
1422
java/src/main/java/com/azure/data/cosmos/core/Utf8String.java
Normal file
1422
java/src/main/java/com/azure/data/cosmos/core/Utf8String.java
Normal file
File diff suppressed because it is too large
Load Diff
309
java/src/main/java/com/azure/data/cosmos/core/UtfAnyString.java
Normal file
309
java/src/main/java/com/azure/data/cosmos/core/UtfAnyString.java
Normal file
@@ -0,0 +1,309 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.core;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static com.azure.data.cosmos.core.Utf8String.transcodeUtf16;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A string whose memory representation may be either UTF-8 or UTF-16.
|
||||||
|
* <p>
|
||||||
|
* This type supports polymorphic use of {@link String} and {@link Utf8String} when equality, hashing, and comparison
|
||||||
|
* are needed against either encoding. An API leveraging {@link UtfAnyString} can avoid separate method overloads
|
||||||
|
* while still accepting either encoding without imposing additional allocations.
|
||||||
|
*/
|
||||||
|
public final class UtfAnyString implements CharSequence, Comparable<UtfAnyString> {
|
||||||
|
|
||||||
|
public static final UtfAnyString EMPTY = new UtfAnyString("");
|
||||||
|
public static final UtfAnyString NULL = new UtfAnyString();
|
||||||
|
|
||||||
|
private static final int NULL_HASHCODE = reduceHashCode(5_381, 5_381);
|
||||||
|
|
||||||
|
private CharSequence buffer;
|
||||||
|
|
||||||
|
public UtfAnyString(final String value) {
|
||||||
|
this.buffer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public UtfAnyString(final Utf8String value) {
|
||||||
|
this.buffer = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private UtfAnyString() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private UtfAnyString(final CharSequence sequence) {
|
||||||
|
this.buffer = sequence;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if the {@link UtfAnyString} is empty.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the {@link UtfAnyString} is empty.
|
||||||
|
*/
|
||||||
|
public boolean isEmpty() {
|
||||||
|
return this.buffer != null && this.buffer.length() == 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if the {@link UtfAnyString} is {@code null}.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the {@link UtfAnyString} is {@code null}.
|
||||||
|
*/
|
||||||
|
public boolean isNull() {
|
||||||
|
return null == this.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if the underlying representation of the {@link UtfAnyString} is a {@link String}.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the underlying representation of the {@link UtfAnyString} is a {@link String}.
|
||||||
|
*/
|
||||||
|
public boolean isUtf16() {
|
||||||
|
return this.buffer instanceof String;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if the underlying representation of the {@link UtfAnyString} is a {@link Utf8String}.
|
||||||
|
*
|
||||||
|
* @return {@code true} if the underlying representation of the {@link UtfAnyString} is a {@link Utf8String}.
|
||||||
|
*/
|
||||||
|
public boolean isUtf8() {
|
||||||
|
return this.buffer instanceof Utf8String;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the {@code char} value at the specified {@code index}.
|
||||||
|
* <p>
|
||||||
|
* An index ranges from zero to {@link UtfAnyString#length()} minus one. The first {@code char} value of the
|
||||||
|
* sequence is at index zero, the next at index one, and so on, as for array indexing. If the {@code char}
|
||||||
|
* value specified by the {@code index} is a surrogate, the surrogate (not the surrogate pair) is returned.
|
||||||
|
*
|
||||||
|
* @param index the index of the {@code char} value to be returned.
|
||||||
|
* @return the specified {@code char} value
|
||||||
|
* @throws IndexOutOfBoundsException if the {@code index} argument is negative or not less than
|
||||||
|
* {@link UtfAnyString#length()}
|
||||||
|
* @throws UnsupportedOperationException if this {@link UtfAnyString} is {@code null}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public char charAt(final int index) {
|
||||||
|
if (this.buffer == null) {
|
||||||
|
throw new UnsupportedOperationException("String is null");
|
||||||
|
}
|
||||||
|
return this.buffer.charAt(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(@Nonnull final String other) {
|
||||||
|
|
||||||
|
checkNotNull(other, "expected non-null other");
|
||||||
|
|
||||||
|
if (other == this.buffer) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.buffer instanceof String
|
||||||
|
? ((String) this.buffer).compareTo(other)
|
||||||
|
: ((Utf8String) this.buffer).compareTo(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int compareTo(@Nonnull final Utf8String other) {
|
||||||
|
|
||||||
|
checkNotNull(other, "expected non-null other");
|
||||||
|
|
||||||
|
if (other == this.buffer) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.buffer instanceof String
|
||||||
|
? -other.compareTo((String) this.buffer)
|
||||||
|
: ((Utf8String) this.buffer).compareTo(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@Nonnull final UtfAnyString other) {
|
||||||
|
|
||||||
|
checkNotNull(other, "expected non-null other");
|
||||||
|
|
||||||
|
if (other.buffer == this.buffer) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other.buffer == null) {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer == null) {
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer instanceof String) {
|
||||||
|
return other.buffer instanceof String
|
||||||
|
? ((String) this.buffer).compareTo((String) other.buffer)
|
||||||
|
: -((Utf8String) other.buffer).compareTo((String) this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((Utf8String) this.buffer).compareTo((Utf8String) other.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static UtfAnyString empty() {
|
||||||
|
return EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(final Object other) {
|
||||||
|
|
||||||
|
if (other == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other instanceof String) {
|
||||||
|
return this.equals((String) other);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other instanceof Utf8String) {
|
||||||
|
return this.equals((Utf8String) other);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (other instanceof UtfAnyString) {
|
||||||
|
return this.equals((UtfAnyString) other);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(final String other) {
|
||||||
|
|
||||||
|
if (null == this.buffer) {
|
||||||
|
return null == other;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer instanceof String) {
|
||||||
|
return other.contentEquals(this.buffer); // skips the type check that String.equals performs
|
||||||
|
}
|
||||||
|
|
||||||
|
return ((Utf8String) this.buffer).equals(other);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(final Utf8String other) {
|
||||||
|
|
||||||
|
if (null == other) {
|
||||||
|
return null == this.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return other.equals(this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(final UtfAnyString other) {
|
||||||
|
|
||||||
|
if (null == other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (null == this.buffer) {
|
||||||
|
return null == other.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.buffer instanceof String ? other.buffer.equals(this.buffer) : this.buffer.equals(other.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
|
||||||
|
final long[] hash = { 5_381, 5_381 };
|
||||||
|
|
||||||
|
if (this.buffer == null) {
|
||||||
|
return NULL_HASHCODE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.buffer instanceof String) {
|
||||||
|
|
||||||
|
final int ignored = ((String) this.buffer).codePoints().reduce(0, (index, codePoint) -> {
|
||||||
|
if (index % 2 == 0) {
|
||||||
|
hash[0] = ((hash[0] << 5) + hash[0]) ^ codePoint;
|
||||||
|
} else {
|
||||||
|
hash[1] = ((hash[1] << 5) + hash[1]) ^ codePoint;
|
||||||
|
}
|
||||||
|
return index;
|
||||||
|
});
|
||||||
|
|
||||||
|
return reduceHashCode(hash[0], hash[1]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.buffer.hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the length of this character sequence.
|
||||||
|
* <p>
|
||||||
|
* The length is the number of 16-bit {@code char}s in the sequence.
|
||||||
|
*
|
||||||
|
* @return the number of {@code char}s in this sequence.
|
||||||
|
* @throws UnsupportedOperationException if this {@link UtfAnyString} is {@code null}.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int length() {
|
||||||
|
if (this.buffer == null) {
|
||||||
|
throw new UnsupportedOperationException("String is null");
|
||||||
|
}
|
||||||
|
return this.buffer.length();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@code CharSequence} that is a subsequence of this sequence.
|
||||||
|
* <p>
|
||||||
|
* The subsequence starts with the {@code char} value at the specified index and ends with the{@code char} value at
|
||||||
|
* index {@code end - 1}. The length (in {@code char}s) of the returned sequence is {@code end - start}, so if
|
||||||
|
* {@code start == end}, an empty sequence is returned.
|
||||||
|
*
|
||||||
|
* @param start the start index, inclusive
|
||||||
|
* @param end the end index, exclusive
|
||||||
|
* @return the specified subsequence
|
||||||
|
* @throws IndexOutOfBoundsException if {@code start} or {@code end} are negative, {@code end} is greater than
|
||||||
|
* {@link UtfAnyString#length()}, or {@code start} is greater than {@code
|
||||||
|
* end}.
|
||||||
|
* @throws UnsupportedOperationException if string is {@code null}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public CharSequence subSequence(final int start, final int end) {
|
||||||
|
if (this.buffer == null) {
|
||||||
|
throw new UnsupportedOperationException("String is null");
|
||||||
|
}
|
||||||
|
return this.buffer.subSequence(start, end);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nonnull
|
||||||
|
public String toString() {
|
||||||
|
return String.valueOf(this.buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toUtf16() {
|
||||||
|
if (null == this.buffer) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.buffer instanceof String ? (String) this.buffer : this.buffer.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
public Utf8String toUtf8() {
|
||||||
|
if (null == this.buffer) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return this.buffer instanceof String ? transcodeUtf16((String) this.buffer) : (Utf8String) this.buffer;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int reduceHashCode(final long h1, final long h2) {
|
||||||
|
return Long.valueOf(h1 + (h2 * 1_566_083_941L)).intValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents an IEEE 754-2008 128-bit decimal floating point number.
|
||||||
|
* <p>
|
||||||
|
* The {@link Float128} represents an IEEE 754-2008 floating point number as a pair of {@code long} values:
|
||||||
|
* {@link #high()} and {@link #low()}.
|
||||||
|
*
|
||||||
|
* @see <a href="https://en.wikipedia.org/wiki/Decimal128_floating-point_format">decimal128 floating-point format</a>
|
||||||
|
* @see <a href="https://ieeexplore.ieee.org/document/4610935">754-2008: IEEE Standard for Floating-Point Arithmetic</a>
|
||||||
|
* @see <a href="http://speleotrove.com/decimal/decbits.html">Decimal Arithmetic Encodings Version 1.01 – 7 Apr 2009</a>
|
||||||
|
*/
|
||||||
|
public final class Float128 {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The size (in bytes) of a {@link Float128}.
|
||||||
|
*/
|
||||||
|
public static final int BYTES = 2 * Long.BYTES;
|
||||||
|
public static final Float128 ZERO = new Float128(0L, 0L);
|
||||||
|
|
||||||
|
private final long high;
|
||||||
|
private final long low;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new instance of the {@link Float128} struct.
|
||||||
|
*
|
||||||
|
* @param high the high-order 64 bits.
|
||||||
|
* @param low the low-order 64 bits.
|
||||||
|
*/
|
||||||
|
public Float128(long high, long low) {
|
||||||
|
this.high = high;
|
||||||
|
this.low = low;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The high-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID encoding scheme.
|
||||||
|
*
|
||||||
|
* @return the high-order 64 bits of the IEEE 754-2008 128-bit floating point number represented by this object.
|
||||||
|
*/
|
||||||
|
public long high() {
|
||||||
|
return this.high;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The low-order 64 bits of the IEEE 754-2008 128-bit decimal floating point, using the BID encoding scheme.
|
||||||
|
*
|
||||||
|
* @return the low-order 64 bits of the IEEE 754-2008 128-bit floating point number represented by this object.
|
||||||
|
*/
|
||||||
|
public long low() {
|
||||||
|
return this.low;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,77 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.annotation.concurrent.Immutable;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An immutable 128-bit hash code.
|
||||||
|
*
|
||||||
|
* The hash code is represented by two {@code long} values: {@link #low()} and {@link #high()}.
|
||||||
|
*/
|
||||||
|
@Immutable
|
||||||
|
public class HashCode128 {
|
||||||
|
|
||||||
|
private final long high;
|
||||||
|
private final long low;
|
||||||
|
|
||||||
|
private HashCode128(final long low, final long high) {
|
||||||
|
this.low = low;
|
||||||
|
this.high = high;
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashCode128(ByteBuf buffer) {
|
||||||
|
this.low = buffer.readLongLE();
|
||||||
|
this.high = buffer.readLongLE();
|
||||||
|
}
|
||||||
|
|
||||||
|
public long high() {
|
||||||
|
return this.high;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long low() {
|
||||||
|
return this.low;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static HashCode128 from(@Nonnull final byte[] buffer) {
|
||||||
|
|
||||||
|
checkNotNull(buffer, "expected non-null buffer");
|
||||||
|
checkArgument(buffer.length >= 2 * Long.BYTES, "expected buffer length >= 16, not %s", buffer.length);
|
||||||
|
|
||||||
|
return new HashCode128(Unpooled.wrappedBuffer(buffer));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads a {@link HashCode128} from a {@link ByteBuf}.
|
||||||
|
* <p>
|
||||||
|
* The hash code is read as a pair of long values serialized in little-endian format. The values are read from the
|
||||||
|
* buffer's current reader index which is advanced by 16 bytes: the length of two long values.
|
||||||
|
*
|
||||||
|
* @param buffer The buffer from which to read the hash code.
|
||||||
|
* @return The hash code read.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public static HashCode128 from(@Nonnull final ByteBuf buffer) {
|
||||||
|
|
||||||
|
checkNotNull(buffer, "expected non-null buffer");
|
||||||
|
|
||||||
|
final int length = buffer.writerIndex() - buffer.readerIndex();
|
||||||
|
checkArgument(length >= 2 * Long.BYTES, "expected at least 16 readable bytes in buffer, not %s", length);
|
||||||
|
|
||||||
|
return new HashCode128(buffer);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nonnull
|
||||||
|
public static HashCode128 of(long low, long high) {
|
||||||
|
return new HashCode128(low, high);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,56 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the header that precedes all valid Hybrid Rows.
|
||||||
|
*/
|
||||||
|
public final class HybridRowHeader {
|
||||||
|
/**
|
||||||
|
* Size (in bytes) of a serialized header.
|
||||||
|
*/
|
||||||
|
public static final int BYTES = HybridRowVersion.BYTES + SchemaId.BYTES;
|
||||||
|
|
||||||
|
private final SchemaId schemaId;
|
||||||
|
private final HybridRowVersion version;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new instance of a {@link HybridRowHeader}.
|
||||||
|
*
|
||||||
|
* @param version The version of the HybridRow library used to write this row.
|
||||||
|
* @param schemaId The unique identifier of the schema whose layout was used to write this row.
|
||||||
|
*/
|
||||||
|
public HybridRowHeader(@Nonnull final HybridRowVersion version, @Nonnull SchemaId schemaId) {
|
||||||
|
|
||||||
|
checkNotNull(version, "expected non-null version");
|
||||||
|
checkNotNull(schemaId, "expected non-null schemaId");
|
||||||
|
|
||||||
|
this.version = version;
|
||||||
|
this.schemaId = schemaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique identifier of the schema whose layout was used to write this {@link HybridRowHeader}.
|
||||||
|
*
|
||||||
|
* @return unique identifier of the schema whose layout was used to write this {@link HybridRowHeader}.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public SchemaId schemaId() {
|
||||||
|
return this.schemaId;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version of the HybridRow serialization library used to write this {@link HybridRowHeader}.
|
||||||
|
*
|
||||||
|
* @return version of the HybridRow serialization library used to write this {@link HybridRowHeader}.
|
||||||
|
*/
|
||||||
|
@Nonnull
|
||||||
|
public HybridRowVersion version() {
|
||||||
|
return this.version;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,50 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import it.unimi.dsi.fastutil.bytes.Byte2ReferenceMap;
|
||||||
|
import it.unimi.dsi.fastutil.bytes.Byte2ReferenceOpenHashMap;
|
||||||
|
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Versions of HybridRow.
|
||||||
|
* <p>
|
||||||
|
* A version from this list MUST be inserted in the version BOM at the beginning of all rows.
|
||||||
|
*/
|
||||||
|
public enum HybridRowVersion {
|
||||||
|
|
||||||
|
INVALID((byte)0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initial version of the HybridRow format.
|
||||||
|
*/
|
||||||
|
V1((byte)0x81);
|
||||||
|
|
||||||
|
public static final int BYTES = Byte.BYTES;
|
||||||
|
|
||||||
|
private static final Supplier<Byte2ReferenceMap<HybridRowVersion>> mappings = Suppliers.memoize(() -> {
|
||||||
|
final HybridRowVersion[] constants = HybridRowVersion.class.getEnumConstants();
|
||||||
|
final byte[] values = new byte[constants.length];
|
||||||
|
for (int i = 0; i < constants.length; i++) {
|
||||||
|
values[i] = constants[i].value();
|
||||||
|
}
|
||||||
|
return new Byte2ReferenceOpenHashMap<>(values, constants);
|
||||||
|
});
|
||||||
|
|
||||||
|
private final byte value;
|
||||||
|
|
||||||
|
HybridRowVersion(final byte value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static HybridRowVersion from(final byte value) {
|
||||||
|
return mappings.get().get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public byte value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The literal null value.
|
||||||
|
* <p>
|
||||||
|
* May be stored hybrid row to indicate the literal null value. Typically this value should not be used and the
|
||||||
|
* corresponding column should be absent from the row.
|
||||||
|
*/
|
||||||
|
public final class NullValue {
|
||||||
|
/**
|
||||||
|
* The default null literal.
|
||||||
|
* This is the same value as default({@link NullValue}).
|
||||||
|
*/
|
||||||
|
public static final NullValue DEFAULT = new NullValue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns true if this is the same value as {@code other}.
|
||||||
|
*
|
||||||
|
* @param other The value to compare against.
|
||||||
|
* @return True if the two values are the same.
|
||||||
|
*/
|
||||||
|
public boolean equals(NullValue other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (null == other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return other instanceof NullValue && this.equals((NullValue)other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return 42;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceArrayMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
public enum Result {
|
||||||
|
|
||||||
|
SUCCESS(0),
|
||||||
|
FAILURE(1),
|
||||||
|
NOT_FOUND(2),
|
||||||
|
EXISTS(3),
|
||||||
|
TOO_BIG(4),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type of an existing field does not match the expected type for this operation.
|
||||||
|
*/
|
||||||
|
TYPE_MISMATCH(5),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An attempt to write in a read-only scope.
|
||||||
|
*/
|
||||||
|
INSUFFICIENT_PERMISSIONS(6),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An attempt to write a field that did not match its (optional) type constraints.
|
||||||
|
*/
|
||||||
|
TYPE_CONSTRAINT(7),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The byte sequence could not be parsed as a valid row.
|
||||||
|
*/
|
||||||
|
INVALID_ROW(8),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The byte sequence was too short for the requested action.
|
||||||
|
*/
|
||||||
|
INSUFFICIENT_BUFFER(9),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The operation was cancelled.
|
||||||
|
*/
|
||||||
|
CANCELED(10);
|
||||||
|
|
||||||
|
public static final int BYTES = Integer.BYTES;
|
||||||
|
|
||||||
|
private static final Supplier<Int2ReferenceMap<Result>> mappings = Suppliers.memoize(() -> {
|
||||||
|
Result[] constants = Result.class.getEnumConstants();
|
||||||
|
int[] values = new int[constants.length];
|
||||||
|
Arrays.setAll(values, index -> constants[index].value);
|
||||||
|
return new Int2ReferenceOpenHashMap<>(values, constants);
|
||||||
|
});
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
Result(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static Result from(int value) {
|
||||||
|
return mappings.get().get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,415 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.UtfAnyString;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.Layout;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTuple;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutType;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypeScope;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutTypes;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgument;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.TypeArgumentList;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
|
||||||
|
public final class RowCursor implements Cloneable {
|
||||||
|
|
||||||
|
private LayoutType cellType;
|
||||||
|
private TypeArgumentList cellTypeArgs;
|
||||||
|
private int count;
|
||||||
|
private boolean deferUniqueIndex;
|
||||||
|
private int endOffset;
|
||||||
|
private boolean exists;
|
||||||
|
private boolean immutable;
|
||||||
|
private int index;
|
||||||
|
private Layout layout;
|
||||||
|
private int metaOffset;
|
||||||
|
private int pathOffset;
|
||||||
|
private int pathToken;
|
||||||
|
private LayoutTypeScope scopeType;
|
||||||
|
private TypeArgumentList scopeTypeArgs;
|
||||||
|
private int start;
|
||||||
|
private int valueOffset;
|
||||||
|
private UtfAnyString writePath;
|
||||||
|
private StringToken writePathToken;
|
||||||
|
|
||||||
|
RowCursor() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the layout code of the existing field, otherwise undefined.
|
||||||
|
*
|
||||||
|
* @return layout code.
|
||||||
|
*/
|
||||||
|
public LayoutType cellType() {
|
||||||
|
return this.cellType;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the layout type of an existing field.
|
||||||
|
*
|
||||||
|
* @param value a {@link LayoutType}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor cellType(LayoutType value) {
|
||||||
|
this.cellType = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For types with generic parameters (e.g. {@link LayoutTuple}, the type parameters.
|
||||||
|
*
|
||||||
|
* @return a {@link TypeArgumentList} or {@code null}.
|
||||||
|
*/
|
||||||
|
public TypeArgumentList cellTypeArgs() {
|
||||||
|
return this.cellTypeArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the layout type arguments of an existing field.
|
||||||
|
*
|
||||||
|
* @param value a {@link TypeArgumentList} or {@code null}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor cellTypeArgs(TypeArgumentList value) {
|
||||||
|
this.cellTypeArgs = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor clone() {
|
||||||
|
try {
|
||||||
|
return (RowCursor) super.clone();
|
||||||
|
} catch (CloneNotSupportedException error) {
|
||||||
|
throw new IllegalStateException(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For sized scopes (e.g. Typed Array), the number of elements.
|
||||||
|
*
|
||||||
|
* @return the number of elements or zero.
|
||||||
|
*/
|
||||||
|
public int count() {
|
||||||
|
return this.count;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the number of elements for a sized scope.
|
||||||
|
*
|
||||||
|
* @param count the number of elements for a sized scope.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor count(int count) {
|
||||||
|
this.count = count;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RowCursor create(RowBuffer row) {
|
||||||
|
|
||||||
|
final SchemaId schemaId = row.readSchemaId(1);
|
||||||
|
final Layout layout = row.resolver().resolve(schemaId);
|
||||||
|
final int offset = row.computeVariableValueOffset(layout, HybridRowHeader.BYTES, layout.numVariable());
|
||||||
|
|
||||||
|
return new RowCursor()
|
||||||
|
.layout(layout)
|
||||||
|
.scopeType(LayoutTypes.UDT)
|
||||||
|
.scopeTypeArgs(new TypeArgumentList(schemaId))
|
||||||
|
.start(HybridRowHeader.BYTES)
|
||||||
|
.metaOffset(offset)
|
||||||
|
.valueOffset(offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RowCursor createForAppend(RowBuffer row) {
|
||||||
|
|
||||||
|
final SchemaId schemaId = row.readSchemaId(1);
|
||||||
|
final Layout layout = row.resolver().resolve(schemaId);
|
||||||
|
|
||||||
|
return new RowCursor()
|
||||||
|
.layout(layout)
|
||||||
|
.scopeType(LayoutTypes.UDT)
|
||||||
|
.scopeTypeArgs(new TypeArgumentList(schemaId))
|
||||||
|
.start(HybridRowHeader.BYTES)
|
||||||
|
.metaOffset(row.length())
|
||||||
|
.valueOffset(row.length());
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If true, this scope is a unique index scope whose index will be built after its items are written.
|
||||||
|
*
|
||||||
|
* @return {@code true}, if this cursor identifies a unique index scope, otherwise {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean deferUniqueIndex() {
|
||||||
|
return this.deferUniqueIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value that indicates whether this cursor identifies a unique index scope.
|
||||||
|
*
|
||||||
|
* @param value {@code true}, if this cursor identifies a unique index scope, otherwise {@code false}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor deferUniqueIndex(boolean value) {
|
||||||
|
this.deferUniqueIndex = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the offset to the end of the existing field.
|
||||||
|
* <p>
|
||||||
|
* This value is used as a hint when skipping forward.
|
||||||
|
*
|
||||||
|
* @return offset of the end of an existing field.
|
||||||
|
*/
|
||||||
|
public int endOffset() {
|
||||||
|
return this.endOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value that indicates whether this cursor identifies a unique index scope.
|
||||||
|
*
|
||||||
|
* @param value {@code true}, if this cursor identifies a unique index scope, otherwise {@code false}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor endOffset(int value) {
|
||||||
|
this.endOffset = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if an existing field matching the search criteria was found.
|
||||||
|
*
|
||||||
|
* @return {@code true} if an existing field matching the search criteria was found, otherwise {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean exists() {
|
||||||
|
return this.exists;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a value that indicates whether this cursor identifies a field matching search criteria.
|
||||||
|
*
|
||||||
|
* @param value {@code true}, if this cursor identifies a field matching search criteria, otherwise {@code false}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor exists(boolean value) {
|
||||||
|
this.exists = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If {@code true}, this scope's nested fields cannot be updated individually.
|
||||||
|
* <p>
|
||||||
|
* The entire scope can still be replaced.
|
||||||
|
*
|
||||||
|
* @return {@code true} if this scope's nested fields cannot be updated individually, otherwise {@code false}.
|
||||||
|
*/
|
||||||
|
public boolean immutable() {
|
||||||
|
return this.immutable;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets a flag indicated whether this scope's nested fields cannot be updated individually.
|
||||||
|
* <p>
|
||||||
|
* The entire scope can still be replaced.
|
||||||
|
*
|
||||||
|
* @param value {@code true} if this scope's nested fields cannot be updated individually, otherwise {@code false}.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor immutable(boolean value) {
|
||||||
|
this.immutable = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For indexed scopes (e.g. an Array scope), the zero-based index into the scope of the sparse field.
|
||||||
|
*
|
||||||
|
* @return the zero-based index into the scope of the sparse field.
|
||||||
|
*/
|
||||||
|
public int index() {
|
||||||
|
return this.index;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the zero-based index into the scope of a sparse field in an indexed scope (e.g. an Array scope).
|
||||||
|
*
|
||||||
|
* @param value the zero-based index into the scope of the sparse field.
|
||||||
|
* @return a reference to this {@link RowCursor}.
|
||||||
|
*/
|
||||||
|
public RowCursor index(int value) {
|
||||||
|
this.index = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The layout describing the contents of the scope, or {@code null} if the scope is unschematized.
|
||||||
|
*
|
||||||
|
* @return layout describing the context of the scope, or {@code null} if the scope is unschematized.
|
||||||
|
*/
|
||||||
|
public Layout layout() {
|
||||||
|
return this.layout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor layout(Layout value) {
|
||||||
|
this.layout = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, offset to the metadata of the existing field, otherwise the location to insert a new field.
|
||||||
|
*
|
||||||
|
* @return offset to the metadata of an existing field or the location to insert a new field.
|
||||||
|
*/
|
||||||
|
public int metaOffset() {
|
||||||
|
return this.metaOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor metaOffset(final int value) {
|
||||||
|
this.metaOffset = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the offset scope relative path for reading.
|
||||||
|
*
|
||||||
|
* @return If existing, the offset scope relative path for reading.
|
||||||
|
*/
|
||||||
|
public int pathOffset() {
|
||||||
|
return this.pathOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor pathOffset(final int value) {
|
||||||
|
this.pathOffset = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the layout string token of scope relative path for reading.
|
||||||
|
*
|
||||||
|
* @return If existing, the layout string token of scope relative path for reading.
|
||||||
|
*/
|
||||||
|
public int pathToken() {
|
||||||
|
return this.pathToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor pathToken(int value) {
|
||||||
|
this.pathToken = value;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The kind of scope within which this edit was prepared.
|
||||||
|
*
|
||||||
|
* @return The kind of scope within which this edit was prepared.
|
||||||
|
*/
|
||||||
|
public LayoutTypeScope scopeType() {
|
||||||
|
return this.scopeType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor scopeType(LayoutTypeScope scopeType) {
|
||||||
|
this.scopeType = scopeType;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The type parameters of the scope within which this edit was prepared.
|
||||||
|
*
|
||||||
|
* @return The type parameters of the scope within which this edit was prepared.
|
||||||
|
*/
|
||||||
|
public TypeArgumentList scopeTypeArgs() {
|
||||||
|
return this.scopeTypeArgs;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor scopeTypeArgs(TypeArgumentList scopeTypeArgs) {
|
||||||
|
this.scopeTypeArgs = scopeTypeArgs;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The 0-based offset from the beginning of the row where the first sparse field within the scope begins.
|
||||||
|
*
|
||||||
|
* @return 0-based offset from the beginning of the row where the first sparse field within the scope begins.
|
||||||
|
*/
|
||||||
|
public int start() {
|
||||||
|
return this.start;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor start(int start) {
|
||||||
|
this.start = start;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
|
||||||
|
try {
|
||||||
|
|
||||||
|
if (this.scopeType() == null) {
|
||||||
|
return "<Invalid>";
|
||||||
|
}
|
||||||
|
|
||||||
|
TypeArgument scopeTypeArg = (this.scopeType() instanceof LayoutEndScope)
|
||||||
|
? TypeArgument.NONE
|
||||||
|
: new TypeArgument(this.scopeType(), this.scopeTypeArgs());
|
||||||
|
|
||||||
|
TypeArgument typeArg = (this.cellType() == null) || (this.cellType() instanceof LayoutEndScope)
|
||||||
|
? TypeArgument.NONE
|
||||||
|
: new TypeArgument(this.cellType(), this.cellTypeArgs());
|
||||||
|
|
||||||
|
String pathOrIndex = this.writePath().isNull() ? String.valueOf(this.index()) : this.writePath().toString();
|
||||||
|
|
||||||
|
return lenientFormat("%s[%s] : %s@%s/%s%s",
|
||||||
|
scopeTypeArg,
|
||||||
|
pathOrIndex,
|
||||||
|
typeArg,
|
||||||
|
this.metaOffset(),
|
||||||
|
this.valueOffset(),
|
||||||
|
this.immutable() ? " immutable" : "");
|
||||||
|
|
||||||
|
} catch (Exception ignored) {
|
||||||
|
return "<???>";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the offset to the value of the existing field, otherwise undefined.
|
||||||
|
*
|
||||||
|
* @return If existing, the offset to the value of the existing field, otherwise undefined.
|
||||||
|
*/
|
||||||
|
public int valueOffset() {
|
||||||
|
return this.valueOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public RowCursor valueOffset(int valueOffset) {
|
||||||
|
this.valueOffset = valueOffset;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If existing, the scope relative path for writing.
|
||||||
|
*
|
||||||
|
* @return If existing, the scope relative path for writing.
|
||||||
|
*/
|
||||||
|
public UtfAnyString writePath() {
|
||||||
|
return this.writePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePath(UtfAnyString writePath) {
|
||||||
|
this.writePath = writePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If {@link #writePath} is tokenized, then its token.
|
||||||
|
*
|
||||||
|
* @return if {@link #writePath} is tokenized, then its token.
|
||||||
|
*/
|
||||||
|
public StringToken writePathToken() {
|
||||||
|
return this.writePathToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void writePathToken(StringToken writePathToken) {
|
||||||
|
this.writePathToken = writePathToken;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,137 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.core.UtfAnyString;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutCode;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.LayoutEndScope;
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.layouts.StringToken;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
public final class RowCursors {
|
||||||
|
|
||||||
|
private RowCursors() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RowCursor Find(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull UtfAnyString path) {
|
||||||
|
checkArgument(!edit.scopeType().isIndexedScope());
|
||||||
|
|
||||||
|
if (!(edit.cellType() instanceof LayoutEndScope)) {
|
||||||
|
while (row.sparseIteratorMoveNext(edit)) {
|
||||||
|
if (path.equals(row.readSparsePath(edit))) {
|
||||||
|
edit.exists(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit.writePath(path);
|
||||||
|
edit.writePathToken(null);
|
||||||
|
|
||||||
|
return edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RowCursor Find(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull StringToken pathToken) {
|
||||||
|
|
||||||
|
checkNotNull(edit);
|
||||||
|
checkNotNull(row);
|
||||||
|
checkNotNull(pathToken);
|
||||||
|
|
||||||
|
checkArgument(!edit.scopeType().isIndexedScope());
|
||||||
|
|
||||||
|
if (!(edit.cellType() instanceof LayoutEndScope)) {
|
||||||
|
while (row.sparseIteratorMoveNext(edit)) {
|
||||||
|
if (pathToken.id() == (long) edit.pathToken()) {
|
||||||
|
edit.exists(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
edit.writePath(new UtfAnyString(pathToken.path()));
|
||||||
|
edit.writePathToken(pathToken);
|
||||||
|
|
||||||
|
return edit;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* An equivalent scope that is read-only.
|
||||||
|
*
|
||||||
|
* @param source source scope.
|
||||||
|
* @return an equivalent scope that is read-only.
|
||||||
|
*/
|
||||||
|
public static RowCursor asReadOnly(RowCursor source) {
|
||||||
|
return source.clone().immutable(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Makes a copy of the current cursor.
|
||||||
|
* <p>
|
||||||
|
* The two cursors will have independent and unconnected lifetimes after cloning. However, mutations to a
|
||||||
|
* {@link RowBuffer} can invalidate any active cursors over the same row.
|
||||||
|
*
|
||||||
|
* @param source source cursor.
|
||||||
|
* @return copy of the source cursor.
|
||||||
|
*/
|
||||||
|
public static RowCursor copy(RowCursor source) {
|
||||||
|
return source.clone();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean moveNext(RowCursor edit, RowBuffer row) {
|
||||||
|
edit.writePath(null);
|
||||||
|
edit.writePathToken(null);
|
||||||
|
return row.sparseIteratorMoveNext(edit);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean moveNext(@Nonnull RowCursor edit, @Nonnull RowBuffer row, @Nonnull RowCursor childScope) {
|
||||||
|
if (childScope.scopeType() != null) {
|
||||||
|
RowCursors.skip(edit.clone(), row, childScope);
|
||||||
|
}
|
||||||
|
return RowCursors.moveNext(edit.clone(), row);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean moveTo(@Nonnull final RowCursor edit, @Nonnull final RowBuffer row, final int index) {
|
||||||
|
|
||||||
|
checkNotNull(row);
|
||||||
|
checkNotNull(edit);
|
||||||
|
checkArgument(edit.index() <= index);
|
||||||
|
|
||||||
|
edit.writePath(null);
|
||||||
|
edit.writePathToken(null);
|
||||||
|
|
||||||
|
while (edit.index() < index) {
|
||||||
|
if (!row.sparseIteratorMoveNext(edit)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void skip(
|
||||||
|
@Nonnull final RowCursor edit, @Nonnull final RowBuffer buffer, @Nonnull final RowCursor childScope) {
|
||||||
|
|
||||||
|
checkNotNull(edit, "expected non-null edit");
|
||||||
|
checkNotNull(buffer, "expected non-null buffer");
|
||||||
|
checkNotNull(childScope, "expected non-null childScope");
|
||||||
|
|
||||||
|
checkArgument(childScope.start() == edit.valueOffset());
|
||||||
|
|
||||||
|
if (!(childScope.cellType() instanceof LayoutEndScope)) {
|
||||||
|
//noinspection StatementWithEmptyBody
|
||||||
|
while (buffer.sparseIteratorMoveNext(childScope)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (childScope.scopeType().isSizedScope()) {
|
||||||
|
edit.endOffset(childScope.metaOffset());
|
||||||
|
} else {
|
||||||
|
edit.endOffset(childScope.metaOffset() + LayoutCode.BYTES); // move past end of scope marker
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.azure.data.cosmos.serialization.hybridrow.schemas.SortDirection;
|
||||||
|
import com.google.common.base.Suppliers;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceArrayMap;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.function.Supplier;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Describes the desired behavior when mutating a hybrid row.
|
||||||
|
*/
|
||||||
|
public enum RowOptions {
|
||||||
|
|
||||||
|
NONE(0),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overwrite an existing value.
|
||||||
|
* <p>
|
||||||
|
* An existing value is assumed to exist at the offset provided. The existing value is
|
||||||
|
* replaced inline. The remainder of the row is resized to accomodate either an increase or decrease
|
||||||
|
* in required space.
|
||||||
|
*/
|
||||||
|
UPDATE(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new value.
|
||||||
|
* <p>
|
||||||
|
* An existing value is assumed NOT to exist at the offset provided. The new value is
|
||||||
|
* inserted immediately at the offset. The remainder of the row is resized to accomodate either an
|
||||||
|
* increase or decrease in required space.
|
||||||
|
*/
|
||||||
|
INSERT(2),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update an existing value or insert a new value, if no value exists.
|
||||||
|
* <p>
|
||||||
|
* If a value exists, then this operation becomes {@link #UPDATE}, otherwise it
|
||||||
|
* becomes {@link #INSERT}.
|
||||||
|
*/
|
||||||
|
UPSERT(3),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Insert a new value moving existing values to the right.
|
||||||
|
* <p>
|
||||||
|
* Within an array scope, inserts a new value immediately at the index moving all subsequent
|
||||||
|
* items to the right. In any other scope behaves the same as {@link #UPSERT}.
|
||||||
|
*/
|
||||||
|
INSERT_AT(4),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Delete an existing value.
|
||||||
|
* <p>
|
||||||
|
* If a value exists, then it is removed. The remainder of the row is resized to accommodate
|
||||||
|
* a decrease in required space. If no value exists this operation is a no-op.
|
||||||
|
*/
|
||||||
|
DELETE(5);
|
||||||
|
|
||||||
|
public static final int BYTES = Integer.BYTES;
|
||||||
|
|
||||||
|
private static final Supplier<Int2ReferenceMap<RowOptions>> mappings = Suppliers.memoize(() -> {
|
||||||
|
RowOptions[] constants = RowOptions.class.getEnumConstants();
|
||||||
|
int[] values = new int[constants.length];
|
||||||
|
Arrays.setAll(values, index -> constants[index].value);
|
||||||
|
return new Int2ReferenceArrayMap<>(values, constants);
|
||||||
|
});
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
RowOptions(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static RowOptions from(int value) {
|
||||||
|
return mappings.get().get(value);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,160 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.core.JsonGenerator;
|
||||||
|
import com.fasterxml.jackson.core.JsonParser;
|
||||||
|
import com.fasterxml.jackson.databind.DeserializationContext;
|
||||||
|
import com.fasterxml.jackson.databind.SerializerProvider;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
|
||||||
|
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
|
||||||
|
import com.fasterxml.jackson.databind.deser.std.StdDeserializer;
|
||||||
|
import com.fasterxml.jackson.databind.exc.MismatchedInputException;
|
||||||
|
import com.fasterxml.jackson.databind.ser.std.StdSerializer;
|
||||||
|
import it.unimi.dsi.fastutil.HashCommon;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceMap;
|
||||||
|
import it.unimi.dsi.fastutil.ints.Int2ReferenceOpenHashMap;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
import static com.google.common.base.Strings.lenientFormat;
|
||||||
|
import static it.unimi.dsi.fastutil.HashCommon.mix;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The unique identifier for a schema.
|
||||||
|
* <p>
|
||||||
|
* Identifiers must be unique within the scope of the database in which they are used.
|
||||||
|
*/
|
||||||
|
@JsonDeserialize(using = SchemaId.JsonDeserializer.class)
|
||||||
|
@JsonSerialize(using = SchemaId.JsonSerializer.class)
|
||||||
|
public final class SchemaId implements Comparable<SchemaId> {
|
||||||
|
|
||||||
|
public static final int BYTES = Integer.BYTES;
|
||||||
|
public static final SchemaId INVALID;
|
||||||
|
public static final SchemaId NONE;
|
||||||
|
|
||||||
|
private static final Int2ReferenceMap<SchemaId> cache;
|
||||||
|
|
||||||
|
static {
|
||||||
|
cache = new Int2ReferenceOpenHashMap<>();
|
||||||
|
cache.put(0, INVALID = NONE = new SchemaId(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new instance of the {@link SchemaId} class.
|
||||||
|
*
|
||||||
|
* @param value The underlying globally unique identifier of the schema.
|
||||||
|
*/
|
||||||
|
private SchemaId(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int compareTo(@Nonnull SchemaId other) {
|
||||||
|
return Integer.compare(this.value, other.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (other == null || this.getClass() != other.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
SchemaId schemaId = (SchemaId) other;
|
||||||
|
return this.value == schemaId.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code true} if this is the same {@link SchemaId} as {@code other}.
|
||||||
|
*
|
||||||
|
* @param other The value to compare against.
|
||||||
|
* @return {@code true} if the two values are the same.
|
||||||
|
*/
|
||||||
|
public boolean equals(SchemaId other) {
|
||||||
|
if (null == other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.value() == other.value();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns a {@link SchemaId} with the given underlying integer value.
|
||||||
|
*
|
||||||
|
* @param value an integer.
|
||||||
|
* @return a {@link SchemaId} with the given underlying integer {@code value}.
|
||||||
|
*/
|
||||||
|
public static SchemaId from(int value) {
|
||||||
|
return cache.computeIfAbsent(value, SchemaId::new);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the hash code value for this {@link SchemaId}.
|
||||||
|
* <p>
|
||||||
|
* This method mixes the bits of the underlying {@code int} value of the {@link SchemaId} by multiplying by the
|
||||||
|
* golden ratio and xor-shifting the result. It has slightly worse behavior than MurmurHash3. In open-addressing
|
||||||
|
* In open-addressing tables the average number of probes is slightly larger, but the computation of the value
|
||||||
|
* is faster.
|
||||||
|
*
|
||||||
|
* @return the hash code value for this {@link SchemaId}.
|
||||||
|
* @see HashCommon#mix(int)
|
||||||
|
* @see <a href="https://github.com/OpenHFT/Koloboke">Koloboke</a>
|
||||||
|
* @see <a href="https://en.wikipedia.org/wiki/MurmurHash">MurmurHash</a>
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return mix(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return Integer.toString(this.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The underlying integer value of this {@link SchemaId}.
|
||||||
|
*
|
||||||
|
* @return The integer value of this {@link SchemaId}
|
||||||
|
*/
|
||||||
|
public int value() {
|
||||||
|
return this.value;
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class JsonDeserializer extends StdDeserializer<SchemaId> {
|
||||||
|
|
||||||
|
private JsonDeserializer() {
|
||||||
|
super(SchemaId.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public SchemaId deserialize(final JsonParser parser, final DeserializationContext context) throws IOException {
|
||||||
|
|
||||||
|
final int value = parser.getIntValue();
|
||||||
|
|
||||||
|
if (value == 0) {
|
||||||
|
String message = "expected non-zero int value for SchemaId";
|
||||||
|
throw MismatchedInputException.from(parser, SchemaId.class, message);
|
||||||
|
}
|
||||||
|
|
||||||
|
return SchemaId.from(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static final class JsonSerializer extends StdSerializer<SchemaId> {
|
||||||
|
|
||||||
|
private JsonSerializer() {
|
||||||
|
super(SchemaId.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void serialize(
|
||||||
|
final SchemaId value, final JsonGenerator generator, final SerializerProvider provider) throws IOException {
|
||||||
|
generator.writeNumber(value.value());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,78 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A wall clock time expressed in milliseconds since the Unix Epoch.
|
||||||
|
* <p>
|
||||||
|
* A {@link UnixDateTime} is a fixed length value-type providing millisecond
|
||||||
|
* granularity as a signed offset from the Unix Epoch (midnight, January 1, 1970 UTC).
|
||||||
|
*/
|
||||||
|
public final class UnixDateTime {
|
||||||
|
/**
|
||||||
|
* Unix epoch.
|
||||||
|
* <p>
|
||||||
|
* {@link UnixDateTime} values are signed values centered on this value.
|
||||||
|
*/
|
||||||
|
public static final UnixDateTime EPOCH = new UnixDateTime();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Size in bytes of a {@link UnixDateTime}.
|
||||||
|
*/
|
||||||
|
public static final int BYTES = Long.SIZE;
|
||||||
|
|
||||||
|
private long milliseconds;
|
||||||
|
|
||||||
|
private UnixDateTime() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes a new instance of the {@link UnixDateTime} class.
|
||||||
|
*
|
||||||
|
* @param milliseconds The number of milliseconds since {@link #EPOCH}.
|
||||||
|
*/
|
||||||
|
public UnixDateTime(long milliseconds) {
|
||||||
|
this.milliseconds = milliseconds;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@code> true} if this value is the same as another value.
|
||||||
|
*
|
||||||
|
* @param other value to compare.
|
||||||
|
* @return {code true} if this value is the same as the {code other}, {@code false} otherwise.
|
||||||
|
*/
|
||||||
|
public boolean equals(UnixDateTime other) {
|
||||||
|
if (other == null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return this.milliseconds() == other.milliseconds();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object other) {
|
||||||
|
if (null == other) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (this == other) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return other instanceof UnixDateTime && this.equals((UnixDateTime)other);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Long.valueOf(this.milliseconds).hashCode();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The number of milliseconds since {@link #EPOCH}.
|
||||||
|
* <p>
|
||||||
|
* This value may be negative.
|
||||||
|
*
|
||||||
|
* @return the number of milliseconds since {@link #EPOCH}.
|
||||||
|
*/
|
||||||
|
public long milliseconds() {
|
||||||
|
return this.milliseconds;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,144 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.codecs;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.time.Instant;
|
||||||
|
import java.time.OffsetDateTime;
|
||||||
|
import java.time.ZoneOffset;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides static methods for encoding and decoding {@link OffsetDateTime}s serialized as {@code System.DateTime}s
|
||||||
|
*
|
||||||
|
* {@link OffsetDateTime} values are serialized as unsigned 64-bit integers:
|
||||||
|
*
|
||||||
|
* <table summary="Layout of field value">
|
||||||
|
* <tbody>
|
||||||
|
* <tr><td>
|
||||||
|
* Bits 01-62
|
||||||
|
* </td><td>
|
||||||
|
* Contain the number of 100-nanosecond ticks where 0 represents {@code 1/1/0001 12:00am}, up until the value
|
||||||
|
* {@code 12/31/9999 23:59:59.9999999}.
|
||||||
|
* </td></tr>
|
||||||
|
* <tr><td>
|
||||||
|
* Bits 63-64
|
||||||
|
* </td><td>
|
||||||
|
* Contain a four-state value that describes the {@code System.DateTimeKind} value of the date time, with a
|
||||||
|
* 2nd value for the rare case where the date time is local, but is in an overlapped daylight savings time
|
||||||
|
* hour and it is in daylight savings time. This allows distinction of these otherwise ambiguous local times
|
||||||
|
* and prevents data loss when round tripping from Local to UTC time.
|
||||||
|
* </td></tr>
|
||||||
|
* </tbody>
|
||||||
|
* </table>
|
||||||
|
*
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/a.html#df6b1eba7461813b">struct DateTime source</a>
|
||||||
|
*/
|
||||||
|
public final class DateTimeCodec {
|
||||||
|
|
||||||
|
public static final int BYTES = Long.BYTES;
|
||||||
|
|
||||||
|
private static final long FLAGS_MASK = 0xC000000000000000L;
|
||||||
|
private static final long KIND_AMBIGUOUS = 0xC000000000000000L;
|
||||||
|
private static final long KIND_LOCAL = 0x8000000000000000L;
|
||||||
|
private static final long KIND_UTC = 0x4000000000000000L;
|
||||||
|
private static final long TICKS_MASK = 0x3FFFFFFFFFFFFFFFL;
|
||||||
|
|
||||||
|
private static final long UNIX_EPOCH_TICKS = 0x89F7FF5F7B58000L;
|
||||||
|
|
||||||
|
private static final ZoneOffset ZONE_OFFSET_LOCAL = OffsetDateTime.now().getOffset();
|
||||||
|
private static final int ZONE_OFFSET_LOCAL_TOTAL_SECONDS = ZONE_OFFSET_LOCAL.getTotalSeconds();
|
||||||
|
private static final int ZONE_OFFSET_UTC_TOTAL_SECONDS = ZoneOffset.UTC.getTotalSeconds();
|
||||||
|
|
||||||
|
private DateTimeCodec() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode an {@link OffsetDateTime} serialized like a {@code System.DateTime} by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param bytes an array containing the serialized value to be decoded.
|
||||||
|
* @return a new {@link OffsetDateTime}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/a.html#df6b1eba7461813b">struct DateTime source</a>
|
||||||
|
*/
|
||||||
|
public static OffsetDateTime decode(@Nonnull final byte[] bytes) {
|
||||||
|
checkNotNull(bytes);
|
||||||
|
return decode(Unpooled.wrappedBuffer(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode an {@link OffsetDateTime} serialized like a {@code System.DateTime} by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param in a {@link ByteBuf} containing the serialized value to be decoded.
|
||||||
|
* @return a new {@link OffsetDateTime}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/a.html#df6b1eba7461813b">struct DateTime source</a>
|
||||||
|
*/
|
||||||
|
public static OffsetDateTime decode(@Nonnull final ByteBuf in) {
|
||||||
|
|
||||||
|
checkNotNull(in, "expected non-null in");
|
||||||
|
|
||||||
|
checkArgument(in.readableBytes() >= BYTES, "expected %s readable bytes, not %s",
|
||||||
|
BYTES,
|
||||||
|
in.readableBytes());
|
||||||
|
|
||||||
|
final long data = in.readLongLE();
|
||||||
|
final long ticks = data & TICKS_MASK;
|
||||||
|
final ZoneOffset zoneOffset = (data & FLAGS_MASK) == KIND_UTC ? ZoneOffset.UTC : ZONE_OFFSET_LOCAL;
|
||||||
|
|
||||||
|
final long epochSecond = ((ticks - UNIX_EPOCH_TICKS) / 10_000_000L) - zoneOffset.getTotalSeconds();
|
||||||
|
final int nanos = (int) (100L * (ticks % 10_000_000L));
|
||||||
|
|
||||||
|
return OffsetDateTime.ofInstant(Instant.ofEpochSecond(epochSecond, nanos), zoneOffset);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an {@link OffsetDateTime} like a {@code System.DateTime} serialized by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param offsetDateTime an {@link OffsetDateTime} to be encoded.
|
||||||
|
* @return a new byte array containing the encoded {@code offsetDateTime}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/a.html#df6b1eba7461813b">struct DateTime source</a>
|
||||||
|
*/
|
||||||
|
public static byte[] encode(final OffsetDateTime offsetDateTime) {
|
||||||
|
final byte[] bytes = new byte[BYTES];
|
||||||
|
encode(offsetDateTime, Unpooled.wrappedBuffer(bytes).clear());
|
||||||
|
return bytes;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode an {@link OffsetDateTime} like a {@code System.DateTime} produced by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param offsetDateTime an {@link OffsetDateTime} to be encoded.
|
||||||
|
* @param out an output {@link ByteBuf}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/a.html#df6b1eba7461813b">struct DateTime source</a>
|
||||||
|
*/
|
||||||
|
public static void encode(final OffsetDateTime offsetDateTime, final ByteBuf out) {
|
||||||
|
|
||||||
|
final ZoneOffset offset = offsetDateTime.getOffset();
|
||||||
|
final Instant instant = offsetDateTime.toInstant();
|
||||||
|
|
||||||
|
final long ticks = UNIX_EPOCH_TICKS + 10_000_000L * (instant.getEpochSecond() + offset.getTotalSeconds())
|
||||||
|
+ instant.getNano() / 100L;
|
||||||
|
|
||||||
|
checkArgument(ticks <= TICKS_MASK, "expected offsetDateTime epoch second in range [0, %s], not %s",
|
||||||
|
TICKS_MASK,
|
||||||
|
ticks);
|
||||||
|
|
||||||
|
final int zoneOffsetTotalSeconds = offsetDateTime.getOffset().getTotalSeconds();
|
||||||
|
final long value;
|
||||||
|
|
||||||
|
if (zoneOffsetTotalSeconds == ZONE_OFFSET_UTC_TOTAL_SECONDS) {
|
||||||
|
value = ticks | KIND_UTC;
|
||||||
|
} else if (zoneOffsetTotalSeconds == ZONE_OFFSET_LOCAL_TOTAL_SECONDS) {
|
||||||
|
value = ticks | KIND_LOCAL;
|
||||||
|
} else {
|
||||||
|
value = ticks | KIND_AMBIGUOUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeLongLE(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,200 @@
|
|||||||
|
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||||
|
// Licensed under the MIT License.
|
||||||
|
|
||||||
|
package com.azure.data.cosmos.serialization.hybridrow.codecs;
|
||||||
|
|
||||||
|
import io.netty.buffer.ByteBuf;
|
||||||
|
import io.netty.buffer.Unpooled;
|
||||||
|
import io.netty.util.ByteProcessor;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.BigInteger;
|
||||||
|
import java.math.MathContext;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
import static com.google.common.base.Preconditions.checkArgument;
|
||||||
|
import static com.google.common.base.Preconditions.checkNotNull;
|
||||||
|
import static com.google.common.base.Preconditions.checkState;
|
||||||
|
import static java.lang.Math.max;
|
||||||
|
import static java.lang.Math.min;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides static methods for encoding and decoding {@link BigDecimal}s serialized as {@code System.Decimal}s
|
||||||
|
*
|
||||||
|
* The serialization format is lossy as the {@link BigDecimal} class represents arbitrary-precision signed decimal
|
||||||
|
* numbers while the binary representation of a {@code System.Decimal} value is constrained to a magnitude of 96-bits
|
||||||
|
* with a scaling factor of 10 and a scale value between 0 and 28. This yields a precision between 28 and 29
|
||||||
|
* decimal digits.
|
||||||
|
*
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/system/decimal.cs.html">struct Decimal source</a>
|
||||||
|
*/
|
||||||
|
public final class DecimalCodec {
|
||||||
|
|
||||||
|
public static final int BYTES = 4 * Integer.BYTES;
|
||||||
|
|
||||||
|
private static final int FLAGS_MASK_INVALID = 0b01111111000000001111111111111111;
|
||||||
|
private static final int FLAGS_MASK_POWER = 0b00000000111111110000000000000000;
|
||||||
|
private static final int FLAGS_MASK_SIGN = 0b10000000000000000000000000000000;
|
||||||
|
|
||||||
|
private static final BigInteger MAGNITUDE_MAX = new BigInteger(new byte[] {
|
||||||
|
(byte)0x00,
|
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
|
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF,
|
||||||
|
(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF });
|
||||||
|
|
||||||
|
private static final BigInteger MAGNITUDE_MIN = new BigInteger(new byte[] {
|
||||||
|
(byte)0xFF,
|
||||||
|
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
|
||||||
|
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x00,
|
||||||
|
(byte)0x00, (byte)0x00, (byte)0x00, (byte)0x01 });
|
||||||
|
|
||||||
|
private static final MathContext REDUCED_PRECISION = new MathContext(28, RoundingMode.HALF_EVEN);
|
||||||
|
|
||||||
|
private static final int SCALE_MAX = 28;
|
||||||
|
private static final int SCALE_MIN = 0;
|
||||||
|
private static final int SCALE_SHIFT = 16;
|
||||||
|
|
||||||
|
private static final int VALUE_LENGTH = 3 * Integer.BYTES;
|
||||||
|
private static final int[] VALUE_OFFSETS = { /* hi */ 0, /* lo */ 2 * Integer.BYTES, /* mid */ Integer.BYTES };
|
||||||
|
|
||||||
|
private DecimalCodec() {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode an {@link BigDecimal} serialized like a {@code System.Decimal} by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param bytes an array containing the serialized {@code System.Decimal} to be decoded.
|
||||||
|
* @return a new {@link BigDecimal}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/system/decimal.cs.html">struct Decimal source</a>
|
||||||
|
*/
|
||||||
|
public static BigDecimal decode(@Nonnull final byte[] bytes) {
|
||||||
|
checkNotNull(bytes);
|
||||||
|
return decode(Unpooled.wrappedBuffer(bytes));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Decode an {@link BigDecimal} serialized like a {@code System.Decimal} by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param in a {@link ByteBuf} containing the serialized {@code System.Decimal} to be decoded.
|
||||||
|
* @return a new {@link BigDecimal}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/system/decimal.cs.html">struct Decimal source</a>
|
||||||
|
*/
|
||||||
|
public static BigDecimal decode(@Nonnull final ByteBuf in) {
|
||||||
|
|
||||||
|
checkNotNull(in, "expected non-null in");
|
||||||
|
|
||||||
|
checkArgument(in.readableBytes() >= BYTES, "expected %s readable bytes, not %s",
|
||||||
|
BYTES,
|
||||||
|
in.readableBytes());
|
||||||
|
|
||||||
|
// The flags field is interpreted as follows
|
||||||
|
//
|
||||||
|
// Bits Interpretation
|
||||||
|
// ----- --------------------------------------------------------------------------------------------
|
||||||
|
// 00-15 unused and must be zero
|
||||||
|
// 16-23 a value between 0 and 28 specifying the number of digits to the right of the decimal point
|
||||||
|
// 24-30 unused and must be zero
|
||||||
|
// 31-31 specifies the sign of the value, 1 meaning negative and 0 meaning non-negative
|
||||||
|
|
||||||
|
final int flags = in.readIntLE();
|
||||||
|
checkState((flags & FLAGS_MASK_INVALID) == 0, "invalid flags field: %s", flags);
|
||||||
|
|
||||||
|
final int scale = (flags & FLAGS_MASK_POWER) >>> SCALE_SHIFT;
|
||||||
|
checkState(scale <= SCALE_MAX);
|
||||||
|
|
||||||
|
final int signum = (flags & FLAGS_MASK_SIGN) == 0 ? 1 : -1;
|
||||||
|
final byte[] magnitude = new byte[VALUE_LENGTH];
|
||||||
|
final int source = in.readerIndex();
|
||||||
|
int target = 0;
|
||||||
|
|
||||||
|
for (int offset : VALUE_OFFSETS) {
|
||||||
|
final int start = target;
|
||||||
|
in.forEachByteDesc(source + offset, Integer.BYTES, new ByteProcessor() {
|
||||||
|
int index = start;
|
||||||
|
@Override
|
||||||
|
public boolean process(byte value) {
|
||||||
|
magnitude[this.index++] = value;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
target += Integer.BYTES;
|
||||||
|
}
|
||||||
|
|
||||||
|
return new BigDecimal(new BigInteger(signum, magnitude), scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a {@link BigDecimal} like a {@code System.Decimal} serialized by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param bigDecimal a {@link BigDecimal} to be encoded.
|
||||||
|
* @return a new byte array containing the encoded {@code bigDecimal}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/system/decimal.cs.html">struct Decimal source</a>
|
||||||
|
*/
|
||||||
|
public static byte[] encode(final BigDecimal bigDecimal) {
|
||||||
|
ByteBuf buffer = Unpooled.wrappedBuffer(new byte[BYTES]).clear();
|
||||||
|
encode(bigDecimal, buffer);
|
||||||
|
return buffer.array();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Encode a {@link BigDecimal} like a {@code System.Decimal} serialized by {@code MemoryMarshal.Write}.
|
||||||
|
*
|
||||||
|
* @param value a {@link BigDecimal} to be encoded.
|
||||||
|
* @param out an output {@link ByteBuf}.
|
||||||
|
* @see <a href="https://referencesource.microsoft.com/mscorlib/system/decimal.cs.html">struct Decimal source</a>
|
||||||
|
*/
|
||||||
|
public static void encode(@Nonnull BigDecimal value, @Nonnull final ByteBuf out) {
|
||||||
|
|
||||||
|
checkNotNull(value, "expected non-null value");
|
||||||
|
checkNotNull(value, "expected non-null out");
|
||||||
|
|
||||||
|
final int signum = value.signum();
|
||||||
|
|
||||||
|
if (signum == 0) {
|
||||||
|
out.writeZero(BYTES);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
BigInteger unscaledValue = value.unscaledValue();
|
||||||
|
|
||||||
|
if (unscaledValue.compareTo(MAGNITUDE_MIN) < 0 || unscaledValue.compareTo(MAGNITUDE_MAX) > 0) {
|
||||||
|
value = value.stripTrailingZeros();
|
||||||
|
unscaledValue = value.unscaledValue();
|
||||||
|
if (unscaledValue.compareTo(MAGNITUDE_MIN) < 0 || unscaledValue.compareTo(MAGNITUDE_MAX) > 0) {
|
||||||
|
value = new BigDecimal(unscaledValue, min(max(value.scale(), SCALE_MIN), SCALE_MAX), REDUCED_PRECISION);
|
||||||
|
unscaledValue = value.unscaledValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (value.scale() < SCALE_MIN) {
|
||||||
|
value = value.setScale(SCALE_MIN, RoundingMode.HALF_EVEN);
|
||||||
|
unscaledValue = value.unscaledValue();
|
||||||
|
} else if (value.scale() > SCALE_MAX) {
|
||||||
|
value = value.setScale(SCALE_MAX, RoundingMode.HALF_EVEN);
|
||||||
|
unscaledValue = value.unscaledValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
final byte[] decimalParts = new byte[VALUE_LENGTH];
|
||||||
|
final byte[] bytes;
|
||||||
|
final int flags;
|
||||||
|
|
||||||
|
if (signum > 0) {
|
||||||
|
flags = value.scale() << SCALE_SHIFT;
|
||||||
|
bytes = unscaledValue.toByteArray();
|
||||||
|
} else {
|
||||||
|
flags = value.scale() << SCALE_SHIFT | FLAGS_MASK_SIGN;
|
||||||
|
bytes = unscaledValue.abs().toByteArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeIntLE(flags);
|
||||||
|
|
||||||
|
for (int i = bytes.length, j = 0; i > 0 && j < decimalParts.length; ) {
|
||||||
|
decimalParts[j++] = bytes[--i];
|
||||||
|
}
|
||||||
|
|
||||||
|
out.writeBytes(decimalParts, 2 * Integer.BYTES, Integer.BYTES); // high
|
||||||
|
out.writeBytes(decimalParts, 0, Integer.BYTES); // low
|
||||||
|
out.writeBytes(decimalParts, Integer.BYTES, Integer.BYTES); // mid
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user