Skip to content

Commit

Permalink
Migrate code base to java 17 (#463)
Browse files Browse the repository at this point in the history
* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17

* Code cleanups for java 17
  • Loading branch information
frimtec authored Oct 9, 2023
1 parent 7d2657e commit 4ac692c
Show file tree
Hide file tree
Showing 71 changed files with 536 additions and 733 deletions.
3 changes: 3 additions & 0 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,24 +1,29 @@
package com.github.frimtec.android.pikettassist.domain;

import androidx.annotation.NonNull;

import java.time.Instant;
import java.util.Collections;
import java.util.Comparator;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;

public class Alert {

private final long id;
private final Instant startTime;
private final Instant confirmTime;
private final boolean confirmed;
private final Instant endTime;
private final List<AlertCall> calls;

public Alert(long id, Instant startTime, Instant confirmTime, boolean confirmed, Instant endTime, List<AlertCall> calls) {
public record Alert(
long id,
Instant startTime,
Instant confirmTime,
boolean confirmed,
Instant endTime,
List<AlertCall> calls
) {

public Alert(
long id,
Instant startTime,
Instant confirmTime,
boolean confirmed,
Instant endTime,
List<AlertCall> calls
) {
this.id = id;
Objects.requireNonNull(startTime);
Objects.requireNonNull(calls);
Expand All @@ -27,77 +32,23 @@ public Alert(long id, Instant startTime, Instant confirmTime, boolean confirmed,
this.confirmed = confirmed;
this.endTime = endTime;
this.calls = new LinkedList<>(calls);
this.calls.sort(Comparator.comparing(AlertCall::getTime));
}

public long getId() {
return id;
}

public Instant getStartTime() {
return startTime;
}

public Instant getConfirmTime() {
return confirmTime;
this.calls.sort(Comparator.comparing(AlertCall::time));
}

public Instant getEndTime() {
return endTime;
}

public List<AlertCall> getCalls() {
@Override
public List<AlertCall> calls() {
return Collections.unmodifiableList(calls);
}

public boolean isConfirmed() {
return confirmed;
}

public boolean isClosed() {
return endTime != null;
}

@NonNull
@Override
public String toString() {
return "Alert{" +
"id=" + id +
", startTime=" + startTime +
", confirmTime=" + confirmTime +
", confirmed=" + confirmed +
", endTime=" + endTime +
", calls=" + calls +
'}';
}

public static class AlertCall {

private final Instant time;
private final String message;
public record AlertCall(Instant time, String message) {

public AlertCall(Instant time, String message) {
public AlertCall {
Objects.requireNonNull(time);
Objects.requireNonNull(message);
this.time = time;
this.message = message;
}

public Instant getTime() {
return time;
}

public String getMessage() {
return message;
}

@NonNull
@Override
public String toString() {
return "AlertCall{" +
"time=" + time +
", message='" + message + '\'' +
'}';
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.github.frimtec.android.pikettassist.domain;

public final class BatteryStatus {
public record BatteryStatus(int level, Charging charging) {

public enum Charging {
NO(false),
Expand All @@ -19,19 +19,4 @@ public boolean isCharging() {
}
}

private final int level;
private final Charging charging;

public BatteryStatus(int level, Charging charging) {
this.level = level;
this.charging = charging;
}

public int getLevel() {
return level;
}

public Charging getCharging() {
return charging;
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,5 @@
package com.github.frimtec.android.pikettassist.domain;

public class Calendar {
public record Calendar(int id, String name) {

private final int id;
private final String name;

public Calendar(int id, String name) {
this.id = id;
this.name = name;
}

public int getId() {
return id;
}

public String getName() {
return name;
}
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
package com.github.frimtec.android.pikettassist.domain;

public class Contact {

private final ContactReference reference;
private final boolean valid;
private final String name;

public Contact(ContactReference reference, boolean valid, String name) {
this.reference = reference;
this.valid = valid;
this.name = name;
}

public ContactReference getReference() {
return this.reference;
}

public boolean isValid() {
return valid;
}

public String getName() {
return name;
}
public record Contact(ContactReference reference, boolean valid, String name) {

}
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package com.github.frimtec.android.pikettassist.domain;

public class ContactReference {
public record ContactReference(long id, String lookupKey) {

public static final ContactReference NO_SELECTION = ContactReference.fromSerializedString("-1;NOT_SET");

private final long id;
private final String lookupKey;

public ContactReference(long id, String lookupKey) {
this.id = id;
this.lookupKey = lookupKey != null ? lookupKey : "";
Expand All @@ -25,39 +22,7 @@ public boolean isComplete() {
return !lookupKey.isEmpty();
}

public long getId() {
return id;
}

public String getLookupKey() {
return lookupKey;
}

public String getSerializedString() {
return id + ";" + lookupKey;
}

@Override
public boolean equals(Object o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

ContactReference reference = (ContactReference) o;

if (id != reference.id) {
return false;
}
return lookupKey.equals(reference.lookupKey);
}

@Override
public int hashCode() {
int result = (int) (id ^ (id >>> 32));
result = 31 * result + lookupKey.hashCode();
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,32 +2,11 @@

import java.time.Instant;

public class TestAlarm {
private final TestAlarmContext context;
private final Instant receivedTime;
private final OnOffState alertState;
private final String message;
public record TestAlarm(
TestAlarmContext context,
Instant receivedTime,
OnOffState alertState,
String message
) {

public TestAlarm(TestAlarmContext context, Instant receivedTime, OnOffState alertState, String message) {
this.context = context;
this.receivedTime = receivedTime;
this.alertState = alertState;
this.message = message;
}

public TestAlarmContext getContext() {
return context;
}

public Instant getReceivedTime() {
return receivedTime;
}

public OnOffState getAlertState() {
return alertState;
}

public String getMessage() {
return message;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,10 @@

import java.util.Objects;

public class TestAlarmContext {
public record TestAlarmContext(String context) {

private final String context;

public TestAlarmContext(String context) {
public TestAlarmContext {
Objects.nonNull(context);
this.context = context;
}

public String getContext() {
return context;
}

@Override
Expand All @@ -29,11 +22,6 @@ public boolean equals(Object o) {
return Objects.equals(context, testAlarmContext.context);
}

@Override
public int hashCode() {
return Objects.hash(context);
}

@NonNull
@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
package com.github.frimtec.android.pikettassist.service;

import static com.github.frimtec.android.pikettassist.service.system.Feature.PERMISSION_CONTACTS_READ;

import android.content.Context;

import com.github.frimtec.android.pikettassist.domain.ContactPerson;
import com.github.frimtec.android.pikettassist.service.dao.ContactDao;

import java.util.Collections;
import java.util.Map;
import java.util.Set;

import static com.github.frimtec.android.pikettassist.service.system.Feature.PERMISSION_CONTACTS_READ;

abstract class AbstractContactService {

private final Context context;
Expand All @@ -21,10 +16,6 @@ public AbstractContactService(Context context) {
this.contactDao = new ContactDao(context);
}

public Map<String, ContactPerson> findContactPersonsByAliases(Set<String> aliases) {
return hasReadContactPermission() ? this.contactDao.findContactPersonsByAliases(aliases) : Collections.emptyMap();
}

protected final boolean hasReadContactPermission() {
return PERMISSION_CONTACTS_READ.isAllowed(this.context);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public void closeAlert() {
public String exportAllAlerts() {
return GSON.toJson(
alertDao.loadAll().stream()
.map(alert -> alertDao.load(alert.getId()))
.map(alert -> alertDao.load(alert.id()))
.collect(Collectors.toList())
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.github.frimtec.android.pikettassist.service.system.AlarmService.ScheduleInfo;

import java.util.Map;
import java.util.Objects;
import java.util.Optional;

class BogusAlarmWorkUnit implements WorkUnit {
Expand All @@ -26,7 +27,7 @@ public BogusAlarmWorkUnit(Map<AlarmType, Runnable> alarmTriggers) {
public Optional<ScheduleInfo> apply(Data inputData) {
AlarmType type = AlarmType.valueOf(inputData.getString(ALARM_TYPE_PARAMETER_KEY));
Log.i(TAG, "Trigger bogus alarm for " + type);
alarmTriggers.getOrDefault(type, () -> Log.e(TAG, "Unknown type " + type)).run();
Objects.requireNonNull(alarmTriggers.getOrDefault(type, () -> Log.e(TAG, "Unknown type " + type))).run();
return Optional.empty();
}
}
Loading

0 comments on commit 4ac692c

Please sign in to comment.