public void write (Kryo kryo, Output output, IdentityMap map) { int length = map.size; output.writeVarInt(length, true); output.writeBoolean(false); // whether type is written (in case future version of IdentityMap supports type awareness) Serializer keySerializer = null; if (keyGenericType != null) { if (keySerializer == null) keySerializer = kryo.getSerializer(keyGenericType); keyGenericType = null; } Serializer valueSerializer = null; if (valueGenericType != null) { if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueGenericType); valueGenericType = null; } for (Iterator iter = map.iterator(); iter.hasNext();) { IdentityMap.Entry entry = (IdentityMap.Entry)iter.next(); if (keySerializer != null) { kryo.writeObject(output, entry.key, keySerializer); } else kryo.writeClassAndObject(output, entry.key); if (valueSerializer != null) { kryo.writeObjectOrNull(output, entry.value, valueSerializer); } else kryo.writeClassAndObject(output, entry.value); } }
public IdentityMap read (Kryo kryo, Input input, Class<IdentityMap> type) { int length = input.readVarInt(true); input.readBoolean(); // currently unused IdentityMap map = new IdentityMap(length); Class keyClass = null; Class valueClass = null; Serializer keySerializer = null; if (keyGenericType != null) { keyClass = keyGenericType; if (keySerializer == null) keySerializer = kryo.getSerializer(keyClass); keyGenericType = null; } Serializer valueSerializer = null; if (valueGenericType != null) { valueClass = valueGenericType; if (valueSerializer == null) valueSerializer = kryo.getSerializer(valueClass); valueGenericType = null; } kryo.reference(map); for (int i = 0; i < length; i++) { Object key; if (keySerializer != null) { key = kryo.readObject(input, keyClass, keySerializer); } else key = kryo.readClassAndObject(input); Object value; if (valueSerializer != null) { value = kryo.readObjectOrNull(input, valueClass, valueSerializer); } else value = kryo.readClassAndObject(input); map.put(key, value); } return map; }
/** @param keyAndValues pairs of keys and values. Each value has to be proceeded by a key. * @return a new identity map with the given values. Not fail-fast - be careful when passing arguments, or it might * result in unexpected map values. */ @SuppressWarnings("unchecked") public static <Key, Value> IdentityMap<Key, Value> newIdentityMap(final Object... keyAndValues) { if (keyAndValues.length % 2 != 0) { throw new IllegalArgumentException("Total number of keys and values has to be even."); } final IdentityMap<Key, Value> map = new IdentityMap<Key, Value>(); for (int pairIndex = 0; pairIndex < keyAndValues.length; pairIndex++) { map.put((Key) keyAndValues[pairIndex], (Value) keyAndValues[++pairIndex]); } return map; }
/** @param keyAndValues pairs of keys and values. Each value has to be proceeded by a key. * @return a new identity map with the given values. Not fail-fast - be careful when passing arguments, or it might * result in unexpected map values. * @param <Key> type of map keys. * @param <Value> type of map values. */ @SuppressWarnings("unchecked") public static <Key, Value> IdentityMap<Key, Value> newIdentityMap(final Object... keyAndValues) { if (keyAndValues.length % 2 != 0) { throw new IllegalArgumentException("Total number of keys and values has to be even."); } final IdentityMap<Key, Value> map = new IdentityMap<Key, Value>(); for (int pairIndex = 0; pairIndex < keyAndValues.length; pairIndex++) { map.put((Key) keyAndValues[pairIndex], (Value) keyAndValues[++pairIndex]); } return map; }
/** Registers {@link GraphHeader} and all of the LibGDX classes supported by GdxToKryo with serializers. * <p> * This registration method must not be used if backward compatibility is necessary for future versions of LibGDX, * because it will make it impossible to guarantee the same registration IDs when this library is updated. * @param kryo */ public static void registerAll (Kryo kryo){ kryo.register(Object.class); // Required because of use for backing arrays in some classes. kryo.register(GraphHeader.class); kryo.register(Color.class, new ColorSerializer()); kryo.register(OrthographicCamera.class, new OrthographicCameraSerializer()); kryo.register(PerspectiveCamera.class, new PerspectiveCameraSerializer()); kryo.register(Pixmap.class, new PixmapSerializer()); kryo.register(Affine2.class, new Affine2Serializer()); kryo.register(Bezier.class, new BezierSerializer()); kryo.register(BSpline.class, new BSplineSerializer()); kryo.register(CatmullRomSpline.class, new CatmullRomSplineSerializer()); kryo.register(Circle.class, new CircleSerializer()); kryo.register(Ellipse.class, new EllipseSerializer()); kryo.register(FloatCounter.class, new FloatCounterSerializer()); kryo.register(GridPoint2.class, new GridPoint2Serializer()); kryo.register(GridPoint3.class, new GridPoint3Serializer()); kryo.register(Matrix3.class, new Matrix3Serializer()); kryo.register(Matrix4.class, new Matrix4Serializer()); kryo.register(Plane.class, new PlaneSerializer()); kryo.register(Polygon.class, new PolygonSerializer()); kryo.register(Polyline.class, new PolylineSerializer()); kryo.register(Quaternion.class, new QuaternionSerializer()); kryo.register(RandomXS128.class, new RandomXS128Serializer()); kryo.register(Rectangle.class, new RectangleSerializer()); kryo.register(Vector2.class, new Vector2Serializer()); kryo.register(Vector3.class, new Vector3Serializer()); kryo.register(WindowedMean.class, new WindowedMeanSerializer()); kryo.register(BoundingBox.class, new BoundingBoxSerializer()); kryo.register(Ray.class, new RaySerializer()); kryo.register(Segment.class, new SegmentSerializer()); kryo.register(Sphere.class, new SphereSerializer()); kryo.register(ArrayMap.class, new ArrayMapSerializer()); kryo.register(Array.class, new ArraySerializer()); kryo.register(Bits.class, new BitsSerializer()); kryo.register(BooleanArray.class, new BooleanArraySerializer()); kryo.register(ByteArray.class, new ByteArraySerializer()); kryo.register(CharArray.class, new CharArraySerializer()); kryo.register(DelayedRemovalArray.class, new DelayedRemovalArraySerializer()); kryo.register(FloatArray.class, new FloatArraySerializer()); kryo.register(IdentityMap.class, new IdentityMapSerializer()); kryo.register(IntArray.class, new IntArraySerializer()); kryo.register(IntFloatMap.class, new IntFloatMapSerializer()); kryo.register(IntIntMap.class, new IntIntMapSerializer()); kryo.register(IntMap.class, new IntMapSerializer()); kryo.register(IntSet.class, new IntSetSerializer()); kryo.register(LongArray.class, new LongArraySerializer()); kryo.register(LongMap.class, new LongMapSerializer()); kryo.register(ObjectFloatMap.class, new ObjectFloatMapSerializer()); kryo.register(ObjectIntMap.class, new ObjectIntMapSerializer()); kryo.register(ObjectMap.class, new ObjectMapSerializer()); kryo.register(ObjectSet.class, new ObjectSetSerializer()); kryo.register(OrderedMap.class, new OrderedMapSerializer()); kryo.register(OrderedSet.class, new OrderedSetSerializer()); kryo.register(Queue.class, new QueueSerializer()); kryo.register(ShortArray.class, new ShortArraySerializer()); kryo.register(SnapshotArray.class, new SnapshotArraySerializer()); kryo.register(SortedIntList.class, new SortedIntListSerializer()); kryo.register(StringBuilder.class, new StringBuilderSerializer()); }
/** Registers {@link GraphHeader} and all of the LibGDX classes supported by GdxToKryo with serializers, starting at * the given ID and incrementing up from there. Currently, 57 classes are registered, including {@link Object}. * <p> * If backward compatibility is desired, it is recommended to reserve a block of unused registration IDs to support * future classes/serializers that GdxToKryo will support, perhaps <code>(startingID + 100)</code>. Alternatively, * {@link #registerGroup(Kryo, int)} can be used to register the classes without the need for reserving IDs. * @param kryo * @param startingID */ public static void registerAll (Kryo kryo, int startingID){ int i = startingID; kryo.register(Object.class, i++); // Required because of use for backing arrays in some classes. kryo.register(GraphHeader.class, i++); kryo.register(Color.class, new ColorSerializer(), i++); kryo.register(OrthographicCamera.class, new OrthographicCameraSerializer(), i++); kryo.register(PerspectiveCamera.class, new PerspectiveCameraSerializer(), i++); kryo.register(Pixmap.class, new PixmapSerializer(), i++); kryo.register(Affine2.class, new Affine2Serializer(), i++); kryo.register(Bezier.class, new BezierSerializer(), i++); kryo.register(BSpline.class, new BSplineSerializer(), i++); kryo.register(CatmullRomSpline.class, new CatmullRomSplineSerializer(), i++); kryo.register(Circle.class, new CircleSerializer(), i++); kryo.register(Ellipse.class, new EllipseSerializer(), i++); kryo.register(FloatCounter.class, new FloatCounterSerializer(), i++); kryo.register(GridPoint2.class, new GridPoint2Serializer(), i++); kryo.register(GridPoint3.class, new GridPoint3Serializer(), i++); kryo.register(Matrix3.class, new Matrix3Serializer(), i++); kryo.register(Matrix4.class, new Matrix4Serializer(), i++); kryo.register(Plane.class, new PlaneSerializer(), i++); kryo.register(Polygon.class, new PolygonSerializer(), i++); kryo.register(Polyline.class, new PolylineSerializer(), i++); kryo.register(Quaternion.class, new QuaternionSerializer(), i++); kryo.register(RandomXS128.class, new RandomXS128Serializer(), i++); kryo.register(Rectangle.class, new RectangleSerializer(), i++); kryo.register(Vector2.class, new Vector2Serializer(), i++); kryo.register(Vector3.class, new Vector3Serializer(), i++); kryo.register(WindowedMean.class, new WindowedMeanSerializer(), i++); kryo.register(BoundingBox.class, new BoundingBoxSerializer(), i++); kryo.register(Ray.class, new RaySerializer(), i++); kryo.register(Segment.class, new SegmentSerializer(), i++); kryo.register(Sphere.class, new SphereSerializer(), i++); kryo.register(ArrayMap.class, new ArrayMapSerializer(), i++); kryo.register(Array.class, new ArraySerializer(), i++); kryo.register(Bits.class, new BitsSerializer(), i++); kryo.register(BooleanArray.class, new BooleanArraySerializer(), i++); kryo.register(ByteArray.class, new ByteArraySerializer(), i++); kryo.register(CharArray.class, new CharArraySerializer(), i++); kryo.register(DelayedRemovalArray.class, new DelayedRemovalArraySerializer(), i++); kryo.register(FloatArray.class, new FloatArraySerializer(), i++); kryo.register(IdentityMap.class, new IdentityMapSerializer(), i++); kryo.register(IntArray.class, new IntArraySerializer(), i++); kryo.register(IntFloatMap.class, new IntFloatMapSerializer(), i++); kryo.register(IntIntMap.class, new IntIntMapSerializer(), i++); kryo.register(IntMap.class, new IntMapSerializer(), i++); kryo.register(IntSet.class, new IntSetSerializer(), i++); kryo.register(LongArray.class, new LongArraySerializer(), i++); kryo.register(LongMap.class, new LongMapSerializer(), i++); kryo.register(ObjectFloatMap.class, new ObjectFloatMapSerializer(), i++); kryo.register(ObjectIntMap.class, new ObjectIntMapSerializer(), i++); kryo.register(ObjectMap.class, new ObjectMapSerializer(), i++); kryo.register(ObjectSet.class, new ObjectSetSerializer(), i++); kryo.register(OrderedMap.class, new OrderedMapSerializer(), i++); kryo.register(OrderedSet.class, new OrderedSetSerializer(), i++); kryo.register(Queue.class, new QueueSerializer(), i++); kryo.register(ShortArray.class, new ShortArraySerializer(), i++); kryo.register(SnapshotArray.class, new SnapshotArraySerializer(), i++); kryo.register(SortedIntList.class, new SortedIntListSerializer(), i++); kryo.register(StringBuilder.class, new StringBuilderSerializer(), i++); }
/** @return an empty, new identity map. */ public static <Key, Value> IdentityMap<Key, Value> newIdentityMap() { return new IdentityMap<Key, Value>(); }
/** @return a new identity map with the passed values. */ public static <Key, Value> IdentityMap<Key, Value> newIdentityMap( final IdentityMap<? extends Key, ? extends Value> map) { return new IdentityMap<Key, Value>(map); }
/** @return an empty, new identity map. * @param <Key> type of map keys. * @param <Value> type of map values. */ public static <Key, Value> IdentityMap<Key, Value> newIdentityMap() { return new IdentityMap<Key, Value>(); }
/** @param map will be copied. * @return a new identity map with the passed values. * @param <Key> type of map keys. * @param <Value> type of map values. */ public static <Key, Value> IdentityMap<Key, Value> newIdentityMap( final IdentityMap<? extends Key, ? extends Value> map) { return new IdentityMap<Key, Value>(map); }
/** @return direct reference to component providers. */ protected IdentityMap<Class<?>, Provider<?>> getComponentProviders() { return context; }
public TabbedPane (TabbedPaneStyle style, Sizes sizes) { this.style = style; this.sizes = sizes; listeners = new Array<TabbedPaneListener>(); sharedCloseActiveButtonStyle = VisUI.getSkin().get("close-active-tab", VisImageButtonStyle.class); group = new ButtonGroup<Button>(); mainTable = new TabbedPaneTable(this); tabsPane = new DragPane(style.vertical ? new VerticalFlowGroup() : new HorizontalFlowGroup()); configureDragPane(style); mainTable.setBackground(style.background); tabs = new Array<Tab>(); tabsButtonMap = new IdentityMap<Tab, TabButtonTable>(); Cell<DragPane> tabsPaneCell = mainTable.add(tabsPane); Cell<Image> separatorCell = null; if (style.vertical) { tabsPaneCell.top().growY().minSize(0, 0); } else { tabsPaneCell.left().growX().minSize(0, 0); } //note: if separatorBar height/width is not set explicitly it may sometimes disappear if (style.separatorBar != null) { if (style.vertical) { separatorCell = mainTable.add(new Image(style.separatorBar)).growY().width(style.separatorBar.getMinWidth()); } else { mainTable.row(); separatorCell = mainTable.add(new Image(style.separatorBar)).growX().height(style.separatorBar.getMinHeight()); } } else { //make sure that tab will fill available space even when there is no separatorBar image set if (style.vertical) { mainTable.add().growY(); } else { mainTable.add().growX(); } } mainTable.setPaneCells(tabsPaneCell, separatorCell); }