Skip to content

Commit

Permalink
[improve] code according to code specifications (#2809)
Browse files Browse the repository at this point in the history
Co-authored-by: shown <[email protected]>
Co-authored-by: aias00 <[email protected]>
  • Loading branch information
3 people authored Nov 8, 2024
1 parent 6298e7a commit dca3e35
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -190,7 +189,7 @@ public void addNewAlertReportFromCloud(String cloudServiceName, String alertRepo
alert = AlertReport.builder()
.content("error do not has cloud service api")
.alertName("/api/alerts/report/" + cloudServiceName)
.alertTime(new Date().getTime())
.alertTime(Instant.now().getEpochSecond())
.priority(1)
.reportType(1)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ default String getDescription() {
}

public static <T extends Enum<T> & IpmiCode.Code> T fromByte(Class<T> type, byte code) {
for (T value : type.getEnumConstants())
if (value.getCode() == code)
for (T value : type.getEnumConstants()) {
if (value.getCode() == code) {
return value;
}
}
throw new IllegalArgumentException("Unknown " + type.getSimpleName() + " code 0x" + UnsignedBytes.toString(code, 16));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,12 @@ public interface Encapsulation {
}

public static <T> T getEncapsulated(Class<T> type, Object value) {
if (type.isInstance(value))
if (type.isInstance(value)) {
return type.cast(value);
if (value instanceof Encapsulation)
}
if (value instanceof Encapsulation) {
return ((Encapsulation) value).getEncapsulated(type);
}
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,9 @@ public void setIpmiPayload(IpmiPayload ipmiPayload) {

@Override
public <T> T getEncapsulated(Class<T> type) {
if (type.isInstance(this))
if (type.isInstance(this)) {
return type.cast(this);
}
return IpmiEncapsulation.getEncapsulated(type, getIpmiPayload());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public IpmiLun getRqLun() {
return rqLun;
}

@Override
public void setRqLun(IpmiLun rqLun) {
this.rqLun = rqLun;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,11 @@ public ByteBuffer decrypt(IpmiSession session, ByteBuffer in) throws InvalidAlgo
this.init(Cipher.DECRYPT_MODE, secretKey, iv);
this.update(in, buffer);
int padLength = ByteConvertUtils.byteToInt(buffer.get(buffer.position() - 1));
for (int i = 1; i <= padLength; i++)
if (ByteConvertUtils.byteToInt(buffer.get(buffer.position() - i - 1)) != padLength - i + 1)
for (int i = 1; i <= padLength; i++) {
if (ByteConvertUtils.byteToInt(buffer.get(buffer.position() - i - 1)) != padLength - i + 1) {
throw new IllegalArgumentException("Bad pad byte " + i);
}
}
buffer.limit(buffer.position() - padLength - 1);
buffer.flip();
return buffer;
Expand All @@ -86,8 +88,9 @@ public ByteBuffer decrypt(IpmiSession session, ByteBuffer in) throws InvalidAlgo
@Override
public int pad(int length) {
int t = length % 16;
if (t == 0)
if (t == 0) {
return 0;
}
return 16 - t;
}

Expand All @@ -96,6 +99,7 @@ public int getEncryptedLength(int length) {
return 16 + length + pad(length);
}

@Override
public void update(ByteBuffer input, ByteBuffer output) throws ShortBufferException {
super.update(input, output);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,9 @@ public Packet withData(RmcpData data) {

@Override
public <T> T getEncapsulated(Class<T> type) {
if (type.isInstance(this))
if (type.isInstance(this)) {
return type.cast(this);
}
return IpmiEncapsulation.getEncapsulated(type, getData());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public AdminClient getConnection() {
}

@Override
public void closeConnection() throws Exception {
if (this.adminClient != null) {
this.adminClient.close();
public void closeConnection() {
if (adminClient != null) {
adminClient.close();
}
}

Expand Down

0 comments on commit dca3e35

Please sign in to comment.