-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clear 'My Logs' if it does not match the new set of open logs
- Loading branch information
Showing
5 changed files
with
226 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
src/main/java/com/tibagni/logviewer/log/EditableLogListTableModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.tibagni.logviewer.log | ||
|
||
import java.util.* | ||
import kotlin.math.abs | ||
|
||
class EditableLogListTableModel(title: String) : LogListTableModel(title) { | ||
|
||
fun addLogIfDoesNotExist(entry: LogEntry) { | ||
// find the nearest time pos to insert the new entry | ||
val indexFound = Collections.binarySearch(entries, entry) | ||
if (indexFound < 0) { // Element not found. Insert | ||
val targetIndex = abs(indexFound + 1) | ||
entries.add(targetIndex, entry) | ||
fireTableRowsInserted(targetIndex, targetIndex) | ||
} | ||
} | ||
|
||
fun removeLog(entry: LogEntry) { | ||
val index = entries.indexOf(entry) | ||
if (index != -1) { | ||
entries.removeAt(index) | ||
fireTableRowsDeleted(index, index) | ||
} | ||
} | ||
|
||
fun clear() { | ||
if (entries.isEmpty()) return | ||
val index = entries.size - 1 | ||
entries.clear() | ||
fireTableRowsDeleted(0, index) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package com.tibagni.logviewer.log | ||
|
||
import org.junit.Assert.* | ||
import org.junit.Test | ||
|
||
class LogEntryTests { | ||
|
||
@Test | ||
fun testLogEntryEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
|
||
assertEquals(entry1, entry2) | ||
assertEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTextNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text2", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryLevelNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.INFO, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampMonthNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(8, 1, 8, 0, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampDayNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 2, 8, 0, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampHourNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 2, 3, 0, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampMinutesNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 2, 8, 10, 0, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampSecondsNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 2, 8, 0, 30, 0)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
|
||
@Test | ||
fun testLogEntryTimestampHundredthNotEquals() { | ||
val entry1 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 1, 8, 0, 0, 0)) | ||
val entry2 = LogEntry("Text1", LogLevel.DEBUG, LogTimestamp(9, 2, 8, 0, 0, 90)) | ||
|
||
assertNotEquals(entry1, entry2) | ||
assertNotEquals(entry1.hashCode(), entry2.hashCode()) | ||
} | ||
} |