2 * Copyright (c) 2014, 2015 Cable Television Laboratories, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
9 package org.pcmm.objects;
11 import org.pcmm.base.impl.PCMMBaseObject;
12 import org.umu.cops.stack.COPSMsgParser;
15 * PCMM SyncOptions object
17 public class SyncOptions extends PCMMBaseObject {
20 * The requested report type
22 private final ReportType reportType;
25 * The requested type of synchronization
27 private final SyncType syncType;
31 * @param reportType - the requested report type
32 * @param syncType - the requested synchronization type
34 public SyncOptions(final ReportType reportType, final SyncType syncType) {
35 super(SNum.SYNC_OPTS, (byte)1);
36 if (reportType == null) throw new IllegalArgumentException("Report type must not be null");
37 if (syncType == null) throw new IllegalArgumentException("Synchronization type must not be null");
38 this.reportType = reportType;
39 this.syncType = syncType;
43 * @return the syncType
45 public SyncType getSyncType() {
50 * @return the reportType
52 public ReportType getReportType() {
57 protected byte[] getBytes() {
58 final byte[] rptTypeBytes = COPSMsgParser.shortToBytes(reportType.getValue());
59 final byte[] syncTypeBytes = COPSMsgParser.shortToBytes(syncType.getValue());
60 final byte[] data = new byte[rptTypeBytes.length + syncTypeBytes.length];
61 System.arraycopy(rptTypeBytes, 0, data, 0, rptTypeBytes.length);
62 System.arraycopy(syncTypeBytes, 0, data, rptTypeBytes.length, syncTypeBytes.length);
67 public boolean equals(final Object o) {
71 if (!(o instanceof SyncOptions)) {
74 if (!super.equals(o)) {
77 final SyncOptions that = (SyncOptions) o;
78 return reportType == that.reportType && syncType == that.syncType;
82 public int hashCode() {
83 int result = super.hashCode();
84 result = 31 * result + reportType.hashCode();
85 result = 31 * result + syncType.hashCode();
90 * Returns a SyncOptions object from a byte array
91 * @param data - the data to parse
92 * @return - the object
93 * TODO - make me more robust as RuntimeExceptions can be thrown here.
95 public static SyncOptions parse(final byte[] data) {
96 return new SyncOptions(ReportType.valueOf(COPSMsgParser.bytesToShort(data[0], data[1])),
97 SyncType.valueOf(COPSMsgParser.bytesToShort(data[2], data[3])));
101 * The supported Report types
103 public enum ReportType {
105 STANDARD_REPORT_DATA((short) 0), COMPLETE_GATE_DATA((short) 1);
107 ReportType(short value) {
111 public short getValue() {
115 public static ReportType valueOf(short v) {
118 return ReportType.STANDARD_REPORT_DATA;
120 return ReportType.COMPLETE_GATE_DATA;
122 throw new IllegalArgumentException("not supported value");
131 * The supported Synchronization types
133 public enum SyncType {
135 FULL_SYNCHRONIZATION((short) 0), INCREMENTAL_SYNCHRONIZATION((short) 1);
137 SyncType(short value) {
141 public short getValue() {
145 public static SyncType valueOf(short v) {
148 return SyncType.FULL_SYNCHRONIZATION;
150 return SyncType.INCREMENTAL_SYNCHRONIZATION;
152 throw new IllegalArgumentException("not supported value");