Mercurial Hosting > luan
view src/luan/LuanImmutabler.java @ 1576:13135e289b50
domain change
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Thu, 28 Jan 2021 20:47:39 -0700 |
parents | e1a13e707bf3 |
children |
line wrap: on
line source
package luan; import java.util.Map; import java.util.Set; import java.util.Collection; import java.util.Collections; import java.util.IdentityHashMap; public final class LuanImmutabler { private final Set handled = Collections.newSetFromMap(new IdentityHashMap()); private Luan luan = null; public void makeImmutable(LuanCloneable obj) throws LuanException { if( obj==null || !handled.add(obj) ) return; if( obj instanceof Luan ) { if( luan != null ) throw new RuntimeException("2 luans in "+this+" - "+luan+" "+obj); luan = (Luan)obj; } obj.makeImmutable(this); } public void makeImmutable(Object[] obj) throws LuanException { if( obj==null || !handled.add(obj) ) return; for( Object entry : obj ) { makeImmutable(entry); } } public void makeImmutable(Map obj) throws LuanException { if( obj==null || !handled.add(obj) ) return; for( Object stupid : obj.entrySet() ) { Map.Entry entry = (Map.Entry)stupid; makeImmutable(entry.getKey()); makeImmutable(entry.getValue()); } } public void makeImmutable(Collection obj) throws LuanException { if( obj==null || !handled.add(obj) ) return; for( Object entry : (Collection)obj ) { makeImmutable(entry); } } public void makeImmutable(Object obj) throws LuanException { if( obj instanceof LuanCloneable ) makeImmutable((LuanCloneable)obj); else if( obj instanceof Object[] ) makeImmutable((Object[])obj); else if( obj instanceof Map ) makeImmutable((Map)obj); else if( obj instanceof Collection ) makeImmutable((Collection)obj); } }