Skip to content

Commit

Permalink
Fix for issue#78 - AVP index getters and fix for insert AVP with index (
Browse files Browse the repository at this point in the history
#79)

* Fix for issue#78 - Get AVP index methods implemented and fix for insertAVP with index handling
  • Loading branch information
Grzegorz Figiel authored and brainslog committed Mar 31, 2017
1 parent 769159c commit 06049de
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -17,6 +17,7 @@
# Maven #
#########
target
\$\{env.JBOSS_HOME\}

# OS generated files #
######################
Expand Down
17 changes: 17 additions & 0 deletions core/jdiameter/api/src/main/java/org/jdiameter/api/AvpSet.java
Expand Up @@ -53,6 +53,8 @@
* Serializable interface allows use this class in SLEE Event objects
*
* @author erick.svenson@yahoo.com
* @author <a href="mailto:grzegorz.figiel@pro-ids.com"> Grzegorz Figiel [ProIDS] </a>
*
* @version 1.5.1 Final
*/
public interface AvpSet extends Iterable<Avp>, Serializable, Wrapper {
Expand Down Expand Up @@ -94,6 +96,21 @@ public interface AvpSet extends Iterable<Avp>, Serializable, Wrapper {
*/
AvpSet getAvps(int avpCode, long vendorId);

/**
* Get position of the first instance of the AVP
* @param avpCode code of the Avp
* @return index (position) of the first occurrence of the Avp. -1 in case Avp is not found
*/
int getAvpIndex(int avpCode);

/**
* Get position of the first instance of the AVP
* @param avpCode code of the Avp
* @param vendorId vendorId of the Avp
* @return index (position) of the first occurrence of the Avp. -1 in case Avp is not found
*/
int getAvpIndex(int avpCode, long vendorId);

/**
* Remove AVPs with avpCode
* @param avpCode code of Avp
Expand Down
Expand Up @@ -68,6 +68,7 @@
* @author erick.svenson@yahoo.com
* @author <a href="mailto:brainslog@gmail.com"> Alexandre Mendonca </a>
* @author <a href="mailto:baranowb@gmail.com"> Bartosz Baranowski </a>
* @author <a href="mailto:grzegorz.figiel@pro-ids.com"> Grzegorz Figiel [ProIDS] </a>
*/
class AvpSetImpl implements AvpSet {

Expand Down Expand Up @@ -132,6 +133,26 @@ public AvpSet getAvps(int avpCode, long vendorId) {
return result;
}

@Override
public int getAvpIndex(int avpCode) {
for (Avp avp : this.avps) {
if (avp.getCode() == avpCode) {
return this.avps.indexOf(avp);
}
}
return -1;
}

@Override
public int getAvpIndex(int avpCode, long vendorId) {
for (Avp avp : this.avps) {
if (avp.getCode() == avpCode && avp.getVendorId() == vendorId) {
return this.avps.indexOf(avp);
}
}
return -1;
}

@Override
public AvpSet removeAvp(int avpCode) {
return removeAvp(avpCode, 0);
Expand Down Expand Up @@ -219,7 +240,7 @@ public Avp insertAvp(int index, int avpCode, long value, boolean mFlag, boolean
public Avp insertAvp(int index, int avpCode, long value, long vndId, boolean mFlag, boolean pFlag, boolean asUnsigned) {
int flags = ((vndId != 0 ? 0x80 : 0) | (mFlag ? 0x40 : 0) | (pFlag ? 0x20 : 0));
Avp res = new AvpImpl(avpCode, flags, vndId, asUnsigned ? parser.intU32ToBytes(value) : parser.int64ToBytes(value));
this.avps.add(res);
this.avps.add(index, res);
return res;
}

Expand Down

0 comments on commit 06049de

Please sign in to comment.