[cscore] VideoMode: Add equals override (Java) (#5397)

This commit is contained in:
Sriman Achanta
2023-06-19 20:12:07 -04:00
committed by GitHub
parent d6bd72d738
commit d4ea5fa902
2 changed files with 47 additions and 0 deletions

View File

@@ -4,6 +4,8 @@
package edu.wpi.first.cscore;
import java.util.Objects;
/** Video mode. */
@SuppressWarnings("MemberName")
public class VideoMode {
@@ -75,4 +77,28 @@ public class VideoMode {
/** Frames per second. */
public int fps;
@Override
public boolean equals(Object other) {
if (this == other) {
return true;
}
if (other == null) {
return false;
}
if (getClass() != other.getClass()) {
return false;
}
VideoMode mode = (VideoMode) other;
return pixelFormat == mode.pixelFormat
&& width == mode.width
&& height == mode.height
&& fps == mode.fps;
}
@Override
public int hashCode() {
return Objects.hash(pixelFormat, width, height, fps);
}
}

View File

@@ -0,0 +1,21 @@
// Copyright (c) FIRST and other WPILib contributors.
// Open Source Software; you can modify and/or share it under the terms of
// the WPILib BSD license file in the root directory of this project.
package edu.wpi.first.cscore;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals;
import org.junit.jupiter.api.Test;
class VideoModeTest {
@Test
void equalityTest() {
VideoMode a = new VideoMode(VideoMode.PixelFormat.kMJPEG, 1920, 1080, 30);
VideoMode b = new VideoMode(VideoMode.PixelFormat.kMJPEG, 1920, 1080, 30);
assertEquals(a, b);
assertNotEquals(a, null);
}
}