diff options
author | Oleksandr Moliavko <o.moliavko@samsung.com> | 2019-10-09 13:39:11 +0300 |
---|---|---|
committer | Oleksandr Moliavko <o.moliavko@samsung.com> | 2019-10-15 14:05:44 +0300 |
commit | bcf93e74a01c1618455b675ae1613890a7d1718f (patch) | |
tree | f5db8c1c1642cc41a2891e562ad89bc38b6bc06a /bpmn/so-bpmn-building-blocks | |
parent | 9c55b74f92bf4d4f017504f917b0bce617a523c8 (diff) |
Removed unused SerializableChecker class; updated
imports in SerializationTest class
Issue-ID: SO-1841
Signed-off-by: Oleksandr Moliavko <o.moliavko@samsung.com>
Change-Id: Ifcbe5352bf5710a3527eeb394e516d3d864537db
Diffstat (limited to 'bpmn/so-bpmn-building-blocks')
-rw-r--r-- | bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java | 163 |
1 files changed, 0 insertions, 163 deletions
diff --git a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java b/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java deleted file mode 100644 index 47ddea1b4f..0000000000 --- a/bpmn/so-bpmn-building-blocks/src/test/java/org/onap/so/SerializableChecker.java +++ /dev/null @@ -1,163 +0,0 @@ -/*- - * ============LICENSE_START======================================================= - * ONAP - SO - * ================================================================================ - * Copyright (C) 2017 - 2018 AT&T Intellectual Property. All rights reserved. - * ================================================================================ - * 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. - * ============LICENSE_END========================================================= - */ - -package org.onap.so; - -import java.io.Serializable; -import java.lang.reflect.Field; -import java.lang.reflect.Modifier; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; - -public final class SerializableChecker { - public static class SerializationFailure { - private final String mContainingClass; - private final String mMemberName; - - public SerializationFailure(String inNonSerializableClass, String inMemberName) { - mContainingClass = inNonSerializableClass; - mMemberName = inMemberName; - } - - public String getContainingClass() { - return mContainingClass; - } - - public String getMemberName() { - return mMemberName; - } - - public String getBadMemberString() { - if (mMemberName == null) - return mContainingClass; - return mContainingClass + "." + mMemberName; - } - - @Override - public String toString() { - return "SerializationFailure [mNonSerializableClass=" + mContainingClass + ", mMemberName=" + mMemberName - + "]"; - } - } - - private static class SerializationCheckerData { - private Set<Class<?>> mSerializableClasses; - - SerializationCheckerData() { - mSerializableClasses = new HashSet<Class<?>>(); - } - - boolean isAlreadyChecked(Class<?> inClass) { - return mSerializableClasses.contains(inClass); - } - - void addSerializableClass(Class<?> inClass) { - mSerializableClasses.add(inClass); - } - } - - private SerializableChecker() {} - - public static SerializationFailure isFullySerializable(Class<?> inClass) { - if (!isSerializable(inClass)) - return new SerializationFailure(inClass.getName(), null); - - return isFullySerializable(inClass, new SerializationCheckerData()); - } - - private static SerializationFailure isFullySerializable(Class<?> inClass, - SerializationCheckerData inSerializationCheckerData) { - for (Field field : declaredFields(inClass)) { - Class<?> fieldDeclaringClass = field.getType(); - - if (field.getType() == Object.class) - continue; - - if (Modifier.isStatic(field.getModifiers())) - continue; - - if (field.isSynthetic()) - continue; - - if (fieldDeclaringClass.isInterface() || fieldDeclaringClass.isPrimitive()) - continue; - - if (Modifier.isAbstract(field.getType().getModifiers())) - continue; - - if (inSerializationCheckerData.isAlreadyChecked(fieldDeclaringClass)) - continue; - - if (isSerializable(fieldDeclaringClass)) { - inSerializationCheckerData.addSerializableClass(inClass); - - SerializationFailure failure = isFullySerializable(field.getType(), inSerializationCheckerData); - if (failure != null) - return failure; - else - continue; - } - - if (Modifier.isTransient(field.getModifiers())) - continue; - - return new SerializationFailure(field.getDeclaringClass().getName(), field.getName()); - } - return null; - } - - private static boolean isSerializable(Class<?> inClass) { - Set<Class<?>> interfaces = getInterfaces(inClass); - if (interfaces == null) - return false; - boolean isSerializable = interfaces.contains(Serializable.class); - if (isSerializable) - return true; - - for (Class<?> classInterface : interfaces) { - if (isSerializable(classInterface)) - return true; - } - - if (inClass.getSuperclass() != null && isSerializable(inClass.getSuperclass())) - return true; - - return false; - } - - private static Set<Class<?>> getInterfaces(Class<?> inFieldDeclaringClass) { - return new HashSet<Class<?>>(Arrays.asList(inFieldDeclaringClass.getInterfaces())); - } - - private static List<Field> declaredFields(Class<?> inClass) { - List<Field> fields = new ArrayList<Field>(Arrays.asList(inClass.getDeclaredFields())); - - Class<?> parentClasses = inClass.getSuperclass(); - - if (parentClasses == null) - return fields; - fields.addAll(declaredFields(parentClasses)); - - return fields; - } -} |