package com.onaro.sanscreen.client.view.tabular.value; import java.text.Collator; import org.apache.commons.lang3.StringUtils; /** * Parses names of the format FA-3A port: 0. This class is immutable and can be cached. */ public class SymmetrixTableValue implements TableValue{ private final Object display; private final String prefix; private final int slot; private final String processor; private final int port; public SymmetrixTableValue(String prefix, int slot, String processor, int port, Object display) { this.display = display; this.port = port; this.slot = slot; this.processor = processor; this.prefix = prefix; } public Object getDisplay() { return display != null ? display : StringUtils.EMPTY; } public int getPort() { return port; } public String getPrefix() { return prefix; } public String getProcessor() { return processor; } public int getSlot() { return slot; } @Override public int compareTo (TableValue o) { if (o instanceof SymmetrixTableValue) { SymmetrixTableValue other = (SymmetrixTableValue) o; int prefixCompare = getPrefix().compareTo(other.getPrefix()); if (prefixCompare == 0) { int slotCompare = getSlot() - other.getSlot(); if(slotCompare == 0){ int processortCompare = getProcessor().compareTo(other.getProcessor()); if(processortCompare == 0){ return getPort() - other.getPort(); }else{ return processortCompare; } }else{ return slotCompare; } } else { return prefixCompare; } } else { // Use natural language sort order. return Collator.getInstance().compare(getDisplay().toString(), (o.getDisplay()).toString()); } } /** * Since this method is used by he grouping-table, it returns the display value. * @return Return's the same value as {@link TableValue#getDisplay} does */ public String toString() { return getDisplay().toString(); } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((display == null) ? 0 : display.hashCode()); result = prime * result + port; result = prime * result + ((prefix == null) ? 0 : prefix.hashCode()); result = prime * result + ((processor == null) ? 0 : processor.hashCode()); result = prime * result + slot; return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; SymmetrixTableValue other = (SymmetrixTableValue) obj; if (port != other.port) return false; if (slot != other.slot) return false; if (prefix == null) { if (other.prefix != null) return false; } else if (!prefix.equals(other.prefix)) return false; if (processor == null) { if (other.processor != null) return false; } else if (!processor.equals(other.processor)) return false; if (display == null) { if (other.display != null) return false; } else if (!display.equals(other.display)) return false; return true; } }