Project

General

Profile

Utility Classes and Methods » History » Version 4

Sergey Smolov, 07/22/2016 03:15 PM

1 1 Sergey Smolov
h1. Utility Classes and Methods
2
3 2 Sergey Smolov
{{toc}}
4
5 1 Sergey Smolov
The HDL Retrascope project includes several classes for utility methods. It is supposed to use these methods for solving common small problems, like reading the file line by line, solving the constraint and so on.
6
This page contains a list of such method signatures with Javadoc headers sorted by classes.
7
8
h2. NodeUtils
9
10
Utility methods for operating with @ru.ispras.fortress.expression.Node@ class objects and it''s descendants.
11
12
<pre><code class="java">
13
  /**
14
   * Returns an equation {@code (nodes[0] == ... == nodes[n - 1])} expression
15
   * of the specified nodes.
16
   *
17
   * @param nodes Expressions to be combined.
18
   *
19
   * @return An equation of the specified nodes.
20
   *
21
   * @throws IllegalArgumentException when argument is either {@code null} or empty.
22
   */
23
  public static Node getEquation(final Node ... nodes)
24
</code></pre>
25
26
<pre><code class="java">
27
  /**
28 4 Sergey Smolov
   * Returns a conjunction of the specified nodes.
29
   * @param nodes Nodes for conjunction.
30
   * @return Conjunction of specified nodes.
31
   * @throws IllegalArgumentException when argument is {@code null}.
32
   */
33
  public static Node getConjunction(final Node ... nodes)
34
</code></pre>
35
36
<pre><code class="java">
37
  /**
38
   * Returns a conjunction of non-empty collection of nodes.
39
   * <p>Repeated nodes will not appear in the result.</p>
40
   * @param nodes Nodes for conjunction.
41
   * @return Conjunction of nodes that are in the specified collection.
42
   * @throws IllegalArgumentException when argument is {@code null}.
43
   * @throws IllegalArgumentException when argument is empty.
44
   */
45
  public static Node getConjunction(final Collection<Node> nodes)
46
</code></pre>
47
48
<pre><code class="java">
49
  /**
50
   * Returns a disjunction of non-empty collection of nodes.
51
   * @param nodes Nodes for disjunction.
52
   * @return Disjunction of nodes that are in the specified collection.
53
   * @throws IllegalArgumentException when argument is {@code null}.
54
   * @throws IllegalArgumentException when argument is empty.
55
   */
56
  public static Node getDisjunction(final Collection<Node> nodes)
57
</code></pre>
58
59
<pre><code class="java">
60
  /**
61 1 Sergey Smolov
   * Returns a collection of names for variables from the specified collection.
62
   *
63
   * @param nodes Collection of nodes.
64
   *
65
   * @return Collection of names for variable nodes from the specified collection.
66
   *
67
   * @throws IllegalArgumentException when argument is {@code null}.
68
   */
69
  public static Collection<String> getVariableNames(final Collection<? extends Node> nodes)
70
</code></pre>
71 4 Sergey Smolov
72 1 Sergey Smolov
<pre><code class="java">
73
/**
74
   * Casts the specified node to the specified data type.
75
   *
76
   * @param node Expression to be casted.
77
   * @param dataType Type to which the expression to be casted to.
78
   *
79
   * @return An expression which is equivalent to the specified node and has the specified type.
80
   *
81
   * @throws IllegalArgumentException when any of arguments is {@code null}.
82
   */
83
  public static Node castToDataType(final Node node, final DataType dataType)
84
</code></pre>
85
86 4 Sergey Smolov
<pre><code class="java">
87
  /**
88
   * Splits the specified node into two parts - one that depends exactly from the specified
89
   * variables and another that does not depend.
90
   * @param node Node to be split.
91
   * @param variables Variables dependence to which is a splitting criterion.
92
   * @return Two nodes that being united (with AND) form a node that is equal to the specified one.
93
   *         The first one depends exactly from the specified variables the second does not depend
94
   *         from all of them.
95
   */
96
  public static Pair<Node, Node> splitByVar(final Node node, final Collection<NodeVariable> variables)
97
</code></pre>
98
99
<pre><code class="java">
100
  /**
101
   * Splits conjunction node into non-conjunction nodes.
102
   * @param node Node to be split.
103
   * @return Collection of nodes that being united by AND operation (a conjunction)
104
   *         forms an expression that is equivalent to the specified one.
105
   */
106
  public static Collection<Node> splitConjunction(final Node node)
107
</code></pre>
108
109 1 Sergey Smolov
h2. ReadWriteUtils
110
111
Utility methods for reading from file, stream etc. and for writing to it.
112
113
<pre><code class="java">
114
/**
115
   * Returns reader for the specified stream object.
116
   * <p>Default charset is used for reading.</p>
117
   * @param stream Stream to be read.
118
   * @return Reader for the specified stream object.
119
   * @throws IllegalArgumentException when argument is {@code null}.
120
   */
121
  public static BufferedReader newBufferedReader(final InputStream stream)
122
</code></pre>
123
<pre><code class="java">
124
/**
125 3 Sergey Smolov
   * Returns reader for the specified path object.
126
   * <p>Default charset is used for reading.</p>
127
   * @param path Path from which data to be read.
128
   * @return Reader for the specified path object.
129
   * @throws IllegalArgumentException when argument is {@code null}.
130
   * @throws RetrascopeRuntimeException when I/O error occurred.
131
   */
132
  public static BufferedReader newBufferedReader(final Path path)
