Simon Hunt

Cleaning up Javadocs in core-ui classes.

Added common constants to AbstractCellFormatter.

Change-Id: Ie20ea62f059646e7d6c7f3660dd60a60c40532fe
Showing 20 changed files with 67 additions and 83 deletions
......@@ -35,9 +35,9 @@ import static com.google.common.base.Preconditions.checkNotNull;
* A simple model of time series chart data.
* <p>
* Note that this is not a full MVC type model; the expected usage pattern
* is to create an empty chart, add data points (by consulting the business model),
* and produce the list of data points which contain a label and a set of data
* values for all serials.
* is to create an empty chart, add data points (by consulting the business
* model), and produce the list of data points which contain a label and a set
* of data values for all serials.
*/
public class ChartModel {
......
......@@ -27,12 +27,12 @@ import java.util.List;
*/
public abstract class ChartRequestHandler extends RequestHandler {
private final String respType;
private final String nodeName;
protected static final String LABEL = "label";
private static final String ANNOTS = "annots";
private final String respType;
private final String nodeName;
/**
* Constructs a chart model handler for a specific graph view. When chart
* requests come in, the handler will generate the appropriate chart data
......@@ -56,7 +56,7 @@ public abstract class ChartRequestHandler extends RequestHandler {
ObjectNode rootNode = MAPPER.createObjectNode();
rootNode.set(nodeName, ChartUtils.generateDataPointArrayNode(cm));
rootNode.set(ANNOTS, ChartUtils.generateAnnotObjectNode(cm));
sendMessage(respType, 0, rootNode);
sendMessage(respType, rootNode);
}
/**
......@@ -72,8 +72,8 @@ public abstract class ChartRequestHandler extends RequestHandler {
List<String> series = new ArrayList<>();
series.addAll(Arrays.asList(getSeries()));
series.add(LABEL);
String[] seiresArray = new String[series.size()];
return new ChartModel(series.toArray(seiresArray));
String[] array = new String[series.size()];
return new ChartModel(series.toArray(array));
}
/**
......
......@@ -15,6 +15,6 @@
*/
/**
* Facilities for creating chart models of data for the GUI.
* Facilities for creating chart models of data for the Web UI.
*/
package org.onosproject.ui.chart;
\ No newline at end of file
......
......@@ -43,7 +43,7 @@ public class UiClusterMember extends UiElement {
* topology instance and the specified controller node instance.
*
* @param topology parent topology containing this cluster member
* @param cnode underlying controller node.
* @param cnode underlying controller node
*/
public UiClusterMember(UiTopology topology, ControllerNode cnode) {
this.topology = topology;
......
......@@ -101,7 +101,7 @@ public class UiDevice extends UiNode {
* Returns the identifier of the region to which this device belongs.
* This will be null if the device does not belong to any region.
*
* @return region identity
* @return region ID
*/
public RegionId regionId() {
return regionId;
......
/*
* Copyright 2016-present Open Networking Laboratory
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.onosproject.ui.model.topo;
/**
* Designates the logical layer of the network that an element belongs to.
*/
public enum UiLayer {
PACKET, OPTICAL;
/**
* Returns the default layer (for those elements that do not explicitly
* define which layer they belong to).
*
* @return default layer
*/
public static UiLayer defaultLayer() {
return PACKET;
}
}
......@@ -49,7 +49,7 @@ public final class UiLinkId {
B_TO_A
}
static final String CP_DELIMITER = "~";
private static final String CP_DELIMITER = "~";
static final String ID_PORT_DELIMITER = "/";
private final RegionId regionA;
......@@ -236,7 +236,8 @@ public final class UiLinkId {
ConnectPoint src = link.src();
ConnectPoint dst = link.dst();
if (src == null || dst == null) {
throw new NullPointerException("null src or dst connect point: " + link);
throw new NullPointerException(
"null src or dst connect point: " + link);
}
ElementId srcId = src.elementId();
......
......@@ -36,7 +36,7 @@ public class UiRegionLink extends UiLink {
* link identifier is one that has region IDs as source and destination.
*
* @param topology parent topology
* @param id canonicalized link identifier
* @param id canonicalized link ID
* @throws IllegalArgumentException if the link ID is not region-region
*/
public UiRegionLink(UiTopology topology, UiLinkId id) {
......
......@@ -24,21 +24,19 @@ public interface CellComparator {
/**
* Compares its two arguments for order. Returns a negative integer,
* zero, or a positive integer as the first argument is less than, equal
* to, or greater than the second.<p>
*
* to, or greater than the second.
* <p>
* Note that nulls are permitted, and should be sorted to the beginning
* of an ascending sort; i.e. null is considered to be "smaller" than
* non-null values.
*
* @see java.util.Comparator#compare(Object, Object)
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the
* first argument is less than, equal to, or greater than the
* second.
* @param o1 the first object to be compared
* @param o2 the second object to be compared
* @return an integer representing relative ordering
* @throws ClassCastException if the arguments' types prevent them from
* being compared by this comparator.
* being compared by this comparator
*/
int compare(Object o1, Object o2);
......
......@@ -50,6 +50,8 @@ import static com.google.common.base.Preconditions.checkNotNull;
*/
public class TableModel {
private static final String DESC = "desc";
private static final CellComparator DEF_CMP = DefaultCellComparator.INSTANCE;
private static final CellFormatter DEF_FMT = DefaultCellFormatter.INSTANCE;
private static final String EMPTY = "";
......@@ -220,6 +222,9 @@ public class TableModel {
Collections.sort(rows, new RowComparator(id1, dir1, id2, dir2));
}
private boolean nullOrEmpty(String s) {
return s == null || EMPTY.equals(s.trim());
}
/** Designates sorting direction. */
public enum SortDir {
......@@ -229,9 +234,6 @@ public class TableModel {
DESC
}
private boolean nullOrEmpty(String s) {
return s == null || EMPTY.equals(s.trim());
}
/**
* Row comparator.
......@@ -381,8 +383,6 @@ public class TableModel {
}
}
private static final String DESC = "desc";
/**
* Returns the appropriate sort direction for the given string.
* <p>
......
......@@ -42,19 +42,17 @@ public abstract class AbstractCellComparator implements CellComparator {
/**
* Compares its two arguments for order. Returns a negative integer,
* zero, or a positive integer as the first argument is less than, equal
* to, or greater than the second.<p>
*
* to, or greater than the second.
* <p>
* Note that both objects are guaranteed to be non-null.
*
* @see java.util.Comparator#compare(Object, Object)
*
* @param o1 the first object to be compared.
* @param o2 the second object to be compared.
* @return a negative integer, zero, or a positive integer as the
* first argument is less than, equal to, or greater than the
* second.
* @param o1 the first object to be compared
* @param o2 the second object to be compared
* @return an integer representing relative ordering
* @throws ClassCastException if the arguments' types prevent them from
* being compared by this comparator.
* being compared by this comparator
*/
protected abstract int nonNullCompare(Object o1, Object o2);
}
......
......@@ -25,9 +25,17 @@ import org.onosproject.ui.table.CellFormatter;
*/
public abstract class AbstractCellFormatter implements CellFormatter {
protected static final String EMPTY = "";
protected static final String SLASH = "/";
protected static final String QUERY = "?";
protected static final String UNDERSCORE = "_";
protected static final String SPACE = " ";
protected static final String OX = "0x";
@Override
public String format(Object value) {
return value == null ? "" : nonNullFormat(value);
return value == null ? EMPTY : nonNullFormat(value);
}
/**
......
......@@ -24,6 +24,8 @@ import org.onosproject.ui.table.CellFormatter;
*/
public final class AppIdFormatter extends AbstractCellFormatter {
private static final String COLON = " : ";
// non-instantiable
private AppIdFormatter() { }
......@@ -31,7 +33,7 @@ public final class AppIdFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
ApplicationId appId = (ApplicationId) value;
return appId.id() + " : " + appId.name();
return appId.id() + COLON + appId.name();
}
/**
......
......@@ -30,7 +30,7 @@ public final class ConnectPointFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
ConnectPoint cp = (ConnectPoint) value;
return cp.elementId() + "/" + cp.port();
return cp.elementId() + SLASH + cp.port();
}
/**
......
......@@ -30,7 +30,7 @@ public final class EnumFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
return capitalizeFully(value.toString().replace("_", " "));
return capitalizeFully(value.toString().replace(UNDERSCORE, SPACE));
}
/**
......
......@@ -28,7 +28,7 @@ public final class HexFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
return "0x" + Integer.toHexString((Integer) value);
return OX + Integer.toHexString((Integer) value);
}
/**
......
......@@ -28,7 +28,7 @@ public final class HexLongFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
return "0x" + Long.toHexString((Long) value);
return OX + Long.toHexString((Long) value);
}
/**
......
......@@ -30,7 +30,7 @@ public final class HostLocationFormatter extends AbstractCellFormatter {
@Override
protected String nonNullFormat(Object value) {
HostLocation loc = (HostLocation) value;
return loc.deviceId() + "/" + loc.port();
return loc.deviceId() + SLASH + loc.port();
}
/**
......
......@@ -22,7 +22,7 @@ import java.text.DecimalFormat;
import java.text.NumberFormat;
/**
* Formats number using the specified format string".
* Formats number using the specified format string.
*/
public final class NumberFormatter extends AbstractCellFormatter {
......
......@@ -20,9 +20,11 @@ import com.google.common.annotations.Beta;
import org.onosproject.ui.table.CellFormatter;
import org.onosproject.ui.table.cell.AbstractCellFormatter;
import java.util.Optional;
/**
* Formats a optical tunnel endpoint as "(type)/(element-id)/(port)".
* Formats a ip tunnel endpoint as "ip".
* Formats an optical tunnel endpoint as "(type)/(element-id)/(port)".
* Formats an IP tunnel endpoint as "ip".
*/
@Beta
public final class TunnelEndPointFormatter extends AbstractCellFormatter {
......@@ -30,17 +32,26 @@ public final class TunnelEndPointFormatter extends AbstractCellFormatter {
private TunnelEndPointFormatter() {
}
private String safeOptional(Optional<?> optional) {
return optional.isPresent() ? optional.get().toString() : QUERY;
}
@Override
protected String nonNullFormat(Object value) {
if (value instanceof DefaultOpticalTunnelEndPoint) {
DefaultOpticalTunnelEndPoint cp = (DefaultOpticalTunnelEndPoint) value;
return cp.type() + "/" + cp.elementId().get() + "/" + cp.portNumber().get();
DefaultOpticalTunnelEndPoint ep =
(DefaultOpticalTunnelEndPoint) value;
String e = safeOptional(ep.elementId());
String p = safeOptional(ep.portNumber());
return ep.type() + SLASH + e + SLASH + p;
} else if (value instanceof IpTunnelEndPoint) {
IpTunnelEndPoint cp = (IpTunnelEndPoint) value;
return cp.ip().toString();
}
return "";
return EMPTY;
}
/**
......