private void initDictInfo(Dictionary<String> newDict, DictionaryInfo newDictInfo) { newDictInfo.setCardinality(newDict.getSize()); newDictInfo.setDictionaryObject(newDict); newDictInfo.setDictionaryClass(newDict.getClass().getName()); }
@Override public DictionaryInfo deserialize(DataInputStream in) throws IOException { String json = in.readUTF(); DictionaryInfo obj = JsonUtil.readValue(json, DictionaryInfo.class); if (infoOnly == false) { Dictionary<String> dict; try { dict = (Dictionary<String>) ClassUtil.forName(obj.getDictionaryClass(), Dictionary.class).getDeclaredConstructor().newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } dict.readFields(in); obj.setDictionaryObject(dict); } return obj; }
private static DictionaryInfo createDictInfo(String[] values) { MockDictionary mockDict = new MockDictionary(); mockDict.values = values; DictionaryInfo info = new DictionaryInfo(); info.setDictionaryObject(mockDict); return info; }
public DictionaryInfo trySaveNewDict(Dictionary<?> newDict, DictionaryInfo newDictInfo) throws IOException { String dupDict = checkDupByContent(newDictInfo, newDict); if (dupDict != null) { logger.info("Identical dictionary content " + newDict + ", reuse existing dictionary at " + dupDict); return getDictionaryInfo(dupDict); } newDictInfo.setDictionaryObject(newDict); newDictInfo.setDictionaryClass(newDict.getClass().getName()); save(newDictInfo); dictCache.put(newDictInfo.getResourcePath(), newDictInfo); return newDictInfo; }
@Override public DictionaryInfo deserialize(DataInputStream in) throws IOException { String json = in.readUTF(); DictionaryInfo obj = JsonUtil.readValue(json, DictionaryInfo.class); if (infoOnly == false) { Dictionary<?> dict; try { dict = (Dictionary<?>) ClassUtil.forName(obj.getDictionaryClass(), Dictionary.class).newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } dict.readFields(in); obj.setDictionaryObject(dict); } return obj; }
private void initDictInfo(Dictionary<String> newDict, DictionaryInfo newDictInfo) { newDictInfo.setCardinality(newDict.getSize()); newDictInfo.setDictionaryObject(newDict); newDictInfo.setDictionaryClass(newDict.getClass().getName()); }
@Override public DictionaryInfo deserialize(DataInputStream in) throws IOException { String json = in.readUTF(); DictionaryInfo obj = JsonUtil.readValue(json, DictionaryInfo.class); if (infoOnly == false) { Dictionary<?> dict; try { dict = (Dictionary<?>) ClassUtil.forName(obj.getDictionaryClass(), Dictionary.class).newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } dict.readFields(in); obj.setDictionaryObject(dict); } return obj; }
@Override public DictionaryInfo deserialize(DataInputStream in) throws IOException { String json = in.readUTF(); DictionaryInfo obj = JsonUtil.readValue(json, DictionaryInfo.class); if (infoOnly == false) { Dictionary<String> dict; try { dict = (Dictionary<String>) ClassUtil.forName(obj.getDictionaryClass(), Dictionary.class).getDeclaredConstructor().newInstance(); } catch (InstantiationException e) { throw new RuntimeException(e); } catch (IllegalAccessException e) { throw new RuntimeException(e); } catch (ClassNotFoundException e) { throw new RuntimeException(e); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } catch (InvocationTargetException e) { throw new RuntimeException(e); } dict.readFields(in); obj.setDictionaryObject(dict); } return obj; }
public DictionaryInfo trySaveNewDict(Dictionary<?> newDict, DictionaryInfo newDictInfo) throws IOException { String dupDict = checkDupByContent(newDictInfo, newDict); if (dupDict != null) { logger.info("Identical dictionary content " + newDict + ", reuse existing dictionary at " + dupDict); return getDictionaryInfo(dupDict); } newDictInfo.setCardinality(newDict.getSize()); newDictInfo.setDictionaryObject(newDict); newDictInfo.setDictionaryClass(newDict.getClass().getName()); save(newDictInfo); dictCache.put(newDictInfo.getResourcePath(), newDictInfo); return newDictInfo; }