Project

General

Profile

Utility Classes and Methods » History » Version 1

Sergey Smolov, 05/12/2016 08:15 PM

1 1 Sergey Smolov
h1. Utility Classes and Methods
2
3
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.
4
This page contains a list of such method signatures with Javadoc headers sorted by classes.
5
6
h2. NodeUtils
7
8
Utility methods for operating with @ru.ispras.fortress.expression.Node@ class objects and it''s descendants.
9
10
<pre><code class="java">
11
  /**
12
   * Returns an equation {@code (nodes[0] == ... == nodes[n - 1])} expression
13
   * of the specified nodes.
14
   *
15
   * @param nodes Expressions to be combined.
16
   *
17
   * @return An equation of the specified nodes.
18
   *
19
   * @throws IllegalArgumentException when argument is either {@code null} or empty.
20
   */
21
  public static Node getEquation(final Node ... nodes)
22
</code></pre>
23
24
<pre><code class="java">
25
  /**
26
   * Returns a collection of names for variables from the specified collection.
27
   *
28
   * @param nodes Collection of nodes.
29
   *
30
   * @return Collection of names for variable nodes from the specified collection.
31
   *
32
   * @throws IllegalArgumentException when argument is {@code null}.
33
   */
34
  public static Collection<String> getVariableNames(final Collection<? extends Node> nodes)
35
</code></pre>
36
<pre><code class="java">
37
/**
38
   * Casts the specified node to the specified data type.
39
   *
40
   * @param node Expression to be casted.
41
   * @param dataType Type to which the expression to be casted to.
42
   *
43
   * @return An expression which is equivalent to the specified node and has the specified type.
44
   *
45
   * @throws IllegalArgumentException when any of arguments is {@code null}.
46
   */
47
  public static Node castToDataType(final Node node, final DataType dataType)
48
</code></pre>
49
50
h2. ReadWriteUtils
51
52
Utility methods for reading from file, stream etc. and for writing to it.
53
54
<pre><code class="java">
55
/**
56
   * Returns reader for the specified stream object.
57
   * <p>Default charset is used for reading.</p>
58
   * @param stream Stream to be read.
59
   * @return Reader for the specified stream object.
60
   * @throws IllegalArgumentException when argument is {@code null}.
61
   */
62
  public static BufferedReader newBufferedReader(final InputStream stream)
63
</code></pre>
64
<pre><code class="java">
65
/**
66
   * Returns writer to the specified stream object.
67
   * <p>Default charset is used for writing.</p>
68
   * @param stream Stream to write to.
69
   * @return Writer to the specified stream object.
70
   * @throws IllegalArgumentException when argument is {@code null}.
71
   */
72
  public static BufferedWriter newBufferedWriter(final OutputStream stream)
73
</code></pre>
74
<pre><code class="java">
75
/**
76
   * Returns writer to the specified file object.
77
   * <p>Default charset is used for writing.</p>
78
   * @param file File to write to.
79
   * @return Writer to the specified file object.
80
   * @throws IllegalArgumentException when argument is {@code null}.
81
   * @throws RetrascopeRuntimeException when the specified file already contains data
82
   *         or when I/O error occurred.
83
   */
84
  public static BufferedWriter newBufferedWriter(final File file)
85
</code></pre>
86
<pre><code class="java">
87
/**
88
   * Returns writer to the specified path object.
89
   * @param path Path to write to.
90
   * @return Writer to the specified path object.
91
   * @throws IllegalArgumentException is {@code null}.
92
   * @throws RetrascopeRuntimeException when the specified file already exists
93
   *         or when an I/O error occurred.
94
   */
95
  public static BufferedWriter newBufferedWriter(final Path path)
96
</code></pre>
97
<pre><code class="java">
98
/**
99
   * Returns writer to the specified file object.
100
   * <p>Default charset is used for writing.</p>
101
   * @param file File to write to.
102
   * @return Writer to the specified file object.
103
   * @throws IllegalArgumentException when argument is {@code null}.
104
   */
105
  public static PrintWriter newPrintWriter(final File file)
106
</code></pre>
107
108
h2. SolverUtils
109
110
Utility methods for constraint and expression solving.
111
112
<pre><code class="java">
113
/**
114
   * Checks whether the specified expression is satisfiable.
115
   *
116
   * @param node Expression to be checked.
117
   * @return {@code true} if the expression is satisfiable or {@code false} otherwise.
118
   *
119
   */
120
  public static boolean isSat(final Node node)
121
</code></pre>
122
<pre><code class="java">
123
/**
124
   * Checks whether the specified logical expressions are compatible
125
   * {@code (getConjunction(nodes[0], ..., nodes[n-1]) is SAT)}.
126
   *
127
   * @param expressions Logical expressions to be checked.
128
   *
129
   * @return {@code true} if the specified expressions are compatible, {@code false} otherwise.
130
   */
131
  public static boolean areCompatible(final Node... expressions)
132
</code></pre>
133
<pre><code class="java">
134
/**
135
   * Checks whether the specified logical expressions are complete
136
   * {@code (!getComplement(nodes[0], ..., nodes[n-1]) is SAT)}.
137
   *
138
   * @param expressions Logical expressions to be checked.
139
   *
140
   * @return {@code true} if the specified expressions are complete, {@code false} otherwise.
141
   */
142
  public static boolean areComplete(final Node... expressions)
143
</code></pre>
144
<pre><code class="java">
145
/**
146
   * Solves the specified expression.
147
   *
148
   * @param node Expression to be solved.
149
   *
150
   * @return Result of solving.
151
   */
152
  public static SolverResult solve(final Node node)
153
</code></pre>
154
155
h2. TransformerUtils
156
157
Utility methods for transformation of expressions.
158
159
<pre><code class="java">
160
/**
161
   * Replace operations in expression with standard counterparts.
162
   * <p>Transforms nodes of the following kinds:
163
   * <ul>
164
   *   <li> EQ operation with more than 2 operands - to conjunction of 2-operand EQs;
165
   * </ul>
166
   * Wrapping method for {@code Transformer.standardize} method.
167
   * Uses it''s internal rules for additional replacements.</p>
168
   *
169
   * @see Transformer
170
   * @param node Expression to be transformed.
171
   * @return Expression with non-standard operations being replaced.
172
   */
173
  public static Node standardize(final Node node)
174
</code></pre>
175
176
h2. TransformUtils
177
178
Utility methods for models and model components transformation.
179
180
<pre><code class="java">
181
/**
182
   * Performs backward substitution on the specified nodes to the specified expression.
183
   *
184
   * <p>The substitution process moves in a backward direction (from last node of the list
185
   * to the first). The result is an expression where all the target variables that are
186
   * defined at least one {@link AssignmentContainer} node from the specified collection
187
   * will be substituted by the value expressions that are assigned to them.</p>
188
   *
189
   * @param blocks Blocks which should be used as a source of substitution.
190
   * @param node Expression to be transformed.
191
   *
192
   * @return Modified expression.
193
   */
194
  public static Node substituteBackward(
195
      final List<? extends AssignmentContainer> blocks,
196
      final Node node)
197
</code></pre>