cleanup (Assert, nullable)

This commit is contained in:
Vladimir Krivosheev
2018-01-16 11:31:24 +01:00
parent 73a89bec29
commit de4069d0d7
3 changed files with 41 additions and 50 deletions
@@ -1,17 +1,5 @@
/*
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.openapi.util;
@@ -138,27 +126,29 @@ public class DefaultJDOMExternalizer {
}
@Nullable
static String filterXMLCharacters(String value) {
if (value != null) {
StringBuilder builder = null;
for (int i=0; i<value.length();i++) {
char c = value.charAt(i);
if (Verifier.isXMLCharacter(c)) {
if (builder != null) {
builder.append(c);
}
}
else {
if (builder == null) {
builder = new StringBuilder(value.length()+5);
builder.append(value, 0, i);
}
static String filterXMLCharacters(@Nullable String value) {
if (value == null) {
return null;
}
StringBuilder builder = null;
for (int i=0; i<value.length();i++) {
char c = value.charAt(i);
if (Verifier.isXMLCharacter(c)) {
if (builder != null) {
builder.append(c);
}
}
if (builder != null) {
value = builder.toString();
else {
if (builder == null) {
builder = new StringBuilder(value.length()+5);
builder.append(value, 0, i);
}
}
}
if (builder != null) {
value = builder.toString();
}
return value;
}
@@ -32,7 +32,7 @@ public class JDOMExternalizableStringList extends ArrayList<String> implements J
public JDOMExternalizableStringList() {
}
public JDOMExternalizableStringList(@NotNull Collection<? extends String> c) {
public JDOMExternalizableStringList(@NotNull Collection<String> c) {
super(c);
}
@@ -78,7 +78,7 @@ public class JDOMExternalizableStringList extends ArrayList<String> implements J
writeList(this, element);
}
public static void writeList(@NotNull List<String> strings, @NotNull Element element) {
private static void writeList(@NotNull List<String> strings, @NotNull Element element) {
int listSize = strings.size();
Element listElement = new Element(ATTR_LIST);
listElement.setAttribute(ATTR_LISTSIZE, Integer.toString(listSize));
@@ -1,20 +1,22 @@
/*
* Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
*/
package com.intellij.util.containers;
import junit.framework.Assert;
import static junit.framework.TestCase.assertEquals;
/**
* @author Sergey Simonchik
*/
public class ByteArrayQueueTest {
@org.junit.Test
public void testSingleAdd() {
ByteArrayQueue queue = new ByteArrayQueue(0);
byte value = 1;
queue.add(value);
Assert.assertEquals(1, queue.size());
Assert.assertEquals(value, queue.poll());
Assert.assertEquals(-1, queue.poll());
assertEquals(1, queue.size());
assertEquals(value, queue.poll());
assertEquals(-1, queue.poll());
}
@org.junit.Test
@@ -22,11 +24,11 @@ public class ByteArrayQueueTest {
ByteArrayQueue queue = new ByteArrayQueue(4);
byte[] buf = new byte[] {1, 2, 3, 4, 5};
queue.addAll(buf);
Assert.assertEquals(queue.size(), buf.length);
assertEquals(queue.size(), buf.length);
for (byte b : buf) {
Assert.assertEquals(b, queue.poll());
assertEquals(b, queue.poll());
}
Assert.assertEquals(-1, queue.poll());
assertEquals(-1, queue.poll());
}
@org.junit.Test
@@ -34,24 +36,23 @@ public class ByteArrayQueueTest {
ByteArrayQueue queue = new ByteArrayQueue(4);
byte[] buf = new byte[] {1, 2, 3, 4, 5, 6, 7, 8};
queue.addAll(buf);
Assert.assertEquals(queue.size(), buf.length);
Assert.assertEquals(buf[0], queue.poll());
Assert.assertEquals(buf[1], queue.poll());
assertEquals(queue.size(), buf.length);
assertEquals(buf[0], queue.poll());
assertEquals(buf[1], queue.poll());
byte v = 9;
queue.add(v);
queue.add(v);
queue.addAll(buf); // array resize with myHead > myTail
Assert.assertEquals(queue.size(), buf.length * 2);
assertEquals(queue.size(), buf.length * 2);
for (int i = 2; i < buf.length; i++) {
Assert.assertEquals(buf[i], queue.poll());
assertEquals(buf[i], queue.poll());
}
Assert.assertEquals(v, queue.poll());
Assert.assertEquals(v, queue.poll());
assertEquals(v, queue.poll());
assertEquals(v, queue.poll());
for (byte b : buf) {
Assert.assertEquals(b, queue.poll());
assertEquals(b, queue.poll());
}
Assert.assertEquals(-1, queue.poll());
assertEquals(-1, queue.poll());
}
}