Symbols { public static Object valueOf(Symbol sym) { Arguments.checkNotNull(sym, "sym"); Identifier id = sym.asIdentifier(); if(id != null) { return id; } DoubleSymbol d = sym.asDouble(); if(d != null) { return d.getValue(); } IntegerSymbol i = sym.asInteger(); if(i != null) { return i.getValue(); } StringSymbol s = sym.asString(); if(s != null) { return s.toString(); } JavaSymbol js = sym.asJava(); if(js != null) { return js.getValue(); } throw new IllegalStateException("Unknown symbol type: " + sym.getClass()); } private  Symbols(); static int getSymbolType(Symbol sym); static Symbol create(SymbolFactory factory, Object value); static Object valueOf(Symbol sym); static List<Symbol> asList(SymbolFactory factory, Object... objects); static char getFirstLetter(Object attr); static Identifier parseIdentifier(SymbolFactory symbols, String idString); static Symbol readAttributeFromString(Agent agent, String s); static double asDouble(Symbol sym); static boolean equalByValue(Symbol s1, Symbol s2); static final int IDENTIFIER_SYMBOL_TYPE; static final int SYM_CONSTANT_SYMBOL_TYPE; static final int INT_CONSTANT_SYMBOL_TYPE; static final int FLOAT_CONSTANT_SYMBOL_TYPE; static final Object NEW_ID; }
@Test public void testValueOfIdentifierReturnsIdentifier() { final Identifier id = syms.createIdentifier('X'); assertSame(id, Symbols.valueOf(id)); }
@Test public void testValueOfInteger() { final IntegerSymbol s = syms.createInteger(42); assertEquals(42L, Symbols.valueOf(s)); }
@Test public void testValueOfDouble() { final DoubleSymbol s = syms.createDouble(3.14159); assertEquals(3.14159, (Double) Symbols.valueOf(s), 0.0001); }
@Test public void testValueOfString() { final StringSymbol s = syms.createString("testValueOfString"); assertEquals("testValueOfString", Symbols.valueOf(s)); }
@Test public void testValueOfNonNullJavaSymbol() { final File f = new File("testValueOfJavaSymbol"); final JavaSymbol s = syms.createJavaSymbol(f); assertSame(f, Symbols.valueOf(s)); }
@Test public void testValueOfNullJavaSymbol() { final JavaSymbol s = syms.createJavaSymbol(null); assertNull(Symbols.valueOf(s)); }