mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-19 00:41:43 +00:00
[cscore] VideoMode: Add equals override (Java) (#5397)
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
21
cscore/src/test/java/edu/wpi/first/cscore/VideoModeTest.java
Normal file
21
cscore/src/test/java/edu/wpi/first/cscore/VideoModeTest.java
Normal 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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user