Skip to content

Commit ffa1df2

Browse files
rvandoosselaerstephengold
authored andcommitted
returns unmodifiable sets (#1071)
* returns an unmodifiable set when retrieving the available animation names and available animation clips instead of an unmodifiable collection. fixes: #1070 * remove unnecessary set wrapper.
1 parent 9c1452b commit ffa1df2

2 files changed

Lines changed: 93 additions & 5 deletions

File tree

jme3-core/src/main/java/com/jme3/anim/AnimComposer.java

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,10 @@
33
import com.jme3.anim.tween.Tween;
44
import com.jme3.anim.tween.Tweens;
55
import com.jme3.anim.tween.action.*;
6-
import com.jme3.export.*;
6+
import com.jme3.export.InputCapsule;
7+
import com.jme3.export.JmeExporter;
8+
import com.jme3.export.JmeImporter;
9+
import com.jme3.export.OutputCapsule;
710
import com.jme3.renderer.RenderManager;
811
import com.jme3.renderer.ViewPort;
912
import com.jme3.scene.control.AbstractControl;
@@ -206,12 +209,25 @@ public void reset() {
206209
}
207210
}
208211

209-
public Collection<AnimClip> getAnimClips() {
210-
return Collections.unmodifiableCollection(animClipMap.values());
212+
/**
213+
* Returns an unmodifiable set of all available animations. When an attempt
214+
* is made to modify the set, an UnsupportedOperationException is thrown.
215+
*
216+
* @return the unmodifiable set of animations
217+
*/
218+
public Set<AnimClip> getAnimClips() {
219+
return Collections.unmodifiableSet(new HashSet<>(animClipMap.values()));
211220
}
212221

213-
public Collection<String> getAnimClipsNames() {
214-
return Collections.unmodifiableCollection(animClipMap.keySet());
222+
/**
223+
* Returns an unmodifiable set of all available animation names. When an
224+
* attempt is made to modify the set, an UnsupportedOperationException is
225+
* thrown.
226+
*
227+
* @return the unmodifiable set of animation names.
228+
*/
229+
public Set<String> getAnimClipsNames() {
230+
return Collections.unmodifiableSet(animClipMap.keySet());
215231
}
216232

217233
@Override
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2009-2019 jMonkeyEngine
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions are
7+
* met:
8+
*
9+
* * Redistributions of source code must retain the above copyright
10+
* notice, this list of conditions and the following disclaimer.
11+
*
12+
* * Redistributions in binary form must reproduce the above copyright
13+
* notice, this list of conditions and the following disclaimer in the
14+
* documentation and/or other materials provided with the distribution.
15+
*
16+
* * Neither the name of 'jMonkeyEngine' nor the names of its contributors
17+
* may be used to endorse or promote products derived from this software
18+
* without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22+
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23+
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
24+
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25+
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26+
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27+
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28+
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29+
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30+
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
*/
32+
package com.jme3.anim;
33+
34+
import org.junit.Assert;
35+
import org.junit.Test;
36+
37+
/**
38+
* @author Remy Van Doosselaer
39+
*/
40+
public class AnimComposerTest {
41+
42+
@Test
43+
public void testGetAnimClips() {
44+
AnimComposer composer = new AnimComposer();
45+
46+
Assert.assertNotNull(composer.getAnimClips());
47+
Assert.assertEquals(0, composer.getAnimClips().size());
48+
}
49+
50+
@Test
51+
public void testGetAnimClipsNames() {
52+
AnimComposer composer = new AnimComposer();
53+
54+
Assert.assertNotNull(composer.getAnimClipsNames());
55+
Assert.assertEquals(0, composer.getAnimClipsNames().size());
56+
}
57+
58+
@Test(expected = UnsupportedOperationException.class)
59+
public void testGetAnimClipsIsNotModifiable() {
60+
AnimComposer composer = new AnimComposer();
61+
62+
composer.getAnimClips().add(new AnimClip("test"));
63+
}
64+
65+
@Test(expected = UnsupportedOperationException.class)
66+
public void testGetAnimClipsNamesIsNotModifiable() {
67+
AnimComposer composer = new AnimComposer();
68+
69+
composer.getAnimClipsNames().add("test");
70+
}
71+
72+
}

0 commit comments

Comments
 (0)