gpt4 book ai didi

java - Objective-C 中的字节数组操作像 Java 一样吗?

转载 作者:行者123 更新时间:2023-11-30 04:57:30 25 4
gpt4 key购买 nike

我想像我的 ANDROID 同事那样实现一项功能。下面是代码片段,我在将该代码转换为 Objective-C 时遇到问题。所以请引导我正确的方向---谢谢

这是代码片段

public String createControlParams() {
controlParams_ = "";
String expiry = "";
String delayedDelivery = "";
String restricted = "";
String priorityIndicator = "";
String acknowledgement = "";
//Note - PMessage.PRIORITY_INDICATOR_WHITE is defined as Int like 1,2,3
if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_WHITE) {
expiryTimeText_ = "";
restrictBackup = false;
restrictForward_ = false;
readAcknowledgement_ = false;
}

if (expiryTimeText_ != null && expiryTimeText_.length() > 0) {
int exptime = Integer.parseInt(expiryTimeText_);
byte h = (byte) (exptime / 60);
byte m = (byte) (exptime % 60);
expiry = new String(new byte[]{'E', 0, h, m});//??? how to get this thing in objective-c
}
if (delayDelivery) {
long timeDifference;
long deliveryTime;
// Fix
// if (midlet_.getPlatform().equalsIgnoreCase("rim")) {
//// timeDifference = Calendar.getInstance().getTimeZone().getRawOffset();
//// deliveryTime = (dateField_.getTime() - (dateField_.getTime() % (24 * 60 * 60 * 1000))) + (24 * 60 * 60 * 1000) + deliverySetTime_ - timeDifference;//+timeDifference;//(((Integer) timeSpinner.getValue()).longValue() * 1000);
// deliveryTime = (dateField_.getTime() + deliverySetTime_);// - timeDifference;
// } else {
deliveryTime = dateField_.getTime() + deliverySetTime_;// - timeDifference;
// }
if (deliveryTime > (new Date().getTime() + 2000)) { // Added to_ make message as instant delivery as opposed to_ delayed delivery if the delivery time is set in past (Added 2 seconds for message processing time)
delayedDelivery = "D" + deliveryTime;
}
}
if (restrictBackup && restrictForward_) {
restricted = new String(new byte[]{'R', (byte) 3});
} else if (restrictForward_) {
restricted = new String(new byte[]{'R', (byte) 1});
} else if (restrictBackup) {
restricted = new String(new byte[]{'R', (byte) 2});
}
if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_RED) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_RED});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_YELLOW) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_YELLOW});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_GREEN) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_GREEN});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_GRAY) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_GRAY});
} else if (priorityIndicator_ == PMessage.PRIORITY_INDICATOR_WHITE) {
priorityIndicator = new String(new byte[]{'P', (byte) PMessage.PRIORITY_INDICATOR_WHITE});
}

if (readAcknowledgement_) {
acknowledgement = new String(new byte[]{'A', PMessage.ACK_READ});
}

controlParams_ = priorityIndicator;
if (!expiry.equals("") && expiry != null) {
controlParams_ += (byte) (-128) + expiry;
}
if (!delayedDelivery.equalsIgnoreCase("") && delayedDelivery != null) {
controlParams_ += (byte) (-128) + delayedDelivery;
}
if (!restricted.equalsIgnoreCase("") && restricted != null) {
controlParams_ += (byte) (-128) + restricted;
}
if (!acknowledgement.equalsIgnoreCase("") && acknowledgement != null) {
controlParams_ += (byte) (-128) + acknowledgement;
}
return controlParams_;
// System.out.println(controlParams_);
}

private void getDraftControlParms(String controlParams_) {
if (!controlParams_.equals("") && controlParams_ != null) {
String[] sysParams = Helpers.splitUsingStringDelim(controlParams_, String.valueOf((byte) (-128)));
try {
for (int i = 0; i < sysParams.length; i++) {
if (!sysParams[i].equals("") && sysParams[i] != null) {

if (sysParams[i].substring(0, 1).equalsIgnoreCase("P")) {
priorityIndicator_ = (int) sysParams[i].getBytes()[1];
}

if (sysParams[i].substring(0, 1).equalsIgnoreCase("E")) {
int expiryFirstByte_ = sysParams[i].getBytes()[2];
int expirySecondByte_ =sysParams[i].getBytes()[3];
int expiryTime=(expiryFirstByte_ * 60) + (expirySecondByte_);
expiryMinutesField_.setText(expiryTime+"");
expiryTimeText_ = expiryMinutesField_.getText();
}

if (sysParams[i].substring(0, 1).equalsIgnoreCase("R")) {
int restrictedByte_ = (byte) sysParams[i].getBytes()[1];
if(restrictedByte_==1){
restrictForward_ = true;
restrictBackup = false;
}else if(restrictedByte_==2){
restrictForward_ = false;
restrictBackup = true;
}else{
restrictForward_ = true;
restrictBackup = true;
}
}
if (sysParams[i].substring(0, 1).equalsIgnoreCase("A")) {
readAcknowledgement_ = true;
}
}

switch (priorityIndicator_) {
case PMessage.PRIORITY_INDICATOR_RED: {
counter.getStyle().setBgColor(0xfe0002);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_YELLOW: {
counter.getStyle().setBgColor(0xffff00);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_GREEN: {
counter.getStyle().setBgColor(0x80ff00);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_GRAY: {
counter.getStyle().setBgColor(0x919594);
counter.getStyle().setBgTransparency(255);
break;
}
case PMessage.PRIORITY_INDICATOR_WHITE: {
counter.getStyle().setBgColor(0xffffff);
counter.getStyle().setBgTransparency(255);
break;
}
}
}

} catch (Exception e) {
e.printStackTrace();
}
}
}

最佳答案

我不是 Objective C 人员,但是你尝试过使用 char 吗?在 C/C++ 中,字符是一个字节,应该执行您需要的操作。

关于java - Objective-C 中的字节数组操作像 Java 一样吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8064573/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com