2 * (c) 2015 Cable Television Laboratories, Inc. All rights reserved.
5 package org.pcmm.objects;
7 import org.pcmm.base.impl.PCMMBaseObject;
8 import org.umu.cops.stack.COPSMsgParser;
11 * PCMM SyncOptions object
13 public class SyncOptions extends PCMMBaseObject {
16 * The requested report type
18 private final ReportType reportType;
21 * The requested type of synchronization
23 private final SyncType syncType;
27 * @param reportType - the requested report type
28 * @param syncType - the requested synchronization type
30 public SyncOptions(final ReportType reportType, final SyncType syncType) {
31 super(SNum.SYNC_OPTS, (byte)1);
32 if (reportType == null) throw new IllegalArgumentException("Report type must not be null");
33 if (syncType == null) throw new IllegalArgumentException("Synchronization type must not be null");
34 this.reportType = reportType;
35 this.syncType = syncType;
39 * @return the syncType
41 public SyncType getSyncType() {
46 * @return the reportType
48 public ReportType getReportType() {
53 protected byte[] getBytes() {
54 final byte[] rptTypeBytes = COPSMsgParser.shortToBytes(reportType.getValue());
55 final byte[] syncTypeBytes = COPSMsgParser.shortToBytes(syncType.getValue());
56 final byte[] data = new byte[rptTypeBytes.length + syncTypeBytes.length];
57 System.arraycopy(rptTypeBytes, 0, data, 0, rptTypeBytes.length);
58 System.arraycopy(syncTypeBytes, 0, data, rptTypeBytes.length, syncTypeBytes.length);
63 public boolean equals(final Object o) {
67 if (!(o instanceof SyncOptions)) {
70 if (!super.equals(o)) {
73 final SyncOptions that = (SyncOptions) o;
74 return reportType == that.reportType && syncType == that.syncType;
78 public int hashCode() {
79 int result = super.hashCode();
80 result = 31 * result + reportType.hashCode();
81 result = 31 * result + syncType.hashCode();
86 * Returns a SyncOptions object from a byte array
87 * @param data - the data to parse
88 * @return - the object
89 * TODO - make me more robust as RuntimeExceptions can be thrown here.
91 public static SyncOptions parse(final byte[] data) {
92 return new SyncOptions(ReportType.valueOf(COPSMsgParser.bytesToShort(data[0], data[1])),
93 SyncType.valueOf(COPSMsgParser.bytesToShort(data[2], data[3])));
97 * The supported Report types
99 public enum ReportType {
101 STANDARD_REPORT_DATA((short) 0), COMPLETE_GATE_DATA((short) 1);
103 ReportType(short value) {
107 public short getValue() {
111 public static ReportType valueOf(short v) {
114 return ReportType.STANDARD_REPORT_DATA;
116 return ReportType.COMPLETE_GATE_DATA;
118 throw new IllegalArgumentException("not supported value");
127 * The supported Synchronization types
129 public enum SyncType {
131 FULL_SYNCHRONIZATION((short) 0), INCREMENTAL_SYNCHRONIZATION((short) 1);
133 SyncType(short value) {
137 public short getValue() {
141 public static SyncType valueOf(short v) {
144 return SyncType.FULL_SYNCHRONIZATION;
146 return SyncType.INCREMENTAL_SYNCHRONIZATION;
148 throw new IllegalArgumentException("not supported value");