Skip to content

Commit

Permalink
Merge pull request praxis-live#58 from codelerity/project-module
Browse files Browse the repository at this point in the history
Add project module, with project and root file models
  • Loading branch information
neilcsmith-net authored Jun 24, 2024
2 parents dbe6d90 + 2eb6c65 commit 29cc682
Show file tree
Hide file tree
Showing 72 changed files with 5,652 additions and 454 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
<module>praxiscore-hub</module>
<module>praxiscore-script</module>
<module>praxiscore-launcher</module>
<module>praxiscore-project</module>
<module>praxiscore-data</module>
<module>praxiscore-video</module>
<module>praxiscore-video-code</module>
Expand Down
111 changes: 57 additions & 54 deletions praxiscore-api/src/main/java/org/praxislive/core/Connection.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2023 Neil C Smith.
* Copyright 2024 Neil C Smith.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3 only, as
Expand All @@ -21,99 +21,102 @@
*/
package org.praxislive.core;

import org.praxislive.core.protocols.ContainerProtocol;
import java.util.Optional;
import org.praxislive.core.types.PArray;
import org.praxislive.core.types.PString;

/**
* A type representing a connection between two ports.
*/
public final class Connection {

private final PArray dataArray;
public final class Connection extends PArray.ArrayBasedValue {

/**
* Create a connection reference. The child IDs must be valid according to
* {@link ComponentAddress#isValidID(java.lang.String)}. The port IDs must
* be valid according to {@link PortAddress#isValidID(java.lang.String)}.
*
* @param child1 ID of first child
* @param port1 ID of port on first child
* @param child2 ID of second child
* @param port2 ID of port on second child
* @throws IllegalArgumentException if the IDs are not valid
* Value type name.
*/
public Connection(String child1, String port1, String child2, String port2) {
verifyChildID(child1);
verifyChildID(child2);
verifyPortID(port1);
verifyPortID(port2);
dataArray = PArray.of(PString.of(child1), PString.of(port1),
PString.of(child2), PString.of(port2));
public static final String TYPE_NAME = "Connection";

private Connection(PArray data) {
super(data);
if (data.size() != 4) {
throw new IllegalArgumentException("Invalid connection data");
}
verifyChildID(data.get(0).toString());
verifyPortID(data.get(1).toString());
verifyChildID(data.get(2).toString());
verifyPortID(data.get(3).toString());
}

/**
* Query the component ID of the first connected component.
* Query the component ID of the source component.
*
* @return ID of first child
*/
public String child1() {
return dataArray.get(0).toString();
public String sourceComponent() {
return dataArray().get(0).toString();
}

/**
* Query the port ID of the connected port on the first component.
* Query the port ID of the source port.
*
* @return ID of port on first child
*/
public String port1() {
return dataArray.get(1).toString();
public String sourcePort() {
return dataArray().get(1).toString();
}

/**
* Query the component ID of the second connected component.
* Query the component ID of the target component.
*
* @return ID of the second child
*/
public String child2() {
return dataArray.get(2).toString();
public String targetComponent() {
return dataArray().get(2).toString();
}

/**
* Query the port ID of the connected port on the second component.
* Query the port ID of the target port.
*
* @return ID of port on second child
*/
public String port2() {
return dataArray.get(3).toString();
public String targetPort() {
return dataArray().get(3).toString();
}

/**
* Access the Connection as the backing PArray data. The data consists of
* four values, {@code child1 port1 child2 port2}.
* <p>
* This is the same format included in the list returned from
* {@link ContainerProtocol#CONNECTIONS}.
* Create a connection reference. The child IDs must be valid according to
* {@link ComponentAddress#isValidID(java.lang.String)}. The port IDs must
* be valid according to {@link PortAddress#isValidID(java.lang.String)}.
*
* @return backing data array
* @param child1 ID of first child
* @param port1 ID of port on first child
* @param child2 ID of second child
* @param port2 ID of port on second child
* @return new connection
* @throws IllegalArgumentException if the IDs are not valid
*/
public PArray dataArray() {
return dataArray;
}

@Override
public String toString() {
return dataArray.toString();
}

@Override
public int hashCode() {
return dataArray.hashCode();
public static Connection of(String child1, String port1, String child2, String port2) {
return new Connection(PArray.of(
PString.of(child1), PString.of(port1),
PString.of(child2), PString.of(port2)
));
}

@Override
public boolean equals(Object obj) {
return obj == this || (obj instanceof Connection c && dataArray.equals(c.dataArray));
/**
* Coerce the provided value into a Connection if possible.
*
* @param value value of unknown type
* @return connection or empty optional
*/
public static Optional<Connection> from(Value value) {
if (value instanceof Connection connection) {
return Optional.of(connection);
} else {
try {
return PArray.from(value).map(Connection::new);
} catch (Exception ex) {
return Optional.empty();
}
}
}

private static void verifyChildID(String childID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ public final class ControlInfo extends PMap.MapBasedValue {
*/
public static final String KEY_EXPERT = "expert";

/**
* Optional map key to mark a control of type function as responding like a
* property. The control will always respond with a single output argument
* with the bound value. All input is optional. Input values may alter the
* bound value, by eg. merging or concatenating.
*/
public static final String KEY_BINDABLE = "bindable";

/**
* The types of a control.
*/
Expand Down
10 changes: 7 additions & 3 deletions praxiscore-api/src/main/java/org/praxislive/core/OrderedMap.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2023 Neil C Smith.
* Copyright 2024 Neil C Smith.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3 only, as
Expand All @@ -23,6 +23,7 @@

import java.util.List;
import java.util.Map;
import java.util.SequencedMap;
import java.util.stream.Stream;

/**
Expand All @@ -32,7 +33,7 @@
* @param <K> key type
* @param <V> value type
*/
public sealed interface OrderedMap<K, V> extends Map<K, V> permits OrderedMapImpl {
public sealed interface OrderedMap<K, V> extends SequencedMap<K, V> permits OrderedMapImpl {

/**
* A {@link List} containing the keys of this OrderedMap.
Expand All @@ -47,6 +48,9 @@ public sealed interface OrderedMap<K, V> extends Map<K, V> permits OrderedMapImp
*/
public List<K> keys();

@Override
public OrderedMap<K, V> reversed();

/**
* Compares the provided object with this map for equality in accordance
* with the specification of {@link Map#equals(java.lang.Object)}.
Expand Down Expand Up @@ -204,7 +208,7 @@ public static <K, V> OrderedMap<K, V> ofEntries(Map.Entry<? extends K, ? extends
* @return an ordered map copy of the provided map
*/
@SuppressWarnings({"rawtypes", "unchecked"})
public static <K, V> OrderedMap<K, V> copyOf(Map<K, V> map) {
public static <K, V> OrderedMap<K, V> copyOf(Map<? extends K, ? extends V> map) {
if (map instanceof OrderedMapImpl) {
return (OrderedMap<K, V>) map;
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright 2023 Neil C Smith.
* Copyright 2024 Neil C Smith.
*
* This code is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License version 3 only, as
Expand Down Expand Up @@ -48,11 +48,6 @@ public List<K> keys() {
return keys;
}

@Override
public void clear() {
map.clear();
}

@Override
public boolean containsKey(Object key) {
return map.containsKey(key);
Expand Down Expand Up @@ -116,18 +111,8 @@ public int size() {
}

@Override
public V put(K key, V value) {
throw new UnsupportedOperationException();
}

@Override
public void putAll(Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}

@Override
public V remove(Object key) {
throw new UnsupportedOperationException();
public OrderedMap<K, V> reversed() {
return new OrderedMapImpl<>(List.copyOf(keys.reversed()), map);
}

@Override
Expand Down Expand Up @@ -178,4 +163,24 @@ public String toString() {
.collect(Collectors.joining(", ", "{", "}"));
}

@Override
public void clear() {
throw new UnsupportedOperationException();
}

@Override
public V put(K key, V value) {
throw new UnsupportedOperationException();
}

@Override
public void putAll(Map<? extends K, ? extends V> m) {
throw new UnsupportedOperationException();
}

@Override
public V remove(Object key) {
throw new UnsupportedOperationException();
}

}
Loading

0 comments on commit 29cc682

Please sign in to comment.