Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*
* Copyright 2021 Adaptive Financial Consulting Ltd.
*
* 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
*
* https://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.
*/
package uk.co.real_logic.artio.dictionary;
import org.agrona.collections.Int2ObjectHashMap;
import uk.co.real_logic.artio.dictionary.ir.BaseType;
import uk.co.real_logic.artio.dictionary.ir.Dictionary;
import uk.co.real_logic.artio.dictionary.ir.Field;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.PrintStream;
import java.util.*;
public class CodecCollisionFinder
{
private static final boolean PRINT_FIELD_TYPE_COLL = false;
private static final boolean PRINT_FIELD_TYPE_COLL_IF_FIXABLE = false;
// Same number, different name
private static final boolean PRINT_FIELD_NUMBER_COLL = false;
private static final boolean PRINT_ENUM_NON_ENUM_COLL = false;
private static final boolean PRINT_ENUM_VALUE_COLL = false;
private static final boolean PRINT_COMPONENT_GROUP_COLL = true;
private static PrintStream out;
public static void main(final String[] args) throws Exception
{
out = new PrintStream(new FileOutputStream("out.txt"));
final File dir = new File(args[0]);
final File[] dictionaryFiles = dir.listFiles((ignore, name) -> name.endsWith(".xml"));
final DictionaryParser parser = new DictionaryParser(true);
final Map fileToDictionary = new HashMap<>();
for (final File dictionaryXmlFile : dictionaryFiles)
{
out.println("Parsing " + dictionaryXmlFile.getName());
try (FileInputStream in = new FileInputStream(dictionaryXmlFile))
{
final Dictionary dictionary = parser.parse(in, null);
fileToDictionary.put(dictionaryXmlFile, dictionary);
}
}
out.println("Analyzing Dictionaries ... ");
findFieldCollisions(fileToDictionary);
findComponentGroupCollisions(fileToDictionary);
}
private static void findComponentGroupCollisions(final Map fileToDictionary)
{
if (!PRINT_COMPONENT_GROUP_COLL)
{
return;
}
final Set groupNames = new HashSet<>();
final Set messageNames = new HashSet<>();
final Set componentNames = new HashSet<>();
final Set fieldNames = new HashSet<>();
for (final Map.Entry pair : fileToDictionary.entrySet())
{
final Dictionary dictionary = pair.getValue();
dictionary.messages().forEach(msg ->
{
messageNames.add(msg.name());
msg.allGroupsIncludingComponents().forEach(group -> groupNames.add(group.name()));
});
fieldNames.addAll(dictionary.fields().keySet());
dictionary.components().values().forEach(msg -> componentNames.add(msg.name()));
}
out.println("Components & Groups: " + intersection(componentNames, groupNames));
out.println("Components & Messages: " + intersection(componentNames, messageNames));
out.println("Messages & Groups: " + intersection(messageNames, groupNames));
// Field names can clash with message names but not group or component names
out.println("Fields & Groups: " + intersection(fieldNames, groupNames));
out.println("Fields & Components: " + intersection(fieldNames, componentNames));
}
private static Set intersection(final Set left, final Set right)
{
final Set commonNames = new HashSet<>(left);
commonNames.retainAll(right);
return commonNames;
}
private static void findFieldCollisions(final Map fileToDictionary)
{
final Map allFields = new HashMap<>();
final Int2ObjectHashMap