TermNode.java

Go to the documentation of this file.
00001 package com.graphbuilder.math;
00002 
00006 public abstract class TermNode extends Expression {
00007 
00008     protected String name = null;
00009     protected boolean negate = false;
00010 
00011     public TermNode(String name, boolean negate) {
00012         setName(name);
00013         setNegate(negate);
00014     }
00015 
00019     public boolean getNegate() {
00020         return negate;
00021     }
00022 
00023     public void setNegate(boolean b) {
00024         negate = b;
00025     }
00026 
00030     public String getName() {
00031         return name;
00032     }
00033 
00040     public void setName(String s) {
00041         if (s == null)
00042             throw new IllegalArgumentException("name cannot be null");
00043 
00044         if (!isValidName(s))
00045             throw new IllegalArgumentException("invalid name: " + s);
00046 
00047         name = s;
00048     }
00049 
00050     private static boolean isValidName(String s) {
00051         if (s.length() == 0) return false;
00052 
00053         char c = s.charAt(0);
00054 
00055         if (c >= '0' && c <= '9' || c == '.' || c == ',' || c == '(' || c == ')' || c == '^' || c == '*' || c == '/' || c == '+' || c == '-' || c == ' ' || c == '\t' || c == '\n')
00056             return false;
00057 
00058         for (int i = 1; i < s.length(); i++) {
00059             c = s.charAt(i);
00060 
00061             if (c == ',' || c == '(' || c == ')' || c == '^' || c == '*' || c == '/' || c == '+' || c == '-' || c == ' ' || c == '\t' || c == '\n')
00062                 return false;
00063         }
00064 
00065         return true;
00066     }
00067 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1