This repository has been archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collapse Runnable interfaces into Procedure classes
- Loading branch information
Showing
19 changed files
with
200 additions
and
241 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
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
22 changes: 22 additions & 0 deletions
22
src/main/java/com/team766/framework3/FunctionalProcedure.java
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,22 @@ | ||
package com.team766.framework3; | ||
|
||
import edu.wpi.first.wpilibj2.command.Subsystem; | ||
import java.util.Set; | ||
import java.util.function.Consumer; | ||
|
||
public final class FunctionalProcedure extends Procedure { | ||
private final Consumer<Context> runnable; | ||
|
||
public FunctionalProcedure(Set<Subsystem> reservations, Consumer<Context> runnable) { | ||
super(runnable.toString()); | ||
this.runnable = runnable; | ||
for (var r : reservations) { | ||
reserve(r); | ||
} | ||
} | ||
|
||
@Override | ||
public void run(Context context) { | ||
runnable.accept(context); | ||
} | ||
} |
30 changes: 0 additions & 30 deletions
30
src/main/java/com/team766/framework3/FunctionalRunnableWithContext.java
This file was deleted.
Oops, something went wrong.
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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,3 +1,60 @@ | ||
package com.team766.framework3; | ||
|
||
public abstract class Procedure extends ProcedureBase implements RunnableWithContext {} | ||
import com.google.common.collect.Sets; | ||
import com.team766.logging.Category; | ||
import edu.wpi.first.wpilibj2.command.Subsystem; | ||
import java.util.Set; | ||
|
||
public abstract class Procedure implements LoggingBase { | ||
// A reusable Procedure that does nothing. | ||
private static final class NoOpProcedure extends InstantProcedure { | ||
@Override | ||
public void run() {} | ||
} | ||
|
||
public static final InstantProcedure NO_OP = new NoOpProcedure(); | ||
|
||
private static int c_idCounter = 0; | ||
|
||
private static synchronized int createNewId() { | ||
return c_idCounter++; | ||
} | ||
|
||
private final String name; | ||
private final Set<Subsystem> reservations = Sets.newHashSet(); | ||
protected Category loggerCategory = Category.PROCEDURES; | ||
|
||
protected Procedure() { | ||
this.name = this.getClass().getName() + "/" + createNewId(); | ||
} | ||
|
||
protected Procedure(String name) { | ||
this.name = name; | ||
} | ||
|
||
public abstract void run(Context context); | ||
|
||
@Override | ||
public final String getName() { | ||
return name; | ||
} | ||
|
||
@Override | ||
public Category getLoggerCategory() { | ||
return loggerCategory; | ||
} | ||
|
||
protected final <M extends Subsystem> M reserve(M m) { | ||
reservations.add(m); | ||
return m; | ||
} | ||
|
||
public final Set<Subsystem> reservations() { | ||
return reservations; | ||
} | ||
|
||
@Override | ||
public final String toString() { | ||
return getName(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.