@Override protected Class<?> delegateClass(int id) { final RegisteredDelegate<?> rd = id < delegates.size() ? delegates.get(id) : null; return rd == null ? null : rd.delegate.typeClass(); }
@Override protected Class<?> delegateClass(int id) { final RegisteredDelegate<?> rd = id < delegates.size() ? delegates.get(id) : null; return rd == null ? null : rd.delegate.typeClass(); }
/** * Registers a delegate. Returns true if registration is successful. */ public <T> boolean registerDelegate(Delegate<T> delegate) { return registerDelegate(delegate.typeClass().getName(), delegate); }
/** * Registers a delegate. Returns true if registration is successful. */ public <T> boolean registerDelegate(Delegate<T> delegate) { return registerDelegate(delegate.typeClass().getName(), delegate); }
/** * Register a {@link Delegate} and assign an id. * <p> * Delegate ids start at 1. */ @Override public <T> Registry registerDelegate(Delegate<T> delegate, int id) { if (id < 1) throw new IllegalArgumentException("delegate ids start at 1."); if (id >= strategy.delegates.size()) grow(strategy.delegates, id + 1); else if (strategy.delegates.get(id) != null) { throw new IllegalArgumentException("Duplicate id registration: " + id + " (" + delegate.typeClass() + ")"); } RegisteredDelegate<T> rd = new RegisteredDelegate<T>(id, delegate, strategy); strategy.delegates.set(id, rd); // just in case if (strategy.delegateMapping.put(delegate.typeClass(), rd) != null) throw new IllegalArgumentException("Duplicate registration for: " + delegate.typeClass()); return this; } }
/** * Register a {@link Delegate} and assign an id. * <p> * Delegate ids start at 1. */ @Override public <T> Registry registerDelegate(Delegate<T> delegate, int id) { if (id < 1) throw new IllegalArgumentException("delegate ids start at 1."); if (id >= strategy.delegates.size()) grow(strategy.delegates, id + 1); else if (strategy.delegates.get(id) != null) { throw new IllegalArgumentException("Duplicate id registration: " + id + " (" + delegate.typeClass() + ")"); } RegisteredDelegate<T> rd = new RegisteredDelegate<T>(id, delegate, strategy); strategy.delegates.set(id, rd); // just in case if (strategy.delegateMapping.put(delegate.typeClass(), rd) != null) throw new IllegalArgumentException("Duplicate registration for: " + delegate.typeClass()); return this; } }
@Override public Object readFrom(Input input, Object owner) throws IOException { if (ID_ARRAY_LEN != input.readFieldNumber(this)) throw new ProtostuffException("Corrupt input."); final int len = input.readInt32(); Object[] array = (Object[])Array.newInstance(delegate.typeClass(), len); if (input instanceof GraphInput) { // update the actual reference. ((GraphInput) input).updateLast(array, owner); } for (int i = 0; i < len;) { switch (input.readFieldNumber(this)) { case ID_ARRAY_DATA: array[i++] = delegate.readFrom(input); break; case ID_ARRAY_NULLCOUNT: i += input.readUInt32(); break; default: throw new ProtostuffException("Corrupt input."); } } if (0 != input.readFieldNumber(this)) throw new ProtostuffException("Corrupt input."); return array; }
@Override public Object readFrom(Input input, Object owner) throws IOException { if (ID_ARRAY_LEN != input.readFieldNumber(this)) throw new ProtostuffException("Corrupt input."); final int len = input.readInt32(); Object[] array = (Object[])Array.newInstance(delegate.typeClass(), len); if (input instanceof GraphInput) { // update the actual reference. ((GraphInput) input).updateLast(array, owner); } for (int i = 0; i < len;) { switch (input.readFieldNumber(this)) { case ID_ARRAY_DATA: array[i++] = delegate.readFrom(input); break; case ID_ARRAY_NULLCOUNT: i += input.readUInt32(); break; default: throw new ProtostuffException("Corrupt input."); } } if (0 != input.readFieldNumber(this)) throw new ProtostuffException("Corrupt input."); return array; }
@Override protected Class<?> delegateClass(int id) { final RegisteredDelegate<?> rd = id < delegates.size() ? delegates.get(id) : null; return rd == null ? null : rd.delegate.typeClass(); }
@Override protected Class<?> delegateClass(int id) { final RegisteredDelegate<?> rd = id < delegates.size() ? delegates.get(id) : null; return rd == null ? null : rd.delegate.typeClass(); }
/** * Register a {@link Delegate} and assign an id. * <p> * Delegate ids start at 1. */ @Override public <T> Registry registerDelegate(Delegate<T> delegate, int id) { if (id < 1) throw new IllegalArgumentException("delegate ids start at 1."); if (id >= strategy.delegates.size()) grow(strategy.delegates, id + 1); else if (strategy.delegates.get(id) != null) { throw new IllegalArgumentException("Duplicate id registration: " + id + " (" + delegate.typeClass() + ")"); } RegisteredDelegate<T> rd = new RegisteredDelegate<T>(id, delegate, strategy); strategy.delegates.set(id, rd); // just in case if (strategy.delegateMapping.put(delegate.typeClass(), rd) != null) throw new IllegalArgumentException("Duplicate registration for: " + delegate.typeClass()); return this; } }
/** * Register a {@link Delegate} and assign an id. * <p> * Delegate ids start at 1. */ @Override public <T> Registry registerDelegate(Delegate<T> delegate, int id) { if (id < 1) throw new IllegalArgumentException("delegate ids start at 1."); if (id >= strategy.delegates.size()) grow(strategy.delegates, id + 1); else if (strategy.delegates.get(id) != null) { throw new IllegalArgumentException("Duplicate id registration: " + id + " (" + delegate.typeClass() + ")"); } RegisteredDelegate<T> rd = new RegisteredDelegate<T>(id, delegate, strategy); strategy.delegates.set(id, rd); // just in case if (strategy.delegateMapping.put(delegate.typeClass(), rd) != null) throw new IllegalArgumentException("Duplicate registration for: " + delegate.typeClass()); return this; } }
/** * Registers a delegate. Returns true if registration is successful. */ public <T> boolean registerDelegate(Delegate<T> delegate) { String key = delegate.typeClass().getName(); HasDelegate<T> hasDelegate = new HasDelegate<>(delegate, this); if (!delegateMapping.containsKey(key)) { synchronized (delegateMappingLock) { if (delegateMapping.containsKey(key)) { return false; } FastMap<String, HasDelegate<?>> tmp = new FastMap<>(delegateMapping); tmp.put(key, hasDelegate); return true; } } return true; }