Simon Hunt

ONOS-3749: Show Flow ID and group ID in the flow table as hex values.

Change-Id: If98e0d76876ada2fa1c8d01a1b89230d1919f6c5
/*
* Copyright 2016 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.table.cell;
import org.onosproject.ui.table.CellFormatter;
/**
* Formats long values as hex strings with a "0x" prefix.
*/
public final class HexLongFormatter extends AbstractCellFormatter {
// non-instantiable
private HexLongFormatter() { }
@Override
protected String nonNullFormat(Object value) {
return "0x" + Long.toHexString((Long) value);
}
/**
* An instance of this class.
*/
public static final CellFormatter INSTANCE = new HexLongFormatter();
}
/*
* Copyright 2016 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.table.cell;
import org.junit.Test;
import org.onosproject.ui.table.CellFormatter;
import static org.junit.Assert.assertEquals;
/**
* Unit tests for {@link HexLongFormatter}.
*/
public class HexLongFormatterTest {
private CellFormatter fmt = HexLongFormatter.INSTANCE;
@Test
public void nullValue() {
assertEquals("null value", "", fmt.format(null));
}
@Test
public void zero() {
assertEquals("zero", "0x0", fmt.format(0L));
}
@Test
public void one() {
assertEquals("one", "0x1", fmt.format(1L));
}
@Test
public void ten() {
assertEquals("ten", "0xa", fmt.format(10L));
}
@Test
public void twenty() {
assertEquals("twenty", "0x14", fmt.format(20L));
}
@Test
public void veryBig() {
assertEquals("very big", "0x7048860f3a38", fmt.format(123456789101112L));
}
@Test
public void maxLong() {
assertEquals("max long", "0x7fffffffffffffff", fmt.format(Long.MAX_VALUE));
}
}
......@@ -30,6 +30,8 @@ import org.onosproject.ui.table.CellFormatter;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.cell.EnumFormatter;
import org.onosproject.ui.table.cell.HexFormatter;
import org.onosproject.ui.table.cell.HexLongFormatter;
import java.util.Collection;
import java.util.List;
......@@ -84,6 +86,8 @@ public class FlowViewMessageHandler extends UiMessageHandler {
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setFormatter(ID, HexLongFormatter.INSTANCE);
tm.setFormatter(GROUP_ID, HexFormatter.INSTANCE);
tm.setFormatter(SELECTOR, new SelectorFormatter());
tm.setFormatter(TREATMENT, new TreatmentFormatter());
tm.setFormatter(STATE, EnumFormatter.INSTANCE);
......
......@@ -29,6 +29,7 @@ import org.onosproject.ui.table.CellFormatter;
import org.onosproject.ui.table.TableModel;
import org.onosproject.ui.table.TableRequestHandler;
import org.onosproject.ui.table.cell.EnumFormatter;
import org.onosproject.ui.table.cell.HexFormatter;
import java.util.Collection;
import java.util.List;
......@@ -75,6 +76,7 @@ public class GroupViewMessageHandler extends UiMessageHandler {
@Override
protected TableModel createTableModel() {
TableModel tm = super.createTableModel();
tm.setFormatter(ID, HexFormatter.INSTANCE);
tm.setFormatter(TYPE, EnumFormatter.INSTANCE);
tm.setFormatter(BUCKETS, new BucketFormatter());
return tm;
......