133
</code></pre>
134
<pre><code class="java">
135
/**
136 1 Sergey Smolov
   * Returns writer to the specified stream object.
137
   * <p>Default charset is used for writing.</p>
138
   * @param stream Stream to write to.
139
   * @return Writer to the specified stream object.
140
   * @throws IllegalArgumentException when argument is {@code null}.
141
   */
142
  public static BufferedWriter newBufferedWriter(final OutputStream stream)
143
</code></pre>
144
<pre><code class="java">
145
/**
146
   * Returns writer to the specified file object.
147
   * <p>Default charset is used for writing.</p>
148
   * @param file File to write to.
149
   * @return Writer to the specified file object.
150
   * @throws IllegalArgumentException when argument is {@code null}.
151
   * @throws RetrascopeRuntimeException when the specified file already contains data
152
   *         or when I/O error occurred.
153
   */
154
  public static BufferedWriter newBufferedWriter(final File file)
155
</code></pre>
156
<pre><code class="java">
157
/**
158
   * Returns writer to the specified path object.
159
   * @param path Path to write to.
160
   * @return Writer to the specified path object.
161
   * @throws IllegalArgumentException is {@code null}.
162
   * @throws RetrascopeRuntimeException when the specified file already exists
163
   *         or when an I/O error occurred.
164
   */
165
  public static BufferedWriter newBufferedWriter(final Path path)
166
</code></pre>
167
<pre><code class="java">
168
/**
169
   * Returns writer to the specified file object.
170
   * <p>Default charset is used for writing.</p>
171
   * @param file File to write to.
172
   * @return Writer to the specified file object.
173
   * @throws IllegalArgumentException when argument is {@code null}.
174
   */
175
  public static PrintWriter newPrintWriter(final File file)
176
</code></pre>
177
178
h2. SolverUtils
179
180
Utility methods for constraint and expression solving.
181
182
<pre><code class="java">
183
/**
184
   * Checks whether the specified expression is satisfiable.
185
   *
186
   * @param node Expression to be checked.
187
   * @return {@code true} if the expression is satisfiable or {@code false} otherwise.
188
   *
189
   */
190
  public static boolean isSat(final Node node)
191
</code></pre>
192
<pre><code class="java">
193
/**
194
   * Checks whether the specified logical expressions are compatible
195
   * {@code (getConjunction(nodes[0], ..., nodes[n-1]) is SAT)}.
196
   *
197
   * @param expressions Logical expressions to be checked.
198
   *
199
   * @return {@code true} if the specified expressions are compatible, {@code false} otherwise.
200
   */
201
  public static boolean areCompatible(final Node... expressions)
202
</code></pre>
203
<pre><code class="java">
204
/**
205
   * Checks whether the specified logical expressions are complete
206
   * {@code (!getComplement(nodes[0], ..., nodes[n-1]) is SAT)}.
207
   *
208
   * @param expressions Logical expressions to be checked.
209
   *
210
   * @return {@code true} if the specified expressions are complete, {@code false} otherwise.
211
   */
212
  public static boolean areComplete(final Node... expressions)
213
</code></pre>
214
<pre><code class="java">
215
/**
216
   * Solves the specified expression.
217
   *
218
   * @param node Expression to be solved.
219
   *
220
   * @return Result of solving.
221
   */
222
  public static SolverResult solve(final Node node)
223
</code></pre>
224
225
h2. TransformerUtils
226
227
Utility methods for transformation of expressions.
228
229
<pre><code class="java">
230
/**
231
   * Replace operations in expression with standard counterparts.
232
   * <p>Transforms nodes of the following kinds:
233
   * <ul>
234
   *   <li> EQ operation with more than 2 operands - to conjunction of 2-operand EQs;
235
   * </ul>
236
   * Wrapping method for {@code Transformer.standardize} method.
237
   * Uses it''s internal rules for additional replacements.</p>
238
   *
239
   * @see Transformer
240
   * @param node Expression to be transformed.
241
   * @return Expression with non-standard operations being replaced.
242
   */
243
  public static Node standardize(final Node node)
244
</code></pre>
245
246 4 Sergey Smolov
<pre><code class="java">
247
  /**
248
   * Reduces the specified expression and tries to convert it to the specified data type.
249
   * <p>It is recommended to use this method for non-variable-dependent expressions
250
   * containing constants and operators.</p>
251
   * @param node Expression to be simplified and converted to the specified type.
252
   * @param dataType Data type to which the specified node should be converted.
253
   * @return Expression that is a simplified form of the specified node and is converted
254
   *         to the specified type.
255
   */
256
  public static Node reduce(final Node node, final DataType dataType)
257
</code></pre>
258
259
h2. ModelTransformUtils
260 1 Sergey Smolov
261
Utility methods for models and model components transformation.
262
263
<pre><code class="java">
264
/**
265
   * Performs backward substitution on the specified nodes to the specified expression.
266
   *
267
   * <p>The substitution process moves in a backward direction (from last node of the list
268
   * to the first). The result is an expression where all the target variables that are
269
   * defined at least one {@link AssignmentContainer} node from the specified collection
270
   * will be substituted by the value expressions that are assigned to them.</p>
271
   *
272
   * @param blocks Blocks which should be used as a source of substitution.
273
   * @param node Expression to be transformed.
274
   *
275
   * @return Modified expression.
276
   */
277
  public static Node substituteBackward(
278
      final List<? extends AssignmentContainer> blocks,
279
      final Node node)
280
</code></pre>