package notesserver; import java.awt.Color; import java.io.File; import java.lang.reflect.Field; public class NoteUnit { enum TextAlignment { right, left, center; } private String symbol; private Double priceLevel; private String note; private Color foregroundColor; private Color backgroundColor; private TextAlignment alignment; private Boolean notificationEnabled; private Boolean soundNotificationEnabled; private Boolean notificationIsRepeatable; private Integer delayBeforeRepeating; private Integer subscribingOffset; private File notificationSound; private boolean isNew; public String getSymbol() { return symbol; } public void setSymbol(String symbol) { this.symbol = symbol; } public Double getPriceLevel() { return priceLevel; } public void setPriceLevel(Double priceLevel) { this.priceLevel = priceLevel; } public String getNote() { return note; } public void setNote(String note) { this.note = note; } public Color getForegroundColor() { return foregroundColor; } public void setForegroundColor(Color foregroundColor) { this.foregroundColor = foregroundColor; } public Color getBackgroundColor() { return backgroundColor; } public void setBackgroundColor(Color backgroundColor) { this.backgroundColor = backgroundColor; } public TextAlignment getAlignment() { return alignment; } public void setAlignment(TextAlignment alignment) { this.alignment = alignment; } public Boolean getNotificationEnabled() { return notificationEnabled; } public void setNotificationEnabled(Boolean notificationEnabled) { this.notificationEnabled = notificationEnabled; } public Boolean getSoundNotificationEnabled() { return soundNotificationEnabled; } public void setSoundNotificationEnabled(Boolean soundNotificationEnabled) { this.soundNotificationEnabled = soundNotificationEnabled; } public Boolean getNotificationIsRepeatable() { return notificationIsRepeatable; } public void setNotificationIsRepeatable(Boolean notificationIsRepeatable) { this.notificationIsRepeatable = notificationIsRepeatable; } public Integer getDelayBeforeRepeating() { return delayBeforeRepeating; } public void setDelayBeforeRepeating(Integer delayBeforeRepeating) { this.delayBeforeRepeating = delayBeforeRepeating; } public Integer getSubscribingOffset() { return subscribingOffset; } public void setSubscribingOffset(Integer subscribingOffset) { this.subscribingOffset = subscribingOffset; } public File getNotificationSound() { return notificationSound; } public void setNotificationSound(File notificationSound) { this.notificationSound = notificationSound; } public boolean isNew() { return isNew; } public void setNew(boolean isNew) { this.isNew = isNew; } public String getCsvLine() { Field[] fields = getClass().getDeclaredFields(); StringBuilder sb = new StringBuilder(); for (Field field : fields) { if (field.getName().equals("isNew")) continue; sb.append("\""); try { Object object = field.get(this); String objectAsText; if (object instanceof Color) { Color color = (Color) object; objectAsText = String.format("#%02x%02x%02x", color.getRed(), color.getGreen(), color.getBlue()); } else { objectAsText = object == null ? "" : String.valueOf(object); } sb.append(objectAsText); } catch (IllegalArgumentException | IllegalAccessException e) { e.printStackTrace(); } sb.append("\","); } sb.deleteCharAt(sb.length() - 1); sb.append("\n"); return sb.toString(); } }