Kirk Rader  1.0-SNAPSHOT
Variable.java
Go to the documentation of this file.
1 /*
2  * Copyright 2016 Kirk Rader
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package us.rader.tt.formula;
18 
19 import java.io.PrintStream;
20 import java.util.HashSet;
21 import java.util.Set;
22 
23 /**
24  * A variable (lower-case alphabetic character) of the monadic predicate
25  * calculus.
26  */
27 public final class Variable extends Expression {
28 
29  /**
30  * The lower-case letter.
31  */
32  private final String symbol;
33 
34  /**
35  * @param symbol
36  * The symbolic representation of this {@link Variable}
37  */
38  public Variable(final String symbol) {
39 
40  this.symbol = symbol;
41 
42  }
43 
44  /**
45  * @see Expression#getNodes
46  */
47  @Override
48  public Set<Expression> getNodes() {
49 
50  return new HashSet<>();
51 
52  }
53 
54  /**
55  * @see Expression#getTerminalNodes
56  */
57  @Override
58  public Set<Expression> getTerminalNodes() {
59 
60  return new HashSet<>();
61 
62  }
63 
64  /**
65  * @see Graphable#printDigraph
66  */
67  @Override
68  public void printDigraph(final PrintStream stream, final int indent) {
69 
70  printIndentation(stream, indent);
71  stream.print(nodeName);
72  stream.print(" [ label=\"");
73  stream.print(symbol);
74  stream.println("\" ]");
75 
76  }
77 
78  /**
79  * @see Expression#replaceVariable
80  */
81  @Override
82  public Expression replaceVariable(final Variable boundVariable, final Expression factor) {
83 
84  if (equals(boundVariable)) {
85 
86  return factor;
87 
88  }
89 
90  return this;
91 
92  }
93 
94  /**
95  * @see Expression#toLaTeX
96  */
97  @Override
98  public void toLaTeX(final PrintStream stream) {
99 
100  stream.print(symbol);
101 
102  }
103 
104  /**
105  * @return The symbolic representation of this {@link Variable}
106  */
107  @Override
108  public String toString() {
109 
110  return symbol;
111 
112  }
113 }
final String symbol
The lower-case letter.
Definition: Variable.java:32
String nodeName
Graphviz digraph node name.
Definition: Expression.java:90
void toLaTeX(final PrintStream stream)
Definition: Variable.java:98
Expression replaceVariable(final Variable boundVariable, final Expression factor)
Definition: Variable.java:82
A variable (lower-case alphabetic character) of the monadic predicate calculus.
Definition: Variable.java:27
final boolean equals(final Object obj)
Base equality on the string representation of a formula.
void printDigraph(final PrintStream stream, final int indent)
Definition: Variable.java:68
Objects with unique Graphviz node names.
Definition: Expression.java:32
Set< Expression > getNodes()
Definition: Variable.java:48
Set< Expression > getTerminalNodes()
Definition: Variable.java:58
Variable(final String symbol)
Definition: Variable.java:38
static void printIndentation(final PrintStream stream, final int indent)
Print the specified number of spaces to the given stream.