Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add 'apply' function to give access to the builder in a build pipeline. #10

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions parser/src/main/java/io/lindstrom/mpd/data/MPD.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.time.OffsetDateTime;
import java.util.List;
import java.util.Objects;
import java.util.function.Function;

@JsonPropertyOrder({
"programInformations",
Expand Down Expand Up @@ -514,6 +515,10 @@ public Builder withSchemaLocation(String schemaLocation) {
return this;
}

public Builder apply(Function<Builder, Builder> fn) {
return fn.apply(this);
}

public MPD build() {
return new MPD(schemaLocation, programInformations, baseURLs, locations, periods, metrics, essentialProperties, supplementalProperties, utcTimings, id, profiles, type, availabilityStartTime, availabilityEndTime, publishTime, mediaPresentationDuration, minimumUpdatePeriod, minBufferTime, timeShiftBufferDepth, suggestedPresentationDelay, maxSegmentDuration, maxSubsegmentDuration);
}
Expand Down
28 changes: 28 additions & 0 deletions parser/src/test/java/io/lindstrom/mpd/data/MPDTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.lindstrom.mpd.data;

import java.time.Duration;
import java.time.OffsetDateTime;
import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertEquals;

public class MPDTest {

@Test
void itUsesTheSuppliedFunctionToModifyTheBuilder() {
MPD mpd = MPD.builder()
.withType(PresentationType.DYNAMIC)
.withAvailabilityStartTime(OffsetDateTime.parse("2024-03-27T13:00:00Z"))
.withPublishTime(OffsetDateTime.parse("2024-03-27T13:00:00Z"))
.apply(builder -> {
if (OffsetDateTime.now().isAfter(OffsetDateTime.MIN)) {
builder.withMaxSegmentDuration(Duration.ofMinutes(1));
}
return builder;
})
.build();

assertEquals(Duration.ofMinutes(1), mpd.getMaxSegmentDuration());
}

}