以下是重构后的内容,保留了原代码的结构和逻辑:
```java
public int[] getBuddyIds() {
int[] buddyIds = new int[this.buddies.size()];
int i = 0;
for (Iterator i$ = this.buddies.values().iterator(); i$.hasNext(); ) {
BuddylistEntry ble = (BuddylistEntry)i$.next();
buddyIds[(i++)] = ble.getCharacterId();
}
return buddyIds;
}
public boolean isFull() {
return (this.buddies.size() >= this.capacity);
}
public void loadFromDb(int characterId) throws SQLException {
PreparedStatement ps = null;
ResultSet rs = null;
try {
ps = DatabaseConnection.getConnection().prepareStatement("SELECT b.buddyid AS b_group, b.pending AS c_pending, c.name AS buddyname FROM buddies AS b JOIN characters AS c ON c.id = b.characterId WHERE c.id = ?");
ps.setInt(1, characterId);
rs = ps.executeQuery();
if (rs.next()) {
String pending = rs.getString("c_pending");
String buddyName = rs.getString("buddyname");
this.addBuddy(characterId, "", false, pending, buddyName);
this.addBuddy(characterId, "", true, pending, buddyName);
} else {
System.out.println("Character not found!");
}
} catch (SQLException e) {
throw new SQLException("Failed to load data from database!", e);
} finally {
if (rs != null && !rs.isClosed()) {
rs.close();
}
if (ps != null && !ps.isClosed()) {
ps.close();
}
}
}
```