-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathBusRefIndex.java
More file actions
110 lines (96 loc) · 2.83 KB
/
BusRefIndex.java
File metadata and controls
110 lines (96 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
package com.powerdata.openpa;
/*
* Copyright (c) 2016, PowerData Corporation, Incremental Systems Corporation
* All rights reserved.
* Licensed under the BSD-3 Clause License.
* See full license at https://powerdata.github.io/openpa/LICENSE.md
*/
import com.powerdata.openpa.impl.BusRefIndexI;
/**
* Provide bus indexes from equipment lists.
*
* For use with applications that make use of indexes rather than objects
*
* Note that indexes are always based in the list derived from the model, either
* getBuses() or getSingleBus(), depending on how it is configured
*
* @author chris@powerdata.com
*
*/
public interface BusRefIndex
{
/**
* return the bus list used for this object, either PAModel.getBuses(), or
* getSingleBus(), depending on startup configuration
*/
BusList getBuses();
/**
* Get the list of bus indexes for the one-terminal device list
* @param t1list list of one-terminal devices
* @return array of bus indexes for each device
* @throws PAModelException
*/
int[] get1TBus(OneTermDevListIfc<? extends OneTermDev> t1list) throws PAModelException;
/**
* Return object for both bus indexes of a list of two-terminal devices
*
* @author chris@powerdata.com
*
*/
public static class TwoTerm
{
int[] _f, _t;
public TwoTerm(int[] f, int[] t)
{
_f = f;
_t = t;
}
public int[] getFromBus() {return _f;}
public int[] getToBus() {return _t;}
}
/**
* Get lists of bus indexes for two-terminal device list
* @param t2list list of two-terminal devices
* @return object containing from- and to- bus indexes for each device
* @throws PAModelException
*/
TwoTerm get2TBus(TwoTermDevListIfc<? extends TwoTermDev> t1list) throws PAModelException;
/**
* Convert a connectivity-based bus to this topology
* @param b the Connectivity-based bus
* @return toplology-based bus
* @throws PAModelException
*/
default Bus getByBus(Bus b) throws PAModelException
{
return getBuses().getByBus(b);
}
/**
* Function that takes a list and index, and return a Bus object
*
* @author chris@powerdata.com
*
* @param <T> A list that can return a bus for some reason
*/
@FunctionalInterface
interface BusFunction
{
Bus apply(int index) throws PAModelException;
}
/**
* Get list of bus indexes for any list that return a bus
* @param rlist List of objects with a function returning buses
* @param bfc
* @return
* @throws PAModelException
*/
public int[] mapBusFcn(BaseList<? extends BaseObject> list, BusFunction bfc) throws PAModelException;
public static BusRefIndex CreateFromConnectivityBuses(PALists m) throws PAModelException
{
return new BusRefIndexI(m.getBuses(), (l,b) -> b);
}
public static BusRefIndex CreateFromSingleBuses(PAModel m) throws PAModelException
{
return new BusRefIndexI(m.getSingleBus(), GroupListIfc::translateBusIndexes);
}
}