Skip to content

Commit 1116055

Browse files
committed
Enh 37059890 - Port UniversalExtractor and UniversalUpdater to C++ and .NET
- minor modifications to bring more in line with the .NET implementation #nobug80 [git-p4: depot-paths = "//dev/main.cpp/": change = 111478]
1 parent e452591 commit 1116055

File tree

3 files changed

+82
-33
lines changed

3 files changed

+82
-33
lines changed

include/public/coherence/util/extractor/UniversalExtractor.hpp

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,16 +78,6 @@ class COH_EXPORT UniversalExtractor
7878
// ----- Object interface -----------------------------------------------
7979

8080
public:
81-
/**
82-
* {@inheritDoc}
83-
*/
84-
virtual bool equals(Object::View v) const;
85-
86-
/**
87-
* {@inheritDoc}
88-
*/
89-
virtual size32_t hashCode() const;
90-
9181
/**
9282
* {@inheritDoc}
9383
*/
@@ -122,6 +112,14 @@ class COH_EXPORT UniversalExtractor
122112
* The parameter array. Must be null or zero length for a property based extractor.
123113
*/
124114
FinalView<ObjectArray> f_vaParam;
115+
116+
// ----- constants ------------------------------------------------------
117+
118+
public:
119+
/**
120+
* If f_vsName ends with this suffix, it represents a method name.
121+
*/
122+
static String::View getMethodSuffix();
125123
};
126124

127125
COH_CLOSE_NAMESPACE3

src/coherence/util/extractor/UniversalExtractor.cpp

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ UniversalExtractor::UniversalExtractor(String::View vsName,
2323
: f_vsName(self(), vsName), f_vaParam(self(), vaParam)
2424
{
2525
COH_ENSURE_PARAM(vsName);
26+
if (vaParam != NULL && vaParam->length > 0 && !vsName->endsWith(getMethodSuffix()))
27+
{
28+
COH_THROW_STREAM(IllegalArgumentException, "UniversalExtractor constructor: parameter vsName[value:"
29+
<< vsName << "] must end with method suffix \"" << getMethodSuffix()
30+
<< "\" when optional parameters provided");
31+
}
2632
m_nTarget = nTarget;
2733
}
2834

@@ -53,29 +59,6 @@ void UniversalExtractor::writeExternal(PofWriter::Handle hOut) const
5359

5460
// ----- Object interface ---------------------------------------------------
5561

56-
bool UniversalExtractor::equals(Object::View v) const
57-
{
58-
if (this == v)
59-
{
60-
return true;
61-
}
62-
63-
UniversalExtractor::View that = cast<UniversalExtractor::View>(v, false);
64-
if (that != NULL)
65-
{
66-
return this->m_nTarget == that->m_nTarget &&
67-
Object::equals(f_vsName, that->f_vsName) &&
68-
Object::equals(f_vaParam, that->f_vaParam);
69-
}
70-
71-
return false;
72-
}
73-
74-
size32_t UniversalExtractor::hashCode() const
75-
{
76-
return f_vsName->hashCode();
77-
}
78-
7962
TypedHandle<const String> UniversalExtractor::toString() const
8063
{
8164
String::View vs = "";
@@ -100,4 +83,14 @@ ObjectArray::View UniversalExtractor::getParameters() const
10083
return f_vaParam;
10184
}
10285

86+
// ----- constants ----------------------------------------------------------
87+
88+
String::View UniversalExtractor::getMethodSuffix()
89+
{
90+
static FinalView<String> vsMethodSuffix(System::common(), String::create("()"));
91+
92+
return vsMethodSuffix;
93+
}
94+
COH_STATIC_INIT(UniversalExtractor::getMethodSuffix());
95+
10396
COH_CLOSE_NAMESPACE3
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
* Copyright (c) 2000, 2024, Oracle and/or its affiliates.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl.
6+
*/
7+
#include "cxxtest/TestSuite.h"
8+
9+
#include "coherence/lang.ns"
10+
11+
#include "coherence/util/extractor/UniversalExtractor.hpp"
12+
13+
#include "coherence/util/filter/EqualsFilter.hpp"
14+
15+
#include "common/TestPerson.hpp"
16+
17+
using namespace coherence::lang;
18+
19+
using coherence::util::extractor::UniversalExtractor;
20+
using coherence::util::filter::EqualsFilter;
21+
22+
using namespace common::test;
23+
24+
/**
25+
* Test Suite for UniversalExtractor.
26+
*/
27+
class UniversalExtractorTest : public CxxTest::TestSuite
28+
{
29+
public:
30+
/**
31+
* Test method suffix validation - required suffix is not present
32+
*/
33+
void testIllegalConstructor()
34+
{
35+
ObjectArray::View vaParams = ObjectArray::create(1);
36+
37+
TS_ASSERT_THROWS(UniversalExtractor::create(String::create("age"), vaParams),
38+
IllegalArgumentException::View);
39+
}
40+
41+
/**
42+
* Test method suffix validation - required suffix is present
43+
*/
44+
void testLegalConstructor()
45+
{
46+
ObjectArray::View vaParams = ObjectArray::create(1);
47+
48+
UniversalExtractor::create(String::create("getAge()"), vaParams);
49+
}
50+
51+
/**
52+
* Test method suffix validation - suffix is not required
53+
*/
54+
void testLegalConstructorNoSuffix()
55+
{
56+
UniversalExtractor::create(String::create("age"));
57+
}
58+
};

0 commit comments

Comments
 (0)