Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 43 additions & 7 deletions src/main/java/com/kavenegar/sdk/enums/MessageStatus.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.kavenegar.sdk.enums;

/**
*
* @author mohsen
* Enum representing various statuses a message can have.
* The code was originally written by Mohsen and later developed further by Reza.
*/
public enum MessageStatus {
Queued(1),
Expand All @@ -18,9 +14,10 @@ public enum MessageStatus {
Filtered(14),
Received(50),
Incorrect(100);

private final int value;

private MessageStatus(int type) {
MessageStatus(int type) {
this.value = type;
}

Expand All @@ -36,4 +33,43 @@ public static MessageStatus valueOf(int type) {
}
return null;
}

/**
* Determines if the message is in a final (completed) state.
*
* @return true if the status is Delivered, Undelivered, Canceled, or Incorrect.
*/
public boolean isFinalState() {
return this == Delivered || this == Undelivered || this == Canceled || this == Incorrect;
}

/**
* Provides a human-readable description of the message status.
*
* @return a string description of the status.
*/
public String getDescription() {
switch (this) {
case Queued:
return "Message is queued for sending.";
case Schulded:
return "Message is scheduled to be sent.";
case SentToCenter:
return "Message has been sent to the operator center.";
case Delivered:
return "Message has been successfully delivered.";
case Undelivered:
return "Message could not be delivered.";
case Canceled:
return "Message was canceled before being sent.";
case Filtered:
return "Message was filtered due to content restrictions.";
case Received:
return "Message was received by the server.";
case Incorrect:
return "Message contained incorrect data or destination.";
default:
return "Unknown message status.";
}
}
}
45 changes: 44 additions & 1 deletion src/main/java/com/kavenegar/sdk/enums/MessageType.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,25 +5,38 @@
package com.kavenegar.sdk.enums;

/**
* Represents the different types of messages that can be sent.
*
* @author mohsen
* The code was originally written by Mohsen and later developed further by Reza.
*/
public enum MessageType {

Flash(0),
MobileMemory(1),
SimMemory(2),
AppMemory(3);

private final int value;

private MessageType(int type) {
this.value = type;
}

/**
* Gets the integer value associated with the message type.
*
* @return the integer value of the message type
*/
public int getValue() {
return value;
}

/**
* Returns the MessageType corresponding to the given integer value.
*
* @param type the integer representation of the MessageType
* @return the MessageType if found, otherwise null
*/
public static MessageType valueOf(int type) {
for (MessageType code : MessageType.values()) {
if (type == code.getValue()) {
Expand All @@ -32,4 +45,34 @@ public static MessageType valueOf(int type) {
}
return null;
}

/**
* Gets a human-readable label for the message type.
*
* @return a string representation of the message type
*/
public String getLabel() {
switch (this) {
case Flash:
return "Flash Message";
case MobileMemory:
return "Mobile Memory Message";
case SimMemory:
return "SIM Memory Message";
case AppMemory:
return "App Memory Message";
default:
return "Unknown Message Type";
}
}

/**
* Validates if the given integer is a valid MessageType.
*
* @param type the integer to validate
* @return true if the value corresponds to a MessageType, otherwise false
*/
public static boolean isValidType(int type) {
return valueOf(type) != null;
}
}
81 changes: 54 additions & 27 deletions src/main/java/com/kavenegar/sdk/enums/MetaData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,71 @@
package com.kavenegar.sdk.enums;

/**
* Enumeration representing metadata/result codes returned by the Kavenegar API.
* <p>
* This refactored version focuses on readability, maintainability and
* safer usage across the codebase:
* <ul>
* <li>Consistent enum identifiers (UPPER_SNAKE_CASE)</li>
* <li>Immutable integer values associated with each enum</li>
* <li>Clear JavaDoc on purpose and behaviour</li>
* <li>Utility lookup method {@link #fromValue(int)} for safe mapping</li>
* </ul>
*
* @author Mohsen
* The original authors: Mohsen (initial) and Reza (further development).
*/
public enum MetaData {

NotChecked(99),
Approved(100),
InvalidApiKey(101),
ExpiredApiKey(102),
AccountDisabled(103),
NotEnoughCredit(104),
ServerisBusy(105),
UndefinedCommand(106),
RequestFailed(107),
ParametersBroken(108),
InvalidRecp(110),
InvalidSenderNumber(111),
EmptyMessage(112),
RecpIsTooLarge(113),
InvalidDate(114),
MsgIsTooLarge(115),
RecpNotEqualWithMessage(116);
private int value;
NOT_CHECKED(99),
APPROVED(100),
INVALID_API_KEY(101),
EXPIRED_API_KEY(102),
ACCOUNT_DISABLED(103),
NOT_ENOUGH_CREDIT(104),
SERVER_IS_BUSY(105),
UNDEFINED_COMMAND(106),
REQUEST_FAILED(107),
PARAMETERS_BROKEN(108),
INVALID_RECIPIENT(110),
INVALID_SENDER_NUMBER(111),
EMPTY_MESSAGE(112),
RECIPIENT_LIST_TOO_LARGE(113),
INVALID_DATE(114),
MESSAGE_TOO_LARGE(115),
RECIPIENT_COUNT_MISMATCH(116);

private MetaData(int type) {
this.value = type;
private final int code;

MetaData(int code) {
this.code = code;
}

/**
* Returns the numeric API code for this metadata value.
*
* @return API integer code
*/
public int getValue() {
return value;
return code;
}

public static MetaData valueOf(int type) {
for (MetaData code : MetaData.values()) {
if (type == code.getValue()) {
return code;
}
/**
* Safely maps an integer code to its corresponding MetaData enum.
* Returns {@code null} if there is no matching enum — callers should
* handle the null case explicitly.
*
* @param value integer value returned by the API
* @return matching MetaData or {@code null} when unknown
*/
public static MetaData fromValue(int value) {
for (MetaData m : MetaData.values()) {
if (m.code == value) return m;
}
return null;
}

@Override
public String toString() {
return String.format("%s(%d)", name(), code);
}
}
Loading