Skip to content

Commit 06049de

Browse files
Grzegorz Figielbrainslog
authored andcommitted
Fix for issue#78 - AVP index getters and fix for insert AVP with index (RestComm#79)
* Fix for issue#78 - Get AVP index methods implemented and fix for insertAVP with index handling
1 parent 769159c commit 06049de

File tree

3 files changed

+40
-1
lines changed

3 files changed

+40
-1
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# Maven #
1818
#########
1919
target
20+
\$\{env.JBOSS_HOME\}
2021

2122
# OS generated files #
2223
######################

core/jdiameter/api/src/main/java/org/jdiameter/api/AvpSet.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,8 @@
5353
* Serializable interface allows use this class in SLEE Event objects
5454
*
5555
56+
* @author <a href="mailto:[email protected]"> Grzegorz Figiel [ProIDS] </a>
57+
*
5658
* @version 1.5.1 Final
5759
*/
5860
public interface AvpSet extends Iterable<Avp>, Serializable, Wrapper {
@@ -94,6 +96,21 @@ public interface AvpSet extends Iterable<Avp>, Serializable, Wrapper {
9496
*/
9597
AvpSet getAvps(int avpCode, long vendorId);
9698

99+
/**
100+
* Get position of the first instance of the AVP
101+
* @param avpCode code of the Avp
102+
* @return index (position) of the first occurrence of the Avp. -1 in case Avp is not found
103+
*/
104+
int getAvpIndex(int avpCode);
105+
106+
/**
107+
* Get position of the first instance of the AVP
108+
* @param avpCode code of the Avp
109+
* @param vendorId vendorId of the Avp
110+
* @return index (position) of the first occurrence of the Avp. -1 in case Avp is not found
111+
*/
112+
int getAvpIndex(int avpCode, long vendorId);
113+
97114
/**
98115
* Remove AVPs with avpCode
99116
* @param avpCode code of Avp

core/jdiameter/impl/src/main/java/org/jdiameter/client/impl/parser/AvpSetImpl.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
6969
* @author <a href="mailto:[email protected]"> Alexandre Mendonca </a>
7070
* @author <a href="mailto:[email protected]"> Bartosz Baranowski </a>
71+
* @author <a href="mailto:[email protected]"> Grzegorz Figiel [ProIDS] </a>
7172
*/
7273
class AvpSetImpl implements AvpSet {
7374

@@ -132,6 +133,26 @@ public AvpSet getAvps(int avpCode, long vendorId) {
132133
return result;
133134
}
134135

136+
@Override
137+
public int getAvpIndex(int avpCode) {
138+
for (Avp avp : this.avps) {
139+
if (avp.getCode() == avpCode) {
140+
return this.avps.indexOf(avp);
141+
}
142+
}
143+
return -1;
144+
}
145+
146+
@Override
147+
public int getAvpIndex(int avpCode, long vendorId) {
148+
for (Avp avp : this.avps) {
149+
if (avp.getCode() == avpCode && avp.getVendorId() == vendorId) {
150+
return this.avps.indexOf(avp);
151+
}
152+
}
153+
return -1;
154+
}
155+
135156
@Override
136157
public AvpSet removeAvp(int avpCode) {
137158
return removeAvp(avpCode, 0);
@@ -219,7 +240,7 @@ public Avp insertAvp(int index, int avpCode, long value, boolean mFlag, boolean
219240
public Avp insertAvp(int index, int avpCode, long value, long vndId, boolean mFlag, boolean pFlag, boolean asUnsigned) {
220241
int flags = ((vndId != 0 ? 0x80 : 0) | (mFlag ? 0x40 : 0) | (pFlag ? 0x20 : 0));
221242
Avp res = new AvpImpl(avpCode, flags, vndId, asUnsigned ? parser.intU32ToBytes(value) : parser.int64ToBytes(value));
222-
this.avps.add(res);
243+
this.avps.add(index, res);
223244
return res;
224245
}
225246

0 commit comments

Comments
 (0)